Conversation
…direction When a transaction touches multiple address-type wallets, each wallet independently emits a BdkWalletEvent, causing duplicate onchain events per sync cycle. Add per-type HashSet deduplication in process_wallet_events so each txid produces at most one event of each type per sync. Also fix PaymentDetails::update to apply direction corrections as secondary wallets sync. When the primary wallet sees only a change output it records the payment as Inbound; once secondary wallets reveal the spent inputs the direction must update to Outbound. Add a never-downgrade guard so a change-only wallet syncing before an input-holding wallet cannot transiently flip a correct Outbound back to Inbound. Add unit tests for the direction logic and integration tests covering event deduplication, direction correction, send_all direction, secondary wallet receives, and reorg deduplication. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
This PR:
list_paymentsWhat was happening
With multiple address-type wallets enabled, each sub-wallet independently emits its own
BdkWalletEventwhen it observes a transaction. A single cross-wallet send (e.g. Legacy inputs + NativeSegwit change) produced twoOnchainTransactionReceivedevents and twoOnchainTransactionConfirmedevents per sync cycle.Additionally,
PaymentDetails::updatedid not apply direction updates, so when the primary wallet synced first and saw only a change output, the payment was stored as Inbound and never corrected even after secondary wallets synced.A secondary bug also existed: if a change-only wallet synced before an input-holding wallet,
sent_and_receivedtemporarily reported more received than sent, which would have flipped a correct Outbound back to Inbound.What changed
src/chain/mod.rs–process_wallet_eventsnow maintains four per-typeHashSets (received, confirmed, reorged, replaced) and skips duplicate txids. Per-type sets are used instead of a single set because two wallets with different sync history can legitimately emit different event types for the same txid in one cycle.src/payment/store.rs–PaymentDetails::updatenow applies direction updates from later wallet syncs, with a one-way guard: Inbound→Outbound corrections are allowed, Outbound→Inbound downgrades are blocked (a pure receive always has sent=0 and can never compute as Outbound, so Outbound is monotonically final).Tests
Added 2 unit tests in
src/payment/store.rsand 6 integration tests intests/multi_address_types_tests.rs:test_cross_wallet_send_emits_single_received_eventtest_cross_wallet_send_emits_single_confirmed_eventtest_cross_wallet_send_payment_direction_is_outboundtest_cross_wallet_reorg_deduplicates_eventstest_send_all_payment_direction_is_outboundtest_receive_to_secondary_wallet_direction_is_inboundQA Notes
Testing
cargo testpasses (integration tests requireulimit -n 10000)cargo clippycleancargo fmt --checkcleanIntegration
OnchainTransactionReceivedlog and wrong payment direction inlistPaymentsfor cross-wallet sends)