Skip to content

Commit 506822e

Browse files
authored
fix(api): Return back fee params backward compatibility for non gateway chains (#4361)
## What ❔ Use default base token conversion params for preserving backward compatibility ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- The `Why` has to be clear to non-Matter Labs entities running their own ZK Chain --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Is this a breaking change? - [ ] Yes - [ ] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`. Signed-off-by: Danil <[email protected]>
1 parent 21ebe9f commit 506822e

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed

core/lib/dal/src/base_token_dal.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,30 @@ impl BaseTokenDal<'_, '_> {
3232
RETURNING
3333
id
3434
"#,
35-
BigDecimal::from_u64(base_token_conversion_ratio.l1.numerator.get()),
36-
BigDecimal::from_u64(base_token_conversion_ratio.l1.denominator.get()),
37-
BigDecimal::from_u64(base_token_conversion_ratio.sl.numerator.get()),
38-
BigDecimal::from_u64(base_token_conversion_ratio.sl.denominator.get()),
35+
BigDecimal::from_u64(
36+
base_token_conversion_ratio
37+
.l1_conversion_ratio()
38+
.numerator
39+
.get()
40+
),
41+
BigDecimal::from_u64(
42+
base_token_conversion_ratio
43+
.l1_conversion_ratio()
44+
.denominator
45+
.get()
46+
),
47+
BigDecimal::from_u64(
48+
base_token_conversion_ratio
49+
.sl_conversion_ratio()
50+
.numerator
51+
.get()
52+
),
53+
BigDecimal::from_u64(
54+
base_token_conversion_ratio
55+
.sl_conversion_ratio()
56+
.denominator
57+
.get()
58+
),
3959
ratio_timestamp,
4060
)
4161
.instrument("insert_token_ratio")

core/lib/types/src/fee_model.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,20 +306,26 @@ impl FeeParamsV2 {
306306
FeeModelConfigV2 {
307307
minimal_l2_gas_price: self.convert_l1_to_base_token(
308308
self.config.minimal_l2_gas_price,
309-
self.conversion_ratio.l1,
309+
self.conversion_ratio.l1_conversion_ratio(),
310310
),
311311
..self.config
312312
}
313313
}
314314

315315
/// Returns the l1 gas price denominated in the chain's base token (WEI or equivalent).
316316
pub fn l1_gas_price(&self) -> u64 {
317-
self.convert_l1_to_base_token(self.l1_gas_price, self.conversion_ratio.sl)
317+
self.convert_l1_to_base_token(
318+
self.l1_gas_price,
319+
self.conversion_ratio.sl_conversion_ratio(),
320+
)
318321
}
319322

320323
/// Returns the l1 pubdata price denominated in the chain's base token (WEI or equivalent).
321324
pub fn l1_pubdata_price(&self) -> u64 {
322-
self.convert_l1_to_base_token(self.l1_pubdata_price, self.conversion_ratio.sl)
325+
self.convert_l1_to_base_token(
326+
self.l1_pubdata_price,
327+
self.conversion_ratio.sl_conversion_ratio(),
328+
)
323329
}
324330

325331
/// Converts the fee param to the base token.
@@ -380,8 +386,8 @@ impl Default for ConversionRatio {
380386
/// The struct that represents the BaseToken<->ETH conversion ratio.
381387
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
382388
pub struct BaseTokenConversionRatio {
383-
pub l1: ConversionRatio,
384-
pub sl: ConversionRatio,
389+
l1: Option<ConversionRatio>,
390+
sl: Option<ConversionRatio>,
385391
#[deprecated(note = "backwards compatibility for API")]
386392
numerator: NonZeroU64,
387393
#[deprecated(note = "backwards compatibility for API")]
@@ -396,12 +402,23 @@ impl BaseTokenConversionRatio {
396402

397403
pub fn new(l1: ConversionRatio, sl: ConversionRatio) -> Self {
398404
Self {
399-
l1,
400-
sl,
405+
l1: Some(l1),
406+
sl: Some(sl),
401407
numerator: l1.numerator,
402408
denominator: l1.denominator,
403409
}
404410
}
411+
412+
pub fn l1_conversion_ratio(&self) -> ConversionRatio {
413+
self.l1.unwrap_or(ConversionRatio {
414+
numerator: self.numerator,
415+
denominator: self.denominator,
416+
})
417+
}
418+
419+
pub fn sl_conversion_ratio(&self) -> ConversionRatio {
420+
self.sl.unwrap_or_default()
421+
}
405422
}
406423

407424
impl Default for BaseTokenConversionRatio {

core/node/base_token_adjuster/src/base_token_ratio_persister.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,14 @@ mod tests {
298298

299299
// Check the latest ratio matches expected values
300300
let ratio = ratio.unwrap();
301-
assert_eq!(ratio.ratio.sl.numerator.get(), expected_num_ratio);
302-
assert_eq!(ratio.ratio.sl.denominator.get(), expected_denom_ratio);
301+
assert_eq!(
302+
ratio.ratio.sl_conversion_ratio().numerator.get(),
303+
expected_num_ratio
304+
);
305+
assert_eq!(
306+
ratio.ratio.sl_conversion_ratio().denominator.get(),
307+
expected_denom_ratio
308+
);
303309
}
304310

305311
const TOKEN_1_ADDRESS: Address = Address::repeat_byte(0x01);

core/node/state_keeper/src/io/tests/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async fn test_filter_with_no_pending_batch(commitment_mode: L1BatchCommitmentMod
125125
// Create a copy of the tx filter that the mempool will use.
126126
let want_filter = l2_tx_filter(
127127
&tester.create_batch_fee_input_provider().await,
128-
ProtocolVersionId::latest().into(),
128+
ProtocolVersionId::latest(),
129129
)
130130
.await
131131
.unwrap();
@@ -174,7 +174,7 @@ async fn test_timestamps(
174174
// Insert a transaction to trigger L1 batch creation.
175175
let tx_filter = l2_tx_filter(
176176
&tester.create_batch_fee_input_provider().await,
177-
ProtocolVersionId::latest().into(),
177+
ProtocolVersionId::latest(),
178178
)
179179
.await
180180
.unwrap();
@@ -569,7 +569,7 @@ async fn l2_block_processing_after_snapshot_recovery(commitment_mode: L1BatchCom
569569
// Insert a transaction into the mempool in order to open a new batch.
570570
let tx_filter = l2_tx_filter(
571571
&tester.create_batch_fee_input_provider().await,
572-
ProtocolVersionId::latest().into(),
572+
ProtocolVersionId::latest(),
573573
)
574574
.await
575575
.unwrap();
@@ -724,7 +724,7 @@ async fn continue_unsealed_batch_on_restart(commitment_mode: L1BatchCommitmentMo
724724
// Insert a transaction into the mempool in order to open a new batch.
725725
let tx_filter = l2_tx_filter(
726726
&tester.create_batch_fee_input_provider().await,
727-
ProtocolVersionId::latest().into(),
727+
ProtocolVersionId::latest(),
728728
)
729729
.await
730730
.unwrap();
@@ -821,7 +821,7 @@ async fn test_mempool_with_timestamp_assertion() {
821821
// Create a copy of the tx filter that the mempool will use.
822822
let want_filter = l2_tx_filter(
823823
&tester.create_batch_fee_input_provider().await,
824-
ProtocolVersionId::latest().into(),
824+
ProtocolVersionId::latest(),
825825
)
826826
.await
827827
.unwrap();

0 commit comments

Comments
 (0)