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

Method SetTimePoint

src/txrequest.cpp:482–511  ·  view source on GitHub ↗

Make the data structure consistent with a given point in time: - REQUESTED announcements with expiry <= now are turned into COMPLETED. - CANDIDATE_DELAYED announcements with reqtime <= now are turned into CANDIDATE_{READY,BEST}. - CANDIDATE_{READY,BEST} announcements with reqtime > now are turned into CANDIDATE_DELAYED.

Source from the content-addressed store, hash-verified

480 //! - CANDIDATE_DELAYED announcements with reqtime <= now are turned into CANDIDATE_{READY,BEST}.
481 //! - CANDIDATE_{READY,BEST} announcements with reqtime > now are turned into CANDIDATE_DELAYED.
482 void SetTimePoint(std::chrono::microseconds now, std::vector<std::pair<NodeId, GenTxid>>* expired)
483 {
484 if (expired) expired->clear();
485
486 // Iterate over all CANDIDATE_DELAYED and REQUESTED from old to new, as long as they're in the past,
487 // and convert them to CANDIDATE_READY and COMPLETED respectively.
488 while (!m_index.empty()) {
489 auto it = m_index.get<ByTime>().begin();
490 if (it->GetState() == State::CANDIDATE_DELAYED && it->m_time <= now) {
491 PromoteCandidateReady(m_index.project<ByTxHash>(it));
492 } else if (it->GetState() == State::REQUESTED && it->m_time <= now) {
493 if (expired) expired->emplace_back(it->m_peer, it->m_gtxid);
494 MakeCompleted(m_index.project<ByTxHash>(it));
495 } else {
496 break;
497 }
498 }
499
500 while (!m_index.empty()) {
501 // If time went backwards, we may need to demote CANDIDATE_BEST and CANDIDATE_READY announcements back
502 // to CANDIDATE_DELAYED. This is an unusual edge case, and unlikely to matter in production. However,
503 // it makes it much easier to specify and test TxRequestTracker::Impl's behaviour.
504 auto it = std::prev(m_index.get<ByTime>().end());
505 if (it->IsSelectable() && it->m_time > now) {
506 ChangeAndReselect(m_index.project<ByTxHash>(it), State::CANDIDATE_DELAYED);
507 } else {
508 break;
509 }
510 }
511 }
512
513public:
514 explicit Impl(bool deterministic) :

Callers

nothing calls this directly

Calls 7

clearMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
GetStateMethod · 0.45
emplace_backMethod · 0.45
endMethod · 0.45
IsSelectableMethod · 0.45

Tested by

no test coverage detected