@@ -474,6 +474,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
474474
475475bool IsStandardTx (const CTransaction& tx, string& reason)
476476{
477+ AssertLockHeld (cs_main);
477478 if (tx.nVersion > CTransaction::CURRENT_VERSION || tx.nVersion < 1 ) {
478479 reason = " version" ;
479480 return false ;
@@ -556,6 +557,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
556557
557558bool IsFinalTx (const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
558559{
560+ AssertLockHeld (cs_main);
559561 // Time based nLockTime implemented in 0.1.6
560562 if (tx.nLockTime == 0 )
561563 return true ;
@@ -667,6 +669,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, CCoinsViewCache& inputs)
667669
668670int CMerkleTx::SetMerkleBranch (const CBlock* pblock)
669671{
672+ AssertLockHeld (cs_main);
670673 CBlock blockTmp;
671674
672675 if (pblock == NULL ) {
@@ -813,6 +816,7 @@ int64_t GetMinFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree,
813816bool AcceptToMemoryPool (CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree ,
814817 bool * pfMissingInputs, bool fRejectInsaneFee )
815818{
819+ AssertLockHeld (cs_main);
816820 if (pfMissingInputs)
817821 *pfMissingInputs = false ;
818822
@@ -958,6 +962,7 @@ int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const
958962{
959963 if (hashBlock == 0 || nIndex == -1 )
960964 return 0 ;
965+ AssertLockHeld (cs_main);
961966
962967 // Find the block it claims to be in
963968 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find (hashBlock);
@@ -981,6 +986,7 @@ int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const
981986
982987int CMerkleTx::GetDepthInMainChain (CBlockIndex* &pindexRet) const
983988{
989+ AssertLockHeld (cs_main);
984990 int nResult = GetDepthInMainChainINTERNAL (pindexRet);
985991 if (nResult == 0 && !mempool.exists (GetHash ()))
986992 return -1 ; // Not in chain, not in mempool
@@ -1304,6 +1310,7 @@ int GetNumBlocksOfPeers()
13041310
13051311bool IsInitialBlockDownload ()
13061312{
1313+ AssertLockHeld (cs_main);
13071314 if (fImporting || fReindex || chainActive.Height () < Checkpoints::GetTotalBlocksEstimate ())
13081315 return true ;
13091316 static int64_t nLastUpdate;
@@ -1323,6 +1330,7 @@ CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL;
13231330
13241331void CheckForkWarningConditions ()
13251332{
1333+ AssertLockHeld (cs_main);
13261334 // Before we get past initial download, we cannot reliably alert about forks
13271335 // (we assume we don't get stuck on a fork before the last checkpoint)
13281336 if (IsInitialBlockDownload ())
@@ -1368,6 +1376,7 @@ void CheckForkWarningConditions()
13681376
13691377void CheckForkWarningConditionsOnNewFork (CBlockIndex* pindexNewForkTip)
13701378{
1379+ AssertLockHeld (cs_main);
13711380 // If we are on a fork that is sufficiently large, set a warning flag
13721381 CBlockIndex* pfork = pindexNewForkTip;
13731382 CBlockIndex* plonger = chainActive.Tip ();
@@ -2078,6 +2087,7 @@ void static FindMostWorkChain() {
20782087
20792088// Try to activate to the most-work chain (thereby connecting it).
20802089bool ActivateBestChain (CValidationState &state) {
2090+ AssertLockHeld (cs_main);
20812091 CBlockIndex *pindexOldTip = chainActive.Tip ();
20822092 bool fComplete = false ;
20832093 while (!fComplete ) {
@@ -2126,6 +2136,7 @@ bool ActivateBestChain(CValidationState &state) {
21262136
21272137bool AddToBlockIndex (CBlock& block, CValidationState& state, const CDiskBlockPos& pos)
21282138{
2139+ AssertLockHeld (cs_main);
21292140 // Check for duplicate
21302141 uint256 hash = block.GetHash ();
21312142 if (mapBlockIndex.count (hash))
@@ -2344,6 +2355,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
23442355
23452356bool AcceptBlock (CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
23462357{
2358+ AssertLockHeld (cs_main);
23472359 // Check for duplicate
23482360 uint256 hash = block.GetHash ();
23492361 if (mapBlockIndex.count (hash))
@@ -2455,6 +2467,7 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns
24552467
24562468int64_t CBlockIndex::GetMedianTime () const
24572469{
2470+ AssertLockHeld (cs_main);
24582471 const CBlockIndex* pindex = this ;
24592472 for (int i = 0 ; i < nMedianTimeSpan/2 ; i++)
24602473 {
@@ -2467,6 +2480,7 @@ int64_t CBlockIndex::GetMedianTime() const
24672480
24682481void PushGetBlocks (CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd)
24692482{
2483+ AssertLockHeld (cs_main);
24702484 // Filter out duplicate requests
24712485 if (pindexBegin == pnode->pindexLastGetBlocksBegin && hashEnd == pnode->hashLastGetBlocksEnd )
24722486 return ;
@@ -2983,6 +2997,7 @@ bool InitBlockIndex() {
29832997
29842998void PrintBlockTree ()
29852999{
3000+ AssertLockHeld (cs_main);
29863001 // pre-compute tree structure
29873002 map<CBlockIndex*, vector<CBlockIndex*> > mapNext;
29883003 for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin (); mi != mapBlockIndex.end (); ++mi)
0 commit comments