submitblock: Check for duplicate submissions explicitly

This commit is contained in:
Luke Dashjr 2014-11-18 19:09:20 +00:00
parent bc6cb4177b
commit 60755dbf76
1 changed files with 21 additions and 4 deletions

View File

@ -618,15 +618,32 @@ Value submitblock(const Array& params, bool fHelp)
+ HelpExampleRpc("submitblock", "\"mydata\"") + HelpExampleRpc("submitblock", "\"mydata\"")
); );
CBlock pblock; CBlock block;
if (!DecodeHexBlk(pblock, params[0].get_str())) if (!DecodeHexBlk(block, params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
uint256 hash = block.GetHash();
BlockMap::iterator mi = mapBlockIndex.find(hash);
if (mi != mapBlockIndex.end()) {
CBlockIndex *pindex = mi->second;
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
return "duplicate";
if (pindex->nStatus & BLOCK_FAILED_MASK)
return "duplicate-invalid";
// Otherwise, we might only have the header - process the block before returning
}
CValidationState state; CValidationState state;
submitblock_StateCatcher sc(pblock.GetHash()); submitblock_StateCatcher sc(block.GetHash());
RegisterValidationInterface(&sc); RegisterValidationInterface(&sc);
bool fAccepted = ProcessNewBlock(state, NULL, &pblock); bool fAccepted = ProcessNewBlock(state, NULL, &block);
UnregisterValidationInterface(&sc); UnregisterValidationInterface(&sc);
if (mi != mapBlockIndex.end())
{
if (fAccepted && !sc.found)
return "duplicate-inconclusive";
return "duplicate";
}
if (fAccepted) if (fAccepted)
{ {
if (!sc.found) if (!sc.found)