Skip to content

Commit

Permalink
Make parallel requests
Browse files Browse the repository at this point in the history
  • Loading branch information
plusminushalf committed Sep 21, 2024
1 parent 9401c29 commit 00c2023
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/handlers/gasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,7 +85,7 @@ export class GasPriceManager {
}
}

public async init() {
public init() {
return Promise.all([
this.updateGasPrice(),
this.legacyTransactions === false
Expand Down Expand Up @@ -453,7 +452,7 @@ export class GasPriceManager {
return baseFee
}

public async getBaseFee(): Promise<bigint> {
public getBaseFee() {
if (this.legacyTransactions) {
throw new RpcError(
"baseFee is not available for legacy transactions"
Expand Down Expand Up @@ -484,8 +483,7 @@ export class GasPriceManager {
return gasPrice
}

// biome-ignore lint/suspicious/useAwait:
public async getGasPrice(): Promise<GasPriceParameters> {
public getGasPrice() {
if (this.gasPriceRefreshIntervalInSeconds === 0) {
return this.updateGasPrice()
}
Expand Down
13 changes: 5 additions & 8 deletions src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 00c2023

Please sign in to comment.