Skip to content

Commit 2c0ca2e

Browse files
committed
GH-1082 Limit apply_blocks in irreversible mode to 500ms similar to apply_blocks in non-irreversible mode.
1 parent 3034775 commit 2c0ca2e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libraries/chain/controller.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,8 @@ struct controller_impl {
15431543
if( new_lib_num <= lib_num )
15441544
return result;
15451545

1546+
const fc::time_point start = fc::time_point::now();
1547+
15461548
auto mark_branch_irreversible = [&, this](auto& fork_db) {
15471549
assert(!irreversible_mode() || fork_db.head());
15481550
const auto& head_id = irreversible_mode() ? fork_db.head()->id() : chain_head.id();
@@ -1582,6 +1584,12 @@ struct controller_impl {
15821584
result = apply_irreversible_block(fork_db, *bitr);
15831585
if (result != controller::apply_blocks_result::complete)
15841586
break;
1587+
// In irreversible mode, break every ~500ms to allow other tasks (e.g. get_info, SHiP) opportunity to run
1588+
const bool more_blocks_to_process = bitr + 1 != branch.rend();
1589+
if (!replaying && more_blocks_to_process && fc::time_point::now() - start > fc::milliseconds(500)) {
1590+
result = controller::apply_blocks_result::incomplete;
1591+
break;
1592+
}
15851593
}
15861594

15871595
emit( irreversible_block, std::tie((*bitr)->block, (*bitr)->id()), __FILE__, __LINE__ );

0 commit comments

Comments
 (0)