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