Add retry policy manager for failed transactions#299
Conversation
Deploying happychain with
|
| Latest commit: |
95598fd
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7fc8403d.happychain.pages.dev |
| Branch Preview URL: | https://gabriel-retry-policy.happychain.pages.dev |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
HAPPY-110 txmanager: Allow retry policy customization
We should allow users to implement their own retry logic with code or perhaps through a configuration when a transaction reverts |
| import type { Attempt, Transaction } from "./Transaction" | ||
| import type { TransactionManager } from "./TransactionManager" | ||
|
|
||
| export interface RevertedTransactionReceipt<T extends "success" | "reverted"> { |
There was a problem hiding this comment.
this seems like it should match the return result from the viem getTransactionReceipt type. we probably don't want to/need to redefine it here do we?
There was a problem hiding this comment.
I agree, this only add the extra typing for the status, but if we really want that (honestly, it doesn't buy us much), we can have it by extending the getTransactionReceipt return type like
export type RevertedTransactionReceipt<Status extends "success" | "reverted> =
TransactionReceipt<bigint, number, Status, "eip1559">
0f3cbd7 to
7bd3300
Compare
7bd3300 to
ade9e83
Compare
14cc193 to
823a467
Compare
norswap
left a comment
There was a problem hiding this comment.
Mostly just docs + some type changes, but otherwise this is good!
| import type { Attempt, Transaction } from "./Transaction" | ||
| import type { TransactionManager } from "./TransactionManager" | ||
|
|
||
| export interface RevertedTransactionReceipt<T extends "success" | "reverted"> { |
There was a problem hiding this comment.
I agree, this only add the extra typing for the status, but if we really want that (honestly, it doesn't buy us much), we can have it by extending the getTransactionReceipt return type like
export type RevertedTransactionReceipt<Status extends "success" | "reverted> =
TransactionReceipt<bigint, number, Status, "eip1559">
ade9e83 to
ba1b173
Compare
823a467 to
85097ef
Compare
a599824 to
3674db3
Compare
85097ef to
2d1b669
Compare
3674db3 to
1b25f8b
Compare
2d1b669 to
039ecfa
Compare
|
@norswap I think there was an error with the diff files in this PR because I didn't restack it, and it was showing the diff from another PR. But anyway, I think the comments you made, even if they aren't for this PR, are good and can be applied to this one. |
| ): Promise<boolean> | ||
| } | ||
|
|
||
| export class DefaultRetryPolicyManager implements RetryPolicyManager { |
There was a problem hiding this comment.
Add docstring that says this retries if running out of gas.
| NotFinalizedStatuses.includes(transaction.status), | ||
| ) | ||
| if (result.isOk()) { | ||
| this.notFinalizedTransactions.push(...notPersistedTransactions) |
There was a problem hiding this comment.
Correct. What we could do here is invert the two lines, which saves on filtering the notPersistedTransactions since they'll always be included. Bit of a micro-optimization.
this.notFinalizedTransactions = this.notFinalizedTransactions.filter((transaction) =>
NotFinalizedStatuses.includes(transaction.status),
)
this.notFinalizedTransactions.push(...notPersistedTransactions)
(current code has the reversed ordering)
c961e6c to
95598fd
Compare

Linked Issues
Description
Introduces a new
RetryPolicyManagerto handle transaction retry logic in a more modular way. The manager determines if failed transactions should be retried based on their receipt and revert reason. Currently implements retry logic for "Out of Gas" errors, either by checking gas consumption or explicit revert messages.Key changes:
RetryPolicyManagerwith extensible interface for custom retry policiesTransactionManagerfor configurable retry behaviorToggle Checklist
Checklist
Basics
norswap/build-system-caching).Correctness
C1. Builds and passes tests.
C2. The code is properly parameterized & compatible with different environments.
C3. I have manually tested my changes & connected features.
C4. I have performed a thorough self-review of my code after submitting the PR.
Architecture & Documentation