| 15 | static_assert(sizeof(CompressedHeader) == 48); |
| 16 | |
| 17 | HeadersSyncState::HeadersSyncState(NodeId id, |
| 18 | const Consensus::Params& consensus_params, |
| 19 | const HeadersSyncParams& params, |
| 20 | const CBlockIndex& chain_start, |
| 21 | const arith_uint256& minimum_required_work) |
| 22 | : m_commit_offset((assert(params.commitment_period > 0), // HeadersSyncParams field must be initialized to non-zero. |
| 23 | FastRandomContext().randrange(params.commitment_period))), |
| 24 | m_id(id), |
| 25 | m_consensus_params(consensus_params), |
| 26 | m_params(params), |
| 27 | m_chain_start(chain_start), |
| 28 | m_minimum_required_work(minimum_required_work), |
| 29 | m_current_chain_work(chain_start.nChainWork), |
| 30 | m_last_header_received(m_chain_start.GetBlockHeader()), |
| 31 | m_current_height(chain_start.nHeight) |
| 32 | { |
| 33 | // Estimate the number of blocks that could possibly exist on the peer's |
| 34 | // chain *right now* using 6 blocks/second (fastest blockrate given the MTP |
| 35 | // rule) times the number of seconds from the last allowed block until |
| 36 | // today. This serves as a memory bound on how many commitments we might |
| 37 | // store from this peer, and we can safely give up syncing if the peer |
| 38 | // exceeds this bound, because it's not possible for a consensus-valid |
| 39 | // chain to be longer than this (at the current time -- in the future we |
| 40 | // could try again, if necessary, to sync a longer chain). |
| 41 | const auto max_seconds_since_start{(Ticks<std::chrono::seconds>(NodeClock::now() - NodeSeconds{std::chrono::seconds{chain_start.GetMedianTimePast()}})) |
| 42 | + MAX_FUTURE_BLOCK_TIME}; |
| 43 | m_max_commitments = 6 * max_seconds_since_start / m_params.commitment_period; |
| 44 | |
| 45 | LogDebug(BCLog::NET, "Initial headers sync started with peer=%d: height=%i, max_commitments=%i, min_work=%s\n", m_id, m_current_height, m_max_commitments, m_minimum_required_work.ToString()); |
| 46 | } |
| 47 | |
| 48 | /** Free any memory in use, and mark this object as no longer usable. This is |
| 49 | * required to guarantee that we won't reuse this object with the same |
nothing calls this directly
no test coverage detected