Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Better API for estimatesmartfee RPC #10707
Conversation
morcos
referenced
this pull request
Jun 29, 2017
Closed
Add allowable range to estimatesmartfee RPC help #10654
fanquake
added RPC/REST/ZMQ TX fees and policy
labels
Jun 30, 2017
jonasschnelli
added this to the
0.15.0
milestone
Jul 6, 2017
| - " feerate and is more likely to be sufficient for the desired target, but is not as\n" | ||
| - " responsive to short term drops in the prevailing fee market\n" | ||
| + "1. nblocks (numeric) Confirmation target in blocks (1 - 1008)\n" | ||
| + "2. \"estimate_mode\" (string, optional, default=CONSERVATIVE) The fee estimate mode.\n" |
|
Needs rebase. |
|
Rebased correctly for #10589 merge |
|
Clean rebase again for changes to #10707 Added a new optional commit which changes the named arguments in I don't feel strongly about this change, but if we want to align the argument names, now is the time to do it. |
Looks like it's the last two commits now, for anyone else looking at this. |
ryanofsky
reviewed
Jul 13, 2017
utACK 7d70bb7. Should update PR description to mention conf_target renames before this is merged.
morcos
referenced
this pull request
Jul 13, 2017
Merged
Improve wallet fee logic and fix GUI bugs #10706
|
rebased on new #10706, no changes |
| + " Whether to return a more conservative estimate which also satisfies\n" | ||
| + " a longer history. A conservative estimate potentially returns a\n" | ||
| + " higher feerate and is more likely to be sufficient for the desired\n" | ||
| + " target, but is not asresponsive to short term drops in the\n" |
| "\nResult:\n" | ||
| "{\n" | ||
| - " \"feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in BTC)\n" | ||
| + " \"feerate\" : x.x, (numeric, optional) estimate fee-per-kilobyte (in BTC)\n" | ||
| + " \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n" |
morcos
Jul 15, 2017
Contributor
The whole command is not necessarily an error. It's just an error in returning a value for that particular horizon. It was my understanding that this was the preferred method rather than silently omitting the horizon. Also there is no error with the request.
Or am I misunderstanding your question?
sipa
Jul 16, 2017
Owner
I see. It makes sense that no RPC error is to be returned for cases where it is not due to something the caller could know. It still seems overkill to create a whole new errors field for just a lack of available information, though. Do we expect more kinds of errors to be added later?
morcos
Jul 16, 2017
Contributor
I had originally thought I'd be able to distinguish between "insufficient data" and "enough data but no passing feerate" (to the extent those are really different things) but it wasn't easy. However I do like the idea of setting the API now to be general enough that we don't have to change the API in the future if suppose we want to give an answer but also give an errors indicating part of the calculation couldn't work or something.
Also estimaterawfee now is merged to master with a similar errors field.
In short, I don't know that there will be more kinds, but I also don't see much harm in adding the errors field. If users don't care they can just ignore it right?
promag
Jul 16, 2017
Contributor
In terms of REST, the status code can represent both situations. In this case it could be a 412 Precondition Failed with { "message": "Insufficient data or no feerate found" } as body instead of a 200 with an error body. Not sure if it can be like that with RPC.
sipa
Jul 17, 2017
Owner
We have RPC error codes, but those are usually for exceptional situations, rather than to communicate a totally inevitable not-enough-data situation.
| + if (!(feeRate == CFeeRate(0))) { | ||
| + result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK()))); | ||
| + } | ||
| + else { |
| "\nResult:\n" | ||
| "{\n" | ||
| - " \"feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in BTC)\n" | ||
| + " \"feerate\" : x.x, (numeric, optional) estimate fee-per-kilobyte (in BTC)\n" | ||
| + " \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n" |
promag
Jul 16, 2017
Contributor
In terms of REST, the status code can represent both situations. In this case it could be a 412 Precondition Failed with { "message": "Insufficient data or no feerate found" } as body instead of a 200 with an error body. Not sure if it can be like that with RPC.
| - CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocks, &feeCalc, ::mempool, conservative); | ||
| - result.push_back(Pair("feerate", feeRate == CFeeRate(0) ? -1.0 : ValueFromAmount(feeRate.GetFeePerK()))); | ||
| + CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative); | ||
| + if (!(feeRate == CFeeRate(0))) { |
|
Rebased now that #10706 is merged. Typo fixed in the comments, 2 white space changes and |
ryanofsky
reviewed
Jul 17, 2017
utACK a9ee31a. Only changes since previous review were rebase, switching to operator != and fixing whitespace around else.
|
Added 2 more lines of RPC help. |
|
utACK 06bcdb8 |
| @@ -806,42 +806,59 @@ UniValue estimatesmartfee(const JSONRPCRequest& request) | ||
| { | ||
| if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) | ||
| throw std::runtime_error( | ||
| - "estimatesmartfee nblocks (conservative)\n" | ||
| + "estimatesmartfee conf_target (\"estimate_mode\")\n" |
| } | ||
| UniValue result(UniValue::VOBJ); | ||
| + UniValue errors(UniValue::VARR); |
| - CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocks, &feeCalc, conservative); | ||
| - result.push_back(Pair("feerate", feeRate == CFeeRate(0) ? -1.0 : ValueFromAmount(feeRate.GetFeePerK()))); | ||
| + CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative); | ||
| + if (feeRate != CFeeRate(0)) { |
promag
Jul 17, 2017
Contributor
Suggestion for future PR, CFeeRate constructor argument could have default value = 0 so CFeeRate() sounds more like null fee rate.
| - RPCTypeCheck(request.params, {UniValue::VNUM}); | ||
| - | ||
| + RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR}); | ||
| + RPCTypeCheckArgument(request.params[0], UniValue::VNUM); |
|
utACK 06bcdb8 |
sipa
merged commit 06bcdb8
into
bitcoin:master
Jul 17, 2017
1 check passed
sipa
added a commit
that referenced
this pull request
Jul 17, 2017
|
|
sipa |
75b5643
|
morcos commentedJun 29, 2017
•
edited
Through 0.14 branch, the estimatesmartfee API was tagged "WARNING: This interface is unstable and may disappear or change!" and this warning is removed for 0.15, so any wanted API updates should happen now.
The changes here are to make the additional parameter for conservative estimates a more general estimate_mode string , to omit the feerate and include an error string instead of returning -1 on error, and to do better parameter checking initially.
It is only the last 2 commits, but it's built on #10706 and #10543.See #10707 (comment) for renaming of nblocks argument to conf_target. Will need to be included before string freeze.
PR description edited for clarity