-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add ChainstateManager::ProcessTransaction
#23173
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.
Concept ACK
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, looks like a good change. Will review soon. |
87a286d
to
58538ff
Compare
Resolved @MarcoFalke's review comment and added a missing lock annotation. |
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
Concept ACK |
58538ff
to
6b2c8c8
Compare
Fixed up an error string and rebased on master to (hopefully) pick up fixes for unrelated CI failures. The fuzz test will still fail, so I'll try to fix that next. |
6b2c8c8
to
1d20d43
Compare
I've reverted the change that made |
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-through. I like that this re-delegates the responsibility of calling mempool.check()
from net_processing to chainstate manager, and see it as the main purpose of this refactoring.
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.
Light code review ACK 1d20d43.
1d20d43
to
3bb34f0
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.
code review ACK 3bb34f0
A few small suggestions if you retouch. The comment touchups sprinkled throughout the commits make the diffs a little noisy.
AcceptToMemoryPool() is called for transactions with fees above minRelayTxFee and with the mempool not full, so setting bypass_limits to true or false has no impact on the test. The only way that changing bypass_limits from true to false could change the result would be to change the outcome to INVALID(TX_MEMPOOL_POLICY). Since all the ATMP calls in this test result in VALID both before and after this change, there is no change in behavior.
AcceptToMemoryPool() is called for an invalid coinbase transaction, so setting bypass_limits to true or false has no impact on the test. The only way that changing bypass_limits from true to false could change the result would be to change the outcome to INVALID(TX_MEMPOOL_POLICY). Since the ATMP call in this test results in INVALID(TX_CONSENSUS) both before and after this change, there is no change in behavior.
"This logic is not necessary for memory pool transactions, as AcceptToMemoryPool already refuses previously-known transaction ids entirely." refers to the logic at https://github.com/bitcoin/bitcoin/blob/a206b0ea12eb4606b93323268fc81a4f1f952531/src/main.cpp#L484-L486, which was later removed in commit 450cbb0.
…rror string User-facing error messages should not leak internal implementation details like function names. Update the MEMPOOL_REJECTED error string from "Transaction rejected by AcceptToMemoryPool" to the more generic "Transaction rejected by mempool". Also update the MEMPOOL_ERROR error message from "AcceptToMemoryPool failed" to the more precise "Mempool internal error" since this error indicates and internal (e.g. logic/hardware/etc) failure, and not a transaction rejection.
This just calls through to AcceptToMemoryPool() internally, and is currently unused. Also add a new transaction validation failure reason TX_NO_MEMPOOL to indicate that there is no mempool.
…action CTxMemPool::check() will carry out internal consistency checks 1/n times, where n is set by the `-checkmempool` configuration option. By default, mempool consistency checks are disabled entirely on mainnet. Therefore, this change has no effect on mainnet nodes running with default configuration. It simply removes the responsibility to trigger mempool consistency checks from net_processing.
f87e07c
to
0fdb619
Compare
Thanks for the thorough review @ryanofsky! I believe I've addressed all of your review comments. |
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.
2c64270 seems to indicate that all AcceptToMemoryPool() calls from outside validation.cpp/h are removed, but it appears there are still two references left. Is this intentional?
Yes, see the
Those two remaining calls to ATMP are the tests that are referenced in that comment. They can't use the |
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.
tACK 0fdb619 on Ubuntu 20.04
This PR successfully removes calls to AcceptToMemoryPool()
from the net_processing layer and allocates them to the validation layer (in the new ProcessTransaction
method and in ActivateBestChainStep
).
It also adds a mempool.check()
call after processing a new transaction. It has no effect on the default setting as m_check_ratio
will be 0 and CTxMemPool ::check()
will return immediately.
txvalidation_tests
and txvalidationcache_tests
ran successfully after changing bypass_limits
from true
to 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.
Code-review ACK 0fdb619
Nice improvement! Happy to see a more consistent higher-level interface for adding transactions to the mempool via ChainstateManager
, with an automatic CTxMemPool::check()
included (which has no effect on mainnet by default, i.e. possible performance losses don't affect users).
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 0fdb619. Only changes since last review: splitting & joining commits, adding more explanations to commit messages, tweaking MEMPOOL_ERROR string, fixing up argument name comments.
This might be ready for merge. It's also a pretty straightforward review if anyone else wants to take a look.
123f5de Remove calls to global Params() in tx_pool test (lsilva01) 9360778 Remove AcceptToMemoryPoolWithTime (lsilva01) Pull request description: This PR refactors AcceptToMemoryPool. . Remove `AcceptToMemoryPoolWithTime` (after #23173, this function is no longer needed). . Remove the `CChainParams chainparams` parameter from ATMP as they can be inferred from the current chain state. . Update the `tx_pool` test with new function signature. ACKs for top commit: jnewbery: reACK 123f5de glozow: light code review ACK 123f5de theStack: re-ACK 123f5de Tree-SHA512: b672d9f091f5fcb4d163c0a443aa469b2ce6f37201136803201c620c3fa329ffb41abd50c5b528787fd1c47e8e09af5ec20ddaa0a4235352c9c619e5691dddb6
f1f10c0 Remove CTxMemPool params from ATMP (lsilva01) Pull request description: Remove `CTxMemPool` parameter from `AcceptToMemoryPool` function, as suggested in bitcoin/bitcoin#23437 (comment) . This requires that `CChainState` has access to `MockedTxPool` in `tx_pool.cpp` as mentioned bitcoin/bitcoin#23173 (comment). So the `MockedTxPool` is attributed to `CChainState::m_mempool` before calling `AcceptToMemoryPool`. Requires #23437. ACKs for top commit: jnewbery: utACK f1f10c0 MarcoFalke: review ACK f1f10c0 🔙 Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
f1f10c0 Remove CTxMemPool params from ATMP (lsilva01) Pull request description: Remove `CTxMemPool` parameter from `AcceptToMemoryPool` function, as suggested in bitcoin#23437 (comment) . This requires that `CChainState` has access to `MockedTxPool` in `tx_pool.cpp` as mentioned bitcoin#23173 (comment). So the `MockedTxPool` is attributed to `CChainState::m_mempool` before calling `AcceptToMemoryPool`. Requires bitcoin#23437. ACKs for top commit: jnewbery: utACK f1f10c0 MarcoFalke: review ACK f1f10c0 🔙 Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
efbb49e Remove CTxMemPool params from ATMP (lsilva01) Pull request description: Remove `CTxMemPool` parameter from `AcceptToMemoryPool` function, as suggested in bitcoin/bitcoin#23437 (comment) . This requires that `CChainState` has access to `MockedTxPool` in `tx_pool.cpp` as mentioned bitcoin/bitcoin#23173 (comment). So the `MockedTxPool` is attributed to `CChainState::m_mempool` before calling `AcceptToMemoryPool`. Requires #23437. ACKs for top commit: jnewbery: utACK efbb49e MarcoFalke: review ACK efbb49e 🔙 Tree-SHA512: 2a4885f4645014fc1fa98bb1090f13721c1a0796bc0021b9cb43bc8cc13920b6eaf057d1f5ed796e0a110e7813e41fe0196334ce7c80d1231fc057a9a3bdf349
Summary: > [test] Don't set bypass_limits to true in txvalidatiocache_tests.cpp > > AcceptToMemoryPool() is called for transactions with fees above > minRelayTxFee and with the mempool not full, so setting bypass_limits to > true or false has no impact on the test. > > The only way that changing bypass_limits from true to false could change > the result would be to change the outcome to INVALID(TX_MEMPOOL_POLICY). > Since all the ATMP calls in this test result in VALID both before and > after this change, there is no change in behavior. bitcoin/bitcoin@497c9e2 > [test] Don't set bypass_limits to true in txvalidation_tests.cpp > > AcceptToMemoryPool() is called for an invalid coinbase transaction, so > setting bypass_limits to true or false has no impact on the test. > > The only way that changing bypass_limits from true to false could change > the result would be to change the outcome to INVALID(TX_MEMPOOL_POLICY). > Since the ATMP call in this test results in INVALID(TX_CONSENSUS) both > before and after this change, there is no change in behavior. This is a backport of [[bitcoin/bitcoin#23173 | core#23173]] bitcoin/bitcoin@5759fd1 Test Plan: `ninja check` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12232
Summary: > "This logic is not necessary for memory pool transactions, as > AcceptToMemoryPool already refuses previously-known transaction ids > entirely." refers to the logic at > https://github.com/bitcoin/bitcoin/blob/a206b0ea12eb4606b93323268fc81a4f1f952531/src/main.cpp#L484-L486, > which was later removed in commit rABC450cbb0944cd20a06ce806e6679a1f4c83c50db2. This is a backport of [[bitcoin/bitcoin#23173 | core#23173]] bitcoin/bitcoin@4c24142 Test Plan: NA Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12233
…rror string Summary: User-facing error messages should not leak internal implementation details like function names. Update the MEMPOOL_REJECTED error string from "Transaction rejected by AcceptToMemoryPool" to the more generic "Transaction rejected by mempool". Also update the MEMPOOL_ERROR error message from "AcceptToMemoryPool failed" to the more precise "Mempool internal error" since this error indicates and internal (e.g. logic/hardware/etc) failure, and not a transaction rejection. These error messages are not covered by tests because they are overwritten with more precise error messages from the ATMP validation state in `sendrawtransaction`. This is a backport of [[bitcoin/bitcoin#23173 | core#23173]] bitcoin/bitcoin@36167fa Test Plan: `ninja all check check-functional-extended` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12234
…outside validation Summary: Also add a new transaction validation failure reason TX_NO_MEMPOOL to indicate that there is no mempool. This is a backport of [[bitcoin/bitcoin#23173 | core#23173]] bitcoin/bitcoin@92a3aee bitcoin/bitcoin@2c64270 Note: due to D1667, there are calls to AcceptToMemoryPool in `DisconnectedBlockTransactions::updateMempoolForReorg` that cannot access the chain manager. However `updateMempoolForReorg` is only called from within validation.cpp, so it should not be a problem. Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D12235
…action Summary: CTxMemPool::check() will carry out internal consistency checks 1/n times, where n is set by the `-checkmempool` configuration option. By default, mempool consistency checks are disabled entirely on mainnet. Therefore, this change has no effect on mainnet nodes running with default configuration. It simply removes the responsibility to trigger mempool consistency checks from net_processing. This concludes a backport of [[bitcoin/bitcoin#23173 | core#23173]] bitcoin/bitcoin@0fdb619 Depends on D12235 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D12236
Similarly to how #18698 added
ProcessNewBlock()
andProcessNewBlockHeaders()
methods to theChainstateManager
class, this PR adds a newProcessTransaction()
method. Code outside validation no longer callsAcceptToMemoryPool()
directly, but calls through the higher-levelProcessTransaction()
method. Advantages:AcceptToMemoryPool()
can only ever be called for the active chainstate, and that chainstate knows which mempool it's using. We can also remove thebypass_limits
argument, since that can only be used internally in validation.CTxMemPool::check()
is removed from the callers, and run automatically byChainstateManager
every timeProcessTransaction()
is called.