From 59967253596822f21c997c55d728be468c4003ba Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Wed, 8 May 2024 20:15:24 -0400 Subject: [PATCH 1/6] Add proposed finalizer policy to SHiP finality_data stream --- libraries/chain/block_state.cpp | 16 ++++++++++++++-- .../chain/include/eosio/chain/block_state.hpp | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index 5d84d2f60a..b6b70c5d38 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -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 proposed_finalizer_policy = std::nullopt; + 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 }; } diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index 35cfcf098e..cb13675756 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -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 proposed_finalizer_policy{std::nullopt}; // finalizer policy, if proposed in the block }; struct block_state : public block_header_state { // block_header_state provides parent link @@ -176,5 +177,5 @@ using block_state_pair = std::pair, 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) ) From 17ddf2385b9d0515f5cbbc1431dbcedce3835409 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 9 May 2024 14:23:57 -0400 Subject: [PATCH 2/6] Use std::move to assign proposed_finalizer_policy --- libraries/chain/block_state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index b6b70c5d38..eecb41f9a7 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -353,7 +353,7 @@ finality_data_t block_state::get_finality_data() { .active_finalizer_policy_generation = active_finalizer_policy->generation, .action_mroot = action_mroot, .base_digest = *base_digest, - .proposed_finalizer_policy = proposed_finalizer_policy + .proposed_finalizer_policy = std::move(proposed_finalizer_policy) }; } From 1be5d61fa6e917ad555a4ad3a8c2029b6102562c Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Thu, 9 May 2024 17:28:06 -0400 Subject: [PATCH 3/6] Remove redundant initialization of proposed_finalizer_policy to std::nullopt --- libraries/chain/block_state.cpp | 2 +- libraries/chain/include/eosio/chain/block_state.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index eecb41f9a7..968ade4300 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -339,7 +339,7 @@ finality_data_t block_state::get_finality_data() { } // Check if there is any proposed finalizer policy in the block - std::optional proposed_finalizer_policy = std::nullopt; + std::optional proposed_finalizer_policy; 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) { diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index cb13675756..04039e864a 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -64,7 +64,7 @@ struct finality_data_t { uint32_t active_finalizer_policy_generation{0}; digest_type action_mroot{}; digest_type base_digest{}; - std::optional proposed_finalizer_policy{std::nullopt}; // finalizer policy, if proposed in the block + std::optional proposed_finalizer_policy; // finalizer policy, if proposed in the block }; struct block_state : public block_header_state { // block_header_state provides parent link From d13759ed61a5a5b05a9de00aaa67b284c991e38e Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Fri, 10 May 2024 10:06:47 -0400 Subject: [PATCH 4/6] Add is_savanna_genesis_block() to block_header_state --- libraries/chain/include/eosio/chain/block_header_state.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/chain/include/eosio/chain/block_header_state.hpp b/libraries/chain/include/eosio/chain/block_header_state.hpp index 7fd43afe32..22c11318f8 100644 --- a/libraries/chain/include/eosio/chain/block_header_state.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state.hpp @@ -119,6 +119,9 @@ 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 + bool is_savanna_genesis_block() const { return core.is_genesis_block_num(block_num()); } + // Returns true if the block is a Proper Savanna Block bool is_proper_svnn_block() const { return header.is_proper_svnn_block(); } From 874879ed9d4808522e7e1280aa62a39211b28cec Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Fri, 10 May 2024 10:08:14 -0400 Subject: [PATCH 5/6] Use active_finalizer_policy for finality_data if it is the Savanna Genesis Block --- libraries/chain/block_state.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index 968ade4300..f2aa9d872c 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -340,11 +340,16 @@ finality_data_t block_state::get_finality_data() { // Check if there is any proposed finalizer policy in the block std::optional proposed_finalizer_policy; - 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; + if (is_savanna_genesis_block()) { + // For Genesis Block, use the acttive 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; + } } } From 60ea6b984f4defe023f9c2a58461d13def42ab95 Mon Sep 17 00:00:00 2001 From: Lin Huang Date: Fri, 10 May 2024 10:59:40 -0400 Subject: [PATCH 6/6] update comments --- libraries/chain/block_state.cpp | 2 +- libraries/chain/include/eosio/chain/block_header_state.hpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index 9273264e0a..f33d5345f1 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -341,7 +341,7 @@ finality_data_t block_state::get_finality_data() { // Check if there is any proposed finalizer policy in the block std::optional proposed_finalizer_policy; if (is_savanna_genesis_block()) { - // For Genesis Block, use the acttive finalizer policy which was proposed in the block. + // 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()); diff --git a/libraries/chain/include/eosio/chain/block_header_state.hpp b/libraries/chain/include/eosio/chain/block_header_state.hpp index 1c4f2718fc..9daf9d7815 100644 --- a/libraries/chain/include/eosio/chain/block_header_state.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state.hpp @@ -119,7 +119,8 @@ 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 + // 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()); } // Returns true if the block is a Proper Savanna Block