Skip to content

Commit

Permalink
Merge branch 'hotstuff_integration' into GH-2141-replay
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner authored Mar 4, 2024
2 parents 1c7aa01 + abfe70b commit fbc29cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
22 changes: 15 additions & 7 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,17 +1221,23 @@ struct controller_impl {
("lib_num", lib_num)("bn", fork_db_root_block_num()) );
}

uint32_t if_lib = block_header::num_from_id(if_irreversible_block_id);
const uint32_t new_lib = if_lib > 0 ? if_lib : fork_db_head_irreversible_blocknum();
uint32_t if_lib_num = block_header::num_from_id(if_irreversible_block_id);
const uint32_t new_lib_num = if_lib_num > 0 ? if_lib_num : fork_db_head_irreversible_blocknum();

if( new_lib <= lib_num )
if( new_lib_num <= lib_num )
return;

auto mark_branch_irreversible = [&, this](auto& forkdb) {
auto branch = (if_lib > 0) ? forkdb.fetch_branch( if_irreversible_block_id, new_lib)
: forkdb.fetch_branch( fork_db_head(forkdb, irreversible_mode())->id(), new_lib );
auto branch = (if_lib_num > 0) ? forkdb.fetch_branch( if_irreversible_block_id, new_lib_num)
: forkdb.fetch_branch( fork_db_head(forkdb, irreversible_mode())->id(), new_lib_num );
try {
auto should_process = [&](auto& bsp) {
// Only make irreversible blocks that have been validated. Blocks in the fork database may not be on our current best head
// and therefore have not been validated.
// An alternative more complex implementation would be to do a fork switch here and validate all blocks so they can be then made
// irreversible. Instead this moves irreversible as much as possible and allows the next maybe_switch_forks call to apply these
// non-validated blocks. After the maybe_switch_forks call (before next produced block or on next received block), irreversible
// can then move forward on the then validated blocks.
return read_mode == db_read_mode::IRREVERSIBLE || bsp->is_valid();
};

Expand Down Expand Up @@ -3956,9 +3962,11 @@ struct controller_impl {
}

void set_if_irreversible_block_id(const block_id_type& id) {
if( block_header::num_from_id(id) > block_header::num_from_id(if_irreversible_block_id) ) {
const block_num_type id_num = block_header::num_from_id(id);
const block_num_type current_num = block_header::num_from_id(if_irreversible_block_id);
if( id_num > current_num ) {
dlog("set irreversible block ${bn}: ${id}, old ${obn}: ${oid}", ("bn", id_num)("id", id)("obn", current_num)("oid", if_irreversible_block_id));
if_irreversible_block_id = id;
dlog("irreversible block ${bn} : ${id}", ("bn", block_header::num_from_id(id))("id", id));
}
}

Expand Down
11 changes: 6 additions & 5 deletions plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,13 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin

bool on_incoming_block(const signed_block_ptr& block, const block_id_type& id, const std::optional<block_handle>& obt) {
auto now = fc::time_point::now();
auto& chain = chain_plug->chain();
_time_tracker.add_idle_time(now);

assert(block);
auto blk_num = block->block_num();

_time_tracker.add_idle_time(now);
if (now - block->timestamp < fc::minutes(5) || (blk_num % 1000 == 0)) // only log every 1000 during sync
fc_dlog(_log, "received incoming block ${n} ${id}", ("n", blk_num)("id", id));

// start a new speculative block, speculative start_block may have been interrupted
auto ensure = fc::make_scoped_exit([this]() {
Expand All @@ -684,6 +687,7 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
}
});

auto& chain = chain_plug->chain();
// de-dupe here... no point in aborting block if we already know the block; avoid exception in create_block_handle_future
if (chain.block_exists(id)) {
return true; // return true because the block is accepted
Expand All @@ -704,9 +708,6 @@ class producer_plugin_impl : public std::enable_shared_from_this<producer_plugin
return true; // return true because block was accepted
}

if (now - block->timestamp < fc::minutes(5) || (blk_num % 1000 == 0)) // only log every 1000 during sync
fc_dlog(_log, "received incoming block ${n} ${id}", ("n", blk_num)("id", id));

// abort the pending block
abort_block();

Expand Down

0 comments on commit fbc29cf

Please sign in to comment.