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:
- Added a new callback to the Validation Interface
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. - Modified the
TransactionAddedToMempool
callback parameter to include additional information about the transaction needed for fee estimation. - Updated
CBlockPolicyEstimator
to process transactions usingCTransactionRef
instead ofCTxMempoolEntry.
- Implemented the
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 in txmempool.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 and CValidationInterface
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
- Some refactoring which are no longer needed.
- Handle reorgs much better in fee estimator.
- Track witness hash malleation in fee estimator
I believe they are a separate change that can come in a follow-up after this.