| 241 | } |
| 242 | |
| 243 | void GetRequestable(int peer) |
| 244 | { |
| 245 | // Implement using naive structure: |
| 246 | |
| 247 | //! list of (sequence number, txhash, is_wtxid) tuples. |
| 248 | std::vector<std::tuple<uint64_t, int, bool>> result; |
| 249 | std::vector<std::pair<NodeId, GenTxid>> expected_expired; |
| 250 | for (int txhash = 0; txhash < MAX_TXHASHES; ++txhash) { |
| 251 | // Mark any expired REQUESTED announcements as COMPLETED. |
| 252 | for (int peer2 = 0; peer2 < MAX_PEERS; ++peer2) { |
| 253 | Announcement& ann2 = m_announcements[txhash][peer2]; |
| 254 | if (ann2.m_state == State::REQUESTED && ann2.m_time <= m_now) { |
| 255 | expected_expired.emplace_back(peer2, ann2.m_is_wtxid ? GenTxid::Wtxid(TXHASHES[txhash]) : GenTxid::Txid(TXHASHES[txhash])); |
| 256 | ann2.m_state = State::COMPLETED; |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | // And delete txids with only COMPLETED announcements left. |
| 261 | Cleanup(txhash); |
| 262 | // CANDIDATEs for which this announcement has the highest priority get returned. |
| 263 | const Announcement& ann = m_announcements[txhash][peer]; |
| 264 | if (ann.m_state == State::CANDIDATE && GetSelected(txhash) == peer) { |
| 265 | result.emplace_back(ann.m_sequence, txhash, ann.m_is_wtxid); |
| 266 | } |
| 267 | } |
| 268 | // Sort the results by sequence number. |
| 269 | std::sort(result.begin(), result.end()); |
| 270 | std::sort(expected_expired.begin(), expected_expired.end()); |
| 271 | |
| 272 | // Compare with TxRequestTracker's implementation. |
| 273 | std::vector<std::pair<NodeId, GenTxid>> expired; |
| 274 | const auto actual = m_tracker.GetRequestable(peer, m_now, &expired); |
| 275 | std::sort(expired.begin(), expired.end()); |
| 276 | assert(expired == expected_expired); |
| 277 | |
| 278 | m_tracker.PostGetRequestableSanityCheck(m_now); |
| 279 | assert(result.size() == actual.size()); |
| 280 | for (size_t pos = 0; pos < actual.size(); ++pos) { |
| 281 | assert(TXHASHES[std::get<1>(result[pos])] == actual[pos].GetHash()); |
| 282 | assert(std::get<2>(result[pos]) == actual[pos].IsWtxid()); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void Check() |
| 287 | { |
no test coverage detected