diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1188,7 +1188,8 @@ // connected in the active best chain CValidationState state; if (!ActivateBestChain(config, state)) { - LogPrintf("Failed to connect best block"); + LogPrintf("Failed to connect best block (%s)\n", + FormatStateMessage(state)); StartShutdown(); return; } diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1281,8 +1281,11 @@ } } // release cs_main before calling ActivateBestChain if (need_activate_chain) { - CValidationState dummy; - ActivateBestChain(config, dummy, a_recent_block); + CValidationState state; + if (!ActivateBestChain(config, state, a_recent_block)) { + LogPrint(BCLog::NET, "failed to activate chain (%s)\n", + FormatStateMessage(state)); + } } LOCK(cs_main); @@ -2285,8 +2288,11 @@ LOCK(cs_most_recent_block); a_recent_block = most_recent_block; } - CValidationState dummy; - ActivateBestChain(config, dummy, a_recent_block); + CValidationState state; + if (!ActivateBestChain(config, state, a_recent_block)) { + LogPrint(BCLog::NET, "failed to activate chain (%s)\n", + FormatStateMessage(state)); + } } LOCK(cs_main); diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -117,7 +117,8 @@ { CValidationState state; if (!ActivateBestChain(config, state)) { - throw std::runtime_error("ActivateBestChain failed."); + throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", + FormatStateMessage(state))); } } nScriptCheckThreads = 3; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2144,14 +2144,20 @@ void FlushStateToDisk() { CValidationState state; const CChainParams &chainparams = Params(); - FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS); + if (!FlushStateToDisk(chainparams, state, FlushStateMode::ALWAYS)) { + LogPrintf("%s: failed to flush state (%s)\n", __func__, + FormatStateMessage(state)); + } } void PruneAndFlush() { CValidationState state; fCheckForPruning = true; const CChainParams &chainparams = Params(); - FlushStateToDisk(chainparams, state, FlushStateMode::NONE); + if (!FlushStateToDisk(chainparams, state, FlushStateMode::NONE)) { + LogPrintf("%s: failed to flush state (%s)\n", __func__, + FormatStateMessage(state)); + } } /** Check warning conditions and do some notifications on new chain tip set. */ @@ -4088,7 +4094,7 @@ if (!ret) { GetMainSignals().BlockChecked(*pblock, state); return error("%s: AcceptBlock FAILED (%s)", __func__, - state.GetDebugMessage()); + FormatStateMessage(state)); } } @@ -4097,7 +4103,8 @@ // Only used to report errors, not invalidity - ignore it CValidationState state; if (!g_chainstate.ActivateBestChain(config, state, pblock)) { - return error("%s: ActivateBestChain failed", __func__); + return error("%s: ActivateBestChain failed (%s)", __func__, + FormatStateMessage(state)); } return true; @@ -4241,8 +4248,11 @@ void PruneBlockFilesManual(int nManualPruneHeight) { CValidationState state; const CChainParams &chainparams = Params(); - FlushStateToDisk(chainparams, state, FlushStateMode::NONE, - nManualPruneHeight); + if (!FlushStateToDisk(chainparams, state, FlushStateMode::NONE, + nManualPruneHeight)) { + LogPrintf("%s: failed to flush state (%s)\n", __func__, + FormatStateMessage(state)); + } } /** @@ -4516,6 +4526,8 @@ LogPrintf("%s: Connecting genesis block...\n", __func__); CValidationState state; if (!ActivateBestChain(config, state)) { + LogPrintf("%s: failed to activate chain (%s)\n", __func__, + FormatStateMessage(state)); return false; } } @@ -4684,9 +4696,10 @@ } if (!g_chainstate.ConnectBlock(config, block, state, pindex, coins)) { - return error( - "VerifyDB(): *** found unconnectable block at %d, hash=%s", - pindex->nHeight, pindex->GetBlockHash().ToString()); + return error("VerifyDB(): *** found unconnectable block at %d, " + "hash=%s (%s)", + pindex->nHeight, pindex->GetBlockHash().ToString(), + FormatStateMessage(state)); } } } @@ -4849,13 +4862,15 @@ } if (!DisconnectTip(config, state, nullptr)) { - return error( - "RewindBlockIndex: unable to disconnect block at height %i", - pindex->nHeight); + return error("RewindBlockIndex: unable to disconnect block at " + "height %i (%s)", + pindex->nHeight, FormatStateMessage(state)); } // Occasionally flush state to disk. if (!FlushStateToDisk(params, state, FlushStateMode::PERIODIC)) { + LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", + FormatStateMessage(state)); return false; } } @@ -4895,6 +4910,8 @@ CValidationState state; if (!FlushStateToDisk(config.GetChainParams(), state, FlushStateMode::ALWAYS)) { + LogPrintf("RewindBlockIndex: unable to flush state to disk (%s)\n", + FormatStateMessage(state)); return false; } } @@ -4983,7 +5000,8 @@ CBlockIndex *pindex = AddToBlockIndex(block); CValidationState state; if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) { - return error("%s: genesis block not accepted", __func__); + return error("%s: genesis block not accepted (%s)", __func__, + FormatStateMessage(state)); } } catch (const std::runtime_error &e) { return error("%s: failed to write genesis block: %s", __func__,