Skip to content

Commit 60755db

Browse files
committed
submitblock: Check for duplicate submissions explicitly
1 parent bc6cb41 commit 60755db

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/rpcmining.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,15 +618,32 @@ Value submitblock(const Array& params, bool fHelp)
618618
+ HelpExampleRpc("submitblock", "\"mydata\"")
619619
);
620620

621-
CBlock pblock;
622-
if (!DecodeHexBlk(pblock, params[0].get_str()))
621+
CBlock block;
622+
if (!DecodeHexBlk(block, params[0].get_str()))
623623
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
624624

625+
uint256 hash = block.GetHash();
626+
BlockMap::iterator mi = mapBlockIndex.find(hash);
627+
if (mi != mapBlockIndex.end()) {
628+
CBlockIndex *pindex = mi->second;
629+
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
630+
return "duplicate";
631+
if (pindex->nStatus & BLOCK_FAILED_MASK)
632+
return "duplicate-invalid";
633+
// Otherwise, we might only have the header - process the block before returning
634+
}
635+
625636
CValidationState state;
626-
submitblock_StateCatcher sc(pblock.GetHash());
637+
submitblock_StateCatcher sc(block.GetHash());
627638
RegisterValidationInterface(&sc);
628-
bool fAccepted = ProcessNewBlock(state, NULL, &pblock);
639+
bool fAccepted = ProcessNewBlock(state, NULL, &block);
629640
UnregisterValidationInterface(&sc);
641+
if (mi != mapBlockIndex.end())
642+
{
643+
if (fAccepted && !sc.found)
644+
return "duplicate-inconclusive";
645+
return "duplicate";
646+
}
630647
if (fAccepted)
631648
{
632649
if (!sc.found)

0 commit comments

Comments
 (0)