Fee Estimator updates from Validation Interface/CScheduler thread#28368
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, 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. |
|
Nice work! So if correctly implemented this should speed up block relay, and enable (future) fee estimator changes to be added without blocking critical codepaths. It would be nice to try and benchmark this somehow, but I'm unsure immediately what the best way to do this would be... @glozow @TheCharlatan @instagibbs would be curious to know what y'all think of the approach here. |
|
I haven't spent much/any time on the interfaces themselves, will defer to others |
vincenzopalazzo
left a comment
There was a problem hiding this comment.
I did a first pass on this but I should take a look in a more deep way
|
Concept ACK! Background fee estimator would be really nice (fwiw it seems like this was always the plan: #10199 (comment) and #11775 had a lot of fans). Updating asynchronously instead of blocking I haven't reviewed the new interface closely yet but will do as soon as I can. |
|
Concept ACK. Not sure i'll be able to review anytime soon though. |
a7250f6 to
b45345d
Compare
b45345d to
2f6d2b1
Compare
2f6d2b1 to
db4849c
Compare
db4849c to
9ae8482
Compare
|
CI failure is unrelated see #28905 |
sedited
left a comment
There was a problem hiding this comment.
ACK 7268aaf36bdcc6b466fd16bbf544782571e680bb
7268aaf to
781c60f
Compare
|
CI restarted. UPD. See #28925 |
…tion If the removal reason of a transaction is BLOCK, then the `removeTx` boolean argument should be true. Before this PR, `CBlockPolicyEstimator` have to complete updating the fee stats before the mempool clears that's why having removeTx call outside reason!= `BLOCK` in `addUnchecked` was not a bug. But in a case where the `CBlockPolicyEstimator` update is asynchronous, the mempool might clear before we update the `CBlockPolicyEstimator` fee stats. Transactions that are removed for `BLOCK` reasons will also be incorrectly removed from `CBlockPolicyEstimator` stats as failures.
…ace` This commit adds a new callback `MempoolTransactionsRemovedForBlock` which notify its listeners of the transactions that are removed from the mempool because a new block is connected, along with the block height the transactions were removed. The transactions are in `RemovedMempoolTransactionInfo` format. `CTransactionRef`, base fee, virtual size, and height which the transaction was added to the mempool are all members of the struct called `RemovedMempoolTransactionInfo`. A struct `NewMempoolTransactionInfo`, which has fields similar to `RemovedMempoolTransactionInfo`, will be added in a later commit, create a struct `TransactionInfo` with all similar fields. They can both have a member with type `TransactionInfo`.
Update `processBlock` parameter to reference to a vector of `RemovedMempoolTransactionInfo`.
…ool` Create a new struct `NewMempoolTransactionInfo` that will be used as the new parameter of `TransactionAddedToMempool` callback.
…ace` notifications `CBlockPolicyEstimator` will implement `CValidationInterface` and subscribe to its notification to process transactions added and removed from the mempool. Re-delegate calculation of `validForFeeEstimation` from validation to fee estimator. Also clean up the validForFeeEstimation arg thats no longer needed in `CTxMempool`. Co-authored-by: Matt Corallo <[email protected]>
This ensures that the most recent fee estimation data is used for the fee estimation with `estimateSmartfee` and `estimaterawfee` RPC's.
|
Thanks for your review @TheCharlatan
|
willcl-ark
left a comment
There was a problem hiding this comment.
ACK 91504cb
Glad to see the fee estimator being decoupled in this way and keen to see more development of additional estimators in the future e.g. as per #27995
I gave the code a review and it seems well thought-out to me at this stage; left a few nits which can be addressed in the case that you re-touch things.
| virtual void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex) {} | ||
| /** | ||
| * Notifies listeners of a block being disconnected | ||
| * Provides the block that was connected. |
There was a problem hiding this comment.
nit if you retouch bfcd401:
| * Provides the block that was connected. | |
| * Provides the block that was disconnected. |
| : info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {} | ||
| }; | ||
|
|
||
| struct NewMempoolTransactionInfo { |
There was a problem hiding this comment.
In dff5ad3
Worth adding a doxygen comment here? Even something simple like:
/**
* Holds information about new transactions added to the mempool.
* In addition to TransactionInfo includes limit bypass, package, chain and parent info.
*/| struct NewMempoolTransactionInfo { | ||
| TransactionInfo info; | ||
| /* | ||
| * This boolean indicates whether the transaction was added |
There was a problem hiding this comment.
In dff5ad3
You've called this m_from_disconnected_block, but described it as whether the tx was added without enforcing mempool fee limits. This seems incorrect or confusing.
SubmitPackage() is calling this using args.m_bypass_limits so i think the comment is correct, and the variable should be renamed?
|
|
||
| // Drop transactions we were still watching, and record fee estimations. | ||
| if (node.fee_estimator) node.fee_estimator->Flush(); | ||
| // Drop transactions we were still watching, record fee estimations and Unregister |
There was a problem hiding this comment.
micro nit, if you end up touching 7145239 again:
| // Drop transactions we were still watching, record fee estimations and Unregister | |
| // Drop transactions we were still watching, record fee estimations and unregister |
| const auto tx_info = NewMempoolTransactionInfo(entry.GetSharedTx(), entry.GetFee(), | ||
| entry.GetTxSize(), entry.GetHeight(), | ||
| /* m_from_disconnected_block */ false, | ||
| /* m_submitted_in_package */ false, |
There was a problem hiding this comment.
In 7145239
Would we want to use fuzzed_data_provider.ConsumeBool() for m_submitted_in_package?
|
Thanks for your review @willcl-ark will address nits if there is need to retouch. |
|
ACK 91504cb |
pablomartin4btc
left a comment
There was a problem hiding this comment.
post merge tACK 91504cb
Tested manually using RPC commands estimatesmartfee and estimaterawfee (following cases from /test/functional/feature_fee_estimation.py).
This is an attempt to #11775
This Pr will enable fee estimator to listen to ValidationInterface notifications to process new transactions added and removed from the mempool.
This PR includes the following changes:
MempoolTransactionsRemovedForConnectedBlock, which notifies listeners about the transactions that have been removed due to a new block being connected, along with the height at which the transactions were removed.TransactionAddedToMempoolcallback parameter to include additional information about the transaction needed for fee estimation.CBlockPolicyEstimatorto process transactions usingCTransactionRefinstead ofCTxMempoolEntry.CValidationInterfaceinterface inCBlockPolicyEstimaterand overridden theTransactionAddedToMempool,TransactionRemovedFromMempool, andMempoolTransactionsRemovedForConnectedBlockmethods to receive updates from their notifications.Prior to this PR, the fee estimator updates from the mempool, i.e whenever a new block is connected all transactions in the block that are in our mempool are going to be removed using the
removeForBlockfunction intxmempool.cpp.This removal triggered updates to the fee estimator. As a result, the fee estimator would block mempool's
csuntil it finished updating every time a new block was connected.Instead of being blocked only on mempool tx removal, we were blocking on both tx removal and fee estimator updating.
If we want to further improve fee estimation, or add heavy-calulation steps to it, it is currently not viable as we would be slowing down block relay in the process
This PR is smaller in terms of the changes made compared to #11775, as it focuses solely on enabling fee estimator updates from the validationInterface/cscheduler thread notifications.
I have not split the validation interface because, as I understand it, the rationale behind the split in #11775 was to have
MempoolInterfacesignals come from the mempool andCValidationInterfaceevents come from validation. I believe this separation can be achieved in a separate refactoring PR when the need arises.Also left out some commits from #11775
I believe they are a separate change that can come in a follow-up after this.