@@ -618,15 +618,32 @@ Value submitblock(const Array& params, bool fHelp)
618
618
+ HelpExampleRpc (" submitblock" , " \" mydata\" " )
619
619
);
620
620
621
- CBlock pblock ;
622
- if (!DecodeHexBlk (pblock , params[0 ].get_str ()))
621
+ CBlock block ;
622
+ if (!DecodeHexBlk (block , params[0 ].get_str ()))
623
623
throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " Block decode failed" );
624
624
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
+
625
636
CValidationState state;
626
- submitblock_StateCatcher sc (pblock .GetHash ());
637
+ submitblock_StateCatcher sc (block .GetHash ());
627
638
RegisterValidationInterface (&sc);
628
- bool fAccepted = ProcessNewBlock (state, NULL , &pblock );
639
+ bool fAccepted = ProcessNewBlock (state, NULL , &block );
629
640
UnregisterValidationInterface (&sc);
641
+ if (mi != mapBlockIndex.end ())
642
+ {
643
+ if (fAccepted && !sc.found )
644
+ return " duplicate-inconclusive" ;
645
+ return " duplicate" ;
646
+ }
630
647
if (fAccepted )
631
648
{
632
649
if (!sc.found )
0 commit comments