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

Replace final_on_strong_qc_block_num in finality digest with other needed data #397

Merged
merged 8 commits into from
Jul 25, 2024
15 changes: 11 additions & 4 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ digest_type block_header_state::compute_base_digest() const {
}

digest_type block_header_state::compute_finality_digest() const {

// compute commitments related to finality violation proofs
auto latest_qc_claim_block_num = core.latest_qc_claim().block_num;
auto blk_ref = core.is_genesis_core() // Savanna Genesis core does not have block_ref
? block_ref{}
: core.get_block_reference(latest_qc_claim_block_num);

level_3_commitments_t level_3_commitments {
.reversible_blocks_mroot = core.get_reversible_blocks_mroot(),
.base_digest = compute_base_digest()
.reversible_blocks_mroot = core.get_reversible_blocks_mroot(),
.latest_qc_claim_block_num = latest_qc_claim_block_num,
.latest_qc_claim_finality_digest = blk_ref.finality_digest,
.latest_qc_claim_timestamp = blk_ref.timestamp,
.timestamp = timestamp(),
.base_digest = compute_base_digest()
};

// compute commitments related to finalizer policy transitions
Expand All @@ -55,7 +63,6 @@ digest_type block_header_state::compute_finality_digest() const {
assert(active_finalizer_policy);
finality_digest_data_v1 finality_digest_data {
.active_finalizer_policy_generation = active_finalizer_policy->generation,
.final_on_strong_qc_block_num = core.final_on_strong_qc_block_num,
.finality_tree_digest = finality_mroot(),
.l2_commitments_digest = fc::sha256::hash(level_2_commitments)
};
Expand Down
22 changes: 16 additions & 6 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,34 @@ finality_data_t block_state::get_finality_data() {
base_digest = compute_base_digest(); // cache it
}

// Check if there is a finalizer policy promoted to pending in the block
auto latest_qc_claim_block_num = core.latest_qc_claim().block_num;
block_ref blk_ref{}; // Savanna Genesis does not have block_ref
std::optional<finalizer_policy_with_string_key> pending_fin_pol;

if (is_savanna_genesis_block()) {
// For Genesis Block, use the active finalizer policy which went through
// proposed to pending to active in the single block.
pending_fin_pol = finalizer_policy_with_string_key(*active_finalizer_policy);
} else if (pending_finalizer_policy.has_value() && pending_finalizer_policy->first == block_num()) {
// The `first` element of `pending_finalizer_policy` pair is the block number
// when the policy becomes pending
pending_fin_pol = finalizer_policy_with_string_key(*pending_finalizer_policy->second);
} else {
// Check if there is a finalizer policy promoted to pending in the block
if (pending_finalizer_policy.has_value() && pending_finalizer_policy->first == block_num()) {
// The `first` element of `pending_finalizer_policy` pair is the block number
// when the policy becomes pending
pending_fin_pol = finalizer_policy_with_string_key(*pending_finalizer_policy->second);
}

blk_ref = core.get_block_reference(latest_qc_claim_block_num);
}

return {
// major_version and minor_version take the default values set by finality_data_t definition
.active_finalizer_policy_generation = active_finalizer_policy->generation,
.final_on_strong_qc_block_num = core.final_on_strong_qc_block_num,
.action_mroot = action_mroot,
.reversible_blocks_mroot = core.get_reversible_blocks_mroot(),
.latest_qc_claim_block_num = latest_qc_claim_block_num,
.latest_qc_claim_finality_digest = blk_ref.finality_digest,
.latest_qc_claim_timestamp = blk_ref.timestamp,
.timestamp = timestamp(),
.base_digest = *base_digest,
.pending_finalizer_policy = std::move(pending_fin_pol)
};
Expand Down
14 changes: 8 additions & 6 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ constexpr uint32_t light_header_protocol_version_minor = 0;

// commitments used in the context of finality violation proofs
struct level_3_commitments_t {
digest_type reversible_blocks_mroot{};
digest_type base_digest{};
digest_type reversible_blocks_mroot{};
block_num_type latest_qc_claim_block_num{0};
digest_type latest_qc_claim_finality_digest;
block_timestamp_type latest_qc_claim_timestamp;
block_timestamp_type timestamp; // This is the timestamp of the current block.
digest_type base_digest{};
};

// commitments used in the context of finalizer policy transitions
Expand All @@ -38,7 +42,6 @@ struct finality_digest_data_v1 {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
uint32_t active_finalizer_policy_generation {0};
uint32_t final_on_strong_qc_block_num {0};
digest_type finality_tree_digest{};
digest_type l2_commitments_digest{};
};
Expand Down Expand Up @@ -177,7 +180,6 @@ FC_REFLECT( eosio::chain::block_header_state, (block_id)(header)
(pending_finalizer_policy)(finalizer_policy_generation)
(last_pending_finalizer_policy_digest))

FC_REFLECT( eosio::chain::level_3_commitments_t, (reversible_blocks_mroot)(base_digest) )
FC_REFLECT( eosio::chain::level_3_commitments_t, (reversible_blocks_mroot)(latest_qc_claim_block_num )(latest_qc_claim_finality_digest)(latest_qc_claim_timestamp)(timestamp)(base_digest))
FC_REFLECT( eosio::chain::level_2_commitments_t, (last_pending_fin_pol_digest)(last_pending_fin_pol_start_num)(l3_commitments_digest) )

FC_REFLECT( eosio::chain::finality_digest_data_v1, (major_version)(minor_version)(active_finalizer_policy_generation)(final_on_strong_qc_block_num)(finality_tree_digest)(l2_commitments_digest) )
FC_REFLECT( eosio::chain::finality_digest_data_v1, (major_version)(minor_version)(active_finalizer_policy_generation)(finality_tree_digest)(l2_commitments_digest) )
9 changes: 6 additions & 3 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ struct finality_data_t {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
uint32_t active_finalizer_policy_generation{0};
uint32_t final_on_strong_qc_block_num{0};
digest_type action_mroot{};
digest_type reversible_blocks_mroot{};
digest_type base_digest{};
block_num_type latest_qc_claim_block_num{0};
digest_type latest_qc_claim_finality_digest;
block_timestamp_type latest_qc_claim_timestamp;
block_timestamp_type timestamp; // This is the timestamp of the current block.
digest_type base_digest{};
// Finalizer policy if one is promoted to pending in the block.
// Use string format for public key in the policy for easier uses.
std::optional<finalizer_policy_with_string_key> pending_finalizer_policy;
Expand Down Expand Up @@ -187,5 +190,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)(timestamp)(parent_timestamp)(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)(final_on_strong_qc_block_num)(action_mroot)(reversible_blocks_mroot)(base_digest)(pending_finalizer_policy) )
FC_REFLECT( eosio::chain::finality_data_t, (major_version)(minor_version)(active_finalizer_policy_generation)(action_mroot)(reversible_blocks_mroot)(latest_qc_claim_block_num)(latest_qc_claim_finality_digest)(latest_qc_claim_timestamp)(timestamp)(base_digest)(pending_finalizer_policy) )
FC_REFLECT_DERIVED( eosio::chain::block_state, (eosio::chain::block_header_state), (block)(strong_digest)(weak_digest)(aggregating_qc)(valid)(validated) )
5 changes: 4 additions & 1 deletion libraries/state_history/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,12 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "major_version", "type": "uint32" },
{ "name": "minor_version", "type": "uint32" },
{ "name": "active_finalizer_policy_generation", "type": "uint32" },
{ "name": "final_on_strong_qc_block_num", "type": "uint32" },
{ "name": "action_mroot", "type": "checksum256" },
{ "name": "reversible_blocks_mroot", "type": "checksum256" },
{ "name": "latest_qc_claim_block_num", "type": "uint32" },
{ "name": "latest_qc_claim_finality_digest", "type": "checksum256" },
{ "name": "latest_qc_claim_timestamp", "type": "block_timestamp_type" },
{ "name": "timestamp", "type": "block_timestamp_type" },
{ "name": "base_digest", "type": "checksum256" },
{ "name": "pending_finalizer_policy", "type": "finalizer_policy_with_string_key?" }
]
Expand Down
190 changes: 95 additions & 95 deletions unittests/deep-mind/deep-mind.log

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion unittests/finality_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ namespace finality_proof {
// compute digest for verification purposes
digest_type finality_digest = fc::sha256::hash(finality_digest_data_v1{
.active_finalizer_policy_generation = is_genesis ? 1 : active_finalizer_policy.generation,
.final_on_strong_qc_block_num = finality_data.final_on_strong_qc_block_num,
.finality_tree_digest = finality_root,
.l2_commitments_digest = level_2_commitments_digest
});
Expand Down