Skip to content

Commit

Permalink
feat: wait low gas price
Browse files Browse the repository at this point in the history
  • Loading branch information
vgorkavenko committed Jul 15, 2024
1 parent 292a203 commit cae798a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/common/prometheus/prometheus.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/prover/duties/withdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down
38 changes: 28 additions & 10 deletions src/common/providers/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@ export class Execution {
populateTxCallback: (...payload: any[]) => Promise<PopulatedTransaction>,
payload: any[],
): Promise<void> {
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;
}
}

Expand Down Expand Up @@ -100,21 +112,27 @@ export class Execution {
}
} else {
if (!isFeePerGasAcceptable) {
this.prometheus.highGasFeeInterruptionsCount.inc();
throw new HighGasFeeError('Transaction is not sent due to high gas fee', context);
}
}
const signed = await this.signer.signTransaction(populated);
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) {
Expand Down

0 comments on commit cae798a

Please sign in to comment.