diff --git a/Cargo.lock b/Cargo.lock index d8fd4c94c..6ec679f96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2950,7 +2950,7 @@ dependencies = [ [[package]] name = "ton_executor" version = "2.0.0" -source = "git+https://github.com/broxus/ton-labs-executor.git?branch=new_cells#923a1061ef70448c487a4ffdd91aa859d3e29335" +source = "git+https://github.com/broxus/ton-labs-executor.git?branch=new_cells#973e3d0ecb4f07ac0ffcbdbda2c1a9825c9fe627" dependencies = [ "ahash", "anyhow", diff --git a/collator/src/collator/do_collate.rs b/collator/src/collator/do_collate.rs index 2cf967f16..b7eff6fac 100644 --- a/collator/src/collator/do_collate.rs +++ b/collator/src/collator/do_collate.rs @@ -73,7 +73,13 @@ impl CollatorStdImpl { collation_data.gen_utime_ms = (next_chain_time % 1000) as u16; collation_data.start_lt = Self::calc_start_lt(mc_data, prev_shard_data, &collation_data)?; collation_data.next_lt = collation_data.start_lt + 1; - collation_data.stats.lt_start = collation_data.start_lt; + collation_data.block_limit.lt_start = collation_data.start_lt; + collation_data.block_limit.lt_current = collation_data.start_lt; + collation_data.block_limit.load_block_limits( + mc_data + .config() + .get_block_limits(self.shard_id.is_masterchain())?, + ); collation_data.processed_upto = prev_shard_data.processed_upto().clone(); tracing::debug!(target: tracing_targets::COLLATOR, "initial processed_upto.externals = {:?}", @@ -195,13 +201,21 @@ impl CollatorStdImpl { loop { let mut timer = Instant::now(); + let soft_level_reached = collation_data.block_limit.reached(BlockLimitsLevel::Soft); + if soft_level_reached { + tracing::debug!(target: tracing_targets::COLLATOR, + "STUB: soft block limit reached: {:?}", + collation_data.block_limit, + ); + } let mut executed_internal_messages = vec![]; let mut internal_messages_sources = FastHashMap::default(); // build messages set let mut msgs_set: Vec> = vec![]; // 1. First try to read min externals amount - let mut ext_msgs = if self.has_pending_externals { + + let mut ext_msgs = if !soft_level_reached && self.has_pending_externals { self.read_next_externals(min_externals_per_set, &mut collation_data)? } else { vec![] @@ -251,7 +265,7 @@ impl CollatorStdImpl { // If not enough existing internals to fill the set then try read more externals msgs_set.append(&mut ext_msgs); remaining_capacity = max_messages_per_set - msgs_set.len(); - if remaining_capacity > 0 && self.has_pending_externals { + if remaining_capacity > 0 && self.has_pending_externals && !soft_level_reached { ext_msgs = self.read_next_externals(remaining_capacity, &mut collation_data)?; tracing::debug!(target: tracing_targets::COLLATOR, ext_count = ext_msgs.len(), @@ -327,7 +341,7 @@ impl CollatorStdImpl { fill_msgs_total_elapsed += timer.elapsed(); // execute msgs processing by groups - 'execute_groups: while !msgs_set_full_processed { + while !msgs_set_full_processed { // Process messages timer = std::time::Instant::now(); let tick = exec_manager.tick(msgs_set_offset).await?; @@ -375,7 +389,7 @@ impl CollatorStdImpl { } collation_data.next_lt = exec_manager.min_next_lt(); - collation_data.stats.lt_current = collation_data.next_lt; + collation_data.block_limit.lt_current = collation_data.next_lt; } msgs_set_offset = tick.new_offset; @@ -396,18 +410,14 @@ impl CollatorStdImpl { if msgs_set_offset == msgs_set_len { msgs_set_full_processed = true; } - } - if let BlockLimitsLevel::Hard = collation_data - .stats - .current_level(&self.config.block_limits) - { + if collation_data.block_limit.reached(BlockLimitsLevel::Hard) { tracing::debug!(target: tracing_targets::COLLATOR, - "STUB: block limit reached: {:?}/{:?}", - collation_data.stats, self.config.block_limits, + "STUB: block limit reached: {:?}", + collation_data.block_limit, ); block_limits_reached = true; - break 'execute_groups; + break; } } @@ -1306,24 +1316,8 @@ fn new_transaction( ); collation_data.execute_count_all += 1; - let transaction = executor_output.transaction.load()?; - let gas_used = 'gas: { - match transaction.load_info()? { - TxInfo::Ordinary(info) => { - if let ComputePhase::Executed(phase) = &info.compute_phase { - break 'gas phase.gas_used.into_inner(); - } - } - TxInfo::TickTock(info) => { - if let ComputePhase::Executed(phase) = &info.compute_phase { - break 'gas phase.gas_used.into_inner(); - } - } - }; - 0 - }; - collation_data.stats.gas_used += gas_used as u32; - collation_data.stats.add_cell(&*in_msg.cell)?; + collation_data.block_limit.gas_used += executor_output.gas_used as u32; + collation_data.block_limit.add_cell(&*in_msg.cell)?; let import_fees; let in_msg_hash = *in_msg.cell.repr_hash(); @@ -1458,7 +1452,7 @@ fn new_transaction( for out_msg_cell in executor_output.out_msgs.values() { let out_msg_cell = out_msg_cell?; - collation_data.stats.add_cell(&*out_msg_cell)?; + collation_data.block_limit.add_cell(&*out_msg_cell)?; let out_msg_hash = *out_msg_cell.repr_hash(); let out_msg_info = out_msg_cell.parse::()?; diff --git a/collator/src/collator/types.rs b/collator/src/collator/types.rs index 22f31390f..762de5804 100644 --- a/collator/src/collator/types.rs +++ b/collator/src/collator/types.rs @@ -323,7 +323,7 @@ pub(super) struct BlockCollationData { pub tx_count: u32, - pub stats: BlockStats, + pub block_limit: BlockLimitStats, pub total_execute_msgs_time_mc: u128, @@ -378,15 +378,20 @@ pub(super) struct BlockCollationData { pub created_by: HashBytes, } #[derive(Debug, Default)] -pub struct BlockStats { +pub struct BlockLimitStats { pub gas_used: u32, pub lt_current: u64, pub lt_start: u64, pub cells_seen: HashSet, pub cells_bits: u32, + pub block_limits: Option, } -impl BlockStats { +impl BlockLimitStats { + pub fn load_block_limits(&mut self, block_limits: BlockLimits) { + self.block_limits = Some(block_limits); + } + pub fn add_cell(&mut self, cell: &DynCell) -> Result<()> { if !self.cells_seen.insert(*cell.repr_hash()) { return Ok(()); @@ -399,13 +404,15 @@ impl BlockStats { } Ok(()) } - pub fn current_level(&self, block_limits: &BlockLimits) -> BlockLimitsLevel { - let mut result = BlockLimitsLevel::Underload; - let BlockLimits { + pub fn reached(&self, level: BlockLimitsLevel) -> bool { + let Some(BlockLimits { bytes, gas, lt_delta, - } = block_limits; + }) = &self.block_limits + else { + return false; + }; let BlockParamLimits { soft_limit, @@ -415,10 +422,10 @@ impl BlockStats { let cells_bytes = self.cells_bits / 8; if cells_bytes >= *hard_limit { - return BlockLimitsLevel::Hard; + return true; } - if cells_bytes >= *soft_limit { - result = BlockLimitsLevel::Soft + if cells_bytes >= *soft_limit && level == BlockLimitsLevel::Soft { + return true; } let BlockParamLimits { @@ -428,10 +435,10 @@ impl BlockStats { } = gas; if self.gas_used >= *hard_limit { - return BlockLimitsLevel::Hard; + return true; } - if self.gas_used >= *soft_limit { - result = BlockLimitsLevel::Soft + if self.gas_used >= *soft_limit && level == BlockLimitsLevel::Soft { + return true; } let BlockParamLimits { @@ -442,12 +449,12 @@ impl BlockStats { let delta_lt = (self.lt_current - self.lt_start) as u32; if delta_lt >= *hard_limit { - return BlockLimitsLevel::Hard; + return true; } - if delta_lt >= *soft_limit { - result = BlockLimitsLevel::Soft + if delta_lt >= *soft_limit && level == BlockLimitsLevel::Soft { + return true; } - result + false } } diff --git a/collator/src/types.rs b/collator/src/types.rs index 59f834052..1bee581a5 100644 --- a/collator/src/types.rs +++ b/collator/src/types.rs @@ -4,8 +4,8 @@ use std::time::Duration; use everscale_crypto::ed25519::KeyPair; use everscale_types::cell::HashBytes; use everscale_types::models::{ - Block, BlockId, BlockInfo, BlockLimits, BlockParamLimits, CurrencyCollection, - GlobalCapabilities, GlobalCapability, IntAddr, ShardIdent, Signature, ValueFlow, + Block, BlockId, BlockInfo, CurrencyCollection, GlobalCapabilities, GlobalCapability, IntAddr, + ShardIdent, Signature, ValueFlow, }; use serde::{Deserialize, Serialize}; use tycho_block_util::block::{BlockStuffAug, ValidatorSubsetInfo}; @@ -25,8 +25,6 @@ pub struct CollationConfig { pub max_uncommitted_chain_length: u32, pub uncommitted_chain_to_import_next_anchor: u32, - pub block_limits: BlockLimits, - pub msgs_exec_params: MsgsExecutionParams, } @@ -42,24 +40,6 @@ impl Default for CollationConfig { max_uncommitted_chain_length: 31, uncommitted_chain_to_import_next_anchor: 4, - block_limits: BlockLimits { - bytes: BlockParamLimits { - underload: 131072, - soft_limit: 524288, - hard_limit: 1048576, - }, - gas: BlockParamLimits { - underload: 900000, - soft_limit: 1200000, - hard_limit: 2000000, - }, - lt_delta: BlockParamLimits { - underload: 1000, - soft_limit: 5000, - hard_limit: 10000, - }, - }, - msgs_exec_params: MsgsExecutionParams::default(), } }