Skip to content

feat: Add pending transaction reconcile max attempt and max age in TransactionService#135

Closed
stanleyyconsensys wants to merge 4 commits into
mainfrom
feat/txn-reconcile-with-attempt
Closed

feat: Add pending transaction reconcile max attempt and max age in TransactionService#135
stanleyyconsensys wants to merge 4 commits into
mainfrom
feat/txn-reconcile-with-attempt

Conversation

@stanleyyconsensys

Copy link
Copy Markdown
Collaborator

Explanation

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 reconcileAttemptCount to 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 via trackError.

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) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants