-
Notifications
You must be signed in to change notification settings - Fork 37.7k
node: Add reference to mempool in NodeContext #17407
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
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.
Code review ACK ae73b97.
Going further in this direction, what would be the next steps ? Passing a mempool pointer to g_chainstate
?
good question. I have decided against that to not interwind chainstate (consensus) with mempool (policy). Otherwise this should be a member function: |
That means keeping |
Yes, but it will become |
This PR doesn't appear to change that, but it sounds like this is the first step in some larger changes. Perhaps you could link to a branch that illustrates what you're planning to do next. |
Ok, will upload my branches tomorrow |
ae73b97
to
faf3207
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
faf3207
to
fafe3d8
Compare
Ok, added some more documentation about future code design in the first commit |
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.
Light code review ACK fafe3d8 (can review more, just let me know)
@@ -53,6 +54,14 @@ static Mutex cs_blockchange; | |||
static std::condition_variable cond_blockchange; | |||
static CUpdatedBlock latestblock; | |||
|
|||
CTxMemPool& EnsureMemPool() |
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 commit "node: Add reference to mempool in NodeContext" (fa5329a)
This looks good. It would be nice in the future to have similar functions for connman and banman in rpc/net.cpp
to minimize uses of g_rpc_node
, and help that global go away at some point.
(Maybe relevant: One way g_rpc_node
might go away is adding a std::any context
member to JSONRPCRequest
assigned to the node context, and having functions like EnsureMempool
take request
arguments and pull the context from the request.)
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.
Sounds like a nice follow-up pull request
fa2d0d3
to
faf24f1
Compare
Addressed @ryanofsky feedback |
Concept ACK. Can you update the PR description, which makes it sound like this PR changes mempool from being a global that is initialized before |
Updated OP as requested by @jnewbery |
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.
Code review ACK faf24f1. Just a few suggested changes since last review, constant rename, test / scripted diff cleanup.
It'd be nice to see followup beginning to make use of the new EnsureMempool function. Could be done either here or in a separate PR depending on how complicated it is.
Not complicated, but not a scripted-diff either. Maybe it could be combined with #17407 (comment), but that sounded more complicated to me. |
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.
Looks good. Please change 'transaction pool' to mempool in the user facing error message and code comments.
Is there a reason we can't make mempool a unique ptr in NodeContext
?
Yes, the memory is not yet managed in |
Currently it is an alias to the global ::mempool and should be used as follows. * Node code (validation and transaction relay) can use either ::mempool or node.mempool, whichever seems a better fit. * RPC code should use the added convenience getter EnsureMempool, which makes sure the mempool exists before use. This prepares the RPC code to a future where the mempool might be disabled at runtime or compile time. * Test code should use m_node.mempool directly, as the mempool is always initialized for tests.
Also, use m_node.mempool instead of the global
-BEGIN VERIFY SCRIPT- # tx pool member access (mempool followed by dot) sed --regexp-extended -i -e 's/(::)?\<mempool\>\.([a-zA-Z])/m_node.mempool->\2/g' $(git grep -l mempool ./src/test) # plain global (mempool not preceeded by dot, but followed by comma) sed --regexp-extended -i -e 's/([^\.])(::)?\<mempool\>,/\1*m_node.mempool,/g' $(git grep -l mempool ./src/test) -END VERIFY SCRIPT-
faf24f1
to
fa53881
Compare
utACK fa53881 Looking forward to mempool being a unique ptr managed by |
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.
Tested ACK fa53881.
@@ -63,6 +63,9 @@ enum RPCErrorCode | |||
RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //!< Invalid IP/Subnet | |||
RPC_CLIENT_P2P_DISABLED = -31, //!< No valid connection manager instance found | |||
|
|||
//! Chain errors |
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: I think this change dissociate further chain from mempool, so may qualify better as a mempool error.
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 think it is fine to keep as is, as mempool and chain are closely related. Also, I'd rather not invalidate ACKs over this.
fa53881 scripted-diff: Replace ::mempool with m_node.mempool in tests (MarcoFalke) 8888ad0 test: Replace recursive lock with locking annotations (MarcoFalke) fac07f2 node: Add reference to mempool in NodeContext (MarcoFalke) Pull request description: This is the first step toward making the mempool a global that is not initialized before main. #### Motivation Currently the mempool is a global that is initialized before the `main` function. This is confusing and easy to get wrong. E.g. the mempool constructor queries state that has not been initialized, like randomness (fixed), or command line arguments (not an issue last time I checked). Also without having the chainstate (chain tip) initialized first, it doesn't make conceptually sense to have a mempool, since the mempool builds txs on top of the utxo set (chain tip). Finally, in the future someone might want to run a consensus-only full node (`-nowallet -noblockfilter -no... -nomempool` command line options) that only verifies blocks and updates the utxo set. This is conceptually the same change that has already been done for the connection manager `CConnman`. ACKs for top commit: jnewbery: utACK fa53881 ariard: Tested ACK fa53881. Tree-SHA512: 2c446a8a51476354aad7126c2b833500d36b24490caa94f847b2bdc622054de0dae28980f23e3d91b1b492dc32931656d98dbd019af9e4e58f2f8c5375aac694
fa53881 scripted-diff: Replace ::mempool with m_node.mempool in tests (MarcoFalke) 8888ad0 test: Replace recursive lock with locking annotations (MarcoFalke) fac07f2 node: Add reference to mempool in NodeContext (MarcoFalke) Pull request description: This is the first step toward making the mempool a global that is not initialized before main. #### Motivation Currently the mempool is a global that is initialized before the `main` function. This is confusing and easy to get wrong. E.g. the mempool constructor queries state that has not been initialized, like randomness (fixed), or command line arguments (not an issue last time I checked). Also without having the chainstate (chain tip) initialized first, it doesn't make conceptually sense to have a mempool, since the mempool builds txs on top of the utxo set (chain tip). Finally, in the future someone might want to run a consensus-only full node (`-nowallet -noblockfilter -no... -nomempool` command line options) that only verifies blocks and updates the utxo set. This is conceptually the same change that has already been done for the connection manager `CConnman`. ACKs for top commit: jnewbery: utACK fa53881 ariard: Tested ACK fa53881. Tree-SHA512: 2c446a8a51476354aad7126c2b833500d36b24490caa94f847b2bdc622054de0dae28980f23e3d91b1b492dc32931656d98dbd019af9e4e58f2f8c5375aac694
Summary: Currently it is an alias to the global ::mempool and should be used as follows. * Node code (validation and transaction relay) can use either ::mempool or node.mempool, whichever seems a better fit. * RPC code should use the added convenience getter EnsureMempool, which makes sure the mempool exists before use. This prepares the RPC code to a future where the mempool might be disabled at runtime or compile time. * Test code should use m_node.mempool directly, as the mempool is always initialized for tests. This is a partial backport of Core [[bitcoin/bitcoin#17407 | PR17407]] : bitcoin/bitcoin@fac07f2 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6437
Summary: Also, use m_node.mempool instead of the global This is a partial backport of Core [[bitcoin/bitcoin#17407 | PR17407]] : bitcoin/bitcoin@8888ad0 Depends on D6437 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6438
fa53881 scripted-diff: Replace ::mempool with m_node.mempool in tests (MarcoFalke) 8888ad0 test: Replace recursive lock with locking annotations (MarcoFalke) fac07f2 node: Add reference to mempool in NodeContext (MarcoFalke) Pull request description: This is the first step toward making the mempool a global that is not initialized before main. #### Motivation Currently the mempool is a global that is initialized before the `main` function. This is confusing and easy to get wrong. E.g. the mempool constructor queries state that has not been initialized, like randomness (fixed), or command line arguments (not an issue last time I checked). Also without having the chainstate (chain tip) initialized first, it doesn't make conceptually sense to have a mempool, since the mempool builds txs on top of the utxo set (chain tip). Finally, in the future someone might want to run a consensus-only full node (`-nowallet -noblockfilter -no... -nomempool` command line options) that only verifies blocks and updates the utxo set. This is conceptually the same change that has already been done for the connection manager `CConnman`. ACKs for top commit: jnewbery: utACK fa53881 ariard: Tested ACK fa53881. Tree-SHA512: 2c446a8a51476354aad7126c2b833500d36b24490caa94f847b2bdc622054de0dae28980f23e3d91b1b492dc32931656d98dbd019af9e4e58f2f8c5375aac694
This is the first step toward making the mempool a global that is not initialized before main.
Motivation
Currently the mempool is a global that is initialized before the
main
function. This is confusing and easy to get wrong. E.g. the mempool constructor queries state that has not been initialized, like randomness (fixed), or command line arguments (not an issue last time I checked). Also without having the chainstate (chain tip) initialized first, it doesn't make conceptually sense to have a mempool, since the mempool builds txs on top of the utxo set (chain tip).Finally, in the future someone might want to run a consensus-only full node (
-nowallet -noblockfilter -no... -nomempool
command line options) that only verifies blocks and updates the utxo set.This is conceptually the same change that has already been done for the connection manager
CConnman
.