@ -35,8 +35,8 @@ uint256 hashGenesisBlock("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3
static CBigNum bnProofOfWorkLimit ( ~ uint256 ( 0 ) > > 32 ) ;
static CBigNum bnProofOfWorkLimit ( ~ uint256 ( 0 ) > > 32 ) ;
CBlockIndex * pindexGenesisBlock = NULL ;
CBlockIndex * pindexGenesisBlock = NULL ;
int nBestHeight = - 1 ;
int nBestHeight = - 1 ;
CBigNum b nBestChainWork = 0 ;
uint256 nBestChainWork = 0 ;
CBigNum b nBestInvalidWork = 0 ;
uint256 nBestInvalidWork = 0 ;
uint256 hashBestChain = 0 ;
uint256 hashBestChain = 0 ;
CBlockIndex * pindexBest = NULL ;
CBlockIndex * pindexBest = NULL ;
set < CBlockIndex * , CBlockIndexWorkComparator > setBlockIndexValid ; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed
set < CBlockIndex * , CBlockIndexWorkComparator > setBlockIndexValid ; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed
@ -1191,20 +1191,20 @@ bool IsInitialBlockDownload()
void static InvalidChainFound ( CBlockIndex * pindexNew )
void static InvalidChainFound ( CBlockIndex * pindexNew )
{
{
if ( pindexNew - > b nChainWork > b nBestInvalidWork)
if ( pindexNew - > nChainWork > nBestInvalidWork )
{
{
b nBestInvalidWork = pindexNew - > b nChainWork;
nBestInvalidWork = pindexNew - > nChainWork ;
pblocktree - > WriteBestInvalidWork ( bnBestInvalidWork ) ;
pblocktree - > WriteBestInvalidWork ( CBigNum ( nBestInvalidWork ) ) ;
uiInterface . NotifyBlocksChanged ( ) ;
uiInterface . NotifyBlocksChanged ( ) ;
}
}
printf ( " InvalidChainFound: invalid block=%s height=%d work=%s date=%s \n " ,
printf ( " InvalidChainFound: invalid block=%s height=%d log2_work=%.8g date=%s \n " ,
pindexNew - > GetBlockHash ( ) . ToString ( ) . c_str ( ) , pindexNew - > nHeight ,
pindexNew - > GetBlockHash ( ) . ToString ( ) . c_str ( ) , pindexNew - > nHeight ,
pindexNew - > b nChainWork. ToString ( ) . c_str ( ) , DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " ,
log ( pindexNew - > nChainWork . getdouble ( ) ) / log ( 2.0 ) , DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " ,
pindexNew - > GetBlockTime ( ) ) . c_str ( ) ) ;
pindexNew - > GetBlockTime ( ) ) . c_str ( ) ) ;
printf ( " InvalidChainFound: current best=%s height=%d work=%s date=%s \n " ,
printf ( " InvalidChainFound: current best=%s height=%d log2_work=%.8g date=%s \n " ,
hashBestChain . ToString ( ) . c_str ( ) , nBestHeight , bnBestChainWork . ToString ( ) . c_str ( ) ,
hashBestChain . ToString ( ) . c_str ( ) , nBestHeight , log ( nBestChainWork . getdouble ( ) ) / log ( 2.0 ) ,
DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " , pindexBest - > GetBlockTime ( ) ) . c_str ( ) ) ;
DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " , pindexBest - > GetBlockTime ( ) ) . c_str ( ) ) ;
if ( pindexBest & & b nBestInvalidWork > b nBestChainWork + pindexBest - > GetBlockWork ( ) * 6 )
if ( pindexBest & & nBestInvalidWork > nBestChainWork + ( pindexBest - > GetBlockWork ( ) * 6 ) . getuint256 ( ) )
printf ( " InvalidChainFound: Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade. \n " ) ;
printf ( " InvalidChainFound: Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade. \n " ) ;
}
}
@ -1230,7 +1230,7 @@ bool ConnectBestBlock(CValidationState &state) {
pindexNewBest = * it ;
pindexNewBest = * it ;
}
}
if ( pindexNewBest = = pindexBest | | ( pindexBest & & pindexNewBest - > b nChainWork = = pindexBest - > b nChainWork) )
if ( pindexNewBest = = pindexBest | | ( pindexBest & & pindexNewBest - > nChainWork = = pindexBest - > nChainWork ) )
return true ; // nothing to do
return true ; // nothing to do
// check ancestry
// check ancestry
@ -1250,7 +1250,7 @@ bool ConnectBestBlock(CValidationState &state) {
break ;
break ;
}
}
if ( pindexBest = = NULL | | pindexTest - > b nChainWork > pindexBest - > b nChainWork)
if ( pindexBest = = NULL | | pindexTest - > nChainWork > pindexBest - > nChainWork )
vAttach . push_back ( pindexTest ) ;
vAttach . push_back ( pindexTest ) ;
if ( pindexTest - > pprev = = NULL | | pindexTest - > pnext ! = NULL ) {
if ( pindexTest - > pprev = = NULL | | pindexTest - > pnext ! = NULL ) {
@ -1858,11 +1858,11 @@ bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew)
pindexBest = pindexNew ;
pindexBest = pindexNew ;
pblockindexFBBHLast = NULL ;
pblockindexFBBHLast = NULL ;
nBestHeight = pindexBest - > nHeight ;
nBestHeight = pindexBest - > nHeight ;
b nBestChainWork = pindexNew - > b nChainWork;
nBestChainWork = pindexNew - > nChainWork ;
nTimeBestReceived = GetTime ( ) ;
nTimeBestReceived = GetTime ( ) ;
nTransactionsUpdated + + ;
nTransactionsUpdated + + ;
printf ( " SetBestChain: new best=%s height=%d work=%s tx=%lu date=%s progress=%f \n " ,
printf ( " SetBestChain: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f \n " ,
hashBestChain . ToString ( ) . c_str ( ) , nBestHeight , bnBestChainWork . ToString ( ) . c_str ( ) , ( unsigned long ) pindexNew - > nChainTx ,
hashBestChain . ToString ( ) . c_str ( ) , nBestHeight , log ( nBestChainWork . getdouble ( ) ) / log ( 2.0 ) , ( unsigned long ) pindexNew - > nChainTx ,
DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " , pindexBest - > GetBlockTime ( ) ) . c_str ( ) ,
DateTimeStrFormat ( " %Y-%m-%d %H:%M:%S " , pindexBest - > GetBlockTime ( ) ) . c_str ( ) ,
Checkpoints : : GuessVerificationProgress ( pindexBest ) ) ;
Checkpoints : : GuessVerificationProgress ( pindexBest ) ) ;
@ -1915,7 +1915,7 @@ bool CBlock::AddToBlockIndex(CValidationState &state, const CDiskBlockPos &pos)
pindexNew - > nHeight = pindexNew - > pprev - > nHeight + 1 ;
pindexNew - > nHeight = pindexNew - > pprev - > nHeight + 1 ;
}
}
pindexNew - > nTx = vtx . size ( ) ;
pindexNew - > nTx = vtx . size ( ) ;
pindexNew - > b nChainWork = ( pindexNew - > pprev ? pindexNew - > pprev - > b nChainWork : 0 ) + pindexNew - > GetBlockWork ( ) ;
pindexNew - > nChainWork = ( pindexNew - > pprev ? pindexNew - > pprev - > nChainWork : 0 ) + pindexNew - > GetBlockWork ( ) . getuint256 ( ) ;
pindexNew - > nChainTx = ( pindexNew - > pprev ? pindexNew - > pprev - > nChainTx : 0 ) + pindexNew - > nTx ;
pindexNew - > nChainTx = ( pindexNew - > pprev ? pindexNew - > pprev - > nChainTx : 0 ) + pindexNew - > nTx ;
pindexNew - > nFile = pos . nFile ;
pindexNew - > nFile = pos . nFile ;
pindexNew - > nDataPos = pos . nPos ;
pindexNew - > nDataPos = pos . nPos ;
@ -2537,7 +2537,7 @@ bool static LoadBlockIndexDB()
boost : : this_thread : : interruption_point ( ) ;
boost : : this_thread : : interruption_point ( ) ;
// Calculate b nChainWork
// Calculate nChainWork
vector < pair < int , CBlockIndex * > > vSortedByHeight ;
vector < pair < int , CBlockIndex * > > vSortedByHeight ;
vSortedByHeight . reserve ( mapBlockIndex . size ( ) ) ;
vSortedByHeight . reserve ( mapBlockIndex . size ( ) ) ;
BOOST_FOREACH ( const PAIRTYPE ( uint256 , CBlockIndex * ) & item , mapBlockIndex )
BOOST_FOREACH ( const PAIRTYPE ( uint256 , CBlockIndex * ) & item , mapBlockIndex )
@ -2549,7 +2549,7 @@ bool static LoadBlockIndexDB()
BOOST_FOREACH ( const PAIRTYPE ( int , CBlockIndex * ) & item , vSortedByHeight )
BOOST_FOREACH ( const PAIRTYPE ( int , CBlockIndex * ) & item , vSortedByHeight )
{
{
CBlockIndex * pindex = item . second ;
CBlockIndex * pindex = item . second ;
pindex - > b nChainWork = ( pindex - > pprev ? pindex - > pprev - > b nChainWork : 0 ) + pindex - > GetBlockWork ( ) ;
pindex - > nChainWork = ( pindex - > pprev ? pindex - > pprev - > nChainWork : 0 ) + pindex - > GetBlockWork ( ) . getuint256 ( ) ;
pindex - > nChainTx = ( pindex - > pprev ? pindex - > pprev - > nChainTx : 0 ) + pindex - > nTx ;
pindex - > nChainTx = ( pindex - > pprev ? pindex - > pprev - > nChainTx : 0 ) + pindex - > nTx ;
if ( ( pindex - > nStatus & BLOCK_VALID_MASK ) > = BLOCK_VALID_TRANSACTIONS & & ! ( pindex - > nStatus & BLOCK_FAILED_MASK ) )
if ( ( pindex - > nStatus & BLOCK_VALID_MASK ) > = BLOCK_VALID_TRANSACTIONS & & ! ( pindex - > nStatus & BLOCK_FAILED_MASK ) )
setBlockIndexValid . insert ( pindex ) ;
setBlockIndexValid . insert ( pindex ) ;
@ -2561,8 +2561,10 @@ bool static LoadBlockIndexDB()
if ( pblocktree - > ReadBlockFileInfo ( nLastBlockFile , infoLastBlockFile ) )
if ( pblocktree - > ReadBlockFileInfo ( nLastBlockFile , infoLastBlockFile ) )
printf ( " LoadBlockIndexDB(): last block file info: %s \n " , infoLastBlockFile . ToString ( ) . c_str ( ) ) ;
printf ( " LoadBlockIndexDB(): last block file info: %s \n " , infoLastBlockFile . ToString ( ) . c_str ( ) ) ;
// Load bnBestInvalidWork, OK if it doesn't exist
// Load nBestInvalidWork, OK if it doesn't exist
CBigNum bnBestInvalidWork ;
pblocktree - > ReadBestInvalidWork ( bnBestInvalidWork ) ;
pblocktree - > ReadBestInvalidWork ( bnBestInvalidWork ) ;
nBestInvalidWork = bnBestInvalidWork . getuint256 ( ) ;
// Check whether we need to continue reindexing
// Check whether we need to continue reindexing
bool fReindexing = false ;
bool fReindexing = false ;
@ -2579,7 +2581,7 @@ bool static LoadBlockIndexDB()
return true ;
return true ;
hashBestChain = pindexBest - > GetBlockHash ( ) ;
hashBestChain = pindexBest - > GetBlockHash ( ) ;
nBestHeight = pindexBest - > nHeight ;
nBestHeight = pindexBest - > nHeight ;
b nBestChainWork = pindexBest - > b nChainWork;
nBestChainWork = pindexBest - > nChainWork ;
// set 'next' pointers in best chain
// set 'next' pointers in best chain
CBlockIndex * pindex = pindexBest ;
CBlockIndex * pindex = pindexBest ;
@ -2675,8 +2677,8 @@ void UnloadBlockIndex()
setBlockIndexValid . clear ( ) ;
setBlockIndexValid . clear ( ) ;
pindexGenesisBlock = NULL ;
pindexGenesisBlock = NULL ;
nBestHeight = 0 ;
nBestHeight = 0 ;
b nBestChainWork = 0 ;
nBestChainWork = 0 ;
b nBestInvalidWork = 0 ;
nBestInvalidWork = 0 ;
hashBestChain = 0 ;
hashBestChain = 0 ;
pindexBest = NULL ;
pindexBest = NULL ;
}
}
@ -2953,7 +2955,7 @@ string GetWarnings(string strFor)
}
}
// Longer invalid proof-of-work chain
// Longer invalid proof-of-work chain
if ( pindexBest & & b nBestInvalidWork > b nBestChainWork + pindexBest - > GetBlockWork ( ) * 6 )
if ( pindexBest & & nBestInvalidWork > nBestChainWork + ( pindexBest - > GetBlockWork ( ) * 6 ) . getuint256 ( ) )
{
{
nPriority = 2000 ;
nPriority = 2000 ;
strStatusBar = strRPC = _ ( " Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade. " ) ;
strStatusBar = strRPC = _ ( " Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade. " ) ;