diff --git a/collator/src/collator/do_collate/mod.rs b/collator/src/collator/do_collate/mod.rs index c6394e89c..674cdc809 100644 --- a/collator/src/collator/do_collate/mod.rs +++ b/collator/src/collator/do_collate/mod.rs @@ -21,7 +21,7 @@ use super::types::{ AnchorsCache, BlockCollationDataBuilder, CollationResult, ExecuteResult, FinalizedBlock, FinalizedCollationResult, ParsedExternals, PrevData, ReadNextExternalsMode, WorkingState, }; -use super::CollatorStdImpl; +use super::{CollatorStdImpl, ForceMasterCollation}; use crate::collator::types::{ AnchorInfo, BlockCollationData, FinalResult, ParsedMessage, ShardDescriptionExt, UpdateQueueDiffResult, @@ -45,6 +45,7 @@ mod phase; mod prepare; impl CollatorStdImpl { + /// [`force_next_mc_block`] - should force next master block collation after this block #[tracing::instrument( parent = None, skip_all, @@ -57,6 +58,7 @@ impl CollatorStdImpl { &mut self, working_state: Box, top_shard_blocks_info: Option>, + force_next_mc_block: ForceMasterCollation, ) -> Result<()> { let labels: [(&str, String); 1] = [("workchain", self.shard_id.workchain().to_string())]; let total_collation_histogram = @@ -161,7 +163,12 @@ impl CollatorStdImpl { let FinalizedCollationResult { handle_block_candidate_elapsed, } = self - .finalize_collation(final_result.has_unprocessed_messages, finalized, tracker) + .finalize_collation( + final_result.has_unprocessed_messages, + finalized, + tracker, + force_next_mc_block, + ) .await?; let total_elapsed = total_collation_histogram.finish(); @@ -1038,6 +1045,7 @@ impl CollatorStdImpl { has_unprocessed_messages: bool, finalized: FinalizedBlock, tracker: MinRefMcStateTracker, + force_next_mc_block: ForceMasterCollation, ) -> Result { let labels = [("workchain", self.shard_id.workchain().to_string())]; @@ -1085,6 +1093,7 @@ impl CollatorStdImpl { prev_mc_block_id: finalized.old_mc_data.block_id, mc_data: finalized.mc_data.clone(), collation_config: collation_config.clone(), + force_next_mc_block, }) .await?; diff --git a/collator/src/collator/mod.rs b/collator/src/collator/mod.rs index 3ef6f1953..80c0bcd88 100644 --- a/collator/src/collator/mod.rs +++ b/collator/src/collator/mod.rs @@ -1374,8 +1374,12 @@ impl CollatorStdImpl { } } - self.do_collate(working_state, Some(top_shard_blocks_info)) - .await + self.do_collate( + working_state, + Some(top_shard_blocks_info), + ForceMasterCollation::No, + ) + .await } /// Run collation if there are internals, @@ -1833,8 +1837,17 @@ impl CollatorStdImpl { "will collate next shard block", ); + // should force next master block collation after this shard block + // when anchor import was skipped + let force_next_mc_block = if anchor_import_skipped { + ForceMasterCollation::ByAnchorImportSkipped + } else { + ForceMasterCollation::No + }; + drop(histogram); - self.do_collate(working_state, None).await?; + self.do_collate(working_state, None, force_next_mc_block) + .await?; } TryCollateCheck::NoPendingMessages | TryCollateCheck::ForceMcBlockByUncommittedChainLength => { diff --git a/collator/src/manager/mod.rs b/collator/src/manager/mod.rs index 40cc0e68b..21f1cc151 100644 --- a/collator/src/manager/mod.rs +++ b/collator/src/manager/mod.rs @@ -920,7 +920,7 @@ where &collation_result.prev_mc_block_id, block_id.shard, candidate_chain_time, - ForceMasterCollation::No, + collation_result.force_next_mc_block, Some(block_id), collation_result.collation_config.mc_block_min_interval_ms as _, ) diff --git a/collator/src/types.rs b/collator/src/types.rs index e26729ba9..d37890c43 100644 --- a/collator/src/types.rs +++ b/collator/src/types.rs @@ -14,6 +14,7 @@ use tycho_block_util::state::{RefMcStateHandle, ShardStateStuff}; use tycho_network::PeerId; use tycho_util::FastHashMap; +use crate::collator::ForceMasterCollation; use crate::mempool::MempoolAnchorId; use crate::utils::block::detect_top_processed_to_anchor; @@ -69,6 +70,7 @@ pub struct BlockCollationResult { pub prev_mc_block_id: BlockId, pub mc_data: Option>, pub collation_config: Arc, + pub force_next_mc_block: ForceMasterCollation, } /// Processed up to info for externals and internals.