Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0.3] Limit apply blocks #921

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1689,8 +1689,6 @@ struct controller_impl {
}

void replay(startup_t startup) {
replaying = true;

bool replay_block_log_needed = should_replay_block_log();

auto blog_head = blog.head();
Expand Down Expand Up @@ -1838,8 +1836,6 @@ struct controller_impl {
};
fork_db.apply<void>(replay_fork_db);

replaying = false;

if( except_ptr ) {
std::rethrow_exception( except_ptr );
}
Expand Down Expand Up @@ -1988,6 +1984,7 @@ struct controller_impl {
ilog( "chain database started with hash: ${hash}", ("hash", calculate_integrity_hash()) );
okay_to_print_integrity_hash_on_stop = true;

fc::scoped_set_value r(replaying, true);
replay( startup ); // replay any irreversible and reversible blocks ahead of current head

if( check_shutdown() ) return;
linh2931 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -3630,8 +3627,6 @@ struct controller_impl {

template<typename BSP>
void log_applied(controller::block_report& br, const BSP& bsp) const {
if (replaying) // fork_db_root_block_num not available during replay
linh2931 marked this conversation as resolved.
Show resolved Hide resolved
return;
fc::time_point now = fc::time_point::now();
if (now - bsp->timestamp() < fc::minutes(5) || (bsp->block_num() % 1000 == 0)) {
ilog("Received block ${id}... #${n} @ ${t} signed by ${p} " // "Received" instead of "Applied" so it matches existing log output
Expand Down Expand Up @@ -4413,6 +4408,7 @@ struct controller_impl {
const forked_callback_t& forked_cb, const trx_meta_cache_lookup& trx_lookup )
{
auto do_maybe_switch_forks = [&](auto& forkdb) {
auto start = fc::time_point::now();
if( new_head->header.previous == chain_head.id() ) {
try {
apply_block( br, new_head, s, trx_lookup );
Expand Down Expand Up @@ -4468,10 +4464,17 @@ struct controller_impl {
br = controller::block_report();
bool applied = apply_block( br, bsp, bsp->is_valid() ? controller::block_status::validated
: controller::block_status::complete, trx_lookup );
if (!switch_fork && (!applied || check_shutdown())) {
shutdown();
break;
if (!switch_fork) { // always complete a switch fork
if (!applied || check_shutdown()) {
shutdown();
break;
}
// Break every ~500ms to allow other tasks (e.g. get_info, SHiP) opportunity to run. There is a post
// for every incoming blocks; enough posted tasks to apply all blocks queued to the fork db.
if (!replaying && fc::time_point::now() - start > fc::milliseconds(500))
break;
}

} catch ( const std::bad_alloc& ) {
throw;
} catch ( const boost::interprocess::bad_alloc& ) {
Expand Down