Skip to content

Commit

Permalink
Fix/timed queue (#353)
Browse files Browse the repository at this point in the history
* increase validity window to 15s

* change to 10s

* update

* set to 20

* fix build

---------

Co-authored-by: mouseless <[email protected]>
  • Loading branch information
mouseless0x and mouseless0x authored Nov 6, 2024
1 parent 1a47fda commit b79869a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/cli/config/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const bundlerOptions: CliCommandOptions<IBundlerArgsInput> = {
"Maximum that the gas prices fetched using pimlico_getUserOperationGasPrice will be accepted for (seconds)",
type: "number",
require: false,
default: 10
default: 20
},
"gas-price-multipliers": {
description:
Expand Down
7 changes: 3 additions & 4 deletions src/handlers/arbitrumGasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ export class ArbitrumManager {
private l1BaseFeeQueue: TimedQueue
private l2BaseFeeQueue: TimedQueue

constructor(maxQueueSize: number) {
const queueValidity = 15_000
this.l1BaseFeeQueue = new TimedQueue(maxQueueSize, queueValidity)
this.l2BaseFeeQueue = new TimedQueue(maxQueueSize, queueValidity)
constructor(queueValidity: number) {
this.l1BaseFeeQueue = new TimedQueue(queueValidity)
this.l2BaseFeeQueue = new TimedQueue(queueValidity)
}

public saveL1BaseFee(baseFee: bigint) {
Expand Down
19 changes: 8 additions & 11 deletions src/handlers/gasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ export class GasPriceManager {
level: config.publicClientLogLevel || config.logLevel
}
)
const maxQueueSize = this.config.gasPriceExpiry

const queueValidity = 10_000 // milliseconds
this.baseFeePerGasQueue = new TimedQueue(maxQueueSize, queueValidity)
this.maxFeePerGasQueue = new TimedQueue(maxQueueSize, queueValidity)
this.maxPriorityFeePerGasQueue = new TimedQueue(
maxQueueSize,
queueValidity
)

const queueValidity = this.config.gasPriceExpiry * 1_000

this.baseFeePerGasQueue = new TimedQueue(queueValidity)
this.maxFeePerGasQueue = new TimedQueue(queueValidity)
this.maxPriorityFeePerGasQueue = new TimedQueue(queueValidity)

// Periodically update gas prices if specified
if (this.config.gasPriceRefreshInterval > 0) {
Expand All @@ -78,8 +75,8 @@ export class GasPriceManager {
}, this.config.gasPriceRefreshInterval * 1000)
}

this.arbitrumManager = new ArbitrumManager(maxQueueSize)
this.mantleManager = new MantleManager(maxQueueSize)
this.arbitrumManager = new ArbitrumManager(queueValidity)
this.mantleManager = new MantleManager(queueValidity)
}

public init() {
Expand Down
14 changes: 5 additions & 9 deletions src/handlers/mantleGasPriceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ export class MantleManager {
private rollupDataGasAndOverheadQueue: TimedQueue
private l1GasPriceQueue: TimedQueue

constructor(maxQueueSize: number) {
const queueValidity = 15_000
this.tokenRatioQueue = new TimedQueue(maxQueueSize, queueValidity)
this.scalarQueue = new TimedQueue(maxQueueSize, queueValidity)
this.rollupDataGasAndOverheadQueue = new TimedQueue(
maxQueueSize,
queueValidity
)
this.l1GasPriceQueue = new TimedQueue(maxQueueSize, queueValidity)
constructor(queueValidity: number) {
this.tokenRatioQueue = new TimedQueue(queueValidity)
this.scalarQueue = new TimedQueue(queueValidity)
this.rollupDataGasAndOverheadQueue = new TimedQueue(queueValidity)
this.l1GasPriceQueue = new TimedQueue(queueValidity)
}

public getMinMantleOracleValues() {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/timedQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ export class TimedQueue {
private maxQueueSize: number
private queueValidity: number

constructor(maxQueueSize: number, queueValidity: number) {
constructor(queueValidity: number) {
this.queue = []
this.maxQueueSize = maxQueueSize
this.maxQueueSize = queueValidity / 1_000
this.queueValidity = queueValidity
}

// Only saves the value if it is lower than the latest value.
public saveValue(value: bigint) {
if (value === 0n) {
return
Expand Down

0 comments on commit b79869a

Please sign in to comment.