Skip to content

Commit

Permalink
feat(collator): force next mc block collation when sc block collated …
Browse files Browse the repository at this point in the history
…after skipped anchor import
  • Loading branch information
SmaGMan committed Dec 6, 2024
1 parent b0ca986 commit 6af5ace
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
13 changes: 11 additions & 2 deletions collator/src/collator/do_collate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -57,6 +58,7 @@ impl CollatorStdImpl {
&mut self,
working_state: Box<WorkingState>,
top_shard_blocks_info: Option<Vec<TopBlockDescription>>,
force_next_mc_block: ForceMasterCollation,
) -> Result<()> {
let labels: [(&str, String); 1] = [("workchain", self.shard_id.workchain().to_string())];
let total_collation_histogram =
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1038,6 +1045,7 @@ impl CollatorStdImpl {
has_unprocessed_messages: bool,
finalized: FinalizedBlock,
tracker: MinRefMcStateTracker,
force_next_mc_block: ForceMasterCollation,
) -> Result<FinalizedCollationResult> {
let labels = [("workchain", self.shard_id.workchain().to_string())];

Expand Down Expand Up @@ -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?;

Expand Down
19 changes: 16 additions & 3 deletions collator/src/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion collator/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _,
)
Expand Down
2 changes: 2 additions & 0 deletions collator/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,6 +70,7 @@ pub struct BlockCollationResult {
pub prev_mc_block_id: BlockId,
pub mc_data: Option<Arc<McData>>,
pub collation_config: Arc<CollationConfig>,
pub force_next_mc_block: ForceMasterCollation,
}

/// Processed up to info for externals and internals.
Expand Down

0 comments on commit 6af5ace

Please sign in to comment.