@@ -637,22 +637,27 @@ Value submitblock(const Array& params, bool fHelp)
637637 throw JSONRPCError (RPC_DESERIALIZATION_ERROR, " Block decode failed" );
638638
639639 uint256 hash = block.GetHash ();
640- BlockMap::iterator mi = mapBlockIndex.find (hash);
641- if (mi != mapBlockIndex.end ()) {
642- CBlockIndex *pindex = mi->second ;
643- if (pindex->IsValid (BLOCK_VALID_SCRIPTS))
644- return " duplicate" ;
645- if (pindex->nStatus & BLOCK_FAILED_MASK)
646- return " duplicate-invalid" ;
647- // Otherwise, we might only have the header - process the block before returning
640+ bool fBlockPresent = false ;
641+ {
642+ LOCK (cs_main);
643+ BlockMap::iterator mi = mapBlockIndex.find (hash);
644+ if (mi != mapBlockIndex.end ()) {
645+ CBlockIndex *pindex = mi->second ;
646+ if (pindex->IsValid (BLOCK_VALID_SCRIPTS))
647+ return " duplicate" ;
648+ if (pindex->nStatus & BLOCK_FAILED_MASK)
649+ return " duplicate-invalid" ;
650+ // Otherwise, we might only have the header - process the block before returning
651+ fBlockPresent = true ;
652+ }
648653 }
649654
650655 CValidationState state;
651656 submitblock_StateCatcher sc (block.GetHash ());
652657 RegisterValidationInterface (&sc);
653658 bool fAccepted = ProcessNewBlock (state, NULL , &block);
654659 UnregisterValidationInterface (&sc);
655- if (mi != mapBlockIndex. end () )
660+ if (fBlockPresent )
656661 {
657662 if (fAccepted && !sc.found )
658663 return " duplicate-inconclusive" ;
0 commit comments