Skip to content

Commit

Permalink
fetch latest gasPrice values when bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless0x committed Oct 30, 2024
1 parent 3debf6e commit 95f42d8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class Executor {
): Promise<ReplaceTransactionResult> {
const newRequest = { ...transactionInfo.transactionRequest }

const gasPriceParameters = await this.gasPriceManager.latestGasPrice()
const gasPriceParameters = await this.gasPriceManager.networkGasPrice()

newRequest.maxFeePerGas = maxBigInt(
gasPriceParameters.maxFeePerGas,
Expand Down Expand Up @@ -489,7 +489,7 @@ export class Executor {

const wallets = Array.from(allWallets)

const gasPrice = await this.gasPriceManager.latestGasPrice()
const gasPrice = await this.gasPriceManager.networkGasPrice()
const promises = wallets.map((wallet) => {
flushStuckTransaction(
this.config.publicClient,
Expand Down Expand Up @@ -648,7 +648,7 @@ export class Executor {
})
childLogger.debug("bundling user operation")

const gasPriceParameters = await this.gasPriceManager.latestGasPrice()
const gasPriceParameters = await this.gasPriceManager.networkGasPrice()
childLogger.debug({ gasPriceParameters }, "got gas price")

const nonce = await this.config.publicClient.getTransactionCount({
Expand Down Expand Up @@ -927,7 +927,7 @@ export class Executor {
})
childLogger.debug("bundling compressed user operation")

const gasPriceParameters = await this.gasPriceManager.latestGasPrice()
const gasPriceParameters = await this.gasPriceManager.networkGasPrice()
childLogger.debug({ gasPriceParameters }, "got gas price")

const nonce = await this.config.publicClient.getTransactionCount({
Expand Down
2 changes: 1 addition & 1 deletion src/executor/executorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ export class ExecutorManager {
await this.refreshUserOperationStatuses()

// for all still not included check if needs to be replaced (based on gas price)
const gasPriceParameters = await this.gasPriceManager.latestGasPrice()
const gasPriceParameters = await this.gasPriceManager.networkGasPrice()
this.logger.trace(
{ gasPriceParameters },
"fetched gas price parameters"
Expand Down
2 changes: 1 addition & 1 deletion src/executor/senderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class SenderManager {

if (Object.keys(balancesMissing).length > 0) {
const { maxFeePerGas, maxPriorityFeePerGas } =
await this.gasPriceManager.latestGasPrice()
await this.gasPriceManager.networkGasPrice()

if (this.config.refillHelperContract) {
const instructions = []
Expand Down
8 changes: 7 additions & 1 deletion src/handlers/gasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "@alto/types"
import { type Logger, maxBigInt, minBigInt, FixedStack } from "@alto/utils"
import * as sentry from "@sentry/node"
import { type PublicClient, parseGwei, Block } from "viem"
import { type PublicClient, parseGwei, Block, toHex } from "viem"
import {
avalanche,
celo,
Expand Down Expand Up @@ -95,6 +95,7 @@ export class GasPriceManager {
return baseFee
}

// Returns the latest cached gasPrice.
public async latestGasPrice(): Promise<GasPriceParameters> {
const gasPrice = this.gasPriceStack.peek()

Expand All @@ -105,6 +106,11 @@ export class GasPriceManager {
return gasPrice
}

// Actively fetches the network gasPrice instead of using the gasPriceStack cache.
public async networkGasPrice(): Promise<GasPriceParameters> {
return await this.innerGetGasPrice()
}

public async getMaxBaseFeePerGas(): Promise<bigint> {
let maxBaseFeePerGas = this.baseFeePerGasStack
.toArray()
Expand Down
6 changes: 3 additions & 3 deletions src/utils/dataStructures/fixedStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export class FixedStack<T> {
this.items.push(item)
}

pop(): T | null {
pop(): T | undefined {
if (this.isEmpty()) {
return null
return undefined
}
return this.items.pop()!
return this.items.shift()
}

peek(): T | null {
Expand Down

0 comments on commit 95f42d8

Please sign in to comment.