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.
| 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 | |
| 513 | public: |
| 514 | explicit Impl(bool deterministic) : |
nothing calls this directly
no test coverage detected