From e8d10a389921366d18b6a407440d31c950f51457 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 27 Mar 2024 14:02:57 -0500 Subject: [PATCH 1/2] GH-2313 When a proposed producer schedule will replace an existing one, do not increase version --- libraries/chain/controller.cpp | 4 ++++ unittests/producer_schedule_if_tests.cpp | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 6017c148e1..6be12ec030 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -479,6 +479,10 @@ struct building_block { uint32_t get_next_proposer_schedule_version() const { if (!parent.proposer_policies.empty()) { + block_timestamp_type active_time = detail::get_next_next_round_block_time(timestamp); + if (auto itr = parent.proposer_policies.find(active_time); itr != parent.proposer_policies.cend()) { + return itr->second->proposer_schedule.version; // will replace so retrun same version + } return (--parent.proposer_policies.end())->second->proposer_schedule.version + 1; } assert(active_proposer_policy); diff --git a/unittests/producer_schedule_if_tests.cpp b/unittests/producer_schedule_if_tests.cpp index 1bee246560..b87bcd2477 100644 --- a/unittests/producer_schedule_if_tests.cpp +++ b/unittests/producer_schedule_if_tests.cpp @@ -127,6 +127,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t vector prev_sch = { producer_authority{"eosio"_n, block_signing_authority_v0{1, {{get_public_key("eosio"_n, "active"), 1}}}}}; BOOST_CHECK_EQUAL( true, compare_schedules( prev_sch, control->active_producers() ) ); + BOOST_CHECK_EQUAL( 0, control->active_producers().version ); // set a new proposer policy sch1 set_producers( {"alice"_n} ); @@ -138,6 +139,7 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t produce_blocks(config::producer_repetitions); // sch1 cannot become active before one round of production + BOOST_CHECK_EQUAL( 0, control->active_producers().version ); BOOST_CHECK_EQUAL( true, compare_schedules( prev_sch, control->active_producers() ) ); // set another ploicy to have multiple pending different active time policies @@ -146,9 +148,17 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t producer_authority{"bob"_n, block_signing_authority_v0{ 1, {{get_public_key("bob"_n, "active"),1}}}}, producer_authority{"carol"_n, block_signing_authority_v0{ 1, {{get_public_key("carol"_n, "active"),1}}}} }; + produce_block(); + + // set another ploicy should replace sch2 + set_producers( {"bob"_n,"alice"_n} ); + vector sch3 = { + producer_authority{"bob"_n, block_signing_authority_v0{ 1, {{get_public_key("bob"_n, "active"),1}}}}, + producer_authority{"alice"_n, block_signing_authority_v0{ 1, {{get_public_key("alice"_n, "active"),1}}}} + }; // another round - produce_blocks(config::producer_repetitions); + produce_blocks(config::producer_repetitions-1); // -1, already produced one of the round above // sch1 must become active no later than 2 rounds but sch2 cannot become active yet BOOST_CHECK_EQUAL( control->active_producers().version, 1u ); @@ -156,9 +166,9 @@ BOOST_FIXTURE_TEST_CASE( proposer_policy_progression_test, validating_tester ) t produce_blocks(config::producer_repetitions); - // sch2 becomes active - BOOST_CHECK_EQUAL( control->active_producers().version, 2u ); - BOOST_CHECK_EQUAL( true, compare_schedules( sch2, control->active_producers() ) ); + // sch3 becomes active + BOOST_CHECK_EQUAL( 2u, control->active_producers().version ); // should be 2 as sch2 was replaced by sch3 + BOOST_CHECK_EQUAL( true, compare_schedules( sch3, control->active_producers() ) ); } FC_LOG_AND_RETHROW() From bf04b0a266b69eef972d3bed4c67a609ac324928 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 28 Mar 2024 07:58:35 -0500 Subject: [PATCH 2/2] GH-2313 Fix spelling --- libraries/chain/controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index 6be12ec030..2658584cee 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -481,7 +481,7 @@ struct building_block { if (!parent.proposer_policies.empty()) { block_timestamp_type active_time = detail::get_next_next_round_block_time(timestamp); if (auto itr = parent.proposer_policies.find(active_time); itr != parent.proposer_policies.cend()) { - return itr->second->proposer_schedule.version; // will replace so retrun same version + return itr->second->proposer_schedule.version; // will replace so return same version } return (--parent.proposer_policies.end())->second->proposer_schedule.version + 1; }