Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 715 Lines • ▼ Show 20 Lines | static UniValue submitblock(const Config &config, | ||||
} | } | ||||
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) { | if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | ||||
"Block does not start with a coinbase"); | "Block does not start with a coinbase"); | ||||
} | } | ||||
uint256 hash = block.GetHash(); | uint256 hash = block.GetHash(); | ||||
bool fBlockPresent = false; | |||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CBlockIndex *pindex = LookupBlockIndex(hash); | const CBlockIndex *pindex = LookupBlockIndex(hash); | ||||
if (pindex) { | if (pindex) { | ||||
if (pindex->IsValid(BlockValidity::SCRIPTS)) { | if (pindex->IsValid(BlockValidity::SCRIPTS)) { | ||||
return "duplicate"; | return "duplicate"; | ||||
} | } | ||||
if (pindex->nStatus.isInvalid()) { | if (pindex->nStatus.isInvalid()) { | ||||
return "duplicate-invalid"; | return "duplicate-invalid"; | ||||
} | } | ||||
// Otherwise, we might only have the header - process the block | |||||
// before returning | |||||
fBlockPresent = true; | |||||
} | } | ||||
} | } | ||||
bool new_block; | |||||
submitblock_StateCatcher sc(block.GetHash()); | submitblock_StateCatcher sc(block.GetHash()); | ||||
RegisterValidationInterface(&sc); | RegisterValidationInterface(&sc); | ||||
bool fAccepted = ProcessNewBlock(config, blockptr, true, nullptr); | bool accepted = | ||||
ProcessNewBlock(config, blockptr, /* fForceProcessing */ true, | |||||
/* fNewBlock */ &new_block); | |||||
UnregisterValidationInterface(&sc); | UnregisterValidationInterface(&sc); | ||||
if (fBlockPresent) { | if (!new_block) { | ||||
if (fAccepted && !sc.found) { | if (!accepted) { | ||||
return "duplicate-inconclusive"; | // TODO Maybe pass down fNewBlock to AcceptBlockHeader, so it is | ||||
// properly set to true in this case? | |||||
return "invalid"; | |||||
} | } | ||||
return "duplicate"; | return "duplicate"; | ||||
} | } | ||||
if (!sc.found) { | if (!sc.found) { | ||||
return "inconclusive"; | return "inconclusive"; | ||||
} | } | ||||
Show All 39 Lines |