Repository navigation
fix/track self payment outputs - #642
Open
henrypeters wants to merge 2 commits into
Open
henrypeters wants to merge 2 commits into
henrypeters wants to merge 2 commits into
Conversation
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.
Summary
build_fee_bumpidentifies change outputs by checking if they belong to the wallet's internal keychain, then strips them before building the replacement transaction. When a user intentionally sends to their own address (a self-payment) and later fee-bumps, build_fee_bump cannot distinguish the self-payment recipient from auto-generated change, so it strips it, silently losing the recipient from the replacement transaction.Fix
I fixed this solutions:
Warning at transaction creation time:
create_txnow checks each recipient against the wallet's known script pubkeys. If a match is found, it returnsCreateTxError::PaymentToOwnAddress { index }instead of silently proceeding with the transaction. The user must call.allow_self_payment()on theTxBuilderto opt in.Tracking for
build_fee_bump: When.allow_self_payment()is used,create_txrecords the output indices of self-payment recipients in a newChangeSetfield:build_fee_bumpchecks this map before removing change from the transaction, tracked outputs are preserved, while untracked outputs is then seen as change and therefore removed.Also, Entries are removed when transactions are confirmed(apply_update) or evicted(apply_evicted_txs), keeping storage minimal. Only unconfirmed self-payment transactions are tracked.
Testing
Existing tests updated: All existing tests that used wallet-owned addresses as dummy recipients have been updated to call .allow_self_payment() where the self-payment is incidental to what the test is actually testing, or switched to external addresses where appropriate.
New dedicated tests in tests/self_payment.rs:
test_payment_to_own_address_is_rejectedtest_payment_to_own_address_allowed_with_flagtest_self_payment_tracked_in_changesettest_build_fee_bump_preserves_self_payment_recipient