|
|
@ -2243,8 +2243,7 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl |
|
|
|
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindexNew))) |
|
|
|
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindexNew))) |
|
|
|
return state.Abort(_("Failed to write block index")); |
|
|
|
return state.Abort(_("Failed to write block index")); |
|
|
|
|
|
|
|
|
|
|
|
// New best?
|
|
|
|
return true; |
|
|
|
return ActivateBestChain(state); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -2520,7 +2519,6 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int nHeight = pindex->nHeight; |
|
|
|
int nHeight = pindex->nHeight; |
|
|
|
uint256 hash = pindex->GetBlockHash(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check that all transactions are finalized
|
|
|
|
// Check that all transactions are finalized
|
|
|
|
BOOST_FOREACH(const CTransaction& tx, block.vtx) |
|
|
|
BOOST_FOREACH(const CTransaction& tx, block.vtx) |
|
|
@ -2593,10 +2591,11 @@ void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd) |
|
|
|
|
|
|
|
|
|
|
|
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp) |
|
|
|
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for duplicate
|
|
|
|
// Check for duplicate
|
|
|
|
uint256 hash = pblock->GetHash(); |
|
|
|
uint256 hash = pblock->GetHash(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
if (mapBlockIndex.count(hash)) |
|
|
|
if (mapBlockIndex.count(hash)) |
|
|
|
return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()), 0, "duplicate"); |
|
|
|
return state.Invalid(error("ProcessBlock() : already have block %d %s", mapBlockIndex[hash]->nHeight, hash.ToString()), 0, "duplicate"); |
|
|
|
if (mapOrphanBlocks.count(hash)) |
|
|
|
if (mapOrphanBlocks.count(hash)) |
|
|
@ -2665,7 +2664,11 @@ bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBl |
|
|
|
mapOrphanBlocksByPrev.erase(hashPrev); |
|
|
|
mapOrphanBlocksByPrev.erase(hashPrev); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LogPrintf("ProcessBlock: ACCEPTED\n"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!ActivateBestChain(state)) |
|
|
|
|
|
|
|
return error("ProcessBlock() : ActivateBestChain failed"); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3101,6 +3104,8 @@ bool InitBlockIndex() { |
|
|
|
CBlockIndex *pindex = AddToBlockIndex(block); |
|
|
|
CBlockIndex *pindex = AddToBlockIndex(block); |
|
|
|
if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) |
|
|
|
if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) |
|
|
|
return error("LoadBlockIndex() : genesis block not accepted"); |
|
|
|
return error("LoadBlockIndex() : genesis block not accepted"); |
|
|
|
|
|
|
|
if (!ActivateBestChain(state)) |
|
|
|
|
|
|
|
return error("LoadBlockIndex() : genesis block cannot be activated"); |
|
|
|
} catch(std::runtime_error &e) { |
|
|
|
} catch(std::runtime_error &e) { |
|
|
|
return error("LoadBlockIndex() : failed to initialize block database: %s", e.what()); |
|
|
|
return error("LoadBlockIndex() : failed to initialize block database: %s", e.what()); |
|
|
|
} |
|
|
|
} |
|
|
@ -3230,7 +3235,6 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) |
|
|
|
|
|
|
|
|
|
|
|
// process block
|
|
|
|
// process block
|
|
|
|
if (nBlockPos >= nStartByte) { |
|
|
|
if (nBlockPos >= nStartByte) { |
|
|
|
LOCK(cs_main); |
|
|
|
|
|
|
|
if (dbp) |
|
|
|
if (dbp) |
|
|
|
dbp->nPos = nBlockPos; |
|
|
|
dbp->nPos = nBlockPos; |
|
|
|
CValidationState state; |
|
|
|
CValidationState state; |
|
|
@ -3919,10 +3923,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) |
|
|
|
CInv inv(MSG_BLOCK, block.GetHash()); |
|
|
|
CInv inv(MSG_BLOCK, block.GetHash()); |
|
|
|
pfrom->AddInventoryKnown(inv); |
|
|
|
pfrom->AddInventoryKnown(inv); |
|
|
|
|
|
|
|
|
|
|
|
LOCK(cs_main); |
|
|
|
{ |
|
|
|
// Remember who we got this block from.
|
|
|
|
LOCK(cs_main); |
|
|
|
mapBlockSource[inv.hash] = pfrom->GetId(); |
|
|
|
// Remember who we got this block from.
|
|
|
|
MarkBlockAsReceived(inv.hash, pfrom->GetId()); |
|
|
|
mapBlockSource[inv.hash] = pfrom->GetId(); |
|
|
|
|
|
|
|
MarkBlockAsReceived(inv.hash, pfrom->GetId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CValidationState state; |
|
|
|
CValidationState state; |
|
|
|
ProcessBlock(state, pfrom, &block); |
|
|
|
ProcessBlock(state, pfrom, &block); |
|
|
|