-
Notifications
You must be signed in to change notification settings - Fork 36.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Wallet] unset change position when there is no change #10294
Conversation
Thanks for the fix. We may want to add a test for this. Shouldn't be too complicated, just fund a tx where amount = getbalance()-somefee. |
@jonasschnelli yes I plan on writing one soon |
f0281be
to
83abe86
Compare
Put in a test that caused segfault consistently otherwise. slightly off-topic, I also ran into some weirdly created outputs via |
Thanks for the test.
fundraw does only create one output, right (the change)? Or did it corrupted an existing output? |
@jonasschnelli it indicated that that output was the change output, which is bizarre because it's a dust value and nonstandard, right? Perhaps it's the same bug, manifested in a different way? |
Ok yes I am able to recreate it again on master but not on this branch. Must be the same bug. The rpc test I added will catch this case if it occurs. |
83abe86
to
fdd5d0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK fdd5d0eba1ecf7413d8b73ffb31a4ff82968f2ba with some nits.
@@ -53,6 +53,11 @@ def run_test(self): | |||
self.nodes[0].generate(121) | |||
self.sync_all() | |||
|
|||
# ensure that setting changPosition in fundraw with an exact match is handled properly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: changPosition
missing an e
# ensure that setting changPosition in fundraw with an exact match is handled properly | ||
rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():50}) | ||
rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]}) | ||
assert_equal(rawmatch["changepos"], -1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This surprises me. I would assume changepos
would equal changePosition
that you supplied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if no resulting change exists, it will be -1 regardless. It was just broken before in the exact match case, sometimes returning a non-(-1) number with a garbage output, or segfault.
src/wallet/wallet.cpp
Outdated
@@ -2564,8 +2564,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT | |||
txNew.vout.insert(position, newTxOut); | |||
} | |||
} | |||
else | |||
else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weak nit: Would love if this was } else {
personally (i.e. no newline after }
).
fixed μ-nits |
utACK 7c58863 |
utACK 7c58863 |
7c58863 [Wallet] unset change position when there is no change on exact match (Gregory Sanders) Tree-SHA512: ce8b9337e4132e32d80f954258d50938052c833a48e39431649d6adb16e3d18626a0ae5d300827e7fa397927fba72a1f066cb31af9b0a3ef7f1feb6024461626
…change 7c58863 [Wallet] unset change position when there is no change on exact match (Gregory Sanders) Tree-SHA512: ce8b9337e4132e32d80f954258d50938052c833a48e39431649d6adb16e3d18626a0ae5d300827e7fa397927fba72a1f066cb31af9b0a3ef7f1feb6024461626
…change 7c58863 [Wallet] unset change position when there is no change on exact match (Gregory Sanders) Tree-SHA512: ce8b9337e4132e32d80f954258d50938052c833a48e39431649d6adb16e3d18626a0ae5d300827e7fa397927fba72a1f066cb31af9b0a3ef7f1feb6024461626
…change 7c58863 [Wallet] unset change position when there is no change on exact match (Gregory Sanders) Tree-SHA512: ce8b9337e4132e32d80f954258d50938052c833a48e39431649d6adb16e3d18626a0ae5d300827e7fa397927fba72a1f066cb31af9b0a3ef7f1feb6024461626
…ate[Fund]Transaction a1bd590 [Doc] Document subtract-fee-from-amount RPC changes in the release notes (random-zebra) 6589429 wallet: first step generalizing CRecipient and ShieldedRecipient usage creating CRecipientBase class. (furszy) 1239506 [QA] Properly test change position in fundraw with sffa (random-zebra) cc9ff09 [RPC] Add fSubtractFeeFromAmount to shieldsendmany (random-zebra) 65d3a80 [Refactoring] Subtract fee from destination when building shield tx (random-zebra) cba898b [Refactoring] SendManyRecipient: use CRecipient for taddr + add sffa (random-zebra) 6fff9f5 [RPC] Add fSubtractFeeFromAmount to sendmany (transparent) (random-zebra) 7e30e3f [MOVE-ONLY] Move fundrawtransaction to rpcwallet (random-zebra) 499d62a [Tests] Add functional test for sffa in fundrawtransaction (random-zebra) 523b24d Subtract fee from amount (random-zebra) Pull request description: Add a feature requested many times (#894, #1079, #2196, ...) Allow the user to deduct the fee from one or more of the transaction recipient amounts. The most common use-case is when sending the whole balance, or a selection of UTXOs, without getting any change back. This is already possible by selecting "after-fee-amount" in coin-control, but such metod is not user-friendly (e.g. in case of shield recipients, to get the correct value, the destinations must already be filled before opening coin-control and copying the "after-fee" value). Plus, this workaround is only available in the GUI. The subtract-fee option makes it easier, and enables it via the cli as well. Here it's exposed only to the RPC, both for transparent and shield recipients: - `sendtoaddress` - `sendmany` - `shieldsendmany` - `fundrawtransaction` GUI connection will be added in a successive PR (which will close those issues). Last commit is coming from bitcoin#10294 Built on top of: - [x] #2337 ACKs for top commit: furszy: rebase + cherry-pick utACK a1bd590. Fuzzbawls: ACK a1bd590 Tree-SHA512: 7ed78f6ab8f1e9300d1468242e66016a4e1867f413256de23b7a60e103c2b628cdadcfc7998e8a7b252a7c2817d45261be108fad0eaa34d5ff892052c09b6e60
Currently it remains set when there is an exact value match, and in the case of
fundrawtransaction
with a set value, it causes segfault when it attempts to insert it into the final CTransaction.Fixes #10293