@@ -2234,6 +2234,17 @@ bool AbortNode(CValidationState& state, const std::string& strMessage, const std
22342234 return state.Error (strMessage);
22352235}
22362236
2237+ bool VerifyPendingSparkBatch (CValidationState& state, const std::string& reason)
2238+ {
2239+ BatchProofContainer* batchProofContainer = BatchProofContainer::get_instance ();
2240+ if (!batchProofContainer->verify_pending ()) {
2241+ return AbortNode (state,
2242+ strprintf (" Spark batch verification failed before %s" , reason),
2243+ _ (" Spark batch verification failed. Please restart with -reindex -batching=0 to identify the invalid Spark spend." ));
2244+ }
2245+ return true ;
2246+ }
2247+
22372248enum DisconnectResult
22382249{
22392250 DISCONNECT_OK , // All good.
@@ -3084,6 +3095,8 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode, int n
30843095 bool fPeriodicFlush = mode == FLUSH_STATE_PERIODIC && nNow > nLastFlush + (int64_t )DATABASE_FLUSH_INTERVAL * 1000000 ;
30853096 // Combine all conditions that result in a full cache flush.
30863097 bool fDoFullFlush = (mode == FLUSH_STATE_ALWAYS ) || fCacheLarge || fCacheCritical || fPeriodicFlush || fFlushForPrune ;
3098+ if ((fDoFullFlush || fPeriodicWrite ) && !VerifyPendingSparkBatch (state, " flushing block index or chainstate" ))
3099+ return false ;
30873100 // Write blocks and block index to disk.
30883101 if (fDoFullFlush || fPeriodicWrite ) {
30893102 // Depend on nMinDiskSpace to ensure we can write block index
@@ -3798,7 +3811,11 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
37983811 // Do batch verification if we reach 1 day old block,
37993812 BatchProofContainer* batchProofContainer = BatchProofContainer::get_instance ();
38003813 batchProofContainer->fCollectProofs = ((GetSystemTimeInSeconds () - pindexNewTip->GetBlockTime ()) > 86400 ) && GetBoolArg (" -batching" , true );
3801- batchProofContainer->verify ();
3814+ if (!batchProofContainer->verify ()) {
3815+ return AbortNode (state,
3816+ " Spark batch verification failed" ,
3817+ _ (" Spark batch verification failed. Please restart with -reindex -batching=0 to identify the invalid Spark spend." ));
3818+ }
38023819
38033820 // When we reach this point, we switched to a new tip (stored in pindexNewTip).
38043821
0 commit comments