Avoid initiating new attempts if the gas conditions persist unchanged#571
Conversation
There was a problem hiding this comment.
Pull Request Overview
A PR to improve the transaction monitoring flow by preventing unnecessary new attempts when the gas price is still competitive. Key changes include:
- Adding a new method in TxMonitor to determine if a new attempt should be emitted based on gas price conditions.
- Integrating a retry logic in TransactionSubmitter with detailed error handling for transaction resubmission.
- Exposing GasPriceOracle fee parameters as public for easier access.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/txm/lib/TxMonitor.ts | Adds a new helper function to decide whether a new attempt is needed and adjusts logging accordingly. |
| packages/txm/lib/TransactionSubmitter.ts | Introduces new error types and a retryAttempt method to resubmit transactions with improved error handling. |
| packages/txm/lib/GasPriceOracle.ts | Changes fee parameter properties to public, enabling external access. |
Comments suppressed due to low confidence (3)
packages/txm/lib/TxMonitor.ts:219
- [nitpick] Please add an inline comment explaining the rationale behind subtracting maxPriorityFeePerGas from maxFeePerGas to aid future maintainers.
if (attempt.maxFeePerGas - attempt.maxPriorityFeePerGas < expectedNextBaseFeePerGas) {
packages/txm/lib/GasPriceOracle.ts:27
- [nitpick] Reconsider exposing fee-related fields as public; using getters could help prevent unintended external modifications.
public expectedNextBaseFeePerGas!: bigint
packages/txm/lib/TransactionSubmitter.ts:226
- [nitpick] Consider adding more detailed logging or context for the 'nonce too low' error to facilitate debugging in production.
if (sendRawTransactionResult.error instanceof TransactionRejectedRpcError && sendRawTransactionResult.error.message.includes("nonce too low")) {
c10757e to
f9acbe6
Compare
3cd874c to
87ef67e
Compare
f9acbe6 to
22fd6dd
Compare
87ef67e to
591e8b7
Compare
22fd6dd to
6e7f328
Compare
591e8b7 to
92fcf3f
Compare
6e7f328 to
a1cf861
Compare
24ecb5b to
1a9913d
Compare
| return ok(undefined) | ||
| } | ||
|
|
||
| async retryAttempt(transaction: Transaction, attempt: Attempt): Promise<RetryAttemptResult> { |
There was a problem hiding this comment.
why cant we re-use/call the existing attemptSubmission() like handleRetryTransaction() does?
There was a problem hiding this comment.
Good question. Because attemptSubmission creates a new attempt, however here we want to retry the same attempt. We do this to avoid accumulating too many attempts unnecessarily, which could cause issues with the RPC, since later during monitoring we have to request the receipt for each of these attempts
There was a problem hiding this comment.
I agree this is a lot of duplicate logic, is there a way to refactor this in such a way that most of the logic is shared between both functions? Maybe a single function with additional parameters / flags?
As is it's pretty hard to reason about the differences between the two paths.
There was a problem hiding this comment.
I refactored the code. Now there's a private function that implements all the common logic and takes a parameter to configure whether to save the new attempt, which was the main difference
bdd1d5c to
d5bfe00
Compare
c0e9e96 to
709b75c
Compare
d5bfe00 to
44f4247
Compare
709b75c to
538a0a1
Compare
44f4247 to
1f2858b
Compare
538a0a1 to
93e241c
Compare
1f2858b to
1356e03
Compare
42bc0db to
ceb064f
Compare
ceb064f to
7a35565
Compare

Description
On Friday, the randomness service crashed because the number of attempts grew exponentially. The issue that caused this behavior has already been addressed. However, we also noticed that creating a new attempt with more gas every time a transaction gets stuck in a block is unnecessary—and can even be problematic—if the gas conditions are still acceptable for the previous attempt. Instead of creating a new attempt with higher gas, we now retry the same attempt
Toggle Checklist
Checklist
Basics
norswap/build-system-caching).Reminder: PR review guidelines
Correctness
testnet, mainnet, standalone wallet, ...).
< INDICATE BROWSER, DEMO APP & OTHER ENV DETAILS USED FOR TESTING HERE >
< INDICATE TESTED SCENARIOS (USER INTERFACE INTERACTION, CODE FLOWS) HERE >
and have updated the code & comments accordingly.
Architecture & Documentation
(2) commenting these boundaries correctly, (3) adding inline comments for context when needed.
comments.
in a Markdown document.
packages/coreandpackages/react), see here for more info.