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