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
16 changes: 14 additions & 2 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,23 @@ 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 = std::nullopt;
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
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 = proposed_finalizer_policy
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
};
heifner marked this conversation as resolved.
Show resolved Hide resolved
}

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{std::nullopt}; // finalizer policy, if proposed in the block
greg7mdp marked this conversation as resolved.
Show resolved Hide resolved
};

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