Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom l1 price #294

Merged
merged 10 commits into from
Jun 27, 2024
Merged
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,

#[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.
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/node/fee_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 23 additions & 2 deletions src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
/// 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;
Expand Down Expand Up @@ -884,6 +884,7 @@
#[derive(Debug, Clone)]
pub struct InMemoryNodeConfig {
// The values to be used when calculating gas.
pub l1_gas_price: Option<u64>,
pub l2_fair_gas_price: u64,
pub show_calls: ShowCalls,
pub show_outputs: bool,
Expand All @@ -897,6 +898,7 @@
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(),
Expand Down Expand Up @@ -943,6 +945,22 @@
observability: Option<Observability>,
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::<u64, H256>::new();
block_hashes.insert(f.l2_block.number.as_u64(), f.l2_block.hash);
Expand All @@ -961,6 +979,7 @@
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 {
Expand Down Expand Up @@ -997,12 +1016,14 @@
create_empty_block(0, NON_FORK_FIRST_BLOCK_TIMESTAMP, 0, None),
);

let mut fee_input_provider = TestNodeFeeInputProvider::default();
fee_input_provider.l1_gas_price = l1_gas_price;

Check failure on line 1020 in src/node/in_memory.rs

View workflow job for this annotation

GitHub Actions / lint

field assignment outside of initializer for an instance created with 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,
Expand Down
Loading