Skip to content

Commit

Permalink
GH-2045 Fix proposer_policy switching time. Enable instant-finality p…
Browse files Browse the repository at this point in the history
…roducer schedule test.
  • Loading branch information
heifner committed Jan 15, 2024
1 parent 9b39982 commit 03f2322
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ block_header_state block_header_state::next(block_header_state_input& input) con

if (input.new_proposer_policy) {
// called when assembling the block
result.proposer_policies[result.header.timestamp] = input.new_proposer_policy;
result.proposer_policies[input.new_proposer_policy->active_time] = input.new_proposer_policy;
}

// finalizer policy
Expand Down
39 changes: 16 additions & 23 deletions unittests/producer_schedule_hs_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

#include <boost/test/unit_test.hpp>

#include "fork_test_utilities.hpp"

using namespace eosio::testing;
using namespace eosio::chain;
using mvo = fc::mutable_variant_object;

BOOST_AUTO_TEST_SUITE(producer_schedule_hs_tests)
BOOST_AUTO_TEST_SUITE(producer_schedule_if_tests)

namespace {

Expand All @@ -20,19 +18,16 @@ inline account_name get_expected_producer(const vector<producer_authority>& sche
};

} // anonymous namespace
#if 0

// [greg todo] Enable test when https://github.com/AntelopeIO/leap/issues/1980 is completed

BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_hotstuff_activation, validating_tester ) try {
BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activation, validating_tester ) try {

// Utility function to ensure that producer schedule work as expected
const auto& confirm_schedule_correctness = [&](const vector<producer_authority>& new_prod_schd, uint32_t expected_schd_ver, uint32_t expected_block_num = 0) {
const uint32_t check_duration = 100; // number of blocks
bool scheduled_changed_to_new = false;
for (uint32_t i = 0; i < check_duration; ++i) {
const auto current_schedule = control->head_block_state()->active_schedule.producers;
if (new_prod_schd == current_schedule) {
const auto current_schedule = control->active_producers();
if (new_prod_schd == current_schedule.producers) {
scheduled_changed_to_new = true;
if (expected_block_num != 0)
BOOST_TEST(control->head_block_num() == expected_block_num);
Expand All @@ -42,7 +37,7 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_hotstuff_activation, val

// Check if the producer is the same as what we expect
const auto block_time = control->head_block_time();
const auto& expected_producer = get_expected_producer(current_schedule, block_time);
const auto& expected_producer = get_expected_producer(current_schedule.producers, block_time);
BOOST_TEST(control->head_block_producer() == expected_producer);

if (scheduled_changed_to_new)
Expand All @@ -69,17 +64,17 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_hotstuff_activation, val
};
create_accounts(producers);

// activate hotstuff
// activate instant_finality
set_finalizers(producers);
auto block = produce_block(); // this block contains the header extension of the finalizer set
BOOST_TEST(lib == 3);
BOOST_TEST(lib == 4); // TODO: currently lib advances immediately on set_finalizers

// ---- Test first set of producers ----
// Send set prods action and confirm schedule correctness
set_producers(producers);
const auto first_prod_schd = get_producer_authorities(producers);
// TODO: update expected when lib for hotstuff is working, will change from 22 at that time
confirm_schedule_correctness(first_prod_schd, 1, 22);
// TODO: update expected when lib for instant_finality is working, will change from 26 at that time, 4+12+12
confirm_schedule_correctness(first_prod_schd, 1, 26);

// ---- Test second set of producers ----
vector<account_name> second_set_of_producer = {
Expand All @@ -88,8 +83,8 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_hotstuff_activation, val
// Send set prods action and confirm schedule correctness
set_producers(second_set_of_producer);
const auto second_prod_schd = get_producer_authorities(second_set_of_producer);
// TODO: update expected when lib for hotstuff is working, will change from 44 at that time
confirm_schedule_correctness(second_prod_schd, 2, 44);
// TODO: update expected when lib for instant_finality is working, will change from 50 at that time, 26+12+12
confirm_schedule_correctness(second_prod_schd, 2, 50);

// ---- Test deliberately miss some blocks ----
const int64_t num_of_missed_blocks = 5000;
Expand All @@ -111,17 +106,15 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_hotstuff_activation, val

} FC_LOG_AND_RETHROW()

#endif

/** TODO: Enable tests after hotstuff LIB is working
/** TODO: Enable tests after instant_finality LIB is working
BOOST_FIXTURE_TEST_CASE( producer_schedule_promotion_test, validating_tester ) try {
create_accounts( {"alice"_n,"bob"_n,"carol"_n} );
while (control->head_block_num() < 3) {
produce_block();
}
// activate hotstuff
// activate instant_finality
set_finalizers({"alice"_n,"bob"_n,"carol"_n});
auto block = produce_block(); // this block contains the header extension of the finalizer set
Expand Down Expand Up @@ -190,7 +183,7 @@ BOOST_AUTO_TEST_CASE( producer_watermark_test ) try {
c.create_accounts( {"alice"_n,"bob"_n,"carol"_n} );
c.produce_block();
// activate hotstuff
// activate instant_finality
c.set_finalizers({"alice"_n,"bob"_n,"carol"_n});
auto block = c.produce_block(); // this block contains the header extension of the finalizer set
Expand Down Expand Up @@ -309,7 +302,7 @@ BOOST_FIXTURE_TEST_CASE( producer_one_of_n_test, validating_tester ) try {
create_accounts( {"alice"_n,"bob"_n} );
produce_block();
// activate hotstuff
// activate instant_finality
set_finalizers({"alice"_n,"bob"_n});
auto block = produce_block(); // this block contains the header extension of the finalizer set
Expand All @@ -331,7 +324,7 @@ BOOST_FIXTURE_TEST_CASE( producer_m_of_n_test, validating_tester ) try {
create_accounts( {"alice"_n,"bob"_n} );
produce_block();
// activate hotstuff
// activate instant_finality
set_finalizers({"alice"_n,"bob"_n});
auto block = produce_block(); // this block contains the header extension of the finalizer set
Expand Down

0 comments on commit 03f2322

Please sign in to comment.