Skip to content
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: error if an explicit fee rate was given but the needed fee rate differed #18275

Merged
merged 1 commit into from Jun 16, 2020

Conversation

kallewoof
Copy link
Member

@kallewoof kallewoof commented Mar 6, 2020

This ensures that the code doesn't silently ignore too low fee reates. It will now trigger an error in the QT client, if the user provides a fee rate below the minimum, and becomes a necessary check for #11413.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 6, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Sjors
Copy link
Member

Sjors commented Mar 6, 2020

Can you add a test with createfundedpsbt's feeRate argument?

// Do not, ever, assume that it's fine to change the fee rate if the user has explicitly
// provided one
if (coin_control.m_feerate && nFeeRateNeeded > *coin_control.m_feerate) {
strFailReason = strprintf("Fee rate is too low for the current mempool. Increase it to %s or modify -maxmempool", nFeeRateNeeded.ToString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mempool fee is not considered when the user picks the fee rate. See also https://doxygen.bitcoincore.org/wallet_2fees_8cpp_source.html#l00028

How did you trigger this bug? It would be nice to include a test vector or steps to reproduce, otherwise this will just be dead code.

Copy link
Member

@Sjors Sjors Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoFalke the error is triggered by setting a fee rate below 1 sat / byte in the updated sendtoaddress RPCs in #11413. See #11413 (comment) for discussion and some alternative ideas.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not possible to hit this case with Bitcoin Core master, it probably makes sense to only add it when it can be hit. And also add a test to hit it.

Copy link
Member Author

@kallewoof kallewoof Mar 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I triggered it with no problem in bitcoin-qt (set fee to 0.00000001 btc/kb; note that the GUI has changed it back to the minimum in the screenshot after I clicked "Send")...

Screen Shot 2020-03-07 at 10 20 51

Without this patch, it goes to confirm screen, silently changing my fee rate:
Screen Shot 2020-03-07 at 10 22 48

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mempool fee is not considered when the user picks the fee rate. See also https://doxygen.bitcoincore.org/wallet_2fees_8cpp_source.html#l00028

How did you trigger this bug? It would be nice to include a test vector or steps to reproduce, otherwise this will just be dead code.

That code calls mempoolMinFee() though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code calls mempoolMinFee() though.

No? It doesn't.

The code is

         // Obey mempool min fee when using smart fee estimation
         CFeeRate min_mempool_feerate = wallet.chain().mempoolMinFee();

Setting a fee manually in the gui is not "smart fee". What am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not missing anything, because you're absolutely right. Should've read the code more carefully...

I've fixed the message.

@kallewoof
Copy link
Member Author

Can you add a test with createfundedpsbt's feeRate argument?

I tried and that takes me all the way to sendrawtransaction before it hits min relay fee not met, 1 < 141. The PSBT stuff doesn't use the same method, unfortunately.

@kallewoof kallewoof force-pushed the 2003-wallet-error-on-feechange branch 2 times, most recently from f6f525c to 7ac14a5 Compare March 7, 2020 01:37
@Sjors
Copy link
Member

Sjors commented Mar 7, 2020

I was hoping this was only an RPC issue. The error message is not very GUI friendly, but this should be bellt-and-suspenders check. The GUI is supposed to prevent you from entering a too low amount.

Your screenshot is a bit confusing, because the UI automatically corrects the input form when the value is below the minimum relay fee. But that correction only happens when you click somewhere else, like another field or the send button.

You can also see the issue when you launch with -minrelayfee=0.001 and then try 0.00001 as the fee. It will switch the amount back to 0.001, but when you click on Send it will still try the low fee rate.

tACK 7ac14a5

On a related note: I don't like that the GUI changes the fee amount from under me. It should just color the field red and show an error message below the field. But that's a separate PR imo, this check is useful regardless.

@fjahr
Copy link
Contributor

fjahr commented Mar 13, 2020

tACK 7ac14a5

@meshcollider
Copy link
Contributor

Concept ACK

@kallewoof kallewoof force-pushed the 2003-wallet-error-on-feechange branch from 7ac14a5 to f9b85c1 Compare April 24, 2020 05:00
@kallewoof
Copy link
Member Author

As @MarcoFalke pointed out, this actually does not rely on the current mempool limitations. I've updated the error message accordingly. It now reads

"Fee rate is lower than the minimum fee rate setting. Increase it to %s or modify -minrelaytxfee", nFeeRateNeeded.ToString()

src/wallet/wallet.cpp Outdated Show resolved Hide resolved
src/wallet/wallet.cpp Outdated Show resolved Hide resolved
@kallewoof kallewoof force-pushed the 2003-wallet-error-on-feechange branch from f9b85c1 to b8711d0 Compare April 25, 2020 14:19
@fjahr
Copy link
Contributor

fjahr commented Apr 30, 2020

re-ACK b8711d0

Only changes were rebasing and improvement of the error message.

@maflcko
Copy link
Member

maflcko commented May 1, 2020

I can not reproduce with the steps given here: #18275 (comment)

@maflcko
Copy link
Member

maflcko commented May 1, 2020

Couldn't reproduce either with feeRate in fundrawtransaction. Still Concept ACK as a belt and suspenders, but this doesn't fix a bug I can reproduce.

@kallewoof
Copy link
Member Author

kallewoof commented May 2, 2020

I can not reproduce with the steps given here: #18275 (comment)

Are you trying to reproduce on this branch or on master? On master, this is what it ends up like (note that it silently resets my desired fee rate when I defocus and/or click send): https://youtu.be/I0JZpmJ-Gls

@maflcko
Copy link
Member

maflcko commented May 2, 2020

I mean I couldn't get the newly introduced error to execute. Not in the GUI, and not in the RPC.

Just tried again with recompile. Maybe this is a mac-specific issue? Or I have something in my gui settings that prevents it.

@Sjors
Copy link
Member

Sjors commented May 4, 2020

tACK b8711d0. Just a rebase and text improvement since my last review.

@kallewoof
Copy link
Member Author

kallewoof commented May 4, 2020

@MarcoFalke Sorry about that [previous now-deleted comment showing 'settxfee' error], I got the messages mixed up. You're right that it doesn't seem possible to trigger this error from RPC/CLI. To trigger in QT, you need to change the fee rate and then click send without defocusing the window. This is probably platform dependent, so it may not be reproducable on non-macOS.

@Sjors
Copy link
Member

Sjors commented May 4, 2020

Just double checked: I can still produce this error in the GUI.

@maflcko
Copy link
Member

maflcko commented May 4, 2020

code-review-only ACK b8711d0, seems this can only be hit on macos

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK b8711d0

@meshcollider
Copy link
Contributor

There is a silent merge conflict, strFailReason no longer exists on master (it has been replaced by a bilingual_str called error)

@kallewoof kallewoof force-pushed the 2003-wallet-error-on-feechange branch from b8711d0 to 1b71a59 Compare May 5, 2020 05:06
@kallewoof
Copy link
Member Author

kallewoof commented May 5, 2020

@meshcollider Weird. Git happily automerged everything when I rebased on latest master. Pushed that rebase though.

Edit: Yeah, nevermind. Fixed.

…te differed

This avoids cases where a user requests a fee rate below the minimum and is silently overruled by the wallet.
@kallewoof kallewoof force-pushed the 2003-wallet-error-on-feechange branch from 1b71a59 to 44cc75f Compare May 5, 2020 05:09
@Sjors
Copy link
Member

Sjors commented May 5, 2020

utACK 44cc75f (rebased)

@fjahr
Copy link
Contributor

fjahr commented May 5, 2020

re-ACK 44cc75f

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jun 9, 2020
…te differed

This avoids cases where a user requests a fee rate below the minimum and is silently overruled by the wallet.

Github-Pull: bitcoin#18275
Rebased-From: 44cc75f
@Sjors
Copy link
Member

Sjors commented Jun 16, 2020

@meshcollider?

@maflcko maflcko merged commit 23b2a68 into bitcoin:master Jun 16, 2020
domob1812 added a commit to domob1812/namecoin-core that referenced this pull request Jun 24, 2020
Due to bitcoin/bitcoin#18275, make sure that
the minimum fee bump is at least matching the required fee level for
relay.  Otherwise the wallet Qt tests fail because they create a zero-fee
transaction and bump its fee, and then run into this new check.
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 7, 2020
…but the needed fee rate differed

44cc75f wallet: error if an explicit fee rate was given but the needed fee rate differed (Karl-Johan Alm)

Pull request description:

  This ensures that the code doesn't silently ignore too low fee reates. It will now trigger an error in the QT client, if the user provides a fee rate below the minimum, and becomes a necessary check for bitcoin#11413.

ACKs for top commit:
  Sjors:
    utACK 44cc75f (rebased)
  fjahr:
    re-ACK 44cc75f

Tree-SHA512: cd5a60ee496e64f7ab37aaa53f7748a7393357b1629ccd9660839d366c6191b6413b871ce3aa7293fce1539336222c300ef6f86304f30a1ae8fe361b02310483
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 26, 2021
…te differed

Summary:
This avoids cases where a user requests a fee rate below the minimum and is silently overruled by the wallet.

This is a backport of [[bitcoin/bitcoin#18275 | core#18275]]

Test Plan:
Run bitcoin-qt and manually set a too low fee when trying to send a transaction.

The following patch may be needed to let the interface set a fee lower than the minimum:

```
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index dc9c4bf699..99da1f837d 100644
--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -188,7 +188,7 @@ void SendCoinsDialog::setModel(WalletModel *_model) {
         connect(ui->customFee, &BitcoinAmountField::valueChanged, this,
                 &SendCoinsDialog::coinControlUpdateLabels);
         Amount requiredFee = model->wallet().getRequiredFee(1000);
-        ui->customFee->SetMinValue(requiredFee);
+        ui->customFee->SetMinValue(Amount::satoshi());
         if (ui->customFee->value() < requiredFee) {
             ui->customFee->setValue(requiredFee);
         }

```

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9936
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants