diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2014-11-18 19:09:20 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2014-11-20 00:15:17 +0000 |
commit | 60755dbf762cd36bb01859b5e9b0bd4447f23229 (patch) | |
tree | d58139b55bf8567201ef222ce135754989cb1452 /src/rpcmining.cpp | |
parent | bc6cb4177b143bf1c3d0fad065d3a4de6df97ef9 (diff) |
submitblock: Check for duplicate submissions explicitly
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r-- | src/rpcmining.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 0d49fb34d2..7a2b6c7789 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -618,15 +618,32 @@ Value submitblock(const Array& params, bool fHelp) + HelpExampleRpc("submitblock", "\"mydata\"") ); - CBlock pblock; - if (!DecodeHexBlk(pblock, params[0].get_str())) + CBlock block; + if (!DecodeHexBlk(block, params[0].get_str())) 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; - submitblock_StateCatcher sc(pblock.GetHash()); + submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - bool fAccepted = ProcessNewBlock(state, NULL, &pblock); + bool fAccepted = ProcessNewBlock(state, NULL, &block); UnregisterValidationInterface(&sc); + if (mi != mapBlockIndex.end()) + { + if (fAccepted && !sc.found) + return "duplicate-inconclusive"; + return "duplicate"; + } if (fAccepted) { if (!sc.found) |