From 00c20237362b673b93f3ec894f20d61da6fece6a Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Sat, 21 Sep 2024 15:19:31 +0100 Subject: [PATCH] Make parallel requests --- src/handlers/gasPriceManager.ts | 8 +++----- src/utils/validation.ts | 13 +++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 342d566b..d5964ea8 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -5,7 +5,6 @@ import { type ChainType } from "@alto/types" import { maxBigInt, minBigInt, type Logger } from "@alto/utils" -// biome-ignore lint/style/noNamespaceImport: explicitly make it clear when sentry is used import * as sentry from "@sentry/node" import { parseGwei, type Chain, type PublicClient } from "viem" import { @@ -86,7 +85,7 @@ export class GasPriceManager { } } - public async init() { + public init() { return Promise.all([ this.updateGasPrice(), this.legacyTransactions === false @@ -453,7 +452,7 @@ export class GasPriceManager { return baseFee } - public async getBaseFee(): Promise { + public getBaseFee() { if (this.legacyTransactions) { throw new RpcError( "baseFee is not available for legacy transactions" @@ -484,8 +483,7 @@ export class GasPriceManager { return gasPrice } - // biome-ignore lint/suspicious/useAwait: - public async getGasPrice(): Promise { + public getGasPrice() { if (this.gasPriceRefreshIntervalInSeconds === 0) { return this.updateGasPrice() } diff --git a/src/utils/validation.ts b/src/utils/validation.ts index b43cef18..1c8c6a76 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -514,8 +514,11 @@ export async function calcOptimismPreVerificationGas( } }) - const { result: l1Fee } = await opGasPriceOracle.simulate.getL1Fee([ - serializedTx + const [{ result: l1Fee }, baseFeePerGas] = await Promise.all([ + opGasPriceOracle.simulate.getL1Fee([serializedTx]), + verify + ? gasPriceManager.getMaxBaseFeePerGas() + : gasPriceManager.getBaseFee() ]) if (op.maxFeePerGas <= 1n || op.maxPriorityFeePerGas <= 1n) { @@ -527,12 +530,6 @@ export async function calcOptimismPreVerificationGas( const l2MaxFee = op.maxFeePerGas - let baseFeePerGas = 0n - if (verify) { - baseFeePerGas = await gasPriceManager.getMaxBaseFeePerGas() - } else { - baseFeePerGas = await gasPriceManager.getBaseFee() - } const l2PriorityFee = baseFeePerGas + op.maxPriorityFeePerGas const l2price = minBigInt(l2MaxFee, l2PriorityFee)