Skip to content

Commit caca6aa

Browse files
committed
Make some globals in main non-public.
This means they are declared static, and their extern definition in main.h is removed. Also moved CBlockIndexWorkComparator to the .cpp file.
1 parent 85eb2ce commit caca6aa

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

src/main.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ unsigned int nTransactionsUpdated = 0;
3333

3434
map<uint256, CBlockIndex*> mapBlockIndex;
3535
CChain chainActive;
36-
CBlockIndex *pindexBestInvalid;
37-
set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed
3836
int64 nTimeBestReceived = 0;
3937
int nScriptCheckThreads = 0;
4038
bool fImporting = false;
@@ -65,7 +63,28 @@ const string strMessageMagic = "Bitcoin Signed Message:\n";
6563
// Settings
6664
int64 nTransactionFee = 0;
6765

66+
// Internal stuff
67+
namespace {
68+
struct CBlockIndexWorkComparator
69+
{
70+
bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
71+
if (pa->nChainWork > pb->nChainWork) return false;
72+
if (pa->nChainWork < pb->nChainWork) return true;
73+
74+
if (pa->GetBlockHash() < pb->GetBlockHash()) return false;
75+
if (pa->GetBlockHash() > pb->GetBlockHash()) return true;
76+
77+
return false; // identical blocks
78+
}
79+
};
80+
81+
CBlockIndex *pindexBestInvalid;
82+
set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed
6883

84+
CCriticalSection cs_LastBlockFile;
85+
CBlockFileInfo infoLastBlockFile;
86+
int nLastBlockFile = 0;
87+
}
6988

7089
//////////////////////////////////////////////////////////////////////////////
7190
//
@@ -2694,10 +2713,6 @@ bool CheckDiskSpace(uint64 nAdditionalBytes)
26942713
return true;
26952714
}
26962715

2697-
CCriticalSection cs_LastBlockFile;
2698-
CBlockFileInfo infoLastBlockFile;
2699-
int nLastBlockFile = 0;
2700-
27012716
FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
27022717
{
27032718
if (pos.IsNull())

src/main.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class CAddress;
2626
class CInv;
2727
class CNode;
2828

29-
struct CBlockIndexWorkComparator;
30-
3129
/** The maximum allowed size for a serialized block, in bytes (network rule) */
3230
static const unsigned int MAX_BLOCK_SIZE = 1000000;
3331
/** The maximum size for mined blocks */
@@ -73,7 +71,6 @@ extern CScript COINBASE_FLAGS;
7371

7472
extern CCriticalSection cs_main;
7573
extern std::map<uint256, CBlockIndex*> mapBlockIndex;
76-
extern std::set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid;
7774
extern unsigned int nTransactionsUpdated;
7875
extern uint64 nLastBlockTx;
7976
extern uint64 nLastBlockSize;
@@ -646,10 +643,6 @@ class CBlockFileInfo
646643
}
647644
};
648645

649-
extern CCriticalSection cs_LastBlockFile;
650-
extern CBlockFileInfo infoLastBlockFile;
651-
extern int nLastBlockFile;
652-
653646
enum BlockStatus {
654647
BLOCK_VALID_UNKNOWN = 0,
655648
BLOCK_VALID_HEADER = 1, // parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future
@@ -849,19 +842,6 @@ class CBlockIndex
849842
}
850843
};
851844

852-
struct CBlockIndexWorkComparator
853-
{
854-
bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
855-
if (pa->nChainWork > pb->nChainWork) return false;
856-
if (pa->nChainWork < pb->nChainWork) return true;
857-
858-
if (pa->GetBlockHash() < pb->GetBlockHash()) return false;
859-
if (pa->GetBlockHash() > pb->GetBlockHash()) return true;
860-
861-
return false; // identical blocks
862-
}
863-
};
864-
865845

866846

867847
/** Used to marshal pointers into hashes for db storage. */

0 commit comments

Comments
 (0)