From 456ac8221043b9b35675a413e81b7448599d678c Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:02:00 +0000 Subject: [PATCH 1/6] add try/catch around getGasPrice --- src/executor/executor.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/executor/executor.ts b/src/executor/executor.ts index e576043a..e50ab690 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -153,8 +153,14 @@ export class Executor { ): Promise { const newRequest = { ...transactionInfo.transactionRequest } - const gasPriceParameters = - await this.gasPriceManager.getNetworkGasPrice() + let gasPriceParameters + try { + gasPriceParameters = await this.gasPriceManager.getNetworkGasPrice() + } catch (err) { + this.logger.error({ error: err }, "Failed to get network gas price") + this.markWalletProcessed(transactionInfo.executor) + return { status: "failed" } + } newRequest.maxFeePerGas = maxBigInt( gasPriceParameters.maxFeePerGas, From 07d779f2bcbc55a1bb2531aa3abc4166559039cb Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:06:31 +0000 Subject: [PATCH 2/6] return 1gwei if fail --- src/handlers/gasPriceManager.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 546bd0d9..43686e3e 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -272,7 +272,10 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback maxPriorityFeePerGas") sentry.captureException(e) - throw e + return { + maxPriorityFeePerGas: parseGwei("1"), + maxFeePerGas: parseGwei("1") + } } } @@ -285,7 +288,10 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback maxFeePerGas") sentry.captureException(e) - throw e + return { + maxPriorityFeePerGas: parseGwei("1"), + maxFeePerGas: parseGwei("1") + } } } From d9a6872c3c50ff093e083d586fcef133a58f8af0 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:10:31 +0000 Subject: [PATCH 3/6] don't throw errors --- src/executor/executor.ts | 10 ++-------- src/handlers/gasPriceManager.ts | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/executor/executor.ts b/src/executor/executor.ts index e50ab690..e576043a 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -153,14 +153,8 @@ export class Executor { ): Promise { const newRequest = { ...transactionInfo.transactionRequest } - let gasPriceParameters - try { - gasPriceParameters = await this.gasPriceManager.getNetworkGasPrice() - } catch (err) { - this.logger.error({ error: err }, "Failed to get network gas price") - this.markWalletProcessed(transactionInfo.executor) - return { status: "failed" } - } + const gasPriceParameters = + await this.gasPriceManager.getNetworkGasPrice() newRequest.maxFeePerGas = maxBigInt( gasPriceParameters.maxFeePerGas, diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 43686e3e..e9664ea1 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -272,10 +272,7 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback maxPriorityFeePerGas") sentry.captureException(e) - return { - maxPriorityFeePerGas: parseGwei("1"), - maxFeePerGas: parseGwei("1") - } + maxPriorityFeePerGas = parseGwei("1") } } @@ -288,10 +285,7 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback maxFeePerGas") sentry.captureException(e) - return { - maxPriorityFeePerGas: parseGwei("1"), - maxFeePerGas: parseGwei("1") - } + maxFeePerGas = parseGwei("1") } } From 31f66d74961d6b478bf0e2d06494723335d88677 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:14:29 +0000 Subject: [PATCH 4/6] add same case to legacy --- src/handlers/gasPriceManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index e9664ea1..77bc63b7 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -229,7 +229,7 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback gasPrice") sentry.captureException(e) - throw e + gasPrice = parseGwei("1") } } From 8d4df7b428311e43888b8ed4091c250dbca4f429 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:33:52 +0000 Subject: [PATCH 5/6] handle cases where gas price can't be found --- src/executor/executor.ts | 18 +++++++++++++----- src/executor/executorManager.ts | 2 +- src/executor/senderManager.ts | 2 +- src/handlers/gasPriceManager.ts | 13 ++++++++----- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/executor/executor.ts b/src/executor/executor.ts index e576043a..b4b255e7 100644 --- a/src/executor/executor.ts +++ b/src/executor/executor.ts @@ -153,8 +153,15 @@ export class Executor { ): Promise { const newRequest = { ...transactionInfo.transactionRequest } - const gasPriceParameters = - await this.gasPriceManager.getNetworkGasPrice() + let gasPriceParameters + try { + gasPriceParameters = + await this.gasPriceManager.tryGetNetworkGasPrice() + } catch (err) { + this.logger.error({ error: err }, "Failed to get network gas price") + this.markWalletProcessed(transactionInfo.executor) + return { status: "failed" } + } newRequest.maxFeePerGas = maxBigInt( gasPriceParameters.maxFeePerGas, @@ -496,7 +503,8 @@ export class Executor { const wallets = Array.from(allWallets) - const gasPrice = await this.gasPriceManager.getNetworkGasPrice() + const gasPrice = await this.gasPriceManager.tryGetNetworkGasPrice() + const promises = wallets.map((wallet) => { try { flushStuckTransaction( @@ -722,7 +730,7 @@ export class Executor { let gasPriceParameters: GasPriceParameters try { ;[gasPriceParameters, nonce] = await Promise.all([ - this.gasPriceManager.getNetworkGasPrice(), + this.gasPriceManager.tryGetNetworkGasPrice(), this.config.publicClient.getTransactionCount({ address: wallet.address, blockTag: "pending" @@ -1021,7 +1029,7 @@ export class Executor { let gasPriceParameters: GasPriceParameters try { ;[gasPriceParameters, nonce] = await Promise.all([ - this.gasPriceManager.getNetworkGasPrice(), + this.gasPriceManager.tryGetNetworkGasPrice(), this.config.publicClient.getTransactionCount({ address: wallet.address, blockTag: "pending" diff --git a/src/executor/executorManager.ts b/src/executor/executorManager.ts index 6fcf22b6..a41f47f7 100644 --- a/src/executor/executorManager.ts +++ b/src/executor/executorManager.ts @@ -776,7 +776,7 @@ export class ExecutorManager { // for all still not included check if needs to be replaced (based on gas price) const gasPriceParameters = - await this.gasPriceManager.getNetworkGasPrice() + await this.gasPriceManager.tryGetNetworkGasPrice() this.logger.trace( { gasPriceParameters }, "fetched gas price parameters" diff --git a/src/executor/senderManager.ts b/src/executor/senderManager.ts index 35dfa07a..279c2015 100644 --- a/src/executor/senderManager.ts +++ b/src/executor/senderManager.ts @@ -138,7 +138,7 @@ export class SenderManager { if (Object.keys(balancesMissing).length > 0) { const { maxFeePerGas, maxPriorityFeePerGas } = - await this.gasPriceManager.getNetworkGasPrice() + await this.gasPriceManager.tryGetNetworkGasPrice() if (this.config.refillHelperContract) { const instructions = [] diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index 77bc63b7..a0ff2418 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -71,7 +71,7 @@ export class GasPriceManager { this.updateBaseFee() } - this.updateGasPrice() + this.tryUpdateGasPrice() }, this.config.gasPriceRefreshInterval * 1000) } @@ -81,7 +81,7 @@ export class GasPriceManager { public init() { return Promise.all([ - this.updateGasPrice(), + this.tryUpdateGasPrice(), this.config.legacyTransactions === false ? this.updateBaseFee() : Promise.resolve() @@ -296,6 +296,7 @@ export class GasPriceManager { return { maxFeePerGas, maxPriorityFeePerGas } } + // This method throws if it can't get a valid RPC response. private async innerGetGasPrice(): Promise { let maxFeePerGas = 0n let maxPriorityFeePerGas = 0n @@ -386,7 +387,8 @@ export class GasPriceManager { return baseFee } - private async updateGasPrice(): Promise { + // This method throws if it can't get a valid RPC response. + private async tryUpdateGasPrice(): Promise { const gasPrice = await this.innerGetGasPrice() this.maxFeePerGasQueue.saveValue(gasPrice.maxFeePerGas) @@ -397,7 +399,7 @@ export class GasPriceManager { public async getGasPrice(): Promise { if (this.config.gasPriceRefreshInterval === 0) { - return await this.updateGasPrice() + return await this.tryUpdateGasPrice() } const maxFeePerGas = this.maxFeePerGasQueue.getLatestValue() @@ -414,7 +416,8 @@ export class GasPriceManager { } } - public async getNetworkGasPrice(): Promise { + // This method throws if it can't get a valid RPC response. + public async tryGetNetworkGasPrice(): Promise { return await this.innerGetGasPrice() } From fdee97b32a309ddb9ca0dda2d80df63ca0727538 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Wed, 4 Dec 2024 23:35:23 +0000 Subject: [PATCH 6/6] throw error --- src/handlers/gasPriceManager.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/handlers/gasPriceManager.ts b/src/handlers/gasPriceManager.ts index a0ff2418..c933c25a 100644 --- a/src/handlers/gasPriceManager.ts +++ b/src/handlers/gasPriceManager.ts @@ -229,7 +229,7 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback gasPrice") sentry.captureException(e) - gasPrice = parseGwei("1") + throw e } } @@ -272,7 +272,7 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback maxPriorityFeePerGas") sentry.captureException(e) - maxPriorityFeePerGas = parseGwei("1") + throw e } } @@ -285,7 +285,7 @@ export class GasPriceManager { } catch (e) { this.logger.error("failed to get fallback maxFeePerGas") sentry.captureException(e) - maxFeePerGas = parseGwei("1") + throw e } }