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
Fee Estimator updates from Validation Interface/CScheduler thread #28368
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first pass
a7250f6
to
b45345d
Compare
b45345d
to
2f6d2b1
Compare
2f6d2b1
to
db4849c
Compare
db4849c
to
9ae8482
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-ACK 91504cb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -140,6 +150,7 @@ class CValidationInterface { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit if you retouch bfcd401:
* Provides the block that was connected. | |
* Provides the block that was disconnected. |
@@ -208,4 +208,33 @@ struct RemovedMempoolTransactionInfo { | |||
: info{entry.GetSharedTx(), entry.GetFee(), entry.GetTxSize(), entry.GetHeight()} {} | |||
}; | |||
|
|||
struct NewMempoolTransactionInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
@@ -285,8 +285,12 @@ void Shutdown(NodeContext& node) | |||
DumpMempool(*node.mempool, MempoolPath(*node.args)); | |||
} | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post merge tACK 91504cb
Tested manually using RPC
commands estimatesmartfee
and estimaterawfee
(following cases from /test/functional/feature_fee_estimation.py
).
b1318dc test: change `m_submitted_in_package` input to fuzz data provider boolean (ismaelsadeeq) 5615e16 tx fees: update `m_from_disconnected_block` to `m_mempool_limit_bypassed` (ismaelsadeeq) fcd4296 doc: fix typo and update incorrect comment (ismaelsadeeq) 562664d test: wait for fee estimator to catch up before estimating fees (ismaelsadeeq) Pull request description: This is a simple PR that does two things 1. Fixes #29000 by waiting for the fee estimator to catch up after `removeForBlock` calls before calling `estimateFee` in the `BlockPolicyEstimates` unit test. 2. Addressed some outstanding review comments from #28368 - Updated `NewMempoolTransactionInfo::m_from_disconnected_block` to `NewMempoolTransactionInfo::m_mempool_limit_bypassed` which now correctly indicates what the boolean does. - Changed input of `processTransaction`'s tx_info `m_submitted_in_package` input from false to fuzz data provider boolean. - Fixed some typos, and update incorrect comment ACKs for top commit: martinus: re-ACK b1318dc glozow: utACK b1318dc Tree-SHA512: 45268729bc044da4748fe004524e0df696d2ec92c5bd053db9aad6e15675f3838429b2a7b9061a6b694be4dc319d1782a876b44df506ddd439d62ad07252d0e1
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.TransactionAddedToMempool
callback parameter to include additional information about the transaction needed for fee estimation.CBlockPolicyEstimator
to process transactions usingCTransactionRef
instead ofCTxMempoolEntry.
CValidationInterface
interface inCBlockPolicyEstimater
and overridden theTransactionAddedToMempool
,TransactionRemovedFromMempool
, andMempoolTransactionsRemovedForConnectedBlock
methods 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
removeForBlock
function intxmempool.cpp
.This removal triggered updates to the fee estimator. As a result, the fee estimator would block mempool's
cs
until 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
MempoolInterface
signals come from the mempool andCValidationInterface
events 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.