Skip to content

Commit

Permalink
fix(collator): pass min top processed to anchor on mempool state update
Browse files Browse the repository at this point in the history
  • Loading branch information
SmaGMan authored and Rexagon committed Dec 10, 2024
1 parent 604d035 commit 3cb9be6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
13 changes: 3 additions & 10 deletions collator/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,6 @@ where
self.blocks_cache.reset_top_shard_blocks_additional_info()?;

let mc_data = McData::load_from_state(state)?;
let top_processed_to_anchor = mc_data.top_processed_to_anchor;

// remove all previous blocks from cache
let mut to_block_keys = vec![mc_block_entry.key()];
Expand All @@ -1361,10 +1360,10 @@ where
self.blocks_cache
.remove_next_collated_blocks_from_cache(&to_block_keys);

self.process_mc_state_update(mc_data, true).await?;
self.process_mc_state_update(mc_data.clone(), true).await?;

// handle top processed to anchor in mempool
self.notify_top_processed_to_anchor_to_mempool(top_processed_to_anchor)?;
self.notify_top_processed_to_anchor_to_mempool(mc_data.top_processed_to_anchor)?;

break;
}
Expand Down Expand Up @@ -1492,16 +1491,10 @@ where
.validator_set_cache
.get_next_validator_set(&mc_data.config)?;

let mc_processed_to_anchor_id = mc_data
.processed_upto
.externals
.as_ref()
.map_or(0, |upto| upto.processed_to.0);

let cx = StateUpdateContext {
mc_block_id: mc_data.block_id,
mc_block_chain_time: mc_data.gen_chain_time,
mc_processed_to_anchor_id,
top_processed_to_anchor_id: mc_data.top_processed_to_anchor,
consensus_info: mc_data.consensus_info,
shuffle_validators: mc_data.config.get_collation_config()?.shuffle_mc_validators,
consensus_config: mc_data.config.get_consensus_config()?,
Expand Down
14 changes: 7 additions & 7 deletions collator/src/mempool/impls/std_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl MempoolAdapterStdImpl {

// Note: mempool is always run from applied mc block
self.top_known_anchor
.set_max_raw(last_state_update.mc_processed_to_anchor_id);
.set_max_raw(last_state_update.top_processed_to_anchor_id);

let engine = Engine::new(
self.key_pair.clone(),
Expand All @@ -116,7 +116,7 @@ impl MempoolAdapterStdImpl {

// actual oldest sync round will be not less than this
let estimated_sync_bottom = last_state_update
.mc_processed_to_anchor_id
.top_processed_to_anchor_id
.saturating_sub(mempool_config.consensus.reset_rounds())
.max(mempool_config.genesis.start_round);
if estimated_sync_bottom >= last_state_update.consensus_info.vset_switch_round {
Expand All @@ -136,10 +136,10 @@ impl MempoolAdapterStdImpl {
"cannot start from outdated peer sets (too short mempool epoch(s)): \
estimated sync bottom {estimated_sync_bottom} \
is older than prev vset switch round {}; \
start round {}, masterchain processed to anchor {} in block {}",
start round {}, top processed to anchor {} in block {}",
last_state_update.consensus_info.prev_vset_switch_round,
mempool_config.genesis.start_round,
last_state_update.mc_processed_to_anchor_id,
last_state_update.top_processed_to_anchor_id,
last_state_update.mc_block_id,
)
};
Expand Down Expand Up @@ -292,11 +292,11 @@ impl MempoolAdapter for MempoolAdapterStdImpl {
// genesis does not have externals, so only strictly greater time and round
// will be saved into next block, so genesis can have values GEQ than in prev block
anyhow::ensure!(
genesis.start_round >= new_cx.mc_processed_to_anchor_id
genesis.start_round >= new_cx.top_processed_to_anchor_id
&& genesis.time_millis >= new_cx.mc_block_chain_time,
"new {genesis:?} should be >= \
master block processed_to_anchor_id {} and gen chain_time {}",
new_cx.mc_processed_to_anchor_id,
top processed_to_anchor_id {} and block gen chain_time {}",
new_cx.top_processed_to_anchor_id,
new_cx.mc_block_chain_time,
);

Expand Down
6 changes: 3 additions & 3 deletions collator/src/mempool/state_update_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::MempoolAnchorId;
pub struct StateUpdateContext {
pub mc_block_id: BlockId,
pub mc_block_chain_time: u64,
pub mc_processed_to_anchor_id: MempoolAnchorId,
pub top_processed_to_anchor_id: MempoolAnchorId,
pub consensus_info: ConsensusInfo,
pub consensus_config: ConsensusConfig,
pub shuffle_validators: bool,
Expand All @@ -25,8 +25,8 @@ impl std::fmt::Debug for DebugStateUpdateContext<'_> {
.field("mc_block_id", &self.0.mc_block_id.as_short_id())
.field("mc_block_chain_time", &self.0.mc_block_chain_time)
.field(
"mc_processed_to_anchor_id",
&self.0.mc_processed_to_anchor_id,
"top_processed_to_anchor_id",
&self.0.top_processed_to_anchor_id,
)
.field("consensus_info", &self.0.consensus_info)
.field("consensus_config", &self.0.consensus_config)
Expand Down

0 comments on commit 3cb9be6

Please sign in to comment.