More economical fee estimates for RBF and RPC options to control #10589

Merged
merged 5 commits into from Jul 11, 2017

Conversation

Projects
None yet
10 participants
Contributor

morcos commented Jun 14, 2017 edited

This PR takes advantage of the new fee estimation feature that will potentially give lower estimates if recent market conditions warrant it. The logic used here is that any time a transaction signals opt-in-RBF and uses automatic fee estimation then it will use the non-conservative estimate. Transactions which do not signal opt-in-RBF will still use the default conservative estimate.

In a nutshell conservative estimates require that your fee rate would meet the necessary confirmation threshold for double your target at longer time horizons as well. This reduces the likelihood that you place a transaction just as the market is starting to get busy again that ends up being stuck for a very long time.

This PR also allows the specification of transaction confirmation target and whether the estimate should be conservative or not on a per-RPC call basis for sendtoaddress, sendmany, bumpfee, and fundrawtransaction using optional named arguments.

Left as an exercise to the reader is adding this to GUI functions to send transactions and bump fee.

Contributor

RHavar commented Jun 14, 2017

Concept ACK, this is really great and something that's been needed for a long time. It'll simplify some of the locking and settxfee stuff I've needed to do.

But it'd be nice if it used an options object or something. Otherwise if I want to specify the conservative_estimate I'll need to fill in all the other fields, which I might not want to know?

But I guess that's something that can be done in a different commit, with if (arguments.length == 3 && typeof arguments == 'object') style

Member

instagibbs commented Jun 14, 2017

@RHavar I had the same exact reaction fwiw. fee_options or something.

Contributor

morcos commented Jun 14, 2017

I thought the whole point of named arguments is we didn't have to worry about that any more. I think I made sure these work correctly with holes so we can use them with named arguments.

Contributor

RHavar commented Jun 14, 2017

Oh yeah, you're right. Guess I should learn how to use named arguments.

Owner

sipa commented Jun 16, 2017

Needs rebase.

Contributor

morcos commented Jun 18, 2017

Rebased due to conflict with #10422

src/wallet/rpcwallet.cpp
- "\nResult:\n"
+ "6. opt_in_rbf (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees\n"
+ "7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
+ "8. conservative_estimate (boolean, optional) Use conservative (potentially higher) fee estimation\n"
@laanwj

laanwj Jun 22, 2017 edited

Owner

I'd prefer to use a string here (which maps to FeeEstimateMode) instead of a boolean. This would also allow adding additional fee estimation strategies in the future without changing the interface.
(if we keep it this way, it should be documented that this is really a tri-value boolean, where null/unset is auto)

Owner

laanwj commented Jun 22, 2017

Concept ACK

morcos changed the title from Add RPC options for RBF, confirmation target and conservative fee estimates to More economical fee estimates for RBF and RPC options to control Jun 27, 2017

Contributor

morcos commented Jun 28, 2017

Switched to an estimate_mode string and squashed
5cbc1f6 (rpcestimatechoice.ver2) -> 1bc6a4a (rpcestimatechoices.ver2.squash)

Contributor

morcos commented Jun 28, 2017

Changed argument name from opt_in_rbf to replaceable for conformance with bumpfee

src/wallet/wallet.cpp
@@ -4145,3 +4148,14 @@ bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState&
{
return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, NULL, false, nAbsurdFee);
}
+
+bool CalculateEstimateType(FeeEstimateMode mode) {
@instagibbs

instagibbs Jul 3, 2017

Member

Not sure this is the best possible name. ConservativeEstimateRequested ?

@instagibbs

instagibbs Jul 3, 2017

Member

Ok we agree it should be a mode being returned ideally.

@TheBlueMatt

TheBlueMatt Jul 6, 2017

Contributor

I think it makes more sense to let it be generic and ideally estimatesmartfee would take a FeeEstimateMode and this functions purpose would be to take any requested mode and other wallet parameters and use wallet logic to determine a final mode. Rather than make all those changes now while not yet needed though, I think I'll just change the RPC interface to conservative estimates to take a string as per #10589 (review)

I stand entirely unconvinced that you shouldn't just do this now - just add more args (or add a struct arg) to GetMinimumFee instead of adding some new function that returns some magic value that you then immediately go and pass into GetMinimumFee everywhere?

@morcos

morcos Jul 6, 2017

Contributor

Please see #10706
CalculateEstimateType is now only used one place, in GetMinimumFee.

@TheBlueMatt

I still dont really feel comfortable ACKing the Qt changes until I get a chance to test, but this is generally a very welcome improvement.

src/wallet/wallet.cpp
@@ -4145,3 +4148,14 @@ bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState&
{
return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, NULL, false, nAbsurdFee);
}
+
+bool CalculateEstimateType(FeeEstimateMode mode) {
@TheBlueMatt

TheBlueMatt Jul 6, 2017

Contributor

I think it makes more sense to let it be generic and ideally estimatesmartfee would take a FeeEstimateMode and this functions purpose would be to take any requested mode and other wallet parameters and use wallet logic to determine a final mode. Rather than make all those changes now while not yet needed though, I think I'll just change the RPC interface to conservative estimates to take a string as per #10589 (review)

I stand entirely unconvinced that you shouldn't just do this now - just add more args (or add a struct arg) to GetMinimumFee instead of adding some new function that returns some magic value that you then immediately go and pass into GetMinimumFee everywhere?

src/wallet/rpcwallet.cpp
+ if (boost::optional<FeeEstimateMode> fee_mode = FeeModeForString(request.params[7].get_str())) {
+ coin_control.m_fee_mode = *fee_mode;
+ }
+ else {
@TheBlueMatt

TheBlueMatt Jul 6, 2017

Contributor

Nit: no need for the \n here (and a few other similar lines in this file.).

jonasschnelli added this to the 0.15.0 milestone Jul 6, 2017

morcos added some commits Jun 13, 2017

@morcos morcos remove default argument from GetMinimumFee cfaef69
@morcos morcos Introduce a fee estimate mode.
GetMinimumFee now passes the conservative argument into estimateSmartFee.
Call CalculateEstimateType(mode) before calling GetMinimumFee or estimateSmartFee to determine the value of this argument.
CCoinControl can now be used to control this mode.
d507c30
@morcos morcos remove default argument from estimateSmartFee e0738e3
@morcos morcos Change default fee estimation mode.
Fee estimates will default to be non-conservative if the transaction in question is opt-in-RBF.
f0bf33d
Contributor

morcos commented Jul 7, 2017

rebased for adjacent line change in #10698 and removed a couple extra \n's

no other changes

I believe we've settled on removing the CalculateEstimateType function entirely at the end of #10706 since it just becomes a helper for GetMinimumFee at that point.

@TheBlueMatt

Looks good. Definitely want #10706 to go in with this.

@@ -166,6 +166,8 @@ void SendCoinsDialog::setModel(WalletModel *_model)
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
+ connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(updateSmartFeeLabel()));
+ connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
@TheBlueMatt

TheBlueMatt Jul 9, 2017

Contributor

Cant comment there, but I believe you also need to move the default setting of optInRBF up a bunch here (about 10 lines below this (set default rbf checkbox state, or does that setting automagically result in calling these registrations?).

@morcos

morcos Jul 10, 2017

Contributor

Not sure if I understand your question (or how QT works) but I'm pretty sure it's correct as is. Calling setCheckState below will trigger the signal if the checkbox changed from its initial value.

@promag

promag Jul 10, 2017

Contributor

Either way, what about make an explicit call to coinControlUpdateLabels()?

@morcos

morcos Jul 10, 2017

Contributor

I don't think this is necessary. It's analogous to setting the default sliderSmartFee done in the same section of code.

@promag

IMO this would be a cleaner implementation

bool FeeEstimateModeFromString(const std::string& string, FeeEstimateMode& fee_estimate_mode)
{
    // lookup string
    return false;
}

...


if (!FeeEstimateModeFromString(request.params[7].get_str(), coin_control.m_fee_mode)) {
    throw JSONRPCError(RPC_INVALID_PARAMETER, ...);
}
src/wallet/rpcwallet.cpp
@@ -401,7 +401,7 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
return NullUniValue;
}
- if (request.fHelp || request.params.size() < 2 || request.params.size() > 5)
+ if (request.fHelp || request.params.size() < 2 || request.params.size() > 8)
throw std::runtime_error(
"sendtoaddress \"address\" amount ( \"comment\" \"comment_to\" subtractfeefromamount )\n"
@promag

promag Jul 10, 2017

Contributor

Missing new arguments.

@morcos

morcos Jul 10, 2017

Contributor

will do

@@ -416,6 +416,12 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
" transaction, just kept in your wallet.\n"
"5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
" The recipient will receive less bitcoins than you enter in the amount field.\n"
+ "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
@promag

promag Jul 10, 2017

Contributor

Add options instead of 3 more optional arguments?

@morcos

morcos Jul 10, 2017

Contributor

I believe named arguments are preferable

@promag

promag Jul 11, 2017

Contributor

I understand, but for those that use indexed arguments, they have to pass the middle arguments.

@@ -416,6 +416,12 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
" transaction, just kept in your wallet.\n"
"5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n"
" The recipient will receive less bitcoins than you enter in the amount field.\n"
+ "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
+ "7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
+ "8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
@promag

promag Jul 10, 2017

Contributor

fee_estimate_mode, fee_mode or estimate_mode?

@morcos

morcos Jul 10, 2017

Contributor

Hmm.. Yes, I think it might make sense to change this to fee_mode, but leave it estimate_mode for estimateSmartFee (done in another PR). Even though they take the same values now, I could imagine they would differ in the future. Any other thoughts?

@promag

promag Jul 10, 2017

Contributor

I just wanted to point out the inconsistencies between arguments, variable names and types.

@morcos

morcos Jul 10, 2017

Contributor

I decided leaving it as estimate_mode in both RPC's is preferable.
The inconsistency between variable and parameter name is not worth the churn imo.

@@ -910,7 +935,13 @@ UniValue sendmany(const JSONRPCRequest& request)
" \"address\" (string) Subtract fee from this address\n"
" ,...\n"
" ]\n"
- "\nResult:\n"
+ "6. replaceable (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees via BIP 125\n"
@promag

promag Jul 10, 2017

Contributor

Add options instead of 3 more optional arguments?

@promag

promag Jul 10, 2017

Contributor

I saw the above comment about named arguments. IMO from the client side feels better as an option.

@@ -166,6 +166,8 @@ void SendCoinsDialog::setModel(WalletModel *_model)
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateFeeSectionControls()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(updateGlobalFeeVariables()));
connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
+ connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(updateSmartFeeLabel()));
+ connect(ui->optInRBF, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels()));
@promag

promag Jul 10, 2017

Contributor

Either way, what about make an explicit call to coinControlUpdateLabels()?

@@ -26,6 +27,8 @@ class CCoinControl
int nConfirmTarget;
//! Signal BIP-125 replace by fee.
bool signalRbf;
+ //! Fee estimation mode to control arguments to estimateSmartFee
+ FeeEstimateMode m_fee_mode;
@promag

promag Jul 10, 2017

Contributor

m_fee_estimate_mode?

@@ -4154,3 +4157,15 @@ bool CMerkleTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState&
{
return ::AcceptToMemoryPool(mempool, state, tx, true, NULL, NULL, false, nAbsurdFee);
}
+
+bool CalculateEstimateType(FeeEstimateMode mode, bool opt_in_rbf) {
@promag

promag Jul 10, 2017

Contributor

IsFeeEstimateConservative?

@morcos

morcos Jul 10, 2017

Contributor

Function removed in #10706 (or will be shortly)

@promag

promag Jul 10, 2017

Contributor

Still, name not clear don't you think?

@morcos

morcos Jul 10, 2017

Contributor

yeah but who cares, its going away completely in a couple of commits

@morcos morcos Add RPC options for RBF, confirmation target, and conservative fee es…
…timation.

Add support for setting each of these attributes on a per RPC call basis to sendtoaddress, sendmany, fundrawtransaction (already had RBF), and bumpfee (already had RBF and conf target).
f135923
Contributor

morcos commented Jul 10, 2017

Contributor

promag commented on src/wallet/rpcwallet.cpp in f135923 Jul 11, 2017 edited

As suggested in another PR, the first condition can be removed since UniValue::operator[] handles out of bounds. Same below.

Owner

laanwj commented Jul 11, 2017

utACK f135923

@laanwj laanwj merged commit f135923 into bitcoin:master Jul 11, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@laanwj laanwj added a commit that referenced this pull request Jul 11, 2017

@laanwj laanwj Merge #10589: More economical fee estimates for RBF and RPC options t…
…o control


f135923 Add RPC options for RBF, confirmation target, and conservative fee estimation. (Alex Morcos)
f0bf33d Change default fee estimation mode. (Alex Morcos)
e0738e3 remove default argument from estimateSmartFee (Alex Morcos)
d507c30 Introduce a fee estimate mode. (Alex Morcos)
cfaef69 remove default argument from GetMinimumFee (Alex Morcos)

Tree-SHA512: 49c3a49a6893790a7e8b4e93a48f123dd5307af26c2017800683b76b4df8fc904ba73402917878676242c7440e3e04288d0c1ff3c2c907418724efc03cedab50
104f5f2

laanwj removed from Blockers in High-priority for review Jul 11, 2017

@laanwj laanwj added a commit that referenced this pull request Jul 17, 2017

@laanwj laanwj Merge #10706: Improve wallet fee logic and fix GUI bugs
11590d3 Properly bound check conf_target in wallet RPC calls (Alex Morcos)
fd29d3d Remove checking of mempool min fee from estimateSmartFee. (Alex Morcos)
2fffaa9 Make QT fee displays use GetMinimumFee instead of estimateSmartFee (Alex Morcos)
1983ca6 Use CoinControl to pass custom fee setting from QT. (Alex Morcos)
03ee701 Refactor to use CoinControl in GetMinimumFee and FeeBumper (Alex Morcos)
ecd81df Make CoinControl a required argument to CreateTransaction (Alex Morcos)

Pull request description:

  This builds on #10589  (first 5 commits from that PR, last 5 commits are new)

  The first couple commits refactor to use the CCoinControl class to pass fee calculation parameters around.

  This allows for fixing the buggy interaction in QT between the global payTxFee which can be modified by the RPC call settxfee or temporarily modified by the QT custom fee settings.  Before these changes the GUI could sometimes send a transaction with a recently set payTxFee and not respect the settings displayed in the GUI.   After these changes, using the GUI does not involve the global transaction confirm target or payTxFee.

  The prospective fee displays in the smart fee slider and the coin control dialog are changed to use the fee calculation from GetMinimumFee, this simplifies the code and makes them slightly more correct in edge cases.

  Maxing the fee calculation with the mempool min fee is move from estimateSmartFee to GetMinimumFee.

  This fixes a long standing bug, and should be tagged for 0.15 as it is holding up finalizing the estimatesmartfee RPC API before release.

Tree-SHA512: 4d36a1bd5934aa62f3806d380fcafbef73e9fe5bdf190fc5259a3e3a13349e5ce796e50e7068c46dc630ccf56d061bce5804f0bfe2e082bb01ca725b63efd4c1
6859ad2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment