@@ -474,6 +474,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
474
474
475
475
bool IsStandardTx (const CTransaction& tx, string& reason)
476
476
{
477
+ AssertLockHeld (cs_main);
477
478
if (tx.nVersion > CTransaction::CURRENT_VERSION || tx.nVersion < 1 ) {
478
479
reason = " version" ;
479
480
return false ;
@@ -556,6 +557,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason)
556
557
557
558
bool IsFinalTx (const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
558
559
{
560
+ AssertLockHeld (cs_main);
559
561
// Time based nLockTime implemented in 0.1.6
560
562
if (tx.nLockTime == 0 )
561
563
return true ;
@@ -667,6 +669,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, CCoinsViewCache& inputs)
667
669
668
670
int CMerkleTx::SetMerkleBranch (const CBlock* pblock)
669
671
{
672
+ AssertLockHeld (cs_main);
670
673
CBlock blockTmp;
671
674
672
675
if (pblock == NULL ) {
@@ -813,6 +816,7 @@ int64_t GetMinFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree,
813
816
bool AcceptToMemoryPool (CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree ,
814
817
bool * pfMissingInputs, bool fRejectInsaneFee )
815
818
{
819
+ AssertLockHeld (cs_main);
816
820
if (pfMissingInputs)
817
821
*pfMissingInputs = false ;
818
822
@@ -958,6 +962,7 @@ int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const
958
962
{
959
963
if (hashBlock == 0 || nIndex == -1 )
960
964
return 0 ;
965
+ AssertLockHeld (cs_main);
961
966
962
967
// Find the block it claims to be in
963
968
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find (hashBlock);
@@ -981,6 +986,7 @@ int CMerkleTx::GetDepthInMainChainINTERNAL(CBlockIndex* &pindexRet) const
981
986
982
987
int CMerkleTx::GetDepthInMainChain (CBlockIndex* &pindexRet) const
983
988
{
989
+ AssertLockHeld (cs_main);
984
990
int nResult = GetDepthInMainChainINTERNAL (pindexRet);
985
991
if (nResult == 0 && !mempool.exists (GetHash ()))
986
992
return -1 ; // Not in chain, not in mempool
@@ -1304,6 +1310,7 @@ int GetNumBlocksOfPeers()
1304
1310
1305
1311
bool IsInitialBlockDownload ()
1306
1312
{
1313
+ AssertLockHeld (cs_main);
1307
1314
if (fImporting || fReindex || chainActive.Height () < Checkpoints::GetTotalBlocksEstimate ())
1308
1315
return true ;
1309
1316
static int64_t nLastUpdate;
@@ -1323,6 +1330,7 @@ CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL;
1323
1330
1324
1331
void CheckForkWarningConditions ()
1325
1332
{
1333
+ AssertLockHeld (cs_main);
1326
1334
// Before we get past initial download, we cannot reliably alert about forks
1327
1335
// (we assume we don't get stuck on a fork before the last checkpoint)
1328
1336
if (IsInitialBlockDownload ())
@@ -1368,6 +1376,7 @@ void CheckForkWarningConditions()
1368
1376
1369
1377
void CheckForkWarningConditionsOnNewFork (CBlockIndex* pindexNewForkTip)
1370
1378
{
1379
+ AssertLockHeld (cs_main);
1371
1380
// If we are on a fork that is sufficiently large, set a warning flag
1372
1381
CBlockIndex* pfork = pindexNewForkTip;
1373
1382
CBlockIndex* plonger = chainActive.Tip ();
@@ -2078,6 +2087,7 @@ void static FindMostWorkChain() {
2078
2087
2079
2088
// Try to activate to the most-work chain (thereby connecting it).
2080
2089
bool ActivateBestChain (CValidationState &state) {
2090
+ AssertLockHeld (cs_main);
2081
2091
CBlockIndex *pindexOldTip = chainActive.Tip ();
2082
2092
bool fComplete = false ;
2083
2093
while (!fComplete ) {
@@ -2126,6 +2136,7 @@ bool ActivateBestChain(CValidationState &state) {
2126
2136
2127
2137
bool AddToBlockIndex (CBlock& block, CValidationState& state, const CDiskBlockPos& pos)
2128
2138
{
2139
+ AssertLockHeld (cs_main);
2129
2140
// Check for duplicate
2130
2141
uint256 hash = block.GetHash ();
2131
2142
if (mapBlockIndex.count (hash))
@@ -2344,6 +2355,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo
2344
2355
2345
2356
bool AcceptBlock (CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
2346
2357
{
2358
+ AssertLockHeld (cs_main);
2347
2359
// Check for duplicate
2348
2360
uint256 hash = block.GetHash ();
2349
2361
if (mapBlockIndex.count (hash))
@@ -2455,6 +2467,7 @@ bool CBlockIndex::IsSuperMajority(int minVersion, const CBlockIndex* pstart, uns
2455
2467
2456
2468
int64_t CBlockIndex::GetMedianTime () const
2457
2469
{
2470
+ AssertLockHeld (cs_main);
2458
2471
const CBlockIndex* pindex = this ;
2459
2472
for (int i = 0 ; i < nMedianTimeSpan/2 ; i++)
2460
2473
{
@@ -2467,6 +2480,7 @@ int64_t CBlockIndex::GetMedianTime() const
2467
2480
2468
2481
void PushGetBlocks (CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd)
2469
2482
{
2483
+ AssertLockHeld (cs_main);
2470
2484
// Filter out duplicate requests
2471
2485
if (pindexBegin == pnode->pindexLastGetBlocksBegin && hashEnd == pnode->hashLastGetBlocksEnd )
2472
2486
return ;
@@ -2983,6 +2997,7 @@ bool InitBlockIndex() {
2983
2997
2984
2998
void PrintBlockTree ()
2985
2999
{
3000
+ AssertLockHeld (cs_main);
2986
3001
// pre-compute tree structure
2987
3002
map<CBlockIndex*, vector<CBlockIndex*> > mapNext;
2988
3003
for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin (); mi != mapBlockIndex.end (); ++mi)
0 commit comments