Skip to content

Commit

Permalink
Change pending_finalizer_policy_generation to last_pending_finalizer_…
Browse files Browse the repository at this point in the history
…policy_generation
  • Loading branch information
linh2931 committed Jul 26, 2024
1 parent 9b18111 commit 0148913
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
8 changes: 4 additions & 4 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ 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,
.pending_finalizer_policy_generation = get_last_pending_finalizer_policy().generation,
.finality_tree_digest = finality_mroot(),
.l2_commitments_digest = fc::sha256::hash(level_2_commitments)
.active_finalizer_policy_generation = active_finalizer_policy->generation,
.last_pending_finalizer_policy_generation = get_last_pending_finalizer_policy().generation,
.finality_tree_digest = finality_mroot(),
.l2_commitments_digest = fc::sha256::hash(level_2_commitments)
};

return fc::sha256::hash(finality_digest_data);
Expand Down
18 changes: 9 additions & 9 deletions libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,15 @@ finality_data_t block_state::get_finality_data() {

return {
// major_version and minor_version take the default values set by finality_data_t definition
.active_finalizer_policy_generation = active_finalizer_policy->generation,
.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,
.base_digest = *base_digest,
.pending_finalizer_policy = std::move(pending_fin_pol),
.pending_finalizer_policy_generation = get_last_pending_finalizer_policy().generation
.active_finalizer_policy_generation = active_finalizer_policy->generation,
.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,
.base_digest = *base_digest,
.pending_finalizer_policy = std::move(pending_fin_pol),
.last_pending_finalizer_policy_generation = get_last_pending_finalizer_policy().generation
};
}

Expand Down
8 changes: 2 additions & 6 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ 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};

// Hold the generation number of pending_finalizer_policy if it exists,
// otherwise hold the same value as active_finalizer_policy_generation
uint32_t pending_finalizer_policy_generation{0};

uint32_t last_pending_finalizer_policy_generation{0}; // use active_finalizer_policy_generation if pending_finalizer_policy does not exist
digest_type finality_tree_digest{};
digest_type l2_commitments_digest{};
};
Expand Down Expand Up @@ -187,4 +183,4 @@ FC_REFLECT( eosio::chain::block_header_state, (block_id)(header)

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)(pending_finalizer_policy_generation)(finality_tree_digest)(l2_commitments_digest) )
FC_REFLECT( eosio::chain::finality_digest_data_v1, (major_version)(minor_version)(active_finalizer_policy_generation)(last_pending_finalizer_policy_generation)(finality_tree_digest)(l2_commitments_digest) )
6 changes: 2 additions & 4 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ struct finality_data_t {
// Use string format for public key in the policy for easier uses.
std::optional<finalizer_policy_with_string_key> pending_finalizer_policy;

// Hold the generation number of pending_finalizer_policy if it exists,
// otherwise hold the same value as active_finalizer_policy_generation
uint32_t pending_finalizer_policy_generation{0};
uint32_t last_pending_finalizer_policy_generation{0}; // // use active_finalizer_policy_generation if pending_finalizer_policy does not exist
};

struct block_state : public block_header_state { // block_header_state provides parent link
Expand Down Expand Up @@ -194,5 +192,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)(action_mroot)(reversible_blocks_mroot)(latest_qc_claim_block_num)(latest_qc_claim_finality_digest)(latest_qc_claim_timestamp)(base_digest)(pending_finalizer_policy)(pending_finalizer_policy_generation) )
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)(base_digest)(pending_finalizer_policy)(last_pending_finalizer_policy_generation) )
FC_REFLECT_DERIVED( eosio::chain::block_state, (eosio::chain::block_header_state), (block)(strong_digest)(weak_digest)(aggregating_qc)(valid)(validated) )
2 changes: 1 addition & 1 deletion libraries/state_history/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "latest_qc_claim_timestamp", "type": "block_timestamp_type" },
{ "name": "base_digest", "type": "checksum256" },
{ "name": "pending_finalizer_policy", "type": "finalizer_policy_with_string_key?" },
{ "name": "pending_finalizer_policy_generation", "type": "uint32" }
{ "name": "last_pending_finalizer_policy_generation", "type": "uint32" }
]
}
],
Expand Down
8 changes: 4 additions & 4 deletions unittests/finality_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ 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,
.pending_finalizer_policy_generation = is_genesis ? 1 : last_pending_finalizer_policy.generation,
.finality_tree_digest = finality_root,
.l2_commitments_digest = level_2_commitments_digest
.active_finalizer_policy_generation = is_genesis ? 1 : active_finalizer_policy.generation,
.last_pending_finalizer_policy_generation = is_genesis ? 1 : last_pending_finalizer_policy.generation,
.finality_tree_digest = finality_root,
.l2_commitments_digest = level_2_commitments_digest
});

// compute finality leaf
Expand Down

0 comments on commit 0148913

Please sign in to comment.