Use a uint256 for bnChainWork

Every block index entry currently requires a separately-allocated
CBigNum. By replacing them with uint256, it's just 32 bytes extra
in CBlockIndex itself.

This should save us a few megabytes in RAM, and less allocation
overhead.
This commit is contained in:
Pieter Wuille
2013-03-28 23:51:50 +01:00
committed by Pieter Wuille
parent 2aa462ec30
commit 1657c4bc49
5 changed files with 48 additions and 36 deletions

View File

@@ -77,8 +77,8 @@ extern std::set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid;
extern uint256 hashGenesisBlock;
extern CBlockIndex* pindexGenesisBlock;
extern int nBestHeight;
extern CBigNum bnBestChainWork;
extern CBigNum bnBestInvalidWork;
extern uint256 nBestChainWork;
extern uint256 nBestInvalidWork;
extern uint256 hashBestChain;
extern CBlockIndex* pindexBest;
extern unsigned int nTransactionsUpdated;
@@ -1619,7 +1619,7 @@ public:
unsigned int nUndoPos;
// (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block
CBigNum bnChainWork;
uint256 nChainWork;
// Number of transactions in this block.
// Note: in a potential headers-first mode, this number cannot be relied upon
@@ -1648,7 +1648,7 @@ public:
nFile = 0;
nDataPos = 0;
nUndoPos = 0;
bnChainWork = 0;
nChainWork = 0;
nTx = 0;
nChainTx = 0;
nStatus = 0;
@@ -1669,7 +1669,7 @@ public:
nFile = 0;
nDataPos = 0;
nUndoPos = 0;
bnChainWork = 0;
nChainWork = 0;
nTx = 0;
nChainTx = 0;
nStatus = 0;
@@ -1793,8 +1793,8 @@ public:
struct CBlockIndexWorkComparator
{
bool operator()(CBlockIndex *pa, CBlockIndex *pb) {
if (pa->bnChainWork > pb->bnChainWork) return false;
if (pa->bnChainWork < pb->bnChainWork) return true;
if (pa->nChainWork > pb->nChainWork) return false;
if (pa->nChainWork < pb->nChainWork) return true;
if (pa->GetBlockHash() < pb->GetBlockHash()) return false;
if (pa->GetBlockHash() > pb->GetBlockHash()) return true;