From cae798a626d0dd1b01b7256c983131989d327a4a Mon Sep 17 00:00:00 2001 From: vgorkavenko Date: Mon, 15 Jul 2024 11:06:35 +0400 Subject: [PATCH] feat: wait low gas price --- src/common/prometheus/prometheus.service.ts | 5 +++ src/common/prover/duties/withdrawals.ts | 4 +-- src/common/providers/execution/execution.ts | 38 +++++++++++++++------ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/common/prometheus/prometheus.service.ts b/src/common/prometheus/prometheus.service.ts index fac9069..395c25d 100644 --- a/src/common/prometheus/prometheus.service.ts +++ b/src/common/prometheus/prometheus.service.ts @@ -125,6 +125,11 @@ export class PrometheusService { name: METRIC_HIGH_GAS_FEE_INTERRUPTIONS_COUNT, help: 'Count of high gas fee interruptions', }); + + public txSendingErrors = this.getOrCreateMetric('Counter', { + name: 'tx_sending_errors', + help: 'Count of transaction sending errors', + }); } export function TrackCLRequest(target: any, propertyKey: string, descriptor: PropertyDescriptor) { diff --git a/src/common/prover/duties/withdrawals.ts b/src/common/prover/duties/withdrawals.ts index a7b7db1..f0410ad 100644 --- a/src/common/prover/duties/withdrawals.ts +++ b/src/common/prover/duties/withdrawals.ts @@ -97,7 +97,7 @@ export class WithdrawalsService { withdrawals, ); for (const payload of payloads) { - this.logger.warn(`📡 Sending withdrawal proof payload for validator index: ${payload.witness.validatorIndex}`); + this.logger.log(`📡 Sending withdrawal proof payload for validator index: ${payload.witness.validatorIndex}`); await this.verifier.sendWithdrawalProof(payload); } } @@ -130,7 +130,7 @@ export class WithdrawalsService { withdrawals, ); for (const payload of payloads) { - this.logger.warn( + this.logger.log( `📡 Sending historical withdrawal proof payload for validator index: ${payload.witness.validatorIndex}`, ); await this.verifier.sendHistoricalWithdrawalProof(payload); diff --git a/src/common/providers/execution/execution.ts b/src/common/providers/execution/execution.ts index 6a572d0..18568cd 100644 --- a/src/common/providers/execution/execution.ts +++ b/src/common/providers/execution/execution.ts @@ -51,15 +51,27 @@ export class Execution { populateTxCallback: (...payload: any[]) => Promise, payload: any[], ): Promise { - try { - await this._execute(emulateTxCallback, populateTxCallback, payload); - } catch (e) { - if (e instanceof NoSignerError || e instanceof DryRunError) { - this.logger.warn(e); + // endless loop to retry transaction execution in case of high gas fee + while (true) { + try { + await this._execute(emulateTxCallback, populateTxCallback, payload); return; + } catch (e) { + if (e instanceof NoSignerError || e instanceof DryRunError) { + this.logger.warn(e); + return; + } + if (!this.isCLI() && e instanceof HighGasFeeError) { + this.prometheus.highGasFeeInterruptionsCount.inc(); + this.logger.warn(e); + this.logger.warn('Retrying in 1 minute...'); + await new Promise((resolve) => setTimeout(resolve, 60 * 1000)); + continue; + } + this.prometheus.txSendingErrors.inc(); + this.logger.error(e); + throw e; } - this.logger.error(e); - throw e; } } @@ -100,7 +112,6 @@ export class Execution { } } else { if (!isFeePerGasAcceptable) { - this.prometheus.highGasFeeInterruptionsCount.inc(); throw new HighGasFeeError('Transaction is not sent due to high gas fee', context); } } @@ -108,13 +119,20 @@ export class Execution { let submitted: TransactionResponse; try { const submittedPromise = this.provider.sendTransaction(signed); + let msg = `Sending transaction with nonce ${populated.nonce} and gasLimit: ${populated.gasLimit}, maxFeePerGas: ${populated.maxFeePerGas}, maxPriorityFeePerGas: ${populated.maxPriorityFeePerGas}`; if (this.isCLI()) { - spinnerFor(submittedPromise, { text: 'Sending transaction' }); + spinnerFor(submittedPromise, { text: msg }); + } else { + this.logger.log(msg); } submitted = await submittedPromise; + this.logger.log(`Transaction sent to mempool. Hash: ${submitted.hash}`); const waitingPromise = submitted.wait(); + msg = `Waiting until the transaction has been mined`; if (this.isCLI()) { - spinnerFor(submittedPromise, { text: 'Waiting until the transaction has been mined' }); + spinnerFor(waitingPromise, { text: msg }); + } else { + this.logger.log(msg); } await waitingPromise; } catch (e) {