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

rpc: update estimatesmartfee to return max of CBlockPolicyEstimator::estimateSmartFee, mempoolMinFee and minRelayTxFee #22722

Merged
merged 1 commit into from Sep 28, 2021

Conversation

pranabp-bit
Copy link
Contributor

This PR is in response to the issue #19699.

Based on the discussion in the comments of PR #22673 changes have been made in the estimatesmartfee itself such that it takes into account mempoolMinFee and relayMinFee . Hence it provides a fee estimate that is most likely to be paid by the user in an actual transaction, preventing issues such as #16072.

The test file test/functional/feature_fee_estimation.py has also been updated to check this functionality.

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Concept ACK

src/rpc/mining.cpp Outdated Show resolved Hide resolved
test/functional/feature_fee_estimation.py Outdated Show resolved Hide resolved
test/functional/feature_fee_estimation.py Outdated Show resolved Hide resolved
src/rpc/mining.cpp Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Aug 17, 2021

Concept ACK (Including mempoolMinFee)

estimatesmartfee should become better (smart) after this change although I am not sure about the approach. Will test it today.

@kristapsk
Copy link
Contributor

Concept ACK

@ghost
Copy link

ghost commented Aug 19, 2021

Tried this on Pop!_OS with regtest. Initially had issues understanding how GetMinFee() works, Andrew Chow answered it in detail on stackexchange: https://bitcoin.stackexchange.com/questions/108126/getminfee-in-blockchain-cpp

I saved minrelaytxfee 0.0002 similar to /test/functional/feature_fee_estimation.py and did some test transactions with different fee rate.

image

estimatesmartfee suggests 20 sat/vB conf_target 2

Changed minrelaytxfee to 0.00001 (default value)

image

estimatesmartfee suggests 1 sat/vB conf_target 2

Expected results:

$bitcoin-cli estimatesmartfee 1

{
  "feerate_min": 0.00001000
  "feerate_max": 0.00020000
  "blocks: 2
}
$bitcoin-cli estimatesmartfee 1

{
  "feerate_min": 0.00001000
  "feerate_max": 0.00100000
  "blocks: 2
}

feerate_min based on mempool fee rate distribution and feerate_max is the fee_rate returned right now

How to calculate feerate_min when conf_target is 2 ?

  1. 2 * average_block_vsize where average_block_vsize is average virtual size of last N blocks

  2. bytes from getmempoolinfo

  3. if ((bytes/ 2 * average_block_vsize) < 1 use minimum fee rate from getmempoolinfo else use same as feerate_max.

Why this will be useful?

  1. Users get a range instead of one fee rate
  2. Better estimates based on fee rates in mempool
  3. Can use feerate_min for RBF transaction and replace with feerate_max if not confirmed in next block

conf_target works for 1 to 1008 blocks right now. This can be reduced to 1-10 if others agree to change it.



💡 One project which can be helpful in improving `estimatesmartfee`

https://github.com/TrueLevelSA/btc-congestion-manager

It returns mempool position which can be added in output for estimatesmartfee:

image

Copy link
Member

@darosior darosior left a comment

Choose a reason for hiding this comment

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

Concept ACK, but i think this should not be restricted to the estimatesmartfee RPC. Maybe we could have a wrapper to CBlockPolicyEstimator's estimateSmartFee in CTxMemPool that would return the max of minerPolicyEstimator->estimateSmartFee() and GetMinFee? This way the node interface would call this wrapper instead of the estimator's one and it would apply this behaviour to all the current call sites.

@pranabp-bit
Copy link
Contributor Author

@prayank23 Thank you for the detailed review. Just wanted to confirm, are you suggesting to change estimatesmartfee such that is returns "feerate_min" and "feerate_max" ? If yes, then maybe I could try that later in a different PR.

@pranabp-bit
Copy link
Contributor Author

@darosior Thank you for the suggestion. But as of now, I only found one other call for the estimateSmartFee and it was in the GetMinimumFeeRate function. And this function returns the feerate_needed after considering the mempoolMinFee. So maybe we can keep this change limited to the estimatesmartfee RPC.

@darosior
Copy link
Member

But as of now, I only found one other call

Sounds good to me, it's already a fix as is and we can always de-duplicate the min(estimateSmarFee, mempoolMinFee) logic in a folowup.

@ghost
Copy link

ghost commented Aug 23, 2021

are you suggesting to change estimatesmartfee such that is returns "feerate_min" and "feerate_max" ? If yes, then maybe I could try that later in a different PR.

Yes. We could do something similar in follow up to improve estimatesmartfee. However, I also wanted to share that results for estimatesmartfee even after this PR are not helpful or misleading in some cases.

For example: In first case mempool has some transactions with fee rate ranging from 1 to 100 sat/vB (less than 2MvB), estimatesmartfee should suggest fee rate close to 1 sat/vB for conf_target 2. It shows 20x what we actually need minimum at that moment.

@instagibbs
Copy link
Member

concept ACK, can you please squash?

Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

ACK aside from test nit

@pranabp-bit
Copy link
Contributor Author

pranabp-bit commented Aug 28, 2021

I updated the test such that in the end, it sets the minrelaytxfee to a value which is 3 times the estimatesmartfee(1) called from the same node. So the test would be more robust against future changes than the previous one in which I set it directly to "0.0003".
I have incorporated most of the suggestions I got, and some of them, I would take up as follow-up in the future.
But for now, do suggest if any other change is required in the current PR.

@laanwj
Copy link
Member

laanwj commented Sep 16, 2021

Can you please change to a more descriptive PR title and commit message? "update estimatesmartfee" doesn't say much 😄

@pranabp-bit pranabp-bit changed the title rpc: update estimatesmartfee rpc: update estimatesmartfee to return max of CBlockPolicyEstimator::estimateSmartFee, mempoollMinFee and minRelayTxFee Sep 17, 2021
@instagibbs
Copy link
Member

ACK pranabp-bit@b2152f3

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 24, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23074 (Package-aware fee estimation by darosior)
  • #22539 (Re-include RBF replacement txs in fee estimation by darosior)

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.

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 b2152f3

@maflcko maflcko changed the title rpc: update estimatesmartfee to return max of CBlockPolicyEstimator::estimateSmartFee, mempoollMinFee and minRelayTxFee rpc: update estimatesmartfee to return max of CBlockPolicyEstimator::estimateSmartFee, mempoolMinFee and minRelayTxFee Sep 27, 2021
Copy link
Member

@darosior darosior left a comment

Choose a reason for hiding this comment

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

utACK b2152f3

src/rpc/mining.cpp Outdated Show resolved Hide resolved
@pranabp-bit pranabp-bit force-pushed the estimatesmartfee branch 2 times, most recently from dbcd679 to 71a3d98 Compare September 28, 2021 13:05
…lMinFee and minRelayTxFee.

This will provide better estimates which would be closer to fee paid in actual
transactions.
The test has also been changed such that when the node is restarted with a
high mempoolMinFee, the estimatesmartfee still returns a feeRate greater
than or equal to the mempoolMinFee, minRelayTxFee.(just like the feeRate of actual transactions)
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.

re-utACK ea31caf

@meshcollider meshcollider merged commit b55232a into bitcoin:master Sep 28, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 28, 2021
…lockPolicyEstimator::estimateSmartFee, mempoolMinFee and minRelayTxFee

ea31caf update estimatesmartfee rpc to return max of estimateSmartFee, mempoolMinFee and minRelayTxFee. (pranabp-bit)

Pull request description:

  This PR is in response to the issue [bitcoin#19699](bitcoin#19699).

  Based on the discussion in the comments of PR [bitcoin#22673](bitcoin#22673) changes have been made in the `estimatesmartfee` itself such that it takes into account `mempoolMinFee` and `relayMinFee` . Hence it provides a fee estimate that is most likely to be paid by the user in an actual transaction, preventing issues such as [bitcoin#16072](bitcoin#16072).

  The test file test/functional/feature_fee_estimation.py has also been updated to check this functionality.

ACKs for top commit:
  meshcollider:
    re-utACK ea31caf

Tree-SHA512: 8f36153a07cbd552c5c13d11d9c6e987a7a555ea4cc83f2573c0c92dd97c706d90c30a7248671437c2f3a836d3272f8fad53d15a5fa6efaa0409ae8009b0a18d
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Oct 10, 2021
…lMinFee and minRelayTxFee.

This will provide better estimates which would be closer to fee paid in actual
transactions.
The test has also been changed such that when the node is restarted with a
high mempoolMinFee, the estimatesmartfee still returns a feeRate greater
than or equal to the mempoolMinFee, minRelayTxFee.(just like the feeRate of actual transactions)

Github-Pull: bitcoin#22722
Rebased-From: b2152f3
maflcko pushed a commit that referenced this pull request Dec 7, 2021
…f smart fee data is unavailable

cd8d156 Bugfix: RPC/mining: Fail properly in estimatesmartfee if smart fee data is unavailable (Luke Dashjr)

Pull request description:

  Fixes a regression introduced by #22722

  (Not entirely sure on the solution)

ACKs for top commit:
  prayank23:
    crACK cd8d156
  darosior:
    utACK cd8d156
  kristapsk:
    utACK cd8d156

Tree-SHA512: eb4aa3cc345c69c44ffd5733b51b90eefe1d7854b7a2855e8cbb98268db24d43b7d0ae9fbb0eccf9b6dc01da644d19433cc77fec52ff67bf890be1fc53a67fc4
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 7, 2021
…rtfee if smart fee data is unavailable

cd8d156 Bugfix: RPC/mining: Fail properly in estimatesmartfee if smart fee data is unavailable (Luke Dashjr)

Pull request description:

  Fixes a regression introduced by bitcoin#22722

  (Not entirely sure on the solution)

ACKs for top commit:
  prayank23:
    crACK bitcoin@cd8d156
  darosior:
    utACK cd8d156
  kristapsk:
    utACK cd8d156

Tree-SHA512: eb4aa3cc345c69c44ffd5733b51b90eefe1d7854b7a2855e8cbb98268db24d43b7d0ae9fbb0eccf9b6dc01da644d19433cc77fec52ff67bf890be1fc53a67fc4
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Dec 14, 2021
…lMinFee and minRelayTxFee.

This will provide better estimates which would be closer to fee paid in actual
transactions.
The test has also been changed such that when the node is restarted with a
high mempoolMinFee, the estimatesmartfee still returns a feeRate greater
than or equal to the mempoolMinFee, minRelayTxFee.(just like the feeRate of actual transactions)

Github-Pull: bitcoin#22722
Rebased-From: b2152f3
@bitcoin bitcoin locked and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants