diff --git a/libraries/chain/block_header_state.cpp b/libraries/chain/block_header_state.cpp index 774788938d..f3786aaad9 100644 --- a/libraries/chain/block_header_state.cpp +++ b/libraries/chain/block_header_state.cpp @@ -106,23 +106,18 @@ void finish_next(const block_header_state& prev, if (!prev.proposer_policies.empty()) { auto it = prev.proposer_policies.begin(); // +1 since this is called after the block is built, this will be the active schedule for the next block - while (it != prev.proposer_policies.end() && it->first.slot <= next_header_state.header.timestamp.slot + 1) { + if (it->first.slot <= next_header_state.header.timestamp.slot + 1) { next_header_state.active_proposer_policy = it->second; - ++it; - } - if (it == prev.proposer_policies.begin()) { // none made active + next_header_state.proposer_policies = { ++it, prev.proposer_policies.end() }; + } else { next_header_state.proposer_policies = prev.proposer_policies; - } else if (it != prev.proposer_policies.end()) { // some made active - next_header_state.proposer_policies = { it, prev.proposer_policies.end() }; - } else { // all made active - // next_header_state.proposer_policies will be emtpy } } if (if_ext.new_proposer_policy) { // called when assembling the block - next_header_state.proposer_policies.emplace_back(if_ext.new_proposer_policy->active_time, - std::move(if_ext.new_proposer_policy)); + next_header_state.proposer_policies[if_ext.new_proposer_policy->active_time] = + std::move(if_ext.new_proposer_policy); } // finality_core diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 1fa819b471..3a3c85b580 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -507,7 +507,7 @@ struct building_block { const producer_authority_schedule& lhs = get_next_sched(); - decltype(lhs.version) v = lhs.version; + auto v = lhs.version; if (!std::ranges::equal(lhs.producers, producers)) { ++v; diff --git a/libraries/chain/include/eosio/chain/block_header_state.hpp b/libraries/chain/include/eosio/chain/block_header_state.hpp index 95683213d0..c7ad66309d 100644 --- a/libraries/chain/include/eosio/chain/block_header_state.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state.hpp @@ -68,18 +68,13 @@ struct block_header_state { finalizer_policy_ptr active_finalizer_policy; // finalizer set + threshold + generation, supports `digest()` proposer_policy_ptr active_proposer_policy; // producer authority schedule, supports `digest()` - // + // block time when proposer_policy will become active + // current algorithm only two entries possible, for for the next,next round and one for block round after that // The active time is the next,next producer round. For example, // round A [1,2,..12], next_round B [1,2,..12], next_next_round C [1,2,..12], D [1,2,..12] // If proposed in A1, A2, .. A12 becomes active in C1 // If proposed in B1, B2, .. B12 becomes active in D1 - // This is a `deque` because the same active block time can contain up to 12 entries (one per block) - // for the entry proposed in a block: - // For example, proposer policy proposed: P1 in A1, P2 in A7, P3 in A12, P4 in B2, P5 in B12 then the map contains: - // [C1 -> P1],[C1 -> P2],[C1 -> P3],[D1 -> P4],[D1 -> P5] - // At C1 P1,P2,P3 are applied causing an active policy of P3 - // At D1 P4,P5 are appliced causing an acive policy of P5 - std::deque> proposer_policies; + flat_map proposer_policies; // track in-flight finalizer policies. This is a `multimap` because the same block number // can hold a `proposed` and a `pending` finalizer_policy. When that block becomes final, the diff --git a/libraries/chain/include/eosio/chain/snapshot_detail.hpp b/libraries/chain/include/eosio/chain/snapshot_detail.hpp index 78f00e3e5b..58e760d03d 100644 --- a/libraries/chain/include/eosio/chain/snapshot_detail.hpp +++ b/libraries/chain/include/eosio/chain/snapshot_detail.hpp @@ -116,7 +116,7 @@ namespace eosio::chain::snapshot_detail { finality_core core; finalizer_policy_ptr active_finalizer_policy; proposer_policy_ptr active_proposer_policy; - std::deque> proposer_policies; + flat_map proposer_policies; flat_multimap finalizer_policies; uint32_t finalizer_policy_generation;