Skip to content

Commit 0d2eb3d

Browse files
committed
Restrict hold on cs_main.
In BlockFactory::CreateNewBlock, hold on to cs_main only as short as possible, namely while we access the active chain tip. This helps prevent potential deadlocks, and should in general make the code run more fluently.
1 parent 5007d39 commit 0d2eb3d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

divi/src/BlockFactory.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ bool BlockFactory::AppendProofOfStakeToBlock(
8484

8585
CBlockTemplate* BlockFactory::CreateNewBlock(const CScript& scriptPubKeyIn, bool fProofOfStake)
8686
{
87-
LOCK(mainCS_);
8887
// Create new block
8988
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
9089
if (!pblocktemplate.get())
@@ -96,7 +95,10 @@ CBlockTemplate* BlockFactory::CreateNewBlock(const CScript& scriptPubKeyIn, bool
9695
block.nVersion = settings.GetArg("-blockversion", block.nVersion);
9796
}
9897

99-
pblocktemplate->previousBlockIndex = chain_.Tip();
98+
{
99+
LOCK(mainCS_);
100+
pblocktemplate->previousBlockIndex = chain_.Tip();
101+
}
100102
if(!pblocktemplate->previousBlockIndex) return NULL;
101103

102104
// Create coinbase tx

0 commit comments

Comments
 (0)