@ -261,7 +261,7 @@ struct CNodeState {
nMisbehavior = 0 ;
nMisbehavior = 0 ;
fShouldBan = false ;
fShouldBan = false ;
pindexBestKnownBlock = NULL ;
pindexBestKnownBlock = NULL ;
hashLastUnknownBlock = uint256 ( 0 ) ;
hashLastUnknownBlock . SetNull ( ) ;
pindexLastCommonBlock = NULL ;
pindexLastCommonBlock = NULL ;
fSyncStarted = false ;
fSyncStarted = false ;
nStallingSince = 0 ;
nStallingSince = 0 ;
@ -349,12 +349,12 @@ void ProcessBlockAvailability(NodeId nodeid) {
CNodeState * state = State ( nodeid ) ;
CNodeState * state = State ( nodeid ) ;
assert ( state ! = NULL ) ;
assert ( state ! = NULL ) ;
if ( state - > hashLastUnknownBlock ! = 0 ) {
if ( ! state - > hashLastUnknownBlock . IsNull ( ) ) {
BlockMap : : iterator itOld = mapBlockIndex . find ( state - > hashLastUnknownBlock ) ;
BlockMap : : iterator itOld = mapBlockIndex . find ( state - > hashLastUnknownBlock ) ;
if ( itOld ! = mapBlockIndex . end ( ) & & itOld - > second - > nChainWork > 0 ) {
if ( itOld ! = mapBlockIndex . end ( ) & & itOld - > second - > nChainWork > 0 ) {
if ( state - > pindexBestKnownBlock = = NULL | | itOld - > second - > nChainWork > = state - > pindexBestKnownBlock - > nChainWork )
if ( state - > pindexBestKnownBlock = = NULL | | itOld - > second - > nChainWork > = state - > pindexBestKnownBlock - > nChainWork )
state - > pindexBestKnownBlock = itOld - > second ;
state - > pindexBestKnownBlock = itOld - > second ;
state - > hashLastUnknownBlock = uint256 ( 0 ) ;
state - > hashLastUnknownBlock . SetNull ( ) ;
}
}
}
}
}
}
@ -1712,7 +1712,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
return false ;
return false ;
// verify that the view's current state corresponds to the previous block
// verify that the view's current state corresponds to the previous block
uint256 hashPrevBlock = pindex - > pprev = = NULL ? uint256 ( 0 ) : pindex - > pprev - > GetBlockHash ( ) ;
uint256 hashPrevBlock = pindex - > pprev = = NULL ? uint256 ( ) : pindex - > pprev - > GetBlockHash ( ) ;
assert ( hashPrevBlock = = view . GetBestBlock ( ) ) ;
assert ( hashPrevBlock = = view . GetBestBlock ( ) ) ;
// Special case for the genesis block, skipping connection of its transactions
// Special case for the genesis block, skipping connection of its transactions
@ -2835,7 +2835,7 @@ boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char
CBlockIndex * InsertBlockIndex ( uint256 hash )
CBlockIndex * InsertBlockIndex ( uint256 hash )
{
{
if ( hash = = 0 )
if ( hash . IsNull ( ) )
return NULL ;
return NULL ;
// Return existing
// Return existing
@ -3369,7 +3369,7 @@ void static ProcessGetData(CNode* pfrom)
vector < CInv > vInv ;
vector < CInv > vInv ;
vInv . push_back ( CInv ( MSG_BLOCK , chainActive . Tip ( ) - > GetBlockHash ( ) ) ) ;
vInv . push_back ( CInv ( MSG_BLOCK , chainActive . Tip ( ) - > GetBlockHash ( ) ) ) ;
pfrom - > PushMessage ( " inv " , vInv ) ;
pfrom - > PushMessage ( " inv " , vInv ) ;
pfrom - > hashContinue = 0 ;
pfrom - > hashContinue . SetNull ( ) ;
}
}
}
}
}
}
@ -3604,7 +3604,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// Use deterministic randomness to send to the same nodes for 24 hours
// Use deterministic randomness to send to the same nodes for 24 hours
// at a time so the setAddrKnowns of the chosen nodes prevent repeats
// at a time so the setAddrKnowns of the chosen nodes prevent repeats
static uint256 hashSalt ;
static uint256 hashSalt ;
if ( hashSalt = = 0 )
if ( hashSalt . IsNull ( ) )
hashSalt = GetRandHash ( ) ;
hashSalt = GetRandHash ( ) ;
uint64_t hashAddr = addr . GetHash ( ) ;
uint64_t hashAddr = addr . GetHash ( ) ;
uint256 hashRand = hashSalt ^ ( hashAddr < < 32 ) ^ ( ( GetTime ( ) + hashAddr ) / ( 24 * 60 * 60 ) ) ;
uint256 hashRand = hashSalt ^ ( hashAddr < < 32 ) ^ ( ( GetTime ( ) + hashAddr ) / ( 24 * 60 * 60 ) ) ;
@ -3738,7 +3738,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
if ( pindex )
if ( pindex )
pindex = chainActive . Next ( pindex ) ;
pindex = chainActive . Next ( pindex ) ;
int nLimit = 500 ;
int nLimit = 500 ;
LogPrint ( " net " , " getblocks %d to %s limit %d from peer=%d \n " , ( pindex ? pindex - > nHeight : - 1 ) , hashStop = = uint256 ( 0 ) ? " end " : hashStop . ToString ( ) , nLimit , pfrom - > id ) ;
LogPrint ( " net " , " getblocks %d to %s limit %d from peer=%d \n " , ( pindex ? pindex - > nHeight : - 1 ) , hashStop . IsNull ( ) ? " end " : hashStop . ToString ( ) , nLimit , pfrom - > id ) ;
for ( ; pindex ; pindex = chainActive . Next ( pindex ) )
for ( ; pindex ; pindex = chainActive . Next ( pindex ) )
{
{
if ( pindex - > GetBlockHash ( ) = = hashStop )
if ( pindex - > GetBlockHash ( ) = = hashStop )
@ -3954,7 +3954,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
// TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue
// from there instead.
// from there instead.
LogPrint ( " net " , " more getheaders (%d) to end to peer=%d (startheight:%d) \n " , pindexLast - > nHeight , pfrom - > id , pfrom - > nStartingHeight ) ;
LogPrint ( " net " , " more getheaders (%d) to end to peer=%d (startheight:%d) \n " , pindexLast - > nHeight , pfrom - > id , pfrom - > nStartingHeight ) ;
pfrom - > PushMessage ( " getheaders " , chainActive . GetLocator ( pindexLast ) , uint256 ( 0 ) ) ;
pfrom - > PushMessage ( " getheaders " , chainActive . GetLocator ( pindexLast ) , uint256 ( ) ) ;
}
}
}
}
@ -4452,7 +4452,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
nSyncStarted + + ;
nSyncStarted + + ;
CBlockIndex * pindexStart = pindexBestHeader - > pprev ? pindexBestHeader - > pprev : pindexBestHeader ;
CBlockIndex * pindexStart = pindexBestHeader - > pprev ? pindexBestHeader - > pprev : pindexBestHeader ;
LogPrint ( " net " , " initial getheaders (%d) to peer=%d (startheight:%d) \n " , pindexStart - > nHeight , pto - > id , pto - > nStartingHeight ) ;
LogPrint ( " net " , " initial getheaders (%d) to peer=%d (startheight:%d) \n " , pindexStart - > nHeight , pto - > id , pto - > nStartingHeight ) ;
pto - > PushMessage ( " getheaders " , chainActive . GetLocator ( pindexStart ) , uint256 ( 0 ) ) ;
pto - > PushMessage ( " getheaders " , chainActive . GetLocator ( pindexStart ) , uint256 ( ) ) ;
}
}
}
}
@ -4483,7 +4483,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
{
{
// 1/4 of tx invs blast to all immediately
// 1/4 of tx invs blast to all immediately
static uint256 hashSalt ;
static uint256 hashSalt ;
if ( hashSalt = = 0 )
if ( hashSalt . IsNull ( ) )
hashSalt = GetRandHash ( ) ;
hashSalt = GetRandHash ( ) ;
uint256 hashRand = inv . hash ^ hashSalt ;
uint256 hashRand = inv . hash ^ hashSalt ;
hashRand = Hash ( BEGIN ( hashRand ) , END ( hashRand ) ) ;
hashRand = Hash ( BEGIN ( hashRand ) , END ( hashRand ) ) ;