mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-03 09:23:01 +01:00
Have testBlockValidity hold cs_main instead of caller
The goal of interfaces is to eventually run in their own process, so we can't use EXCLUSIVE_LOCKS_REQUIRED in their declaration. However TestBlockValidaty will crash (in its call to ConnectBlock) if the tip changes from under the proposed block. Have the testBlockValidity implementation hold the lock instead, and non-fatally check for this condition.
This commit is contained in:
@@ -872,8 +872,15 @@ public:
|
||||
|
||||
bool testBlockValidity(const CBlock& block, bool check_merkle_root, BlockValidationState& state) override
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, chainman().ActiveChain().Tip(), /*fCheckPOW=*/false, check_merkle_root);
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* tip{chainman().ActiveChain().Tip()};
|
||||
// Fail if the tip updated before the lock was taken
|
||||
if (block.hashPrevBlock != tip->GetBlockHash()) {
|
||||
state.Error("Block does not connect to current chain tip.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return TestBlockValidity(state, chainman().GetParams(), chainman().ActiveChainstate(), block, tip, /*fCheckPOW=*/false, check_merkle_root);
|
||||
}
|
||||
|
||||
std::unique_ptr<CBlockTemplate> createNewBlock(const CScript& script_pub_key, bool use_mempool) override
|
||||
|
||||
Reference in New Issue
Block a user