-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Move fee estimator into validationinterface/cscheduler thread #11775
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
Move fee estimator into validationinterface/cscheduler thread #11775
Conversation
1e08182 to
88de71e
Compare
|
Obviously this cleans up some of the interface gook from #10286, and adds some more docs that probably could have been there. Next up after this one is moving alll the remaining events all into the background thread, with associated net_processing cleanups in the process. |
88de71e to
50abdd3
Compare
|
Rebased. |
3cd22de to
455585f
Compare
|
Concept ACK. Though I'm nervous about backgrounding more stuff before safeguarding against outside (unsynchronized) access. For example, the mempool/feeestimator may now be significantly ahead of what the wallet has processed. So calling CreateTransaction when we're in the middle of connecting 10 blocks seems... dangerous, even with the BlockUntilSyncedToCurrentChain hack. |
|
Hmm? If anything the fee estimator should be at much lower risk there than for wallet...at worst you'll get out of date fee estimates...something you'd get anyway because you're calling the fee estimator in the middle of syncing stuff. Note that #11824 also keeps the queue depth at no more than 10, though I dont really want to rely on that and would prefer to implement the dump/reload-from-disk proposal suggested at https://github.com/bitcoin/bitcoin/pull/11775/files#diff-e8d9e22d9683f73a9fb8399be0dab640R145 |
455585f to
14b299f
Compare
|
Rebased. |
14b299f to
68d7445
Compare
jimpo
left a comment
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. Overall, this looks awesome and simplifies a lot of code. I'm all for decoupling stuff through the ValidationInterface.
I did find it hard to review because it is so large and would prefer it be broken up into fee estimate stuff and non-fee estimate specific refactors.
Also, there's a typo in the commit title of "Make fee estimation not need CTxMemPoolEntry is block processing"
src/txmempool.h
Outdated
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.
commit: Split removeRecursive into calculate/remove steps
style: Capitalize function name.
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.
This PR was created long before the introduction of that part of the style guide, so it matches the capitalization of removeRecursive.
src/txmempool.cpp
Outdated
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.
commit: Split removeRecursive into calculate/remove steps
Should this AssertLockHeld?
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.
Done (bonus: also fixed the whitespace issues in that commit).
src/txmempool.cpp
Outdated
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.
commit: Track the set of transactions removed/conflicted in removeForBlock
I think this reserve call could be less performant than skipping it if there are a sufficient number of conflicting inputs. https://stackoverflow.com/a/1742961
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.
Good catch. Removed.
src/wallet/wallet.cpp
Outdated
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.
commit: BlockConnected(vtxConflicted) -> New MempoolInterface callback
Why not just move that logic here from BlockConnected as well?
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.
Because we still need it in BlockConnected - there may be txn that weren't in our mempool that got confirmed, so copying it would be useless.
src/init.cpp
Outdated
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.
commit: Add txn_replaced to Added callback, remove lReplaced ATMP arg
nit: Space after if
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.
Fixed.
src/policy/fees.cpp
Outdated
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.
commit: Make fee estimation not need CTxMemPoolEntry is block processing
I'd move this erase immediately after the removeTx above and define double fee_per_k = (double)pos->second.m_fee_per_k; as a variable up there as well.
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.
Would also need to copy blockHeight as well, at which point you'd just be copying the whole struct so that you can remove it.
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.
Yeah, I think copying the struct for the sake of simplifying the control flow (by only erasing in one place) is actually good. Also would just make it more readable to have a descriptive variable name like tx_info instead of pos->second.
src/policy/fees.h
Outdated
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.
commit: Make fee estimation not need CTxMemPoolEntry is block processing
I don't really like that this method has the same name as the other removeTx because it's responsibilities are different.
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.
Happy to rename it, but honestly I dont remember what the different responsibilities are. Its been so long since I wrote this I dont know how it works anymore. Any suggestions?
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.
Actually, it's fine leaving this one as is because in the later commit (Process fee estimates in the background via MempoolInterface), the other removeTx gets renamed to removeTxNotInBlock.
Not really necessary, but maybe rename the other function to removeTxNotInBlock in this commit instead of a later commit to avoid the confusion here.
src/policy/fees.cpp
Outdated
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.
commit: Track witness hash malleation in fee estimator
Why don't we want to record the blocks to confirm in this case?
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.
Because we don't know how long its been around/it waited.
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 don't understand. We have the record of when the tx entered the mempool (albeit with different witness data). How does the malleated witness change things?
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.
Because clearly there was a propagation issue. We dont know whether the lower-feerate version (or some other version) was the one most miners saw or the higher-feerate version. Better to just ignore it.
src/test/policyestimator_tests.cpp
Outdated
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.
commit: Process fee estimates in the background via MempoolInterface
Use SyncWithValidationInterfaceQueue?
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.
This was written before that existed. Fixed.
src/policy/fees.h
Outdated
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.
commit: Process fee estimates in the background via MempoolInterface
Make the callbacks protected?
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.
Fixed.
68d7445 to
4c526df
Compare
|
I've started reviewing and testing the first few commits in this PR, but I already agree with @jimpo above, that this would be easier to review if it was split up. Perhaps we could first have a PR that changed the callback interface around, and then another PR that reworks the fee estimator to take advantage of the new interface? (also this needs rebase) |
|
ConceptACK for what it's worth, but definitely split this up -- it overflows my mental stack, and both times I've tried to review it it's already had conflicts with master that make a review not crazy useful... Breaking out the trivial bits, at least "Clarify validationinterface notification ordering" and "Remove useless scoped (sic?) in AcceptToMemoryPool" seems like a good first move. Maybe "Split removeRecursive" as well. Otherwise just splitting the remaining patches into mempool/validationinterface vs fee-estimation focused seems plausible. |
|
I haven't looked at the changes but a +700/-600 diff is somewhat intimidating. I'd love to help you make progress on this and will happily review PRs that are a subset of this. |
|
Tested ACK. I'm kidding |
4c526df to
4e82ca6
Compare
|
Now based on #12979. |
bbfb971 to
eaa71b2
Compare
Because many listeners (eg wallet) will want both types of events to be well-ordered, they are parallel and connected on the backend. However, they are exposed separately to clients to separate the logic (and because, hopefully, eventually, they can be exposed to external clients of Bitcoin Core via libconsensus or similar).
eaa71b2 to
8bd9d71
Compare
This removes the whole ConnectTrace object, which may make it slightly harder to remove the unbounded-memory-during-reorg bug by throwing blocks out of memory and re-loading them from disk later. Comments are added to validationinterface to note where this should likely happen instead of ConnectTrace.
This makes the processBlock function in CBlockPolicyEstimator much more simlar to MempoolInterface's MempoolUpdatedForBlockConnect callback.
There are lots of better things we can do, but this is much better than it was.
8bd9d71 to
6697c02
Compare
This does a few things in a PR, so I'm happy to split it up if people prefer.
a) It clarifies the validationinterface stuff into a mempoolinterface and the validationinterface, splitting the two up into separate systems with the mempool creating events for mempoolinterface and validationinterface functions coming from validation. They are conjoined in the backend to provide ordering guarantees for listeners which are both mempool interfaces and validation interfaces, but are otherwise fully separated. There are a few cleanups that are enabled here, which I went ahead and did.
b) fee estimator becomes a listener to the mempool interface which provides a bit of additional info about transactions being added more than just the tx (eg feerate, etc)
c) a few minor edge cases in the fee estimator are handled (witness malleation changing feerate, and handling reorgs better, specifically).