@@ -1552,6 +1552,24 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uin
15521552 return true ;
15531553}
15541554
1555+ /* * Abort with a message */
1556+ bool AbortNode (const std::string& strMessage, const std::string& userMessage=" " )
1557+ {
1558+ strMiscWarning = strMessage;
1559+ LogPrintf (" *** %s\n " , strMessage);
1560+ uiInterface.ThreadSafeMessageBox (
1561+ userMessage.empty () ? _ (" Error: A fatal internal error occured, see debug.log for details" ) : userMessage,
1562+ " " , CClientUIInterface::MSG_ERROR);
1563+ StartShutdown ();
1564+ return false ;
1565+ }
1566+
1567+ bool AbortNode (CValidationState& state, const std::string& strMessage, const std::string& userMessage=" " )
1568+ {
1569+ AbortNode (strMessage, userMessage);
1570+ return state.Error (strMessage);
1571+ }
1572+
15551573} // anon namespace
15561574
15571575/* *
@@ -1831,7 +1849,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18311849 if (!FindUndoPos (state, pindex->nFile , pos, ::GetSerializeSize (blockundo, SER_DISK, CLIENT_VERSION) + 40 ))
18321850 return error (" ConnectBlock(): FindUndoPos failed" );
18331851 if (!UndoWriteToDisk (blockundo, pos, pindex->pprev ->GetBlockHash ()))
1834- return state. Abort ( " Failed to write undo data" );
1852+ return AbortNode (state, " Failed to write undo data" );
18351853
18361854 // update nUndoPos in block index
18371855 pindex->nUndoPos = pos.nPos ;
@@ -1844,7 +1862,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
18441862
18451863 if (fTxIndex )
18461864 if (!pblocktree->WriteTxIndex (vPos))
1847- return state. Abort ( " Failed to write transaction index" );
1865+ return AbortNode (state, " Failed to write transaction index" );
18481866
18491867 // add this block to the view's block chain
18501868 view.SetBestBlock (pindex->GetBlockHash ());
@@ -1938,7 +1956,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
19381956 setDirtyBlockIndex.erase (it++);
19391957 }
19401958 if (!pblocktree->WriteBatchSync (vFiles, nLastBlockFile, vBlocks)) {
1941- return state. Abort ( " Files to write to block index database" );
1959+ return AbortNode (state, " Files to write to block index database" );
19421960 }
19431961 }
19441962 // Finally remove any pruned files
@@ -1959,7 +1977,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
19591977 return state.Error (" out of disk space" );
19601978 // Flush the chainstate (which may refer to block index entries).
19611979 if (!pcoinsTip->Flush ())
1962- return state. Abort ( " Failed to write to coin database" );
1980+ return AbortNode (state, " Failed to write to coin database" );
19631981 nLastFlush = nNow;
19641982 }
19651983 if ((mode == FLUSH_STATE_ALWAYS || mode == FLUSH_STATE_PERIODIC) && nNow > nLastSetChain + (int64_t )DATABASE_WRITE_INTERVAL * 1000000 ) {
@@ -1968,7 +1986,7 @@ bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode) {
19681986 nLastSetChain = nNow;
19691987 }
19701988 } catch (const std::runtime_error& e) {
1971- return state. Abort ( std::string (" System error while flushing: " ) + e.what ());
1989+ return AbortNode (state, std::string (" System error while flushing: " ) + e.what ());
19721990 }
19731991 return true ;
19741992}
@@ -2032,7 +2050,7 @@ bool static DisconnectTip(CValidationState &state) {
20322050 // Read block from disk.
20332051 CBlock block;
20342052 if (!ReadBlockFromDisk (block, pindexDelete))
2035- return state. Abort ( " Failed to read block" );
2053+ return AbortNode (state, " Failed to read block" );
20362054 // Apply the block atomically to the chain state.
20372055 int64_t nStart = GetTimeMicros ();
20382056 {
@@ -2083,7 +2101,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
20832101 CBlock block;
20842102 if (!pblock) {
20852103 if (!ReadBlockFromDisk (block, pindexNew))
2086- return state. Abort ( " Failed to read block" );
2104+ return AbortNode (state, " Failed to read block" );
20872105 pblock = █
20882106 }
20892107 // Apply the block atomically to the chain state.
@@ -2790,11 +2808,11 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,
27902808 return error (" AcceptBlock(): FindBlockPos failed" );
27912809 if (dbp == NULL )
27922810 if (!WriteBlockToDisk (block, blockPos))
2793- return state. Abort ( " Failed to write block" );
2811+ AbortNode (state, " Failed to write block" );
27942812 if (!ReceivedBlockTransactions (block, state, pindex, blockPos))
27952813 return error (" AcceptBlock(): ReceivedBlockTransactions failed" );
27962814 } catch (const std::runtime_error& e) {
2797- return state. Abort ( std::string (" System error: " ) + e.what ());
2815+ return AbortNode (state, std::string (" System error: " ) + e.what ());
27982816 }
27992817
28002818 if (fCheckForPruning )
@@ -2869,24 +2887,6 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
28692887 return true ;
28702888}
28712889
2872-
2873-
2874-
2875-
2876-
2877-
2878-
2879- bool AbortNode (const std::string &strMessage, const std::string &userMessage) {
2880- strMiscWarning = strMessage;
2881- LogPrintf (" *** %s\n " , strMessage);
2882- uiInterface.ThreadSafeMessageBox (
2883- userMessage.empty () ? _ (" Error: A fatal internal error occured, see debug.log for details" ) : userMessage,
2884- " " , CClientUIInterface::MSG_ERROR);
2885- StartShutdown ();
2886- return false ;
2887- }
2888-
2889-
28902890/* *
28912891 * BLOCK PRUNING CODE
28922892 */
0 commit comments