From b5f34a98599af04a09819760aee99cbb64254882 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Tue, 1 Oct 2024 18:58:48 +0100 Subject: [PATCH] use maxL1BaseFeeEstimate if l1BaseFee=0 --- src/handlers/gasPriceManager.ts | 13 +++++++++++++ src/utils/validation.ts | 9 ++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 00cdb66c..c8fe5325 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -93,6 +93,19 @@ class ArbitrumManager { ) } + public async getMaxL1BaseFee() { + const queue = this.queueL1BaseFee + + if (queue.length === 0) { + return maxUint128 + } + + return queue.reduce( + (acc: bigint, cur) => maxBigInt(cur.baseFee, acc), + queue[0].baseFee + ) + } + public async getMaxL2BaseFee() { const queue = this.queueL2BaseFee diff --git a/src/utils/validation.ts b/src/utils/validation.ts index e4d591f0..92f135f8 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -660,10 +660,13 @@ export async function calcArbitrumPreVerificationGas( gasPriceManager.arbitrumManager.saveL2BaseFee(l2BaseFee) if (validate) { + if (l1BaseFeeEstimate === 0n) { + l1BaseFeeEstimate = + await gasPriceManager.arbitrumManager.getMaxL1BaseFee() + } + // gasEstimateL1Component source: https://github.com/OffchainLabs/nitro/blob/5cd7d6913eb6b4dedb08f6ea49d7f9802d2cc5b9/execution/nodeInterface/NodeInterface.go#L515-L551 - const l1BaseFee = - l1BaseFeeEstimate === 0n ? maxUint256 : l1BaseFeeEstimate - const feesForL1 = (gasForL1 * l2BaseFee) / l1BaseFee + const feesForL1 = (gasForL1 * l2BaseFee) / l1BaseFeeEstimate const minL1BaseFeeEstimate = await gasPriceManager.arbitrumManager.getMinL1BaseFee()