diff --git a/src/main.rs b/src/main.rs index 9e1c56da..284850c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -233,6 +233,10 @@ struct Cli { /// Show Gas details information show_gas_details: ShowGasDetails, + #[arg(long)] + /// If provided, uses a custom value as the L1 gas price. + l1_gas_price: Option, + #[arg(long)] /// If provided, uses a custom value as the L2 gas price. If not provided the gas price will be /// inferred from the protocol version. @@ -395,6 +399,7 @@ async fn main() -> anyhow::Result<()> { fork_details, Some(observability), InMemoryNodeConfig { + l1_gas_price: opt.l1_gas_price, l2_fair_gas_price, show_calls: opt.show_calls, show_outputs: opt.show_outputs, diff --git a/src/node/fee_model.rs b/src/node/fee_model.rs index 609ecc81..c29185ec 100644 --- a/src/node/fee_model.rs +++ b/src/node/fee_model.rs @@ -5,7 +5,7 @@ use zksync_types::L1_GAS_PER_PUBDATA_BYTE; use super::{ DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR, DEFAULT_ESTIMATE_GAS_SCALE_FACTOR, - DEFAULT_L2_GAS_PRICE, L1_GAS_PRICE, + DEFAULT_L1_GAS_PRICE, DEFAULT_L2_GAS_PRICE, }; #[derive(Debug, Clone, PartialEq)] @@ -84,8 +84,8 @@ impl BatchFeeModelInputProvider for TestNodeFeeInputProvider { impl Default for TestNodeFeeInputProvider { fn default() -> Self { Self { - l1_gas_price: L1_GAS_PRICE, - l1_pubdata_price: L1_GAS_PRICE * L1_GAS_PER_PUBDATA_BYTE as u64, + l1_gas_price: DEFAULT_L1_GAS_PRICE, + l1_pubdata_price: DEFAULT_L1_GAS_PRICE * L1_GAS_PER_PUBDATA_BYTE as u64, l2_gas_price: DEFAULT_L2_GAS_PRICE, compute_overhead_part: 0.0, pubdata_overhead_part: 1.0, diff --git a/src/node/in_memory.rs b/src/node/in_memory.rs index d8b52887..23d57ce8 100644 --- a/src/node/in_memory.rs +++ b/src/node/in_memory.rs @@ -74,7 +74,7 @@ pub const NON_FORK_FIRST_BLOCK_TIMESTAMP: u64 = 1_000; /// Network ID we use for the test node. pub const TEST_NODE_NETWORK_ID: u32 = 260; /// L1 Gas Price. -pub const L1_GAS_PRICE: u64 = 50_000_000_000; +pub const DEFAULT_L1_GAS_PRICE: u64 = 50_000_000_000; // TODO: for now, that's fine, as computation overhead is set to zero, but we may consider using calculated fee input everywhere. /// The default L2 Gas Price to be used if not supplied via the CLI argument. pub const DEFAULT_L2_GAS_PRICE: u64 = 25_000_000; @@ -884,6 +884,7 @@ pub struct Snapshot { #[derive(Debug, Clone)] pub struct InMemoryNodeConfig { // The values to be used when calculating gas. + pub l1_gas_price: Option, pub l2_fair_gas_price: u64, pub show_calls: ShowCalls, pub show_outputs: bool, @@ -897,6 +898,7 @@ pub struct InMemoryNodeConfig { impl Default for InMemoryNodeConfig { fn default() -> Self { Self { + l1_gas_price: None, l2_fair_gas_price: DEFAULT_L2_GAS_PRICE, show_calls: Default::default(), show_outputs: Default::default(), @@ -943,6 +945,22 @@ impl InMemoryNode { observability: Option, config: InMemoryNodeConfig, ) -> Self { + let default_l1_gas_price = if let Some(f) = &fork { + f.l1_gas_price + } else { + DEFAULT_L1_GAS_PRICE + }; + let l1_gas_price = if let Some(custom_l1_gas_price) = config.l1_gas_price { + tracing::info!( + "L1 gas price set to {} (overridden from {})", + to_human_size(custom_l1_gas_price.into()), + to_human_size(default_l1_gas_price.into()) + ); + custom_l1_gas_price + } else { + default_l1_gas_price + }; + let inner = if let Some(f) = &fork { let mut block_hashes = HashMap::::new(); block_hashes.insert(f.l2_block.number.as_u64(), f.l2_block.hash); @@ -961,6 +979,7 @@ impl InMemoryNode { f.estimate_gas_scale_factor, ) }; + fee_input_provider.l1_gas_price = l1_gas_price; fee_input_provider.l2_gas_price = config.l2_fair_gas_price; InMemoryNodeInner { @@ -997,12 +1016,16 @@ impl InMemoryNode { create_empty_block(0, NON_FORK_FIRST_BLOCK_TIMESTAMP, 0, None), ); + let fee_input_provider = TestNodeFeeInputProvider { + l1_gas_price, + ..Default::default() + }; InMemoryNodeInner { current_timestamp: NON_FORK_FIRST_BLOCK_TIMESTAMP, current_batch: 0, current_miniblock: 0, current_miniblock_hash: block_hash, - fee_input_provider: TestNodeFeeInputProvider::default(), + fee_input_provider, tx_results: Default::default(), blocks, block_hashes,