-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Introduce MempoolObserver interface to break "policy/fees -> txmempool -> policy/fees" circular dependency #13949
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
Conversation
45ef07c
to
2a44b30
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
Concept ACK Thanks for working on these circular dependencies! |
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.
Concept ACK. Thanks @Empact!
src/policy/fees.h
Outdated
/** Remove a transaction from the mempool tracking stats | ||
* Removal is not inBlock as in-block removals are handled internally. | ||
*/ | ||
bool removeTx(uint256 hash); |
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.
You can mark the declarations of interfaces::MempoolObserver
methods in CBlockPolicyEstimator
with override
:
void processBlock(unsigned int nBlockHeight,
std::vector<const CTxMemPoolEntry*>& entries) override;
void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate) override;
bool removeTx(uint256 hash) override;
src/policy/fees.h
Outdated
@@ -198,8 +199,10 @@ class CBlockPolicyEstimator | |||
/** Process a transaction accepted to the mempool*/ | |||
void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate); | |||
|
|||
/** Remove a transaction from the mempool tracking stats*/ | |||
bool removeTx(uint256 hash, bool inBlock); | |||
/** Remove a transaction from the mempool tracking stats |
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.
To prevent redundant documentation, maybe you can declare the interfaces::MempoolObserver
methods in CBlockPolicyEstimator
without copying the documentation from the method declarations in interfaces::MempoolObserver
.
void processBlock(unsigned int nBlockHeight,
std::vector<const CTxMemPoolEntry*>& entries);
void processTransaction(const CTxMemPoolEntry& entry, bool validFeeEstimate);
/**
* Removal is not inBlock as in-block removals are handled internally.
*/
bool removeTx(uint256 hash);
2a44b30
to
2ec0a07
Compare
Marked methods |
2ec0a07
to
56ec018
Compare
Made the |
utACK 56ec018 when squashed. One nit: I was wondering about the location of |
d8c390b
to
7b31ea2
Compare
Thanks for calling out the readme. Fixed, rebased, and squashed. |
7b31ea2
to
f58e17e
Compare
yw, nice refactor! utACK f58e17e |
src/policy/fees.cpp
Outdated
@@ -509,6 +509,12 @@ void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHe | |||
// tracked. Txs that were part of a block have already been removed in | |||
// processBlockTx to ensure they are never double tracked, but it is | |||
// of no harm to try to remove them again. | |||
void CBlockPolicyEstimator::removeTx(uint256 hash) |
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.
hash
should be passed by const reference?
f58e17e
to
e44968a
Compare
Changed |
copy-paste from #15638 (comment) by @ryanofsky: While I think in some cases fixing An example would be the circular dependency between The simple and obvious way to write this code is to declare the mempool entry struct in
It's possible changes like these would be good for other reasons, but in general I think cleaning up spew from |
re: #13949 (comment) Wow, I didn't know about (or maybe forgot about?) this PR. Looking over this change, it may not be a bad idea if there are justifications for it other than fixing circular dependencies. In the pasted comment, I was actually complaining circular dependency errors in the context of #10443, not this PR. |
This refactoring change is +80-17. Generally I'd prefer if refactoring simplified things, not made them harder |
e87926c
to
8501bdc
Compare
Now +70 −16, with +43 coming from the interface header itself. I would argue this does make things simpler, by making A practical benefit is that this makes |
utACK 8501bdc. The introduction of the |
This is an abstract interface which presents removes the dependency between CBlockPolicyEstimator and CTxMemPool
Needs rebase |
Closing in favor of #17786 |
A simple interface which make the implementations independent of one another.
Note I also removed the
inBlock
argument to the publicCBlockPolicyEstimator::removeTx
, as all block-related removal calls are internal to the class. This simplifies the extracted interface and reduces CBlockPolicyEstimator surface area.