Next step toward #19556
Instead of relying on the mempool global, each chainstate is given a reference to a mempool to keep up to date with the tip (block connections, disconnections, reorgs, ...)
Next step toward #19556
Instead of relying on the mempool global, each chainstate is given a reference to a mempool to keep up to date with the tip (block connections, disconnections, reorgs, ...)
Concept ACK
Will review / test soon.
edit: didn't want to make it an "approve" review...
2874 | @@ -2867,7 +2875,8 @@ bool CChainState::ActivateBestChain(BlockValidationState &state, const CChainPar 2875 | LimitValidationInterfaceQueue(); 2876 | 2877 | { 2878 | - LOCK2(cs_main, ::mempool.cs); // Lock transaction pool for at least as long as it takes for connectTrace to be consumed
We want to ditch LOCK2?
No it can stay, but here LOCK2 doesn't support pointers or interfaces, so if someone wants to pick up #19629 again, LOCK(cs_main) will likely end up to be separate anyway.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, 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
Concept ACK: decoupling is good^Wgreat!
Code review ACK fa0572d0f3b083b4c8e2e883a66e2b198c6779f1.
ACK fa0572d0f3b083b4c8e2e883a66e2b198c6779f1
Reviewed, and tested against #18766 rebased on top of (a rebased version of) #19556. A nice upside of using a reference is that if you intend to do the same for the node context's mempool, it would substantially simplify #18766 :).
369 | @@ -370,9 +370,10 @@ static bool IsCurrentForFeeEstimation() EXCLUSIVE_LOCKS_REQUIRED(cs_main) 370 | * and instead just erase from the mempool as needed. 371 | */ 372 | 373 | -static void UpdateMempoolForReorg(DisconnectedBlockTransactions& disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs) 374 | +static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransactions& disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, mempool.cs)
While touching this line maybe explicitly mention the global namespace for cs_main:
static void UpdateMempoolForReorg(CTxMemPool& mempool, DisconnectedBlockTransactions& disconnectpool, bool fAddToMempool)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, mempool.cs)
?
Thanks. Will add the :: when I have to retouch or on the next commit that touches those lines.
2485 | @@ -2485,8 +2486,11 @@ void static UpdateTip(const CBlockIndex* pindexNew, const CChainParams& chainPar 2486 | * disconnectpool (note that the caller is responsible for mempool consistency 2487 | * in any case). 2488 | */ 2489 | -bool CChainState::DisconnectTip(BlockValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions *disconnectpool) 2490 | +bool CChainState::DisconnectTip(BlockValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions* disconnectpool) 2491 | { 2492 | + AssertLockHeld(cs_main);
nit:
AssertLockHeld(::cs_main);
Thanks. Will add the :: when I have to retouch or on the next commit that touches those lines.
2588 | @@ -2585,6 +2589,9 @@ class ConnectTrace { 2589 | */ 2590 | bool CChainState::ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool) 2591 | { 2592 | + AssertLockHeld(cs_main);
nit:
AssertLockHeld(::cs_main);
Thanks. Will add the :: when I have to retouch or on the next commit that touches those lines.
2874 | @@ -2867,7 +2875,8 @@ bool CChainState::ActivateBestChain(BlockValidationState &state, const CChainPar 2875 | LimitValidationInterfaceQueue(); 2876 | 2877 | { 2878 | - LOCK2(cs_main, ::mempool.cs); // Lock transaction pool for at least as long as it takes for connectTrace to be consumed 2879 | + LOCK(cs_main);
nit:
LOCK(::cs_main);
Thanks. Will add the :: when I have to retouch or on the next commit that touches those lines.
4525 | @@ -4517,7 +4526,8 @@ bool CChainState::RewindBlockIndex(const CChainParams& params) 4526 | // Loop until the tip is below nHeight, or we reach a pruned block. 4527 | while (!ShutdownRequested()) { 4528 | { 4529 | - LOCK2(cs_main, ::mempool.cs); 4530 | + LOCK(cs_main);
nit:
LOCK(::cs_main);
Thanks. Will add the :: when I have to retouch or on the next commit that touches those lines.
644 | @@ -642,7 +645,7 @@ class CChainState { 645 | CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); 646 | 647 | // Apply the effects of a block disconnection on the UTXO set. 648 | - bool DisconnectTip(BlockValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions* disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs); 649 | + bool DisconnectTip(BlockValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions* disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs);
nit:
bool DisconnectTip(BlockValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions* disconnectpool)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_mempool.cs);
Thanks. Will add the :: when I have to retouch or on the next commit that touches those lines.
687 | @@ -685,8 +688,8 @@ class CChainState { 688 | std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); 689 | 690 | private: 691 | - bool ActivateBestChainStep(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs); 692 | - bool ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs); 693 | + bool ActivateBestChainStep(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs); 694 | + bool ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs);
nit:
bool ActivateBestChainStep(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_mempool.cs);
bool ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_mempool.cs);
Thanks. Will add the :: when I have to retouch or on the next commit that touches those lines.
ACK fa0572d0f3b083b4c8e2e883a66e2b198c6779f1, reviewed and tested on Linux Mint 20 (x86_64).
Code review ACK b224f98033992cf6d84c5e8d1d81c4e361b88135