@@ -629,22 +629,27 @@ Value submitblock(const Array& params, bool fHelp)
629
629
throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " Block decode failed" );
630
630
631
631
uint256 hash = block.GetHash ();
632
- BlockMap::iterator mi = mapBlockIndex.find (hash);
633
- if (mi != mapBlockIndex.end ()) {
634
- CBlockIndex *pindex = mi->second ;
635
- if (pindex->IsValid (BLOCK_VALID_SCRIPTS))
636
- return " duplicate" ;
637
- if (pindex->nStatus & BLOCK_FAILED_MASK)
638
- return " duplicate-invalid" ;
639
- // Otherwise, we might only have the header - process the block before returning
632
+ bool fBlockPresent = false ;
633
+ {
634
+ LOCK (cs_main);
635
+ BlockMap::iterator mi = mapBlockIndex.find (hash);
636
+ if (mi != mapBlockIndex.end ()) {
637
+ CBlockIndex *pindex = mi->second ;
638
+ if (pindex->IsValid (BLOCK_VALID_SCRIPTS))
639
+ return " duplicate" ;
640
+ if (pindex->nStatus & BLOCK_FAILED_MASK)
641
+ return " duplicate-invalid" ;
642
+ // Otherwise, we might only have the header - process the block before returning
643
+ fBlockPresent = true ;
644
+ }
640
645
}
641
646
642
647
CValidationState state;
643
648
submitblock_StateCatcher sc (block.GetHash ());
644
649
RegisterValidationInterface (&sc);
645
650
bool fAccepted = ProcessNewBlock (state, NULL , &block);
646
651
UnregisterValidationInterface (&sc);
647
- if (mi != mapBlockIndex. end () )
652
+ if (fBlockPresent )
648
653
{
649
654
if (fAccepted && !sc.found )
650
655
return " duplicate-inconclusive" ;
0 commit comments