From 0a0cb71b824a51259025547d9ecd368e5e95d093 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 12 Jul 2024 16:11:35 -0500 Subject: [PATCH 1/2] GH-353 Renamed instant_finality_extension to finality_extension --- libraries/chain/abi_serializer.cpp | 10 ++--- libraries/chain/block_header_state.cpp | 18 ++++---- libraries/chain/block_header_state_legacy.cpp | 12 +++--- libraries/chain/block_state.cpp | 8 ++-- libraries/chain/controller.cpp | 42 +++++++++---------- .../include/eosio/chain/abi_serializer.hpp | 4 +- .../include/eosio/chain/block_header.hpp | 4 +- .../eosio/chain/block_header_state.hpp | 2 +- .../chain/include/eosio/chain/block_state.hpp | 2 +- ...y_extension.hpp => finality_extension.hpp} | 12 +++--- .../testing/include/eosio/testing/tester.hpp | 2 +- plugins/net_plugin/net_plugin.cpp | 6 +-- unittests/block_header_tests.cpp | 38 ++++++++--------- unittests/finality_proof.hpp | 8 ++-- unittests/finality_tests.cpp | 12 +++--- unittests/finalizer_update_tests.cpp | 4 +- unittests/producer_schedule_if_tests.cpp | 18 ++++---- unittests/vote_processor_tests.cpp | 4 +- 18 files changed, 103 insertions(+), 103 deletions(-) rename libraries/chain/include/eosio/chain/finality/{instant_finality_extension.hpp => finality_extension.hpp} (69%) diff --git a/libraries/chain/abi_serializer.cpp b/libraries/chain/abi_serializer.cpp index 532e7cbafe..c73356163b 100644 --- a/libraries/chain/abi_serializer.cpp +++ b/libraries/chain/abi_serializer.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -634,11 +634,11 @@ namespace eosio { namespace chain { _variant_to_binary(type, var, ds, ctx); } - void impl::abi_to_variant::add_block_header_instant_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts ) { - if (header_exts.count(instant_finality_extension::extension_id())) { + void impl::abi_to_variant::add_block_header_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts ) { + if (header_exts.count(finality_extension::extension_id())) { const auto& if_extension = - std::get(header_exts.lower_bound(instant_finality_extension::extension_id())->second); - mvo("instant_finality_extension", if_extension); + std::get(header_exts.lower_bound(finality_extension::extension_id())->second); + mvo("finality_extension", if_extension); } } diff --git a/libraries/chain/block_header_state.cpp b/libraries/chain/block_header_state.cpp index 555482d0ee..7e20d683b0 100644 --- a/libraries/chain/block_header_state.cpp +++ b/libraries/chain/block_header_state.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -174,7 +174,7 @@ void evaluate_finalizer_policies_for_promotion(const block_header_state& prev, // ------------------------------------------------------------------------------------------------- // `finish_next` updates the next `block_header_state` according to the contents of the -// header extensions (either new protocol_features or instant_finality_extension) applicable to this +// header extensions (either new protocol_features or finality_extension) applicable to this // next block . // // These extensions either result from the execution of the previous block (in case this node @@ -183,7 +183,7 @@ void evaluate_finalizer_policies_for_promotion(const block_header_state& prev, void finish_next(const block_header_state& prev, block_header_state& next_header_state, vector new_protocol_feature_activations, - instant_finality_extension if_ext, + finality_extension if_ext, bool log) { // only log on assembled blocks, to avoid double logging // activated protocol features // --------------------------- @@ -296,11 +296,11 @@ block_header_state block_header_state::next(block_header_state_input& input) con if (input.new_proposer_policy) { new_proposer_policy_diff = get_last_proposed_proposer_policy().create_diff(*input.new_proposer_policy); } - instant_finality_extension new_if_ext { input.most_recent_ancestor_with_qc, + finality_extension new_if_ext { input.most_recent_ancestor_with_qc, std::move(new_finalizer_policy_diff), std::move(new_proposer_policy_diff) }; - uint16_t if_ext_id = instant_finality_extension::extension_id(); + uint16_t if_ext_id = finality_extension::extension_id(); emplace_extension(next_header_state.header.header_extensions, if_ext_id, fc::raw::pack(new_if_ext)); next_header_state.header_exts.emplace(if_ext_id, new_if_ext); @@ -351,12 +351,12 @@ block_header_state block_header_state::next(const signed_block_header& h, valida validator( timestamp(), activated_protocol_features->protocol_features, new_protocol_feature_activations ); } - // retrieve instant_finality_extension data from block header extension + // retrieve finality_extension data from block header extension // -------------------------------------------------------------------- - EOS_ASSERT(exts.count(instant_finality_extension::extension_id()) > 0, invalid_block_header_extension, + EOS_ASSERT(exts.count(finality_extension::extension_id()) > 0, invalid_block_header_extension, "Instant Finality Extension is expected to be present in all block headers after switch to IF"); - auto if_entry = exts.lower_bound(instant_finality_extension::extension_id()); - const auto& if_ext = std::get(if_entry->second); + auto if_entry = exts.lower_bound(finality_extension::extension_id()); + const auto& if_ext = std::get(if_entry->second); if (h.is_proper_svnn_block()) { // if there is no Finality Tree Root associated with the block, diff --git a/libraries/chain/block_header_state_legacy.cpp b/libraries/chain/block_header_state_legacy.cpp index 01cbe4113e..b4ba6001fb 100644 --- a/libraries/chain/block_header_state_legacy.cpp +++ b/libraries/chain/block_header_state_legacy.cpp @@ -156,9 +156,9 @@ namespace eosio::chain { result.producer_to_last_implied_irb[proauth.producer_name] = dpos_proposed_irreversible_blocknum; } - if (header_exts.count(instant_finality_extension::extension_id())) { // transition to savanna has started + if (header_exts.count(finality_extension::extension_id())) { // transition to savanna has started const auto& if_extension = - std::get(header_exts.lower_bound(instant_finality_extension::extension_id())->second); + std::get(header_exts.lower_bound(finality_extension::extension_id())->second); // copy over qc_claim from IF Genesis Block result.qc_claim = if_extension.qc_claim; } @@ -222,11 +222,11 @@ namespace eosio::chain { .is_strong_qc = false }; finalizer_policy no_policy; auto new_fin_policy_diff = no_policy.create_diff(*new_finalizer_policy); - emplace_extension(h.header_extensions, instant_finality_extension::extension_id(), - fc::raw::pack(instant_finality_extension{ initial_if_claim, std::move(new_fin_policy_diff), {} })); + emplace_extension(h.header_extensions, finality_extension::extension_id(), + fc::raw::pack(finality_extension{ initial_if_claim, std::move(new_fin_policy_diff), {} })); } else if (qc_claim) { - emplace_extension(h.header_extensions, instant_finality_extension::extension_id(), - fc::raw::pack(instant_finality_extension{ *qc_claim, {}, {} })); + emplace_extension(h.header_extensions, finality_extension::extension_id(), + fc::raw::pack(finality_extension{ *qc_claim, {}, {} })); } return h; diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index 7643526313..a7be0c7ad3 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -69,8 +69,8 @@ block_state_ptr block_state::create_if_genesis_block(const block_state_legacy& b result.header = bsp.header; result.activated_protocol_features = bsp.activated_protocol_features; - assert(bsp.block->contains_header_extension(instant_finality_extension::extension_id())); // required by transition mechanism - instant_finality_extension if_ext = bsp.block->extract_header_extension(); + assert(bsp.block->contains_header_extension(finality_extension::extension_id())); // required by transition mechanism + finality_extension if_ext = bsp.block->extract_header_extension(); assert(if_ext.new_finalizer_policy_diff); // required by transition mechanism result.active_finalizer_policy = std::make_shared(finalizer_policy{}.apply_diff(std::move(*if_ext.new_finalizer_policy_diff))); @@ -299,10 +299,10 @@ void block_state::verify_qc(const valid_quorum_certificate& qc) const { } qc_claim_t block_state::extract_qc_claim() const { - auto itr = header_exts.lower_bound(instant_finality_extension::extension_id()); + auto itr = header_exts.lower_bound(finality_extension::extension_id()); if (itr == header_exts.end()) return {}; - const auto& if_ext = std::get(itr->second); + const auto& if_ext = std::get(itr->second); return if_ext.qc_claim; } diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 5578d89297..0fd693891d 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -1345,7 +1345,7 @@ struct controller_impl { } void transition_to_savanna() { - assert(chain_head.header().contains_header_extension(instant_finality_extension::extension_id())); + assert(chain_head.header().contains_header_extension(finality_extension::extension_id())); // copy head branch from legacy forkdb legacy to savanna forkdb if (check_shutdown()) return; @@ -1463,7 +1463,7 @@ struct controller_impl { root_id = (*bitr)->id(); if constexpr (std::is_same_v>) { - if ((*bitr)->header.contains_header_extension(instant_finality_extension::extension_id())) { + if ((*bitr)->header.contains_header_extension(finality_extension::extension_id())) { savanna_transition_required = true; // Do not advance irreversible past IF Genesis Block break; @@ -1591,7 +1591,7 @@ struct controller_impl { }); block_handle_accessor::apply_l(chain_head, [&](const auto& head) { // chain_head is updated via replay_push_block assert(!next->is_proper_svnn_block()); - if (next->contains_header_extension(instant_finality_extension::extension_id())) { + if (next->contains_header_extension(finality_extension::extension_id())) { assert(legacy_branch.empty() || head->block->previous == legacy_branch.back()->block->calculate_id()); legacy_branch.push_back(head); // note if is_proper_svnn_block is not reached then transistion will happen live @@ -1799,7 +1799,7 @@ struct controller_impl { init(startup_t::snapshot); block_handle_accessor::apply_l(chain_head, [&](auto& head) { - if (block_states.second && head->header.contains_header_extension(instant_finality_extension::extension_id())) { + if (block_states.second && head->header.contains_header_extension(finality_extension::extension_id())) { // snapshot generated in transition to savanna if (fork_db.version_in_use() == fork_database::in_use_t::legacy) { fork_db.switch_from_legacy(block_states.second); @@ -2055,7 +2055,7 @@ struct controller_impl { { return block_handle_accessor::apply(chain_head, overloaded{ [&](const block_state_legacy_ptr& head) -> block_state_pair { - if (head->header.contains_header_extension(instant_finality_extension::extension_id())) { + if (head->header.contains_header_extension(finality_extension::extension_id())) { // During transition to Savanna, we need to build Transition Savanna block // from Savanna Genesis block return { head, get_transition_savanna_block(head) }; @@ -3275,7 +3275,7 @@ struct controller_impl { if (auto* dm_logger = get_deep_mind_logger(false)) { block_handle_accessor::apply(chain_head, [&](const block_state_legacy_ptr& head) { - if (head->block->contains_header_extension(instant_finality_extension::extension_id())) { + if (head->block->contains_header_extension(finality_extension::extension_id())) { auto bsp = get_transition_savanna_block(head); assert(bsp); assert(bsp->active_finalizer_policy); @@ -3426,15 +3426,15 @@ struct controller_impl { if (b.header_extensions != ab.header_extensions) { flat_multimap bheader_exts = b.validate_and_extract_header_extensions(); - if (bheader_exts.count(instant_finality_extension::extension_id())) { + if (bheader_exts.count(finality_extension::extension_id())) { const auto& if_extension = - std::get(bheader_exts.lower_bound(instant_finality_extension::extension_id())->second); + std::get(bheader_exts.lower_bound(finality_extension::extension_id())->second); elog("b if: ${i}", ("i", if_extension)); } flat_multimap abheader_exts = ab.validate_and_extract_header_extensions(); - if (abheader_exts.count(instant_finality_extension::extension_id())) { + if (abheader_exts.count(finality_extension::extension_id())) { const auto& if_extension = - std::get(abheader_exts.lower_bound(instant_finality_extension::extension_id())->second); + std::get(abheader_exts.lower_bound(finality_extension::extension_id())->second); elog("ab if: ${i}", ("i", if_extension)); } } @@ -3445,8 +3445,8 @@ struct controller_impl { static std::optional extract_qc_data(const signed_block_ptr& b) { std::optional qc_data; auto hexts = b->validate_and_extract_header_extensions(); - if (auto if_entry = hexts.lower_bound(instant_finality_extension::extension_id()); if_entry != hexts.end()) { - auto& if_ext = std::get(if_entry->second); + if (auto if_entry = hexts.lower_bound(finality_extension::extension_id()); if_entry != hexts.end()) { + auto& if_ext = std::get(if_entry->second); // get the matching qc extension if present auto exts = b->validate_and_extract_extensions(); @@ -3711,14 +3711,14 @@ struct controller_impl { }); } - // Verify QC claim made by instant_finality_extension in header extension + // Verify QC claim made by finality_extension in header extension // and quorum_certificate_extension in block extension are valid. // Called from net-threads. It is thread safe as signed_block is never modified // after creation. // ----------------------------------------------------------------------------- void verify_qc_claim( const block_id_type& id, const signed_block_ptr& b, const block_header_state& prev ) { auto qc_ext_id = quorum_certificate_extension::extension_id(); - auto if_ext_id = instant_finality_extension::extension_id(); + auto if_ext_id = finality_extension::extension_id(); // extract current block extension and previous header extension auto block_exts = b->validate_and_extract_extensions(); @@ -3745,7 +3745,7 @@ struct controller_impl { } assert(header_ext); - const auto& if_ext = std::get(*header_ext); + const auto& if_ext = std::get(*header_ext); const auto new_qc_claim = if_ext.qc_claim; // If there is a header extension, but the previous block does not have a header extension, @@ -3765,7 +3765,7 @@ struct controller_impl { // ---------------------------------------------------------------------------------------- assert(header_ext && prev_header_ext); - const auto& prev_if_ext = std::get(*prev_header_ext); + const auto& prev_if_ext = std::get(*prev_header_ext); const auto prev_qc_claim = prev_if_ext.qc_claim; // validate QC claim against previous block QC info @@ -3832,7 +3832,7 @@ struct controller_impl { block_handle create_block_state_i( ForkDB& forkdb, const block_id_type& id, const signed_block_ptr& b, const BS& prev ) { constexpr bool savanna_mode = std::is_same_v, block_state>; if constexpr (savanna_mode) { - // Verify claim made by instant_finality_extension in block header extension and + // Verify claim made by finality_extension in block header extension and // quorum_certificate_extension in block extension are valid. // This is the only place the evaluation is done. verify_qc_claim(id, b, prev); @@ -4517,14 +4517,14 @@ struct controller_impl { // (where root() is updated), like in SHiP case where it is called // as a result receiving accepted_block signal. // Search both root and legacy_branch for the first block having - // instant_finality_extension -- the Savanna Genesis Block. + // finality_extension -- the Savanna Genesis Block. // Then start from the Savanna Genesis Block to create corresponding // Savanna blocks. - if (legacy_root->header.contains_header_extension(instant_finality_extension::extension_id())) { + if (legacy_root->header.contains_header_extension(finality_extension::extension_id())) { prev = block_state::create_if_genesis_block(*legacy_root); } else { for (; bitr != legacy_branch.rend(); ++bitr) { - if ((*bitr)->header.contains_header_extension(instant_finality_extension::extension_id())) { + if ((*bitr)->header.contains_header_extension(finality_extension::extension_id())) { prev = block_state::create_if_genesis_block(*(*bitr)); ++bitr; break; @@ -4561,7 +4561,7 @@ struct controller_impl { [&](const block_state_legacy_ptr& head) -> std::optional { // When in Legacy, if it is during transition to Savana, we need to // build finality_data for the corresponding Savanna block - if (head->header.contains_header_extension(instant_finality_extension::extension_id())) { + if (head->header.contains_header_extension(finality_extension::extension_id())) { // during transition return get_transition_block_finality_data(head); } else { diff --git a/libraries/chain/include/eosio/chain/abi_serializer.hpp b/libraries/chain/include/eosio/chain/abi_serializer.hpp index d11e014138..0820f38cea 100644 --- a/libraries/chain/include/eosio/chain/abi_serializer.hpp +++ b/libraries/chain/include/eosio/chain/abi_serializer.hpp @@ -637,7 +637,7 @@ namespace impl { out(name, std::move(mvo)); } - static void add_block_header_instant_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts ); + static void add_block_header_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts ); /** * overload of to_variant_object for signed_block @@ -679,7 +679,7 @@ namespace impl { std::get(header_exts.lower_bound(producer_schedule_change_extension::extension_id())->second); mvo("new_producer_schedule", new_producer_schedule); } - add_block_header_instant_finality_extension(mvo, header_exts); + add_block_header_finality_extension(mvo, header_exts); mvo("producer_signature", block.producer_signature); add(mvo, "transactions", block.transactions, resolver, ctx); diff --git a/libraries/chain/include/eosio/chain/block_header.hpp b/libraries/chain/include/eosio/chain/block_header.hpp index 8facfe2cba..c29752948c 100644 --- a/libraries/chain/include/eosio/chain/block_header.hpp +++ b/libraries/chain/include/eosio/chain/block_header.hpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -20,7 +20,7 @@ namespace eosio::chain { using block_header_extension_types = detail::block_header_extension_types< protocol_feature_activation, producer_schedule_change_extension, - instant_finality_extension + finality_extension >; using block_header_extension = block_header_extension_types::block_header_extension_t; diff --git a/libraries/chain/include/eosio/chain/block_header_state.hpp b/libraries/chain/include/eosio/chain/block_header_state.hpp index 7493026740..68bcd04970 100644 --- a/libraries/chain/include/eosio/chain/block_header_state.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/libraries/chain/include/eosio/chain/block_state.hpp b/libraries/chain/include/eosio/chain/block_state.hpp index df96f3b431..13e75d98ae 100644 --- a/libraries/chain/include/eosio/chain/block_state.hpp +++ b/libraries/chain/include/eosio/chain/block_state.hpp @@ -127,7 +127,7 @@ struct block_state : public block_header_state { // block_header_state provi std::optional get_best_qc() const { return pending_qc.get_best_qc(block_num()); } // thread safe bool valid_qc_is_strong() const { return pending_qc.valid_qc_is_strong(); } // thread safe void set_valid_qc(const valid_quorum_certificate& qc) { pending_qc.set_valid_qc(qc); } - // extract the qc_claim from block header instant_finality_extension + // extract the qc_claim from block header finality_extension qc_claim_t extract_qc_claim() const; // heuristic for determination if we are syncing or replaying for optimizations diff --git a/libraries/chain/include/eosio/chain/finality/instant_finality_extension.hpp b/libraries/chain/include/eosio/chain/finality/finality_extension.hpp similarity index 69% rename from libraries/chain/include/eosio/chain/finality/instant_finality_extension.hpp rename to libraries/chain/include/eosio/chain/finality/finality_extension.hpp index e3c893dc9c..ed1126b7e6 100644 --- a/libraries/chain/include/eosio/chain/finality/instant_finality_extension.hpp +++ b/libraries/chain/include/eosio/chain/finality/finality_extension.hpp @@ -6,12 +6,12 @@ namespace eosio::chain { -struct instant_finality_extension : fc::reflect_init { +struct finality_extension : fc::reflect_init { static constexpr uint16_t extension_id() { return 2; } static constexpr bool enforce_unique() { return true; } - instant_finality_extension() = default; - instant_finality_extension(qc_claim_t qc_claim, + finality_extension() = default; + finality_extension(qc_claim_t qc_claim, std::optional&& new_finalizer_policy_diff, std::optional&& new_proposer_policy_diff) : qc_claim(qc_claim), @@ -21,8 +21,8 @@ struct instant_finality_extension : fc::reflect_init { void reflector_init() const { static_assert( fc::raw::has_feature_reflector_init_on_unpacked_reflected_types, - "instant_finality_extension expects FC to support reflector_init" ); - static_assert( extension_id() == 2, "instant_finality_extension extension id must be 2" ); + "finality_extension expects FC to support reflector_init" ); + static_assert( extension_id() == 2, "finality_extension extension id must be 2" ); } qc_claim_t qc_claim; @@ -32,4 +32,4 @@ struct instant_finality_extension : fc::reflect_init { } /// eosio::chain -FC_REFLECT( eosio::chain::instant_finality_extension, (qc_claim)(new_finalizer_policy_diff)(new_proposer_policy_diff) ) +FC_REFLECT( eosio::chain::finality_extension, (qc_claim)(new_finalizer_policy_diff)(new_proposer_policy_diff) ) diff --git a/libraries/testing/include/eosio/testing/tester.hpp b/libraries/testing/include/eosio/testing/tester.hpp index ac85283d90..d6494ae903 100644 --- a/libraries/testing/include/eosio/testing/tester.hpp +++ b/libraries/testing/include/eosio/testing/tester.hpp @@ -907,7 +907,7 @@ namespace eosio::testing { // Do some sanity checks on the genesis block // ------------------------------------------ - const auto& ext = genesis_block->template extract_header_extension(); + const auto& ext = genesis_block->template extract_header_extension(); const auto& fin_policy_diff = ext.new_finalizer_policy_diff; BOOST_TEST(!!fin_policy_diff); BOOST_TEST(fin_policy_diff->finalizers_diff.insert_indexes.size() == fin_policy_size); diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 805fffe3d7..80048f97a1 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -673,10 +673,10 @@ namespace eosio { constexpr uint16_t proto_dup_node_id_goaway = 6; // eosio 2.1: support peer node_id based duplicate connection resolution constexpr uint16_t proto_leap_initial = 7; // leap client, needed because none of the 2.1 versions are supported constexpr uint16_t proto_block_range = 8; // include block range in notice_message - constexpr uint16_t proto_instant_finality = 9; // instant finality + constexpr uint16_t proto_savanna = 9; // savanna #pragma GCC diagnostic pop - constexpr uint16_t net_version_max = proto_instant_finality; + constexpr uint16_t net_version_max = proto_savanna; /** * Index by start_block_num @@ -2714,7 +2714,7 @@ namespace eosio { if( !cp->current() ) return true; if( cp->connection_id == exclude_peer ) return true; cp->strand.post( [cp, msg]() { - if (cp->protocol_version >= proto_instant_finality) { + if (cp->protocol_version >= proto_savanna) { if (vote_logger.is_enabled(fc::log_level::debug)) peer_dlog(cp, "sending vote msg"); cp->enqueue_buffer( msg, no_reason ); diff --git a/unittests/block_header_tests.cpp b/unittests/block_header_tests.cpp index 05551a7bc3..112aa3c854 100644 --- a/unittests/block_header_tests.cpp +++ b/unittests/block_header_tests.cpp @@ -9,12 +9,12 @@ BOOST_AUTO_TEST_SUITE(block_header_tests) BOOST_AUTO_TEST_CASE(block_header_without_extension_test) { block_header header; - std::optional ext = header.extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = header.extract_header_extension(finality_extension::extension_id()); BOOST_REQUIRE(!ext); } -// test for empty instant_finality_extension -BOOST_AUTO_TEST_CASE(instant_finality_extension_with_empty_values_test) +// test for empty finality_extension +BOOST_AUTO_TEST_CASE(finality_extension_with_empty_values_test) { block_header header; constexpr uint32_t last_qc_block_num {0}; @@ -22,30 +22,30 @@ BOOST_AUTO_TEST_CASE(instant_finality_extension_with_empty_values_test) emplace_extension( header.header_extensions, - instant_finality_extension::extension_id(), - fc::raw::pack( instant_finality_extension{qc_claim_t{last_qc_block_num, is_last_strong_qc}, + finality_extension::extension_id(), + fc::raw::pack( finality_extension{qc_claim_t{last_qc_block_num, is_last_strong_qc}, std::optional{}, std::optional{}} ) ); - std::optional ext = header.extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = header.extract_header_extension(finality_extension::extension_id()); BOOST_REQUIRE( !!ext ); - const auto& if_extension = std::get(*ext); + const auto& if_extension = std::get(*ext); BOOST_REQUIRE_EQUAL( if_extension.qc_claim.block_num, last_qc_block_num ); BOOST_REQUIRE_EQUAL( if_extension.qc_claim.is_strong_qc, is_last_strong_qc ); BOOST_REQUIRE( !if_extension.new_finalizer_policy_diff ); BOOST_REQUIRE( !if_extension.new_proposer_policy_diff ); } -// test for instant_finality_extension uniqueness -BOOST_AUTO_TEST_CASE(instant_finality_extension_uniqueness_test) +// test for finality_extension uniqueness +BOOST_AUTO_TEST_CASE(finality_extension_uniqueness_test) { block_header header; emplace_extension( header.header_extensions, - instant_finality_extension::extension_id(), - fc::raw::pack( instant_finality_extension{qc_claim_t{0, false}, {std::nullopt}, + finality_extension::extension_id(), + fc::raw::pack( finality_extension{qc_claim_t{0, false}, {std::nullopt}, std::optional{}} ) ); @@ -57,15 +57,15 @@ BOOST_AUTO_TEST_CASE(instant_finality_extension_uniqueness_test) emplace_extension( header.header_extensions, - instant_finality_extension::extension_id(), - fc::raw::pack( instant_finality_extension{qc_claim_t{100, true}, new_finalizer_policy_diff, new_proposer_policy_diff} ) + finality_extension::extension_id(), + fc::raw::pack( finality_extension{qc_claim_t{100, true}, new_finalizer_policy_diff, new_proposer_policy_diff} ) ); BOOST_CHECK_THROW(header.validate_and_extract_header_extensions(), invalid_block_header_extension); } -// test for instant_finality_extension with values -BOOST_AUTO_TEST_CASE(instant_finality_extension_with_values_test) +// test for finality_extension with values +BOOST_AUTO_TEST_CASE(finality_extension_with_values_test) { block_header header; constexpr uint32_t last_qc_block_num {10}; @@ -79,14 +79,14 @@ BOOST_AUTO_TEST_CASE(instant_finality_extension_with_values_test) emplace_extension( header.header_extensions, - instant_finality_extension::extension_id(), - fc::raw::pack( instant_finality_extension{qc_claim_t{last_qc_block_num, is_strong_qc}, new_finalizer_policy_diff, new_proposer_policy_diff} ) + finality_extension::extension_id(), + fc::raw::pack( finality_extension{qc_claim_t{last_qc_block_num, is_strong_qc}, new_finalizer_policy_diff, new_proposer_policy_diff} ) ); - std::optional ext = header.extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = header.extract_header_extension(finality_extension::extension_id()); BOOST_REQUIRE( !!ext ); - const auto& if_extension = std::get(*ext); + const auto& if_extension = std::get(*ext); BOOST_REQUIRE_EQUAL( if_extension.qc_claim.block_num, last_qc_block_num ); BOOST_REQUIRE_EQUAL( if_extension.qc_claim.is_strong_qc, is_strong_qc ); diff --git a/unittests/finality_proof.hpp b/unittests/finality_proof.hpp index 7c52dfc53b..4e0ba7b70b 100644 --- a/unittests/finality_proof.hpp +++ b/unittests/finality_proof.hpp @@ -71,8 +71,8 @@ namespace finality_proof { static qc_data_t extract_qc_data(const signed_block_ptr& b) { assert(b); auto hexts = b->validate_and_extract_header_extensions(); - if (auto if_entry = hexts.lower_bound(instant_finality_extension::extension_id()); if_entry != hexts.end()) { - auto& if_ext = std::get(if_entry->second); + if (auto if_entry = hexts.lower_bound(finality_extension::extension_id()); if_entry != hexts.end()) { + auto& if_ext = std::get(if_entry->second); // get the matching qc extension if present auto exts = b->validate_and_extract_extensions(); @@ -88,7 +88,7 @@ namespace finality_proof { static bool has_finalizer_policy_diffs(const signed_block_ptr& block){ // extract new finalizer policy - instant_finality_extension if_ext = block->extract_header_extension(); + finality_extension if_ext = block->extract_header_extension(); return if_ext.new_finalizer_policy_diff.has_value(); @@ -97,7 +97,7 @@ namespace finality_proof { static finalizer_policy update_finalizer_policy(const signed_block_ptr block, const finalizer_policy& current_policy){ // extract new finalizer policy - instant_finality_extension if_ext = block->extract_header_extension(); + finality_extension if_ext = block->extract_header_extension(); assert(if_ext.new_finalizer_policy_diff.has_value()); diff --git a/unittests/finality_tests.cpp b/unittests/finality_tests.cpp index 28f9cc688d..bf9bf62451 100644 --- a/unittests/finality_tests.cpp +++ b/unittests/finality_tests.cpp @@ -26,9 +26,9 @@ BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try { // this block contains the header extension for the instant finality, savanna activated when it is LIB auto block = t.produce_block(); - std::optional ext = block->extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = block->extract_header_extension(finality_extension::extension_id()); BOOST_TEST(!!ext); - std::optional fin_policy_diff = std::get(*ext).new_finalizer_policy_diff; + std::optional fin_policy_diff = std::get(*ext).new_finalizer_policy_diff; BOOST_TEST(!!fin_policy_diff); BOOST_TEST(fin_policy_diff->finalizers_diff.insert_indexes.size() == num_finalizers); BOOST_TEST(fin_policy_diff->generation == 1); @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try { auto fb = t.control->fetch_block_by_id(t.lib_id); BOOST_REQUIRE(!!fb); BOOST_TEST(fb->calculate_id() == t.lib_id); - ext = fb->extract_header_extension(instant_finality_extension::extension_id()); + ext = fb->extract_header_extension(finality_extension::extension_id()); BOOST_REQUIRE(!!ext); BOOST_TEST(if_genesis_block_id == fb->calculate_id()); @@ -75,9 +75,9 @@ void test_finality_transition(const vector& accounts, // this block contains the header extension for the instant finality, savanna activated when it is LIB auto block = t.produce_block(); - std::optional ext = block->extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = block->extract_header_extension(finality_extension::extension_id()); BOOST_TEST(!!ext); - std::optional fin_policy_diff = std::get(*ext).new_finalizer_policy_diff; + std::optional fin_policy_diff = std::get(*ext).new_finalizer_policy_diff; BOOST_TEST(!!fin_policy_diff); BOOST_TEST(fin_policy_diff->finalizers_diff.insert_indexes.size() == accounts.size()); BOOST_TEST(fin_policy_diff->generation == 1); @@ -92,7 +92,7 @@ void test_finality_transition(const vector& accounts, auto fb = t.control->fetch_block_by_id(t.lib_id); BOOST_REQUIRE(!!fb); BOOST_TEST(fb->calculate_id() == t.lib_id); - ext = fb->extract_header_extension(instant_finality_extension::extension_id()); + ext = fb->extract_header_extension(finality_extension::extension_id()); BOOST_REQUIRE(!!ext); BOOST_TEST(if_genesis_block_id == fb->calculate_id()); diff --git a/unittests/finalizer_update_tests.cpp b/unittests/finalizer_update_tests.cpp index 9c98bea9b1..3383f7a64d 100644 --- a/unittests/finalizer_update_tests.cpp +++ b/unittests/finalizer_update_tests.cpp @@ -74,9 +74,9 @@ BOOST_AUTO_TEST_CASE(savanna_set_finalizer_multiple_test) { try { size_t finset_size = 21u; auto verify_block_finality_policy_diff = [](const signed_block_ptr& block, uint32_t gen, const bls_public_key& key) { - std::optional ext = block->extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = block->extract_header_extension(finality_extension::extension_id()); BOOST_TEST(!!ext); - std::optional fin_policy_diff = std::get(*ext).new_finalizer_policy_diff; + std::optional fin_policy_diff = std::get(*ext).new_finalizer_policy_diff; BOOST_TEST(!!fin_policy_diff); BOOST_TEST(fin_policy_diff->generation == gen); // each set_finalizer_policy in this test removes one and adds one diff --git a/unittests/producer_schedule_if_tests.cpp b/unittests/producer_schedule_if_tests.cpp index c1f7272a72..93860444dc 100644 --- a/unittests/producer_schedule_if_tests.cpp +++ b/unittests/producer_schedule_if_tests.cpp @@ -21,7 +21,7 @@ inline account_name get_expected_producer(const vector& sche } // anonymous namespace // Use legacy_validating_tester because it transitions to savanna as part of the test. -BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activation, legacy_validating_tester ) try { +BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_savanna_activation, legacy_validating_tester ) try { // Utility function to ensure that producer schedule work as expected const auto& confirm_schedule_correctness = [&](const vector& new_prod_schd, uint32_t expected_schd_ver, uint32_t expected_block_num = 0) { @@ -71,7 +71,7 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activat }; create_accounts(producers); - // enable instant_finality + // enable savanna set_finalizers(producers); auto setfin_block = produce_block(); // this block contains the header extension of the finalizer set @@ -138,9 +138,9 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes }; auto verify_block_if_ext_producer = [](const signed_block_ptr& block, uint32_t version, account_name new_producer) { - std::optional ext = block->extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = block->extract_header_extension(finality_extension::extension_id()); BOOST_TEST(!!ext); - std::optional policy_diff = std::get(*ext).new_proposer_policy_diff; + std::optional policy_diff = std::get(*ext).new_proposer_policy_diff; BOOST_TEST_REQUIRE(!!policy_diff); BOOST_TEST(policy_diff->version == version); bool new_producer_in_insert = std::ranges::find_if(policy_diff->producer_auth_diff.insert_indexes, @@ -154,7 +154,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes produce_block(); } - // activate instant_finality + // activate savanna set_finalizers({"alice"_n,"bob"_n,"carol"_n}); produce_block(); // this block contains the header extension of the finalizer set produce_block(); // one producer, lib here @@ -218,9 +218,9 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes // test no change to active schedule set_producers( {"bob"_n,"alice"_n} ); // same as before, so no change b = produce_block(); - std::optional ext = b->extract_header_extension(instant_finality_extension::extension_id()); + std::optional ext = b->extract_header_extension(finality_extension::extension_id()); BOOST_TEST(!!ext); - std::optional policy_diff = std::get(*ext).new_proposer_policy_diff; + std::optional policy_diff = std::get(*ext).new_proposer_policy_diff; BOOST_TEST_REQUIRE(!policy_diff); // no diff produce_blocks(config::producer_repetitions-1, true); @@ -377,7 +377,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_misc_tests, legacy_validating_tester ) produce_block(); } - // activate instant_finality + // activate savanna set_finalizers({"alice"_n,"bob"_n}); produce_block(); // this block contains the header extension of the finalizer set produce_block(); // one producer, lib here @@ -409,7 +409,7 @@ BOOST_AUTO_TEST_CASE( switch_producers_test ) try { chain.create_accounts( accounts ); chain.produce_block(); - // activate instant_finality + // activate savanna chain.set_finalizers(accounts); chain.set_producers( accounts ); chain.produce_block(); diff --git a/unittests/vote_processor_tests.cpp b/unittests/vote_processor_tests.cpp index 37383c4f0f..d47fb9da4c 100644 --- a/unittests/vote_processor_tests.cpp +++ b/unittests/vote_processor_tests.cpp @@ -48,8 +48,8 @@ auto create_genesis_block_state() { // block 2 finalizer_policy_diff new_finalizer_policy_diff = finalizer_policy{}.create_diff(new_finalizer_policy); qc_claim_t initial_if_claim { .block_num = 2, .is_strong_qc = false }; - emplace_extension(block->header_extensions, instant_finality_extension::extension_id(), - fc::raw::pack(instant_finality_extension{ initial_if_claim, new_finalizer_policy_diff, {} })); + emplace_extension(block->header_extensions, finality_extension::extension_id(), + fc::raw::pack(finality_extension{ initial_if_claim, new_finalizer_policy_diff, {} })); producer_authority_schedule schedule = { 0, { producer_authority{block->producer, block_signing_authority_v0{ 1, {{pub_key, 1}} } } } }; auto genesis = std::make_shared(); From dae8e99875944a2b5c97057bc6fbb0e035368449 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 15 Jul 2024 08:14:51 -0500 Subject: [PATCH 2/2] GH-353 rename some variables --- libraries/chain/abi_serializer.cpp | 5 +-- libraries/chain/block_header_state.cpp | 34 ++++++++--------- libraries/chain/block_header_state_legacy.cpp | 5 +-- libraries/chain/block_state.cpp | 10 ++--- libraries/chain/controller.cpp | 32 ++++++++-------- .../eosio/chain/block_header_state.hpp | 2 +- unittests/block_header_tests.cpp | 32 ++++++++-------- unittests/finality_proof.hpp | 18 ++++----- ...pp => producer_schedule_savanna_tests.cpp} | 38 +++++++++---------- 9 files changed, 86 insertions(+), 90 deletions(-) rename unittests/{producer_schedule_if_tests.cpp => producer_schedule_savanna_tests.cpp} (94%) diff --git a/libraries/chain/abi_serializer.cpp b/libraries/chain/abi_serializer.cpp index c73356163b..a510445aa7 100644 --- a/libraries/chain/abi_serializer.cpp +++ b/libraries/chain/abi_serializer.cpp @@ -636,9 +636,8 @@ namespace eosio { namespace chain { void impl::abi_to_variant::add_block_header_finality_extension( mutable_variant_object& mvo, const header_extension_multimap& header_exts ) { if (header_exts.count(finality_extension::extension_id())) { - const auto& if_extension = - std::get(header_exts.lower_bound(finality_extension::extension_id())->second); - mvo("finality_extension", if_extension); + const auto& f_ext = std::get(header_exts.lower_bound(finality_extension::extension_id())->second); + mvo("finality_extension", f_ext); } } diff --git a/libraries/chain/block_header_state.cpp b/libraries/chain/block_header_state.cpp index 7e20d683b0..c6a6cdba0d 100644 --- a/libraries/chain/block_header_state.cpp +++ b/libraries/chain/block_header_state.cpp @@ -183,7 +183,7 @@ void evaluate_finalizer_policies_for_promotion(const block_header_state& prev, void finish_next(const block_header_state& prev, block_header_state& next_header_state, vector new_protocol_feature_activations, - finality_extension if_ext, + finality_extension f_ext, bool log) { // only log on assembled blocks, to avoid double logging // activated protocol features // --------------------------- @@ -210,8 +210,8 @@ void finish_next(const block_header_state& prev, } std::optional new_proposer_policy; - if (if_ext.new_proposer_policy_diff) { - new_proposer_policy = prev.get_last_proposed_proposer_policy().apply_diff(*if_ext.new_proposer_policy_diff); + if (f_ext.new_proposer_policy_diff) { + new_proposer_policy = prev.get_last_proposed_proposer_policy().apply_diff(*f_ext.new_proposer_policy_diff); } if (new_proposer_policy) { // called when assembling the block @@ -226,7 +226,7 @@ void finish_next(const block_header_state& prev, .timestamp = prev.timestamp(), .finalizer_policy_generation = prev.active_finalizer_policy->generation }; - next_header_state.core = prev.core.next(parent_block, if_ext.qc_claim); + next_header_state.core = prev.core.next(parent_block, f_ext.qc_claim); // finalizer policy // ---------------- @@ -236,8 +236,8 @@ void finish_next(const block_header_state& prev, next_header_state.last_pending_finalizer_policy_digest = fc::sha256::hash(next_header_state.get_last_pending_finalizer_policy()); - if (if_ext.new_finalizer_policy_diff) { - finalizer_policy new_finalizer_policy = prev.get_last_proposed_finalizer_policy().apply_diff(*if_ext.new_finalizer_policy_diff); + if (f_ext.new_finalizer_policy_diff) { + finalizer_policy new_finalizer_policy = prev.get_last_proposed_finalizer_policy().apply_diff(*f_ext.new_finalizer_policy_diff); // a new `finalizer_policy` was proposed in the previous block, and is present in the previous // block's header extensions. @@ -296,13 +296,13 @@ block_header_state block_header_state::next(block_header_state_input& input) con if (input.new_proposer_policy) { new_proposer_policy_diff = get_last_proposed_proposer_policy().create_diff(*input.new_proposer_policy); } - finality_extension new_if_ext { input.most_recent_ancestor_with_qc, - std::move(new_finalizer_policy_diff), - std::move(new_proposer_policy_diff) }; + finality_extension new_f_ext { input.most_recent_ancestor_with_qc, + std::move(new_finalizer_policy_diff), + std::move(new_proposer_policy_diff) }; - uint16_t if_ext_id = finality_extension::extension_id(); - emplace_extension(next_header_state.header.header_extensions, if_ext_id, fc::raw::pack(new_if_ext)); - next_header_state.header_exts.emplace(if_ext_id, new_if_ext); + uint16_t f_ext_id = finality_extension::extension_id(); + emplace_extension(next_header_state.header.header_extensions, f_ext_id, fc::raw::pack(new_f_ext)); + next_header_state.header_exts.emplace(f_ext_id, new_f_ext); // add protocol_feature_activation extension // ----------------------------------------- @@ -314,7 +314,7 @@ block_header_state block_header_state::next(block_header_state_input& input) con next_header_state.header_exts.emplace(ext_id, std::move(pfa_ext)); } - finish_next(*this, next_header_state, std::move(input.new_protocol_feature_activations), std::move(new_if_ext), true); + finish_next(*this, next_header_state, std::move(input.new_protocol_feature_activations), std::move(new_f_ext), true); return next_header_state; } @@ -355,13 +355,13 @@ block_header_state block_header_state::next(const signed_block_header& h, valida // -------------------------------------------------------------------- EOS_ASSERT(exts.count(finality_extension::extension_id()) > 0, invalid_block_header_extension, "Instant Finality Extension is expected to be present in all block headers after switch to IF"); - auto if_entry = exts.lower_bound(finality_extension::extension_id()); - const auto& if_ext = std::get(if_entry->second); + auto f_entry = exts.lower_bound(finality_extension::extension_id()); + const auto& f_ext = std::get(f_entry->second); if (h.is_proper_svnn_block()) { // if there is no Finality Tree Root associated with the block, // then this needs to validate that h.action_mroot is the empty digest - auto next_core_metadata = core.next_metadata(if_ext.qc_claim); + auto next_core_metadata = core.next_metadata(f_ext.qc_claim); bool no_finality_tree_associated = core.is_genesis_block_num(next_core_metadata.final_on_strong_qc_block_num); EOS_ASSERT(no_finality_tree_associated == h.action_mroot.empty(), block_validate_exception, @@ -371,7 +371,7 @@ block_header_state block_header_state::next(const signed_block_header& h, valida ("f", next_core_metadata.final_on_strong_qc_block_num)); }; - finish_next(*this, next_header_state, std::move(new_protocol_feature_activations), if_ext, false); + finish_next(*this, next_header_state, std::move(new_protocol_feature_activations), f_ext, false); return next_header_state; } diff --git a/libraries/chain/block_header_state_legacy.cpp b/libraries/chain/block_header_state_legacy.cpp index b4ba6001fb..15b453a7f3 100644 --- a/libraries/chain/block_header_state_legacy.cpp +++ b/libraries/chain/block_header_state_legacy.cpp @@ -157,10 +157,9 @@ namespace eosio::chain { } if (header_exts.count(finality_extension::extension_id())) { // transition to savanna has started - const auto& if_extension = - std::get(header_exts.lower_bound(finality_extension::extension_id())->second); + const auto& f_ext = std::get(header_exts.lower_bound(finality_extension::extension_id())->second); // copy over qc_claim from IF Genesis Block - result.qc_claim = if_extension.qc_claim; + result.qc_claim = f_ext.qc_claim; } return result; diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index a7be0c7ad3..ee0d88beef 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -70,9 +70,9 @@ block_state_ptr block_state::create_if_genesis_block(const block_state_legacy& b result.activated_protocol_features = bsp.activated_protocol_features; assert(bsp.block->contains_header_extension(finality_extension::extension_id())); // required by transition mechanism - finality_extension if_ext = bsp.block->extract_header_extension(); - assert(if_ext.new_finalizer_policy_diff); // required by transition mechanism - result.active_finalizer_policy = std::make_shared(finalizer_policy{}.apply_diff(std::move(*if_ext.new_finalizer_policy_diff))); + finality_extension f_ext = bsp.block->extract_header_extension(); + assert(f_ext.new_finalizer_policy_diff); // required by transition mechanism + result.active_finalizer_policy = std::make_shared(finalizer_policy{}.apply_diff(std::move(*f_ext.new_finalizer_policy_diff))); block_ref genesis_block_ref { .block_id = bsp.id(), @@ -302,8 +302,8 @@ qc_claim_t block_state::extract_qc_claim() const { auto itr = header_exts.lower_bound(finality_extension::extension_id()); if (itr == header_exts.end()) return {}; - const auto& if_ext = std::get(itr->second); - return if_ext.qc_claim; + const auto& f_ext = std::get(itr->second); + return f_ext.qc_claim; } valid_t block_state::new_valid(const block_header_state& next_bhs, const digest_type& action_mroot, const digest_type& strong_digest) const { diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 0fd693891d..115cec3a2d 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -3427,15 +3427,13 @@ struct controller_impl { if (b.header_extensions != ab.header_extensions) { flat_multimap bheader_exts = b.validate_and_extract_header_extensions(); if (bheader_exts.count(finality_extension::extension_id())) { - const auto& if_extension = - std::get(bheader_exts.lower_bound(finality_extension::extension_id())->second); - elog("b if: ${i}", ("i", if_extension)); + const auto& f_ext = std::get(bheader_exts.lower_bound(finality_extension::extension_id())->second); + elog("b if: ${i}", ("i", f_ext)); } flat_multimap abheader_exts = ab.validate_and_extract_header_extensions(); if (abheader_exts.count(finality_extension::extension_id())) { - const auto& if_extension = - std::get(abheader_exts.lower_bound(finality_extension::extension_id())->second); - elog("ab if: ${i}", ("i", if_extension)); + const auto& f_ext = std::get(abheader_exts.lower_bound(finality_extension::extension_id())->second); + elog("ab if: ${i}", ("i", f_ext)); } } @@ -3445,16 +3443,16 @@ struct controller_impl { static std::optional extract_qc_data(const signed_block_ptr& b) { std::optional qc_data; auto hexts = b->validate_and_extract_header_extensions(); - if (auto if_entry = hexts.lower_bound(finality_extension::extension_id()); if_entry != hexts.end()) { - auto& if_ext = std::get(if_entry->second); + if (auto f_entry = hexts.lower_bound(finality_extension::extension_id()); f_entry != hexts.end()) { + auto& f_ext = std::get(f_entry->second); // get the matching qc extension if present auto exts = b->validate_and_extract_extensions(); if (auto entry = exts.lower_bound(quorum_certificate_extension::extension_id()); entry != exts.end()) { auto& qc_ext = std::get(entry->second); - return qc_data_t{ std::move(qc_ext.qc), if_ext.qc_claim }; + return qc_data_t{ std::move(qc_ext.qc), f_ext.qc_claim }; } - return qc_data_t{ {}, if_ext.qc_claim }; + return qc_data_t{ {}, f_ext.qc_claim }; } return {}; } @@ -3718,12 +3716,12 @@ struct controller_impl { // ----------------------------------------------------------------------------- void verify_qc_claim( const block_id_type& id, const signed_block_ptr& b, const block_header_state& prev ) { auto qc_ext_id = quorum_certificate_extension::extension_id(); - auto if_ext_id = finality_extension::extension_id(); + auto f_ext_id = finality_extension::extension_id(); // extract current block extension and previous header extension auto block_exts = b->validate_and_extract_extensions(); - std::optional prev_header_ext = prev.header.extract_header_extension(if_ext_id); - std::optional header_ext = b->extract_header_extension(if_ext_id); + std::optional prev_header_ext = prev.header.extract_header_extension(f_ext_id); + std::optional header_ext = b->extract_header_extension(f_ext_id); bool qc_extension_present = block_exts.count(qc_ext_id) != 0; uint32_t block_num = b->block_num(); @@ -3745,8 +3743,8 @@ struct controller_impl { } assert(header_ext); - const auto& if_ext = std::get(*header_ext); - const auto new_qc_claim = if_ext.qc_claim; + const auto& f_ext = std::get(*header_ext); + const auto new_qc_claim = f_ext.qc_claim; // If there is a header extension, but the previous block does not have a header extension, // ensure the block does not have a QC and the QC claim of the current block has a block_num @@ -3765,8 +3763,8 @@ struct controller_impl { // ---------------------------------------------------------------------------------------- assert(header_ext && prev_header_ext); - const auto& prev_if_ext = std::get(*prev_header_ext); - const auto prev_qc_claim = prev_if_ext.qc_claim; + const auto& prev_f_ext = std::get(*prev_header_ext); + const auto prev_qc_claim = prev_f_ext.qc_claim; // validate QC claim against previous block QC info diff --git a/libraries/chain/include/eosio/chain/block_header_state.hpp b/libraries/chain/include/eosio/chain/block_header_state.hpp index 68bcd04970..e5179a4832 100644 --- a/libraries/chain/include/eosio/chain/block_header_state.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state.hpp @@ -91,7 +91,7 @@ struct block_header_state { std::optional> pending_finalizer_policy; // generation increases by one each time a new finalizer_policy is proposed in a block - // It matches the finalizer policy generation most recently included in this block's `if_extension` or its ancestors + // It matches the finalizer policy generation most recently included in this block's `finality_extension` or its ancestors uint32_t finalizer_policy_generation{1}; // digest of the finalizer policy (which includes the generation number in it) with the greatest generation number diff --git a/unittests/block_header_tests.cpp b/unittests/block_header_tests.cpp index 112aa3c854..b27d72ec76 100644 --- a/unittests/block_header_tests.cpp +++ b/unittests/block_header_tests.cpp @@ -30,11 +30,11 @@ BOOST_AUTO_TEST_CASE(finality_extension_with_empty_values_test) std::optional ext = header.extract_header_extension(finality_extension::extension_id()); BOOST_REQUIRE( !!ext ); - const auto& if_extension = std::get(*ext); - BOOST_REQUIRE_EQUAL( if_extension.qc_claim.block_num, last_qc_block_num ); - BOOST_REQUIRE_EQUAL( if_extension.qc_claim.is_strong_qc, is_last_strong_qc ); - BOOST_REQUIRE( !if_extension.new_finalizer_policy_diff ); - BOOST_REQUIRE( !if_extension.new_proposer_policy_diff ); + const auto& f_ext = std::get(*ext); + BOOST_REQUIRE_EQUAL( f_ext.qc_claim.block_num, last_qc_block_num ); + BOOST_REQUIRE_EQUAL( f_ext.qc_claim.is_strong_qc, is_last_strong_qc ); + BOOST_REQUIRE( !f_ext.new_finalizer_policy_diff ); + BOOST_REQUIRE( !f_ext.new_proposer_policy_diff ); } // test for finality_extension uniqueness @@ -86,20 +86,20 @@ BOOST_AUTO_TEST_CASE(finality_extension_with_values_test) std::optional ext = header.extract_header_extension(finality_extension::extension_id()); BOOST_REQUIRE( !!ext ); - const auto& if_extension = std::get(*ext); + const auto& f_ext = std::get(*ext); - BOOST_REQUIRE_EQUAL( if_extension.qc_claim.block_num, last_qc_block_num ); - BOOST_REQUIRE_EQUAL( if_extension.qc_claim.is_strong_qc, is_strong_qc ); + BOOST_REQUIRE_EQUAL( f_ext.qc_claim.block_num, last_qc_block_num ); + BOOST_REQUIRE_EQUAL( f_ext.qc_claim.is_strong_qc, is_strong_qc ); - BOOST_REQUIRE( !!if_extension.new_finalizer_policy_diff ); - BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->generation, 1u); - BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->threshold, 100u); - BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.description, "test description"); - BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.weight, 50u); - BOOST_REQUIRE_EQUAL(if_extension.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.public_key.to_string(), "PUB_BLS_qVbh4IjYZpRGo8U_0spBUM-u-r_G0fMo4MzLZRsKWmm5uyeQTp74YFaMN9IDWPoVVT5rj_Tw1gvps6K9_OZ6sabkJJzug3uGfjA6qiaLbLh5Fnafwv-nVgzzzBlU2kwRrcHc8Q"); + BOOST_REQUIRE( !!f_ext.new_finalizer_policy_diff ); + BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->generation, 1u); + BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->threshold, 100u); + BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.description, "test description"); + BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.weight, 50u); + BOOST_REQUIRE_EQUAL(f_ext.new_finalizer_policy_diff->finalizers_diff.insert_indexes[0].second.public_key.to_string(), "PUB_BLS_qVbh4IjYZpRGo8U_0spBUM-u-r_G0fMo4MzLZRsKWmm5uyeQTp74YFaMN9IDWPoVVT5rj_Tw1gvps6K9_OZ6sabkJJzug3uGfjA6qiaLbLh5Fnafwv-nVgzzzBlU2kwRrcHc8Q"); - BOOST_REQUIRE( !!if_extension.new_proposer_policy_diff ); - fc::time_point t = (fc::time_point)(if_extension.new_proposer_policy_diff->active_time); + BOOST_REQUIRE( !!f_ext.new_proposer_policy_diff ); + fc::time_point t = (fc::time_point)(f_ext.new_proposer_policy_diff->active_time); BOOST_REQUIRE_EQUAL(t.time_since_epoch().to_seconds(), 946684900ll); } diff --git a/unittests/finality_proof.hpp b/unittests/finality_proof.hpp index 4e0ba7b70b..37166441e9 100644 --- a/unittests/finality_proof.hpp +++ b/unittests/finality_proof.hpp @@ -71,16 +71,16 @@ namespace finality_proof { static qc_data_t extract_qc_data(const signed_block_ptr& b) { assert(b); auto hexts = b->validate_and_extract_header_extensions(); - if (auto if_entry = hexts.lower_bound(finality_extension::extension_id()); if_entry != hexts.end()) { - auto& if_ext = std::get(if_entry->second); + if (auto f_entry = hexts.lower_bound(finality_extension::extension_id()); f_entry != hexts.end()) { + auto& f_ext = std::get(f_entry->second); // get the matching qc extension if present auto exts = b->validate_and_extract_extensions(); if (auto entry = exts.lower_bound(quorum_certificate_extension::extension_id()); entry != exts.end()) { auto& qc_ext = std::get(entry->second); - return qc_data_t{ std::move(qc_ext.qc), if_ext.qc_claim }; + return qc_data_t{ std::move(qc_ext.qc), f_ext.qc_claim }; } - return qc_data_t{ {}, if_ext.qc_claim }; + return qc_data_t{ {}, f_ext.qc_claim }; } return {}; } @@ -88,21 +88,21 @@ namespace finality_proof { static bool has_finalizer_policy_diffs(const signed_block_ptr& block){ // extract new finalizer policy - finality_extension if_ext = block->extract_header_extension(); + finality_extension f_ext = block->extract_header_extension(); - return if_ext.new_finalizer_policy_diff.has_value(); + return f_ext.new_finalizer_policy_diff.has_value(); } static finalizer_policy update_finalizer_policy(const signed_block_ptr block, const finalizer_policy& current_policy){ // extract new finalizer policy - finality_extension if_ext = block->extract_header_extension(); + finality_extension f_ext = block->extract_header_extension(); - assert(if_ext.new_finalizer_policy_diff.has_value()); + assert(f_ext.new_finalizer_policy_diff.has_value()); finalizer_policy active_finalizer_policy = - current_policy.apply_diff(if_ext.new_finalizer_policy_diff.value()); + current_policy.apply_diff(f_ext.new_finalizer_policy_diff.value()); return active_finalizer_policy; diff --git a/unittests/producer_schedule_if_tests.cpp b/unittests/producer_schedule_savanna_tests.cpp similarity index 94% rename from unittests/producer_schedule_if_tests.cpp rename to unittests/producer_schedule_savanna_tests.cpp index 93860444dc..7da9f42b70 100644 --- a/unittests/producer_schedule_if_tests.cpp +++ b/unittests/producer_schedule_savanna_tests.cpp @@ -8,7 +8,7 @@ using namespace eosio::testing; using namespace eosio::chain; using mvo = fc::mutable_variant_object; -BOOST_AUTO_TEST_SUITE(producer_schedule_if_tests) +BOOST_AUTO_TEST_SUITE(producer_schedule_savanna_tests) namespace { @@ -137,7 +137,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes fc::mutable_variant_object()("schedule", schedule_variant), DEFAULT_EXPIRATION_DELTA + (++unique)); }; - auto verify_block_if_ext_producer = [](const signed_block_ptr& block, uint32_t version, account_name new_producer) { + auto verify_block_finality_ext_producer = [](const signed_block_ptr& block, uint32_t version, account_name new_producer) { std::optional ext = block->extract_header_extension(finality_extension::extension_id()); BOOST_TEST(!!ext); std::optional policy_diff = std::get(*ext).new_proposer_policy_diff; @@ -168,7 +168,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes // set a new proposer policy sch1 set_producers( {"alice"_n} ); auto b = produce_block(); - verify_block_if_ext_producer(b, 1, "alice"_n); + verify_block_finality_ext_producer(b, 1, "alice"_n); vector alice_sch = { producer_authority{"alice"_n, block_signing_authority_v0{1, {{get_public_key("alice"_n, "active"), 1}}}} }; @@ -187,7 +187,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes producer_authority{"carol"_n, block_signing_authority_v0{ 1, {{get_public_key("carol"_n, "active"),1}}}} }; b = produce_block(); - verify_block_if_ext_producer(b, 2u, "bob"_n); + verify_block_finality_ext_producer(b, 2u, "bob"_n); // set another ploicy should replace sch2 set_producers( {"bob"_n,"alice"_n} ); @@ -196,7 +196,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes producer_authority{"alice"_n, block_signing_authority_v0{ 1, {{get_public_key("alice"_n, "active"),1}}}} }; b = produce_block(); - verify_block_if_ext_producer(b, 3u, "alice"_n); + verify_block_finality_ext_producer(b, 3u, "alice"_n); // another round produce_blocks(config::producer_repetitions-2, true); // -2, already produced tow of the round above @@ -248,11 +248,11 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes // test change in same block where there is an existing proposed that is the same set_producers( {"bob"_n,"alice"_n} ); b = produce_block(); - verify_block_if_ext_producer(b, 5u, "alice"_n); + verify_block_finality_ext_producer(b, 5u, "alice"_n); set_producers( {"bob"_n,"carol"_n} ); set_producers_force({"bob"_n,"carol"_n} ); b = produce_block(); - verify_block_if_ext_producer(b, 6u, "carol"_n); + verify_block_finality_ext_producer(b, 6u, "carol"_n); produce_blocks(config::producer_repetitions-2, true); produce_blocks(config::producer_repetitions, true); BOOST_CHECK_EQUAL( 6u, control->active_producers().version ); // should be 6 now as bob,carol now active @@ -283,10 +283,10 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes produce_block(); set_producers({"bob"_n,"carol"_n}); // B2 b = produce_block(); - verify_block_if_ext_producer(b, 8u, "bob"_n); + verify_block_finality_ext_producer(b, 8u, "bob"_n); set_producers({"bob"_n, "alice"_n} ); // P3 b = produce_block(); - verify_block_if_ext_producer(b, 9u, "alice"_n); + verify_block_finality_ext_producer(b, 9u, "alice"_n); produce_blocks(config::producer_repetitions-3, true); // B12 produce_block(); // C1 BOOST_CHECK_EQUAL( 7u, control->active_producers().version ); @@ -307,15 +307,15 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes produce_block(); set_producers({"bob"_n,"carol"_n}); // A2, P1 b = produce_block(); - verify_block_if_ext_producer(b, 10u, "carol"_n); + verify_block_finality_ext_producer(b, 10u, "carol"_n); produce_blocks(config::producer_repetitions-2, true); // A12 produce_block(); set_producers({"alice"_n}); // B2 b = produce_block(); - verify_block_if_ext_producer(b, 11u, "alice"_n); + verify_block_finality_ext_producer(b, 11u, "alice"_n); set_producers({"bob"_n,"carol"_n}); // P3 == P1 b = produce_block(); - verify_block_if_ext_producer(b, 12u, "bob"_n); + verify_block_finality_ext_producer(b, 12u, "bob"_n); produce_blocks(config::producer_repetitions-3, true); // B12 produce_block(); // C1 BOOST_CHECK_EQUAL( 10u, control->active_producers().version ); @@ -334,32 +334,32 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, legacy_validating_tes produce_block(); // 2 set_producers({"alice"_n}); b = produce_block(); // 3 - verify_block_if_ext_producer(b, 13u, "alice"_n); + verify_block_finality_ext_producer(b, 13u, "alice"_n); set_producers({"carol"_n,"alice"_n}); b = produce_block(); // 4 - verify_block_if_ext_producer(b, 14u, "carol"_n); + verify_block_finality_ext_producer(b, 14u, "carol"_n); set_producers({"carol"_n}); produce_block(); // 5 set_producers({"alice"_n}); b = produce_block(); // 6 - verify_block_if_ext_producer(b, 16u, "alice"_n); + verify_block_finality_ext_producer(b, 16u, "alice"_n); set_producers({"bob"_n,"carol"_n}); b = produce_block(); - verify_block_if_ext_producer(b, 17u, "bob"_n); + verify_block_finality_ext_producer(b, 17u, "bob"_n); produce_blocks(config::producer_repetitions-7, true); set_producers({"bob"_n}); produce_block(); // 2 set_producers({"bob"_n,"carol"_n}); b = produce_block(); // 3 - verify_block_if_ext_producer(b, 19u, "carol"_n); + verify_block_finality_ext_producer(b, 19u, "carol"_n); set_producers({"carol"_n,"bob"_n}); produce_block(); // 4 set_producers({"alice"_n} ); b = produce_block(); // 5 - verify_block_if_ext_producer(b, 21u, "alice"_n); + verify_block_finality_ext_producer(b, 21u, "alice"_n); set_producers({"bob"_n,"carol"_n}); b = produce_block(); - verify_block_if_ext_producer(b, 22u, "bob"_n); + verify_block_finality_ext_producer(b, 22u, "bob"_n); produce_blocks(config::producer_repetitions-6, true); // B12 BOOST_CHECK_EQUAL( 17u, control->active_producers().version ); BOOST_CHECK_EQUAL( true, compare_schedules( bob_carol_sch, control->active_producers() ) );