From 03147c12cf158c542e6bd492916f46cf0abb5460 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Mon, 22 Jul 2024 14:23:15 +0200 Subject: [PATCH 01/11] fix: comments, docs --- core/node/fee_model/src/lib.rs | 4 ++-- docs/guides/advanced/fee_model.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index 00d804de6c81..7feb6150861a 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -191,7 +191,7 @@ fn compute_batch_fee_model_input_v2( let l1_batch_overhead_wei = U256::from(l1_gas_price) * U256::from(batch_overhead_l1_gas); let fair_l2_gas_price = { - // Firstly, we calculate which part of the overall overhead overhead each unit of L2 gas should cover. + // Firstly, we calculate which part of the overall overhead each unit of L2 gas should cover. let l1_batch_overhead_per_gas = ceil_div_u256(l1_batch_overhead_wei, U256::from(max_gas_per_batch)); @@ -206,7 +206,7 @@ fn compute_batch_fee_model_input_v2( }; let fair_pubdata_price = { - // Firstly, we calculate which part of the overall overhead overhead each pubdata byte should cover. + // Firstly, we calculate which part of the overall overhead each pubdata byte should cover. let l1_batch_overhead_per_pubdata = ceil_div_u256(l1_batch_overhead_wei, U256::from(max_pubdata_per_batch)); diff --git a/docs/guides/advanced/fee_model.md b/docs/guides/advanced/fee_model.md index 3e6473d3ab96..cd2b09ce04cc 100644 --- a/docs/guides/advanced/fee_model.md +++ b/docs/guides/advanced/fee_model.md @@ -171,7 +171,7 @@ proportional to the part of the batch you are using. | gas_limit | `<= max_allowed_l2_tx_gas_limit` | The limit (4G gas) is set in the `StateKeeper` config; it's the limit for the entire L1 batch. | | gas_limit | `<= MAX_GAS_PER_TRANSACTION` | This limit (80M) is set in bootloader. | | gas_limit | `> l2_tx_intrinsic_gas` | This limit (around 14k gas) is hardcoded to ensure that the transaction has enough gas to start. | -| max_fee_per_gas | `<= fair_l2_gas_price` | Fair L2 gas price (0.25 Gwei) is set in the `StateKeeper` config | +| max_fee_per_gas | `>= fair_l2_gas_price` | Fair L2 gas price (0.25 Gwei) is set in the `StateKeeper` config | | | `<=validation_computational_gas_limit` | There is an additional, stricter limit (300k gas) on the amount of gas that a transaction can use during validation. | ### Why do we have two limits: 80M and 4G From 8e6554ca3f5532460b07fc9de212d1ff94595906 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Mon, 22 Jul 2024 15:51:53 +0200 Subject: [PATCH 02/11] feat: set maximum l2 gas price on server to 10 gwei --- core/lib/types/src/fee_model.rs | 7 +++++++ core/node/fee_model/src/lib.rs | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/lib/types/src/fee_model.rs b/core/lib/types/src/fee_model.rs index 38d785113e5f..7bd6c2389c17 100644 --- a/core/lib/types/src/fee_model.rs +++ b/core/lib/types/src/fee_model.rs @@ -203,6 +203,13 @@ pub struct FeeModelConfigV2 { pub max_pubdata_per_batch: u64, } +impl FeeModelConfigV2 { + /// The maximum acceptable L2 gas price. Currently, this is required by the bootloader. + pub fn maximum_l2_gas_price(&self) -> u64 { + 10_000_000_000_000 // 10k gwei + } +} + impl Default for FeeModelConfig { /// Config with all zeroes is not a valid config (since for instance having 0 max gas per batch may incur division by zero), /// so we implement a sensible default config here. diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index 7feb6150861a..e38dff0e5cdf 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -202,7 +202,13 @@ fn compute_batch_fee_model_input_v2( (l1_batch_overhead_per_gas.as_u64() as f64 * compute_overhead_part) as u64; // We sum up the minimal L2 gas price (i.e. the raw prover/compute cost of a single L2 gas) and the overhead for batch being closed. - minimal_l2_gas_price + gas_overhead_wei + let calculated_price = minimal_l2_gas_price + gas_overhead_wei; + + if calculated_price < config.maximum_l2_gas_price() { + calculated_price + } else { + config.maximum_l2_gas_price() + } }; let fair_pubdata_price = { From 15c98f9ffafe4337bbfe06f326107d7962e067db Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Tue, 23 Jul 2024 16:14:23 +0200 Subject: [PATCH 03/11] feat: Tests for l2 gas price limit --- core/node/fee_model/src/lib.rs | 76 +++++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 10 deletions(-) diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index e38dff0e5cdf..82df71a992d0 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -265,9 +265,11 @@ mod tests { // To test that overflow never happens, we'll use giant L1 gas price, i.e. // almost realistic very large value of 100k gwei. Since it is so large, we'll also // use it for the L1 pubdata price. - const GIANT_L1_GAS_PRICE: u64 = 100_000_000_000_000; + const GWEI: u64 = 1_000_000_000; + const GIANT_L1_GAS_PRICE: u64 = 1_000 * GWEI; + const GIANT_L1_PUB_DATA_PRICE: u64 = 100_000_000 * GWEI; - // As a small small L2 gas price we'll use the value of 1 wei. + // As a small L2 gas price we'll use the value of 1 wei. const SMALL_L1_GAS_PRICE: u64 = 1; #[test] @@ -289,7 +291,7 @@ mod tests { let params = FeeParamsV2::new( config, GIANT_L1_GAS_PRICE, - GIANT_L1_GAS_PRICE, + GIANT_L1_PUB_DATA_PRICE, BaseTokenConversionRatio::default(), ); @@ -297,8 +299,8 @@ mod tests { let input = compute_batch_fee_model_input_v2(params, 3.0, 3.0); assert_eq!(input.l1_gas_price, GIANT_L1_GAS_PRICE * 3); - assert_eq!(input.fair_l2_gas_price, 130_000_000_000_000); - assert_eq!(input.fair_pubdata_price, 15_300_000_000_000_000); + assert_eq!(input.fair_l2_gas_price, 1_300_000_000_000); + assert_eq!(input.fair_pubdata_price, 300_150_000_000_000_000); } #[test] @@ -342,7 +344,7 @@ mod tests { let params = FeeParamsV2::new( config, GIANT_L1_GAS_PRICE, - GIANT_L1_GAS_PRICE, + GIANT_L1_PUB_DATA_PRICE, BaseTokenConversionRatio::default(), ); @@ -351,14 +353,14 @@ mod tests { // The fair L2 gas price is identical to the minimal one. assert_eq!(input.fair_l2_gas_price, 100_000_000_000); // The fair pubdata price is the minimal one plus the overhead. - assert_eq!(input.fair_pubdata_price, 800_000_000_000_000); + assert_eq!(input.fair_pubdata_price, 100_007_000_000_000_000); } #[test] fn test_compute_baxtch_fee_model_input_v2_only_compute_overhead() { // Here we use sensible config, but when only compute is used to close the batch let config = FeeModelConfigV2 { - minimal_l2_gas_price: 100_000_000_000, + minimal_l2_gas_price: 1_000_000_000, compute_overhead_part: 1.0, pubdata_overhead_part: 0.0, batch_overhead_l1_gas: 700_000, @@ -376,7 +378,7 @@ mod tests { let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); assert_eq!(input.l1_gas_price, GIANT_L1_GAS_PRICE); // The fair L2 gas price is identical to the minimal one, plus the overhead - assert_eq!(input.fair_l2_gas_price, 240_000_000_000); + assert_eq!(input.fair_l2_gas_price, 2_400_000_000); // The fair pubdata price is equal to the original one. assert_eq!(input.fair_pubdata_price, GIANT_L1_GAS_PRICE); } @@ -497,6 +499,60 @@ mod tests { ); } + #[test] + fn test_compute_batch_fee_model_input_v2_gas_price_over_limit_due_to_l1_gas() { + // In this test we check the gas price limit works as expected + let config = FeeModelConfigV2 { + minimal_l2_gas_price: 100 * GWEI, + compute_overhead_part: 0.5, + pubdata_overhead_part: 0.5, + batch_overhead_l1_gas: 700_000, + max_gas_per_batch: 500_000_000, + max_pubdata_per_batch: 100_000, + }; + + let l1_gas_price = 1_000_000_000 * GWEI; + let params = FeeParamsV2::new( + config, + l1_gas_price, + GIANT_L1_PUB_DATA_PRICE, + BaseTokenConversionRatio::default(), + ); + + let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); + assert_eq!(input.l1_gas_price, l1_gas_price); + // The fair L2 gas price is identical to the maximum + assert_eq!(input.fair_l2_gas_price, config.maximum_l2_gas_price()); + } + + #[test] + fn test_compute_batch_fee_model_input_v2_gas_price_over_limit_due_to_conversion_rate() { + // In this test we check the gas price limit works as expected + let config = FeeModelConfigV2 { + minimal_l2_gas_price: GWEI, + compute_overhead_part: 0.5, + pubdata_overhead_part: 0.5, + batch_overhead_l1_gas: 700_000, + max_gas_per_batch: 500_000_000, + max_pubdata_per_batch: 100_000, + }; + + let params = FeeParamsV2::new( + config, + GWEI, + 2 * GWEI, + BaseTokenConversionRatio { + numerator: NonZeroU64::new(3_000_000).unwrap(), + denominator: NonZeroU64::new(1).unwrap(), + }, + ); + + let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); + assert_eq!(input.l1_gas_price, 3_000_000 * GWEI); + // The fair L2 gas price is identical to the maximum + assert_eq!(input.fair_l2_gas_price, config.maximum_l2_gas_price()); + } + #[tokio::test] async fn test_get_fee_model_params() { struct TestCase { @@ -550,7 +606,7 @@ mod tests { expected_l1_pubdata_price: 3000, }, TestCase { - name: "Large conversion - 1 ETH = 1_000 BaseToken", + name: "Large conversion - 1 ETH = 1_000_000 BaseToken", conversion_ratio: BaseTokenConversionRatio { numerator: NonZeroU64::new(1_000_000).unwrap(), denominator: NonZeroU64::new(1).unwrap(), From 2387f8d1aebdb4405e7acb2237b2fab91831739e Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Wed, 24 Jul 2024 14:17:46 +0200 Subject: [PATCH 04/11] docs --- core/lib/types/src/fee_model.rs | 1 + docs/guides/advanced/fee_model.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/core/lib/types/src/fee_model.rs b/core/lib/types/src/fee_model.rs index 7bd6c2389c17..4c9ebf0a3204 100644 --- a/core/lib/types/src/fee_model.rs +++ b/core/lib/types/src/fee_model.rs @@ -205,6 +205,7 @@ pub struct FeeModelConfigV2 { impl FeeModelConfigV2 { /// The maximum acceptable L2 gas price. Currently, this is required by the bootloader. + /// TODO remove when no longer required by bootloader pub fn maximum_l2_gas_price(&self) -> u64 { 10_000_000_000_000 // 10k gwei } diff --git a/docs/guides/advanced/fee_model.md b/docs/guides/advanced/fee_model.md index cd2b09ce04cc..4592c5007ea2 100644 --- a/docs/guides/advanced/fee_model.md +++ b/docs/guides/advanced/fee_model.md @@ -171,7 +171,7 @@ proportional to the part of the batch you are using. | gas_limit | `<= max_allowed_l2_tx_gas_limit` | The limit (4G gas) is set in the `StateKeeper` config; it's the limit for the entire L1 batch. | | gas_limit | `<= MAX_GAS_PER_TRANSACTION` | This limit (80M) is set in bootloader. | | gas_limit | `> l2_tx_intrinsic_gas` | This limit (around 14k gas) is hardcoded to ensure that the transaction has enough gas to start. | -| max_fee_per_gas | `>= fair_l2_gas_price` | Fair L2 gas price (0.25 Gwei) is set in the `StateKeeper` config | +| max_fee_per_gas | `>= fair_l2_gas_price` | Fair L2 gas price (0.1 Gwei on Era) is set in the `StateKeeper` config | | | `<=validation_computational_gas_limit` | There is an additional, stricter limit (300k gas) on the amount of gas that a transaction can use during validation. | ### Why do we have two limits: 80M and 4G From 2ba5090d183e6f183187fe8691b1caf104926040 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Wed, 24 Jul 2024 14:18:08 +0200 Subject: [PATCH 05/11] fix: Add warn on exceeded max gas price --- core/node/fee_model/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index 82df71a992d0..a98d3753d61b 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -207,6 +207,11 @@ fn compute_batch_fee_model_input_v2( if calculated_price < config.maximum_l2_gas_price() { calculated_price } else { + tracing::warn!( + "Fair l2 gas price {} exceeds maximum. Limiting to {}", + calculated_price, + config.maximum_l2_gas_price() + ); config.maximum_l2_gas_price() } }; From c24f7a23784d7b6692d6a108da4d2a045029eab6 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Wed, 24 Jul 2024 14:35:22 +0200 Subject: [PATCH 06/11] feat: limit pubdata price to 1M gwei --- core/lib/types/src/fee_model.rs | 6 ++++++ core/node/fee_model/src/lib.rs | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/core/lib/types/src/fee_model.rs b/core/lib/types/src/fee_model.rs index 4c9ebf0a3204..6a07f0d3d9df 100644 --- a/core/lib/types/src/fee_model.rs +++ b/core/lib/types/src/fee_model.rs @@ -209,6 +209,12 @@ impl FeeModelConfigV2 { pub fn maximum_l2_gas_price(&self) -> u64 { 10_000_000_000_000 // 10k gwei } + + /// The maximum acceptable pubdata. Currently, this is required by the bootloader. + /// TODO remove when no longer required by bootloader + pub fn maximum_pubdata_price(&self) -> u64 { + 1_000_000_000_000_000 // 1M gwei + } } impl Default for FeeModelConfig { diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index a98d3753d61b..22a2dc6355d0 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -228,7 +228,18 @@ fn compute_batch_fee_model_input_v2( (l1_batch_overhead_per_pubdata.as_u64() as f64 * pubdata_overhead_part) as u64; // We sum up the raw L1 pubdata price (i.e. the expected price of publishing a single pubdata byte) and the overhead for batch being closed. - l1_pubdata_price + pubdata_overhead_wei + let calculated_price = l1_pubdata_price + pubdata_overhead_wei; + + if calculated_price < config.maximum_pubdata_price() { + calculated_price + } else { + tracing::warn!( + "Fair pubdata price {} exceeds maximum. Limitting to {}", + calculated_price, + config.maximum_pubdata_price() + ); + config.maximum_pubdata_price() + } }; PubdataIndependentBatchFeeModelInput { @@ -272,7 +283,7 @@ mod tests { // use it for the L1 pubdata price. const GWEI: u64 = 1_000_000_000; const GIANT_L1_GAS_PRICE: u64 = 1_000 * GWEI; - const GIANT_L1_PUB_DATA_PRICE: u64 = 100_000_000 * GWEI; + const GIANT_L1_PUB_DATA_PRICE: u64 = 100_000 * GWEI; // As a small L2 gas price we'll use the value of 1 wei. const SMALL_L1_GAS_PRICE: u64 = 1; @@ -305,7 +316,7 @@ mod tests { assert_eq!(input.l1_gas_price, GIANT_L1_GAS_PRICE * 3); assert_eq!(input.fair_l2_gas_price, 1_300_000_000_000); - assert_eq!(input.fair_pubdata_price, 300_150_000_000_000_000); + assert_eq!(input.fair_pubdata_price, 450_000_000_000_000); } #[test] @@ -358,7 +369,7 @@ mod tests { // The fair L2 gas price is identical to the minimal one. assert_eq!(input.fair_l2_gas_price, 100_000_000_000); // The fair pubdata price is the minimal one plus the overhead. - assert_eq!(input.fair_pubdata_price, 100_007_000_000_000_000); + assert_eq!(input.fair_pubdata_price, 107_000_000_000_000); } #[test] From fa78110a8eb745fdb2037bc4a0769abbb90259f7 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Wed, 24 Jul 2024 16:09:09 +0200 Subject: [PATCH 07/11] fix: zk fmt --- docs/guides/external-node/09_decentralization.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/guides/external-node/09_decentralization.md b/docs/guides/external-node/09_decentralization.md index aa9598a825ca..fa780ba9ff55 100644 --- a/docs/guides/external-node/09_decentralization.md +++ b/docs/guides/external-node/09_decentralization.md @@ -17,11 +17,10 @@ On the gossipnet, the data integrity will be protected by the BFT (byzantine fau > current implementation it may take a couple of hours and gets faster the more nodes you add to the > `gossip_static_outbound` list (see below). We are working to remove this inconvenience. - > [!NOTE] > -> The minimal supported server version for this is [24.11.0](https://github.com/matter-labs/zksync-era/releases/tag/core-v24.11.0) - +> The minimal supported server version for this is +> [24.11.0](https://github.com/matter-labs/zksync-era/releases/tag/core-v24.11.0) ### Generating secrets From ae287ac1f2728ee2a180f48df24d08f6d2995bc2 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Thu, 25 Jul 2024 12:41:49 +0200 Subject: [PATCH 08/11] fix: separate clipping logic into a function --- core/lib/types/src/fee_model.rs | 15 ----- core/node/fee_model/src/lib.rs | 98 ++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 59 deletions(-) diff --git a/core/lib/types/src/fee_model.rs b/core/lib/types/src/fee_model.rs index 6a07f0d3d9df..6f5985d46108 100644 --- a/core/lib/types/src/fee_model.rs +++ b/core/lib/types/src/fee_model.rs @@ -202,21 +202,6 @@ pub struct FeeModelConfigV2 { /// The maximum amount of pubdata that can be used by the batch. Note that if the calldata is used as pubdata, this variable should not exceed 128kb. pub max_pubdata_per_batch: u64, } - -impl FeeModelConfigV2 { - /// The maximum acceptable L2 gas price. Currently, this is required by the bootloader. - /// TODO remove when no longer required by bootloader - pub fn maximum_l2_gas_price(&self) -> u64 { - 10_000_000_000_000 // 10k gwei - } - - /// The maximum acceptable pubdata. Currently, this is required by the bootloader. - /// TODO remove when no longer required by bootloader - pub fn maximum_pubdata_price(&self) -> u64 { - 1_000_000_000_000_000 // 1M gwei - } -} - impl Default for FeeModelConfig { /// Config with all zeroes is not a valid config (since for instance having 0 max gas per batch may incur division by zero), /// so we implement a sensible default config here. diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index 22a2dc6355d0..6584e69cd817 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -34,13 +34,13 @@ pub trait BatchFeeModelInputProvider: fmt::Debug + 'static + Send + Sync { params, l1_gas_price_scale_factor, )), - FeeParams::V2(params) => { - BatchFeeInput::PubdataIndependent(compute_batch_fee_model_input_v2( + FeeParams::V2(params) => BatchFeeInput::PubdataIndependent( + clip_batch_fee_model_input_v2(compute_batch_fee_model_input_v2( params, l1_gas_price_scale_factor, l1_pubdata_price_scale_factor, - )) - } + )), + ), }) } @@ -202,18 +202,7 @@ fn compute_batch_fee_model_input_v2( (l1_batch_overhead_per_gas.as_u64() as f64 * compute_overhead_part) as u64; // We sum up the minimal L2 gas price (i.e. the raw prover/compute cost of a single L2 gas) and the overhead for batch being closed. - let calculated_price = minimal_l2_gas_price + gas_overhead_wei; - - if calculated_price < config.maximum_l2_gas_price() { - calculated_price - } else { - tracing::warn!( - "Fair l2 gas price {} exceeds maximum. Limiting to {}", - calculated_price, - config.maximum_l2_gas_price() - ); - config.maximum_l2_gas_price() - } + minimal_l2_gas_price + gas_overhead_wei }; let fair_pubdata_price = { @@ -228,18 +217,7 @@ fn compute_batch_fee_model_input_v2( (l1_batch_overhead_per_pubdata.as_u64() as f64 * pubdata_overhead_part) as u64; // We sum up the raw L1 pubdata price (i.e. the expected price of publishing a single pubdata byte) and the overhead for batch being closed. - let calculated_price = l1_pubdata_price + pubdata_overhead_wei; - - if calculated_price < config.maximum_pubdata_price() { - calculated_price - } else { - tracing::warn!( - "Fair pubdata price {} exceeds maximum. Limitting to {}", - calculated_price, - config.maximum_pubdata_price() - ); - config.maximum_pubdata_price() - } + l1_pubdata_price + pubdata_overhead_wei }; PubdataIndependentBatchFeeModelInput { @@ -249,6 +227,33 @@ fn compute_batch_fee_model_input_v2( } } +/// Bootloader places limitations on fair_l2_gas_price and fair_pubdata_price. +/// (MAX_ALLOWED_FAIR_L2_GAS_PRICE and MAX_ALLOWED_FAIR_PUBDATA_PRICE in bootloader code respectively) +/// Server needs to clip this prices in order to allow chain continues operation at a loss. The alternative +/// would be to stop accepting the transactions until the conditions improve. +/// TODO PE-153, to be removed when bootloader limitation is removed +fn clip_batch_fee_model_input_v2( + fee_model: PubdataIndependentBatchFeeModelInput, +) -> PubdataIndependentBatchFeeModelInput { + /// MAX_ALLOWED_FAIR_L2_GAS_PRICE + const MAXIMUM_L2_GAS_PRICE: u64 = 10_000_000_000_000; + /// MAX_ALLOWED_FAIR_PUBDATA_PRICE + const MAXIMUM_PUBDATA_PRICE: u64 = 1_000_000_000_000_000; + PubdataIndependentBatchFeeModelInput { + l1_gas_price: fee_model.l1_gas_price, + fair_l2_gas_price: if fee_model.fair_l2_gas_price < MAXIMUM_L2_GAS_PRICE { + fee_model.fair_l2_gas_price + } else { + MAXIMUM_L2_GAS_PRICE + }, + fair_pubdata_price: if fee_model.fair_pubdata_price < MAXIMUM_PUBDATA_PRICE { + fee_model.fair_pubdata_price + } else { + MAXIMUM_PUBDATA_PRICE + }, + } +} + /// Mock [`BatchFeeModelInputProvider`] implementation that returns a constant value. /// Intended to be used in tests only. #[derive(Debug)] @@ -282,8 +287,7 @@ mod tests { // almost realistic very large value of 100k gwei. Since it is so large, we'll also // use it for the L1 pubdata price. const GWEI: u64 = 1_000_000_000; - const GIANT_L1_GAS_PRICE: u64 = 1_000 * GWEI; - const GIANT_L1_PUB_DATA_PRICE: u64 = 100_000 * GWEI; + const GIANT_L1_GAS_PRICE: u64 = 100_000 * GWEI; // As a small L2 gas price we'll use the value of 1 wei. const SMALL_L1_GAS_PRICE: u64 = 1; @@ -307,7 +311,7 @@ mod tests { let params = FeeParamsV2::new( config, GIANT_L1_GAS_PRICE, - GIANT_L1_PUB_DATA_PRICE, + GIANT_L1_GAS_PRICE, BaseTokenConversionRatio::default(), ); @@ -315,8 +319,8 @@ mod tests { let input = compute_batch_fee_model_input_v2(params, 3.0, 3.0); assert_eq!(input.l1_gas_price, GIANT_L1_GAS_PRICE * 3); - assert_eq!(input.fair_l2_gas_price, 1_300_000_000_000); - assert_eq!(input.fair_pubdata_price, 450_000_000_000_000); + assert_eq!(input.fair_l2_gas_price, 130_000_000_000_000); + assert_eq!(input.fair_pubdata_price, 15_300_000_000_000_000); } #[test] @@ -338,7 +342,8 @@ mod tests { BaseTokenConversionRatio::default(), ); - let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); + let input = + clip_batch_fee_model_input_v2(compute_batch_fee_model_input_v2(params, 1.0, 1.0)); assert_eq!(input.l1_gas_price, SMALL_L1_GAS_PRICE); assert_eq!(input.fair_l2_gas_price, SMALL_L1_GAS_PRICE); @@ -360,23 +365,24 @@ mod tests { let params = FeeParamsV2::new( config, GIANT_L1_GAS_PRICE, - GIANT_L1_PUB_DATA_PRICE, + GIANT_L1_GAS_PRICE, BaseTokenConversionRatio::default(), ); - let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); + let input = + clip_batch_fee_model_input_v2(compute_batch_fee_model_input_v2(params, 1.0, 1.0)); assert_eq!(input.l1_gas_price, GIANT_L1_GAS_PRICE); // The fair L2 gas price is identical to the minimal one. assert_eq!(input.fair_l2_gas_price, 100_000_000_000); // The fair pubdata price is the minimal one plus the overhead. - assert_eq!(input.fair_pubdata_price, 107_000_000_000_000); + assert_eq!(input.fair_pubdata_price, 800_000_000_000_000); } #[test] fn test_compute_baxtch_fee_model_input_v2_only_compute_overhead() { // Here we use sensible config, but when only compute is used to close the batch let config = FeeModelConfigV2 { - minimal_l2_gas_price: 1_000_000_000, + minimal_l2_gas_price: 100_000_000_000, compute_overhead_part: 1.0, pubdata_overhead_part: 0.0, batch_overhead_l1_gas: 700_000, @@ -394,7 +400,7 @@ mod tests { let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); assert_eq!(input.l1_gas_price, GIANT_L1_GAS_PRICE); // The fair L2 gas price is identical to the minimal one, plus the overhead - assert_eq!(input.fair_l2_gas_price, 2_400_000_000); + assert_eq!(input.fair_l2_gas_price, 240_000_000_000); // The fair pubdata price is equal to the original one. assert_eq!(input.fair_pubdata_price, GIANT_L1_GAS_PRICE); } @@ -531,14 +537,16 @@ mod tests { let params = FeeParamsV2::new( config, l1_gas_price, - GIANT_L1_PUB_DATA_PRICE, + GIANT_L1_GAS_PRICE, BaseTokenConversionRatio::default(), ); - let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); + let input = + clip_batch_fee_model_input_v2(compute_batch_fee_model_input_v2(params, 1.0, 1.0)); assert_eq!(input.l1_gas_price, l1_gas_price); // The fair L2 gas price is identical to the maximum - assert_eq!(input.fair_l2_gas_price, config.maximum_l2_gas_price()); + assert_eq!(input.fair_l2_gas_price, 10_000 * GWEI); + assert_eq!(input.fair_pubdata_price, 1_000_000 * GWEI); } #[test] @@ -563,10 +571,12 @@ mod tests { }, ); - let input = compute_batch_fee_model_input_v2(params, 1.0, 1.0); + let input = + clip_batch_fee_model_input_v2(compute_batch_fee_model_input_v2(params, 1.0, 1.0)); assert_eq!(input.l1_gas_price, 3_000_000 * GWEI); // The fair L2 gas price is identical to the maximum - assert_eq!(input.fair_l2_gas_price, config.maximum_l2_gas_price()); + assert_eq!(input.fair_l2_gas_price, 10_000 * GWEI); + assert_eq!(input.fair_pubdata_price, 1_000_000 * GWEI); } #[tokio::test] From 2b5293c251d1f58aa03cbda2dcdd0d2e36b952fb Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Tue, 30 Jul 2024 10:34:25 +0200 Subject: [PATCH 09/11] fix: style --- core/node/fee_model/src/lib.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index 6584e69cd817..37560e680f91 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -1,4 +1,4 @@ -use std::{fmt, sync::Arc}; +use std::{cmp::min, fmt, sync::Arc}; use anyhow::Context as _; use async_trait::async_trait; @@ -231,7 +231,7 @@ fn compute_batch_fee_model_input_v2( /// (MAX_ALLOWED_FAIR_L2_GAS_PRICE and MAX_ALLOWED_FAIR_PUBDATA_PRICE in bootloader code respectively) /// Server needs to clip this prices in order to allow chain continues operation at a loss. The alternative /// would be to stop accepting the transactions until the conditions improve. -/// TODO PE-153, to be removed when bootloader limitation is removed +/// TODO (PE-153): to be removed when bootloader limitation is removed fn clip_batch_fee_model_input_v2( fee_model: PubdataIndependentBatchFeeModelInput, ) -> PubdataIndependentBatchFeeModelInput { @@ -241,16 +241,8 @@ fn clip_batch_fee_model_input_v2( const MAXIMUM_PUBDATA_PRICE: u64 = 1_000_000_000_000_000; PubdataIndependentBatchFeeModelInput { l1_gas_price: fee_model.l1_gas_price, - fair_l2_gas_price: if fee_model.fair_l2_gas_price < MAXIMUM_L2_GAS_PRICE { - fee_model.fair_l2_gas_price - } else { - MAXIMUM_L2_GAS_PRICE - }, - fair_pubdata_price: if fee_model.fair_pubdata_price < MAXIMUM_PUBDATA_PRICE { - fee_model.fair_pubdata_price - } else { - MAXIMUM_PUBDATA_PRICE - }, + fair_l2_gas_price: min(fee_model.fair_l2_gas_price, MAXIMUM_L2_GAS_PRICE), + fair_pubdata_price: min(fee_model.fair_pubdata_price, MAXIMUM_PUBDATA_PRICE), } } From ef445c040bda02ab71117106705538c22c24c882 Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Tue, 30 Jul 2024 12:56:50 +0200 Subject: [PATCH 10/11] fix: readd log --- core/node/fee_model/src/lib.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index 37560e680f91..2698c402f85d 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -241,8 +241,26 @@ fn clip_batch_fee_model_input_v2( const MAXIMUM_PUBDATA_PRICE: u64 = 1_000_000_000_000_000; PubdataIndependentBatchFeeModelInput { l1_gas_price: fee_model.l1_gas_price, - fair_l2_gas_price: min(fee_model.fair_l2_gas_price, MAXIMUM_L2_GAS_PRICE), - fair_pubdata_price: min(fee_model.fair_pubdata_price, MAXIMUM_PUBDATA_PRICE), + fair_l2_gas_price: if fee_model.fair_l2_gas_price < MAXIMUM_L2_GAS_PRICE { + fee_model.fair_l2_gas_price + } else { + tracing::warn!( + "Fair l2 gas price {} exceeds maximum. Limitting to {}", + fee_model.fair_l2_gas_price, + MAXIMUM_L2_GAS_PRICE + ); + MAXIMUM_L2_GAS_PRICE + }, + fair_pubdata_price: if fee_model.fair_pubdata_price < MAXIMUM_PUBDATA_PRICE { + fee_model.fair_pubdata_price + } else { + tracing::warn!( + "Fair pubdata price {} exceeds maximum. Limitting to {}", + fee_model.fair_pubdata_price, + MAXIMUM_PUBDATA_PRICE + ); + MAXIMUM_PUBDATA_PRICE + }, } } From 918239f0951b76fc8ebdd95808fdd8e9a70b649c Mon Sep 17 00:00:00 2001 From: Artur Puzio Date: Tue, 30 Jul 2024 13:15:31 +0200 Subject: [PATCH 11/11] fix: import --- core/node/fee_model/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/node/fee_model/src/lib.rs b/core/node/fee_model/src/lib.rs index 2698c402f85d..66a1c07a1c64 100644 --- a/core/node/fee_model/src/lib.rs +++ b/core/node/fee_model/src/lib.rs @@ -1,4 +1,4 @@ -use std::{cmp::min, fmt, sync::Arc}; +use std::{fmt, sync::Arc}; use anyhow::Context as _; use async_trait::async_trait;