Skip to content

Commit

Permalink
Merge pull request #2122 from AntelopeIO/GH-1580-confirmed
Browse files Browse the repository at this point in the history
IF: confirmed==0 after instant finality enabled
  • Loading branch information
heifner authored Jan 22, 2024
2 parents 016ef65 + d750db9 commit 405ce52
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ block_header_state block_header_state::next(block_header_state_input& input) con
result.header = block_header {
.timestamp = input.timestamp, // [greg todo] do we have to do the slot++ stuff from the legacy version?
.producer = input.producer,
.confirmed = hs_block_confirmed, // todo: consider 0 instead
.confirmed = 0,
.previous = input.parent_id,
.transaction_mroot = input.transaction_mroot,
.action_mroot = input.action_mroot,
Expand Down Expand Up @@ -173,6 +173,7 @@ block_header_state block_header_state::next(const signed_block_header& h, const

EOS_ASSERT( h.previous == id, unlinkable_block_exception, "previous mismatch" );
EOS_ASSERT( h.producer == producer, wrong_producer, "wrong producer specified" );
EOS_ASSERT( h.confirmed == 0, block_validate_exception, "invalid confirmed ${c}", ("c", h.confirmed) );

auto exts = h.validate_and_extract_header_extensions();

Expand Down
9 changes: 4 additions & 5 deletions libraries/chain/include/eosio/chain/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ namespace eosio::chain {

using validator_t = const std::function<void(block_timestamp_type, const flat_set<digest_type>&, const vector<digest_type>&)>;

// totem for block_header.confirmed that indicates hotstuff consensus is active
constexpr uint16_t hs_block_confirmed = std::numeric_limits<uint16_t>::max();

struct block_header
{
block_timestamp_type timestamp;
account_name producer;

/**
* Legacy block confirmation:
* By signing this block this producer is confirming blocks [block_num() - confirmed, blocknum())
* as being the best blocks for that range and that he has not signed any other
* statements that would contradict.
Expand All @@ -45,8 +43,9 @@ namespace eosio::chain {
* behavior. When producing a block a producer is always confirming at least the block he
* is building off of. A producer cannot confirm "this" block, only prior blocks.
*
* After hotstuff activation a producer can no longer confirm blocks only propose them;
* confirmed will be std::numeric_limits<uint16_t>::max() after hotstuff activation.
* Instant-finality:
* Once instant-finality is enabled a producer can no longer confirm blocks, only propose them;
* confirmed is 0 after instant-finality is enabled.
*/
uint16_t confirmed = 1;

Expand Down
4 changes: 2 additions & 2 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3902,7 +3902,7 @@ BOOST_AUTO_TEST_CASE(set_finalizer_test) { try {
// BOOST_TEST(block_state->dpos_irreversible_blocknum != hs_dpos_irreversible_blocknum);

block = t.produce_block(); // hotstuff now active
BOOST_TEST(block->confirmed == std::numeric_limits<uint16_t>::max());
BOOST_TEST(block->confirmed == 0);
auto fb = t.control->fetch_block_by_id(block->calculate_id());
BOOST_REQUIRE(!!fb);
BOOST_TEST(fb == block);
Expand All @@ -3911,7 +3911,7 @@ BOOST_AUTO_TEST_CASE(set_finalizer_test) { try {

// and another on top of a instant-finality block
block = t.produce_block();
BOOST_TEST(block->confirmed == std::numeric_limits<uint16_t>::max());
BOOST_TEST(block->confirmed == 0);
fb = t.control->fetch_block_by_id(block->calculate_id());
BOOST_REQUIRE(!!fb);
BOOST_TEST(fb == block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activat
BOOST_TEST(control->head_block_num() == expected_block_num);
}

produce_block();
auto b = produce_block();
BOOST_TEST( b->confirmed == 0); // must be 0 after instant finality is enabled

// Check if the producer is the same as what we expect
const auto block_time = control->head_block_time();
Expand Down Expand Up @@ -64,7 +65,7 @@ BOOST_FIXTURE_TEST_CASE( verify_producer_schedule_after_instant_finality_activat
};
create_accounts(producers);

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

0 comments on commit 405ce52

Please sign in to comment.