Repository navigation
fix(wallet_sdk_services): prevent duplicate submissions, stream drops, and blocking in TransactionService - #4242
Open
cyczzhao-lab wants to merge 1 commit into
Conversation
…, and blocking in TransactionService - Coordinate initial submissions with background polls so in-flight New transactions are not double-submitted or stripped of context - Dispatch dry-run and transaction submissions onto background tasks so slow network calls do not block finalization events or polls - Track New and Pending wallet transactions before network submission, await in-flight status writes on early finalization events, and resynchronize tracked IDs after event-channel lag - Keep CheckScope::All armed until all pending transaction checks complete without error
This branch has not been deployed
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.
Description
Fixes four concurrency, event-lag, and retry bugs in
tari_ootle_wallet_sdk_services::transaction_service::TransactionService(crates/wallet/sdk_services/src/transaction_service/service.rs):Prevent concurrent duplicate submission and lost
TransactionContextbetween initial submission and background polls:TransactionServicepreviously stored a new transaction asTransactionStatus::Newbefore recording itsTransactionContextindeferred_contextsand without marking its initialsubmit_transactioncall as in flight.on_poll(resubmit_new_transactions) could pick up theNewrow while the initial submission was still in flight, broadcasting the transaction a second time (and if the duplicate call receivedTransactionRejected, marking the live transactionInvalidTransactionand releasing its linked input locks) or emittingTransactionSubmittedEventwithout itsTransactionContext(such asClaimBurn).SubmissionCoordinator(InFlightSubmissionRAII guard) and populatestrackedanddeferred_contextsbefore spawning the network call soresubmit_new_transactionsskips in-flight IDs.Avoid head-of-line blocking the
TransactionServiceevent loop during network dry runs and submissions:TransactionService::runpreviously awaitedhandle_request(req).awaitinline inside itstokio::select!loop over anmpsc::channel(1). A single slowsubmit_dry_run_transactionorsubmit_transactionnetwork call stalled finalization stream handling, wallet event processing, stale-lock sweeps, and concurrent requests (and reported caller cancellation onreply.sendasServiceShutdown).Preserve finalization stream notifications across fast commits, startup
Newrows, and broadcast event lag:pendingwas previously seeded only fromTransactionStatus::Pendingon startup, populated only afterevents_subscriptiondeliveredWalletEvent::TransactionSubmitted, and never resynchronized onRecvError::Lagged. Notifications arriving beforesubmit_transactionreturned (while the row was stillNew) or after a laggedTransactionSubmittedevent were ignored.tracked(NewandPending) before network submission, waits for any in-flight submission write to settle inon_transaction_finalizedbefore checking store status, and resynchronizestrackedfrom storage on startup and afterRecvError::Lagged.Keep
CheckScope::Allarmed when a catch-up result check fails:check_all_on_next_tickwas previously cleared as soon ason_poll(CheckScope::All)spawned its task. If a pending transaction'scheck_pending_transactioncall failed transiently during that catch-up poll (or after aFinalizednotification returnedNone/error), subsequent ticks reverted toCheckScope::PendingFor(silent_transaction_timeout)and stopped querying younger transactions.must_check_allviaAtomicBooland re-arms it whenever aCheckScope::Allpoll oron_transaction_finalizedcheck does not cleanly resolve.Motivation and Context
Prevents duplicate network submissions and premature lock release on slow indexers, keeps finalization notifications and concurrent submissions responsive while dry-runs or validator-set syncs are in flight, ensures fast commits and broadcast-lagged submissions still resolve promptly via the SSE stream, and avoids stranding missed finalizations until
silent_transaction_timeoutafter transient query errors.How Has This Been Tested?
crates/wallet/sdk_tests/tests/transaction_service.rs:poll_does_not_double_submit_an_in_flight_submission_or_clobber_its_locksslow_dry_run_does_not_block_finalization_stream_or_concurrent_submissionsfinalization_arriving_during_submission_or_after_event_lag_is_acted_ontransient_query_error_on_check_all_poll_retries_on_next_tickstartup_tracks_stored_new_transactions_for_early_finalization_notificationscargo test -p tari_ootle_wallet_sdk_services --all-features(37 passed), alltari_ootle_wallet_sdk_testssuites (including 5 consecutive runs of--test transaction_service, 13/13 passed), andcargo test -p tari_ootle_walletd --lib(248 passed).lints.tomlcargo clippy --all-targets --all-features,cargo +nightly-2025-12-05 fmt --all -- --check, and./scripts/file_license_check.sh.What process can a PR reviewer use to test or verify this change?
Breaking Changes