Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proposed finalizer policy to SHiP finality_data stream #124

Merged
merged 9 commits into from
May 10, 2024
21 changes: 19 additions & 2 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,28 @@ finality_data_t block_state::get_finality_data() {
if (!base_digest) {
base_digest = compute_base_digest(); // cache it
}

// Check if there is any proposed finalizer policy in the block
std::optional<finalizer_policy> proposed_finalizer_policy;
if (is_savanna_genesis_block()) {
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
// For Genesis Block, use the active finalizer policy which was proposed in the block.
proposed_finalizer_policy = *active_finalizer_policy;
} else {
auto range = finalizer_policies.equal_range(block_num());
for (auto itr = range.first; itr != range.second; ++itr) {
if (itr->second.state == finalizer_policy_tracker::state_t::proposed) {
proposed_finalizer_policy = *itr->second.policy;
break;
}
}
}

return {
// other fields take the default values set by finality_data_t definition
.active_finalizer_policy_generation = active_finalizer_policy->generation,
.action_mroot = action_mroot,
.base_digest = *base_digest
.action_mroot = action_mroot,
.base_digest = *base_digest,
.proposed_finalizer_policy = std::move(proposed_finalizer_policy)
};
heifner marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
4 changes: 4 additions & 0 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ struct block_header_state {
digest_type compute_base_digest() const;
digest_type compute_finality_digest() const;

// Returns true if the block is a Savanna Genesis Block.
// This method is applicable to any transition block which is re-classified as a Savanna block.
bool is_savanna_genesis_block() const { return core.is_genesis_block_num(block_num()); }
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved

// Returns true if the block is a Proper Savanna Block
bool is_proper_svnn_block() const { return header.is_proper_svnn_block(); }

Expand Down
3 changes: 2 additions & 1 deletion libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct finality_data_t {
uint32_t active_finalizer_policy_generation{0};
digest_type action_mroot{};
digest_type base_digest{};
std::optional<finalizer_policy> proposed_finalizer_policy; // finalizer policy, if proposed in the block
};

struct block_state : public block_header_state { // block_header_state provides parent link
Expand Down Expand Up @@ -176,5 +177,5 @@ using block_state_pair = std::pair<std::shared_ptr<block_state_legacy>, blo
// not exporting pending_qc or valid_qc
FC_REFLECT( eosio::chain::valid_t::finality_leaf_node_t, (major_version)(minor_version)(block_num)(finality_digest)(action_mroot) )
FC_REFLECT( eosio::chain::valid_t, (validation_tree)(validation_mroots))
FC_REFLECT( eosio::chain::finality_data_t, (major_version)(minor_version)(active_finalizer_policy_generation)(action_mroot)(base_digest))
FC_REFLECT( eosio::chain::finality_data_t, (major_version)(minor_version)(active_finalizer_policy_generation)(action_mroot)(base_digest)(proposed_finalizer_policy) )
FC_REFLECT_DERIVED( eosio::chain::block_state, (eosio::chain::block_header_state), (block)(strong_digest)(weak_digest)(pending_qc)(valid)(validated) )
Loading