Skip to content

Commit

Permalink
GH-6 Revert back to flat_map for simpler and not storing unneeded imp…
Browse files Browse the repository at this point in the history
…lementation
  • Loading branch information
heifner committed May 1, 2024
1 parent 5c310b5 commit 887b057
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
15 changes: 5 additions & 10 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, proposer policy>
// 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<std::pair<block_timestamp_type, proposer_policy_ptr>> proposer_policies;
flat_map<block_timestamp_type, proposer_policy_ptr> 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
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/snapshot_detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::pair<block_timestamp_type, proposer_policy_ptr>> proposer_policies;
flat_map<block_timestamp_type, proposer_policy_ptr> proposer_policies;
flat_multimap<block_num_type, finalizer_policy_tracker> finalizer_policies;
uint32_t finalizer_policy_generation;

Expand Down

0 comments on commit 887b057

Please sign in to comment.