-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Subtract fee from amount #4331
Subtract fee from amount #4331
Conversation
Untested ACK |
Such a large change to the wallet needs much more than an untested ack. If you want this merged, help testing. |
I'm a tad surprised that this gets no testing. Lots of complaints about this problem with the wallet, and then someone attempts to solve it and the pull is virtually ignored. |
Needs to be rebased first. |
@@ -187,6 +187,12 @@ class CTxOut | |||
return (nValue < 3*minRelayTxFee.GetFee(nSize)); | |||
} | |||
|
|||
int64_t getDustThreshold(CFeeRate minRelayTxFee) const |
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.
I'd love to see a comment here, what the 148u are and why 3*minRelayTxFee.
Code looks good apart from my nits. I'm going to test this tomorrow! |
Rebased and fixed @Diapolo comments (thanks for reviewing!):
|
Has there been any further testing or updates done with this? |
Also, there appears to be a bug when sending money to yourself (same input as output). In this scenario, it will subtract the fees from the other recipient(the random change address). It seems a bit misleading, but it is a fairly uncommon scenario for any purpose but testing |
@Earlz Thanks for testing. I just tried this, I can not reproduce the bug you describe. A change address is inserted at a random position in the raw transaction. The fee is subtracted from the first recipient, but Before the change address is inserted. The fee should never be subtracted from the change address. Did you look at the confirmation dialog before sending and did it show the correct total value? As this would be unexpected, would you mind retesting this? |
Yea, I'm not able to reproduce this behavior now either. Maybe I didn't use the subtractfeefromtotal option when sending it or some such. Also, unrelated, but I merged this PR into a downstream coin fork and added a command line option to subtract fees by default, as well as splitting fees evenly among all recipients in a manysend. If you are interested in these changes I can rebase them onto bitcoin and submit a patch against this PR. |
update: The checkbox moved to the bottom in the UI, I think this is cleaner than what we had before, only |
@cozz It looks better, but with multiple recipients now it's not clear from which of the amounts the fee will get subtracted. Edit: hm no, that makes it impossible to send your entire balance to multiple addresses... |
Or move the checkbox next to each amount field "subtree fee from this amount"? |
@sipa What would happen if it's selected for multiple? Or should that be avoided somehow by providing a kind of radio button. |
EIther prevent it, or use equal split? |
So you prefer the checkbox on the top. Then simplest may be, If we leave it at the bottom we can simply change the description: |
But if you always deduct it equally from all amounts, that means you cannot chose from which amount the fee is deducted. If that is a big loss I don't know, maybe no one cares about that. N.B.: in the case of equal division, if you send very large amounts as well as very small amounts, be careful that some amounts without the partial fee deducted may be negative or beneath the dust threshold. |
Ok, I will look into it, choosing individually. |
update: Now showing the checkbox for each recipient, letting the user choose individually, I had to make some small design-changes to CWallet::CreateTransaction
|
@@ -31,6 +31,7 @@ | |||
using namespace std; | |||
QList<qint64> CoinControlDialog::payAmounts; | |||
CCoinControl* CoinControlDialog::coinControl = new CCoinControl(); | |||
bool CoinControlDialog::fSubtractFeeFromAmount = false; |
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.
I think it is strange to have these as a static variable, instead of part of the class - but this is an existing problem, it's not something to be solved in this pull.
UI looks good to me now! I still need to take a better look at the code and test around with functionality on regtest. |
Works for me. This needs RPC tests, though (or an update to the current RPC tests so that the new parameters are tested). |
Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p4331_b8956a0de3ae9eb8127ce7f5b995512bb53d2a25/ for binaries and test log. |
Added a quick RPC test. |
rebased |
@cozz What about this after your smart fee pull git merged? |
I'd very much like to have a feature to support this. There is an related change which I'd also like to see: Round UP the payment to avoid change. E.g. If I say pay 1.0 btc, and I have a 1.001 coin, and I'm just paying another account of my own, it's stupid to take 0.001 btc in change. Interface was do you have an thoughts if this pull would obstruct doing that? (I'd always envisioned the round up working by augmenting values, e.g. 1.0+ would do a configurable amount of round up while 1.0+0.1 would round up upto 0.1 more.). Round up and fee from amount are 2/3rds of why I use raw txn for all my transactions currently. |
@Diapolo If we wanted this for 0.10 it would have been merged earlier, I guess. But yeah, would be nice to see this merged after branch off, especially as the workflow of sending everything minus the fee, is harder to do now because we removed the rounding of fees. @gmaxwell Would a simple option "Never create change smaller than x" make you happy? |
The logic around this I find most troublesome was introduced in #85. The current incarnation of it in |
Rebased as #5831 |
Fixes #2724 and #1570.
Adds the automatically-subtract-the-fee-from-the-amount-and-send-whats-left feature to the GUI and rpc (sendtoaddres,sendfrom,sendmany).
The checkbox is only shown for the first recipient. This is to avoid confusion and to make the implementation
as simple as possible: We deduct the fee from the first recipient, if its not enough -> fail
If whats left to send is dust -> fail
There is an edge case to consider: Instead of moving dust change to fees, we raise the change
until no dust and deduct from the recipient.
Example:
Amount: 10000 satoshis
Fee: 300 satoshis
Selected unspent output: 10001 satoshis
Now normally:
Recipient receives: 9700
Fee: 300
Change: 1
To pay: 10000
But 1 satoshi is dust, so instead we do:
Recipient receives: 9155 (9700 - 545)
Fee: 300
Change: 546 (1 + 545)
To pay: 9455
So you end up paying less than 10000 in this edge case. But if we would move dust-change to fees (or recipient) you would pay 10001 which would be totally unexpected if you enter 10000 and say "please just deduct the fee from the 10000 and send whats left".
Without checkbox
![subtractfeefromamount4](https://cloud.githubusercontent.com/assets/2814559/3252150/0eab2c18-f1bc-11e3-95b7-417f85a0d642.png)
With checkbox
![subtractfeefromamount3](https://cloud.githubusercontent.com/assets/2814559/3252154/166c5468-f1bc-11e3-9b47-17b3cc0787b4.png)
Dust edge case
![subtractfeefromamount5](https://cloud.githubusercontent.com/assets/2814559/3252158/1f515790-f1bc-11e3-91cc-75b242912050.png)
rpc
![subtractfeefromamount6](https://cloud.githubusercontent.com/assets/2814559/3252160/244fe5cc-f1bc-11e3-9a18-48acc6e080c2.png)