Push cs_mains down in ProcessBlock
This commit is contained in:
parent
202e01941c
commit
18e72167dd
3 changed files with 32 additions and 26 deletions
20
src/main.cpp
20
src/main.cpp
|
@ -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);
|
LOCK(cs_main);
|
||||||
// Remember who we got this block from.
|
// Remember who we got this block from.
|
||||||
mapBlockSource[inv.hash] = pfrom->GetId();
|
mapBlockSource[inv.hash] = pfrom->GetId();
|
||||||
MarkBlockAsReceived(inv.hash, pfrom->GetId());
|
MarkBlockAsReceived(inv.hash, pfrom->GetId());
|
||||||
|
}
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
ProcessBlock(state, pfrom, &block);
|
ProcessBlock(state, pfrom, &block);
|
||||||
|
|
|
@ -484,6 +484,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
|
if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
|
||||||
return error("BitcoinMiner : generated block is stale");
|
return error("BitcoinMiner : generated block is stale");
|
||||||
|
}
|
||||||
|
|
||||||
// Remove key from key pool
|
// Remove key from key pool
|
||||||
reservekey.KeepKey();
|
reservekey.KeepKey();
|
||||||
|
@ -498,7 +499,6 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
if (!ProcessBlock(state, NULL, pblock))
|
if (!ProcessBlock(state, NULL, pblock))
|
||||||
return error("BitcoinMiner : ProcessBlock, block not accepted");
|
return error("BitcoinMiner : ProcessBlock, block not accepted");
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,7 +254,7 @@ static const CRPCCommand vRPCCommands[] =
|
||||||
{ "getblocktemplate", &getblocktemplate, true, false, false },
|
{ "getblocktemplate", &getblocktemplate, true, false, false },
|
||||||
{ "getmininginfo", &getmininginfo, true, false, false },
|
{ "getmininginfo", &getmininginfo, true, false, false },
|
||||||
{ "getnetworkhashps", &getnetworkhashps, true, false, false },
|
{ "getnetworkhashps", &getnetworkhashps, true, false, false },
|
||||||
{ "submitblock", &submitblock, false, false, false },
|
{ "submitblock", &submitblock, false, true, false },
|
||||||
|
|
||||||
/* Raw transactions */
|
/* Raw transactions */
|
||||||
{ "createrawtransaction", &createrawtransaction, false, false, false },
|
{ "createrawtransaction", &createrawtransaction, false, false, false },
|
||||||
|
|
Loading…
Reference in a new issue