@@ -1498,7 +1498,7 @@ struct controller_impl {
14981498 }
14991499 }
15001500
1501- void log_irreversible () {
1501+ controller::apply_blocks_result log_irreversible () {
15021502 EOS_ASSERT ( fork_db_has_root (), fork_database_exception, " fork database not properly initialized" );
15031503
15041504 const std::optional<block_id_type> log_head_id = blog.head_id ();
@@ -1538,9 +1538,10 @@ struct controller_impl {
15381538
15391539 const block_id_type new_lib_id = pending_lib_id ();
15401540 const block_num_type new_lib_num = block_header::num_from_id (new_lib_id);
1541+ controller::apply_blocks_result result = controller::apply_blocks_result::complete;
15411542
15421543 if ( new_lib_num <= lib_num )
1543- return ;
1544+ return result ;
15441545
15451546 const fc::time_point start = fc::time_point::now ();
15461547
@@ -1555,22 +1556,15 @@ struct controller_impl {
15551556 // pending LIB. If the pending LIB not found on the head branch then fetch_branch returns an empty branch.
15561557 // Otherwise fetch_branch will return from chain_head to root iff chain_head on pending LIB branch.
15571558 auto branch = new_lib_num <= head_num ? fork_db.fetch_branch (head_id, new_lib_id) : fork_db.fetch_branch (new_lib_id, head_id);
1558- try {
1559+ try { try {
15591560 auto should_process = [&](auto & bsp) {
15601561 // Only make irreversible blocks that have been validated. Blocks in the fork database may not be on our current best head
15611562 // and therefore have not been validated.
15621563 // An alternative more complex implementation would be to do a fork switch here and validate all blocks so they can be then made
15631564 // irreversible. Instead, this moves irreversible as much as possible and allows the next maybe_switch_forks call to apply these
15641565 // non-validated blocks. After the maybe_switch_forks call (before next produced block or on next received block), irreversible
15651566 // can then move forward on the then validated blocks.
1566- // In irreversible mode, break every ~500ms to allow other tasks (e.g. get_info, SHiP) opportunity to run. There is a post
1567- // for every incoming blocks; enough posted tasks to apply all blocks queued to the fork db.
1568- if (irreversible_mode ()) {
1569- if (!replaying && fc::time_point::now () - start > fc::milliseconds (500 ))
1570- return false ;
1571- return true ;
1572- }
1573- return bsp->is_valid ();
1567+ return irreversible_mode () || bsp->is_valid ();
15741568 };
15751569
15761570 using packed_block_future = std::future<std::vector<char >>;
@@ -1587,7 +1581,8 @@ struct controller_impl {
15871581 packed_block_future f;
15881582 if (irreversible_mode ()) {
15891583 f = post_async_task ( thread_pool.get_executor (), [b=(*bitr)->block ]() { return fc::raw::pack (*b); } );
1590- if (apply_irreversible_block (fork_db, *bitr) != controller::apply_blocks_result::complete)
1584+ result = apply_irreversible_block (fork_db, *bitr);
1585+ if (result != controller::apply_blocks_result::complete)
15911586 break ;
15921587 }
15931588
@@ -1604,10 +1599,19 @@ struct controller_impl {
16041599 fork_db_.switch_to (fork_database::in_use_t ::savanna);
16051600 break ;
16061601 }
1602+ if (irreversible_mode ()) {
1603+ // In irreversible mode, break every ~500ms to allow other tasks (e.g. get_info, SHiP) opportunity to run
1604+ const bool more_blocks_to_process = bitr + 1 != branch.rend ();
1605+ if (!replaying && more_blocks_to_process && fc::time_point::now () - start > fc::milliseconds (500 )) {
1606+ result = controller::apply_blocks_result::incomplete;
1607+ break ;
1608+ }
1609+ }
16071610 }
1608- } catch ( const std ::exception& e ) {
1611+ } FC_CAPTURE_AND_RETHROW () } catch ( const fc ::exception& e ) {
16091612 try {
1610- elog (" Caught exception while logging irreversible: ${e}" , (" e" , e.what ()));
1613+ if (e.code () != interrupt_exception::code_value)
1614+ elog (" Caught exception while logging irreversible: ${e}" , (" e" , e.to_detail_string ()));
16111615 if (root_id != fork_db.root ()->id ()) {
16121616 fork_db.advance_root (root_id);
16131617 }
@@ -1631,6 +1635,8 @@ struct controller_impl {
16311635 };
16321636
16331637 fork_db_.apply <void >(mark_branch_irreversible);
1638+
1639+ return result;
16341640 }
16351641
16361642 void initialize_blockchain_state (const genesis_state& genesis) {
@@ -4357,9 +4363,9 @@ struct controller_impl {
43574363 return maybe_apply_blocks ( cb, trx_lookup );
43584364 }
43594365
4360- log_irreversible ();
4366+ auto result = log_irreversible ();
43614367 transition_to_savanna_if_needed ();
4362- return should_pause () ? controller::apply_blocks_result::paused : controller::apply_blocks_result::complete ;
4368+ return result ;
43634369 } catch (fc::exception& e) {
43644370 if (e.code () != interrupt_exception::code_value) {
43654371 wlog (" ${d}" , (" d" ,e.to_detail_string ()));
@@ -4500,8 +4506,10 @@ struct controller_impl {
45004506 }
45014507
45024508 // irreversible can change even if block not applied to head, integrated qc can move LIB
4503- log_irreversible ();
4509+ auto log_result = log_irreversible ();
45044510 transition_to_savanna_if_needed ();
4511+ if (log_result != controller::apply_blocks_result::complete)
4512+ result = log_result;
45054513 };
45064514
45074515 fork_db_.apply <void >(do_apply_blocks);
0 commit comments