feat: Add pending transaction reconcile max attempt and max age in TransactionService#135
Closed
stanleyyconsensys wants to merge 4 commits into
Closed
feat: Add pending transaction reconcile max attempt and max age in TransactionService#135stanleyyconsensys wants to merge 4 commits into
stanleyyconsensys wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces configurable eviction for stale pending transactions by tracking Horizon “not found” reconcile attempts and enforcing a maximum pending age, while also tightening error handling/telemetry around XDR parsing and client request flows.
Changes:
- Add
reconcileAttemptCountto snap-state transactions and evict pending transactions only when both max attempts and max age are exceeded. - Update transaction sync/reconcile logic and repository persistence to carry reconcile metadata internally but strip it for keyring APIs/events.
- Standardize several parsing/validation paths to throw typed exceptions with
cause, and track unexpected failures viatrackError.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/snap/src/ui/confirmation/utils.ts | Switch asset reference parsing to a safe parser that can return null. |
| packages/snap/src/services/transaction/xdrParser.ts | Make XDR parsing failures throw XdrParseException with cause; refine SEP-41 invoke parsing error handling. |
| packages/snap/src/services/transaction/xdrParser.test.ts | Update tests for new throwing behavior and removal of the “safe” SEP-41 parser. |
| packages/snap/src/services/transaction/utils.ts | Add helpers for stripping reconcile metadata and for pending-eviction decisions (attempts + age). |
| packages/snap/src/services/transaction/TransactionSynchronizeService.ts | Track reconcile attempts on Horizon “not found”, persist pending txs with metadata, strip metadata before emits. |
| packages/snap/src/services/transaction/TransactionSynchronizeService.test.ts | Add coverage for reconcile attempt increment behavior. |
| packages/snap/src/services/transaction/TransactionService.ts | Track persistence failures via trackError and downgrade logging to warn. |
| packages/snap/src/services/transaction/TransactionRepository.ts | Store StellarKeyringTransaction, evict stale pending txs, and strip metadata on public reads. |
| packages/snap/src/services/transaction/TransactionRepository.test.ts | Add tests for pending eviction and reconcileAttemptCount update semantics. |
| packages/snap/src/services/transaction/TransactionMapper.ts | Remove SEP-41 “safe” parser usage; improve logging around best-effort parsing/mapping. |
| packages/snap/src/services/transaction/TransactionBuilder.ts | Attach cause to builder exceptions (selected paths). |
| packages/snap/src/services/transaction/Transaction.ts | Throw typed service exception for missing fee source; include cause on deserialization failure. |
| packages/snap/src/services/transaction/simulation/simulators.ts | Let XdrParseException propagate (distinguish internal parse failures from user-facing validation). |
| packages/snap/src/services/transaction/exceptions.ts | Convert transaction exceptions to StellarSnapException hierarchy and add cause support. |
| packages/snap/src/services/transaction/api.ts | Introduce StellarKeyringTransaction type with optional reconcileAttemptCount. |
| packages/snap/src/services/sync/SynchronizeService.ts | Use trackError + warn logging for sync task failures; make asset/pair loads safe. |
| packages/snap/src/services/network/exceptions.ts | Add transactionHash field to TransactionNotFoundException for reconcile handling. |
| packages/snap/src/handlers/clientRequest/onAmountInput.ts | Return structured invalid responses without tracking during typing; keep insufficient-balance codes. |
| packages/snap/src/handlers/clientRequest/onAmountInput.test.ts | Update tests for “return invalid” behavior on unexpected/XDR parse errors. |
| packages/snap/src/handlers/clientRequest/onAddressInput.ts | Remove logger dependency; treat validation failure as a simple invalid response. |
| packages/snap/src/handlers/clientRequest/onAddressInput.test.ts | Update handler construction to match the new no-args constructor. |
| packages/snap/src/handlers/clientRequest/confirmSend.ts | Track unexpected failures (except user rejection) and return { valid: false } instead of throwing. |
| packages/snap/src/handlers/clientRequest/confirmSend.test.ts | Update tests to assert tracking + invalid responses for unexpected failures. |
| packages/snap/src/context.ts | Instantiate OnAddressInputHandler with the new signature. |
| packages/snap/src/config.ts | Add maxReconcileAttempts and maxPendingTransactionAge config plumbing. |
| packages/snap/snap.config.ts | Expose new env vars to the snap build configuration. |
| packages/snap/.env.example | Document new env vars for reconcile attempts and pending age. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+248
to
250
| // Pending txs are unique and belong to the submitting account only. | ||
| // Hence we dont need to group by account id. | ||
| for (const transaction of transactions) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
References
Checklist