MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetRequestable

Method GetRequestable

src/test/fuzz/txrequest.cpp:244–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 3

CheckMethod · 0.45
FUZZ_TARGETFunction · 0.45
GetRequestsToSendMethod · 0.45

Calls 6

IsWtxidMethod · 0.80
emplace_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected