diff --git a/src/addrdb.cpp b/src/addrdb.cpp index 8b1a321097..c41c9c9086 100644 --- a/src/addrdb.cpp +++ b/src/addrdb.cpp @@ -44,7 +44,7 @@ bool SerializeDB(Stream& stream, const Data& data) hashwriter << Params().MessageStart() << data; stream << hashwriter.GetHash(); } catch (const std::exception& e) { - error("%s: Serialize or I/O error - %s", __func__, e.what()); + LogError("%s: Serialize or I/O error - %s\n", __func__, e.what()); return false; } @@ -65,7 +65,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data if (fileout.IsNull()) { fileout.fclose(); remove(pathTmp); - error("%s: Failed to open file %s", __func__, fs::PathToString(pathTmp)); + LogError("%s: Failed to open file %s\n", __func__, fs::PathToString(pathTmp)); return false; } @@ -78,7 +78,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data if (!FileCommit(fileout.Get())) { fileout.fclose(); remove(pathTmp); - error("%s: Failed to flush file %s", __func__, fs::PathToString(pathTmp)); + LogError("%s: Failed to flush file %s\n", __func__, fs::PathToString(pathTmp)); return false; } fileout.fclose(); @@ -86,7 +86,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data // replace existing file, if any, with new file if (!RenameOver(pathTmp, path)) { remove(pathTmp); - error("%s: Rename-into-place failed", __func__); + LogError("%s: Rename-into-place failed\n", __func__); return false; } @@ -144,7 +144,7 @@ bool CBanDB::Write(const banmap_t& banSet) } for (const auto& err : errors) { - error("%s", err); + LogError("%s\n", err); } return false; } diff --git a/src/flatfile.cpp b/src/flatfile.cpp index a040e0a484..2bff663d8b 100644 --- a/src/flatfile.cpp +++ b/src/flatfile.cpp @@ -82,17 +82,17 @@ bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize) { FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos if (!file) { - error("%s: failed to open file %d", __func__, pos.nFile); + LogError("%s: failed to open file %d\n", __func__, pos.nFile); return false; } if (finalize && !TruncateFile(file, pos.nPos)) { fclose(file); - error("%s: failed to truncate file %d", __func__, pos.nFile); + LogError("%s: failed to truncate file %d\n", __func__, pos.nFile); return false; } if (!FileCommit(file)) { fclose(file); - error("%s: failed to commit file %d", __func__, pos.nFile); + LogError("%s: failed to commit file %d\n", __func__, pos.nFile); return false; } DirectoryCommit(m_dir); diff --git a/src/index/base.cpp b/src/index/base.cpp index 907c832752..036292cd8a 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -229,7 +229,7 @@ bool BaseIndex::Commit() } } if (!ok) { - error("%s: Failed to commit latest %s state", __func__, GetName()); + LogError("%s: Failed to commit latest %s state\n", __func__, GetName()); return false; } return true; diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index de6bd833c3..65993e830e 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -119,7 +119,7 @@ bool BlockFilterIndex::CustomInit(const std::optional& blo // indicate database corruption or a disk failure, and starting the index would cause // further corruption. if (m_db->Exists(DB_FILTER_POS)) { - error("%s: Cannot read current %s state; index may be corrupted", + LogError("%s: Cannot read current %s state; index may be corrupted\n", __func__, GetName()); return false; } @@ -138,11 +138,11 @@ bool BlockFilterIndex::CustomCommit(CDBBatch& batch) // Flush current filter file to disk. AutoFile file{m_filter_fileseq->Open(pos)}; if (file.IsNull()) { - error("%s: Failed to open filter file %d", __func__, pos.nFile); + LogError("%s: Failed to open filter file %d\n", __func__, pos.nFile); return false; } if (!FileCommit(file.Get())) { - error("%s: Failed to commit filter file %d", __func__, pos.nFile); + LogError("%s: Failed to commit filter file %d\n", __func__, pos.nFile); return false; } @@ -163,13 +163,13 @@ bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256& try { filein >> block_hash >> encoded_filter; if (Hash(encoded_filter) != hash) { - error("Checksum mismatch in filter decode."); + LogError("Checksum mismatch in filter decode.\n"); return false; } filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true); } catch (const std::exception& e) { - error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what()); + LogError("%s: Failed to deserialize block filter from disk: %s\n", __func__, e.what()); return false; } @@ -242,7 +242,7 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block) uint256 expected_block_hash = *Assert(block.prev_hash); if (read_out.first != expected_block_hash) { - error("%s: previous block header belongs to unexpected block %s; expected %s", + LogError("%s: previous block header belongs to unexpected block %s; expected %s\n", __func__, read_out.first.ToString(), expected_block_hash.ToString()); return false; } @@ -278,14 +278,14 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block) for (int height = start_height; height <= stop_height; ++height) { if (!db_it.GetKey(key) || key.height != height) { - error("%s: unexpected key in %s: expected (%c, %d)", + LogError("%s: unexpected key in %s: expected (%c, %d)\n", __func__, index_name, DB_BLOCK_HEIGHT, height); return false; } std::pair value; if (!db_it.GetValue(value)) { - error("%s: unable to read value in %s at key (%c, %d)", + LogError("%s: unable to read value in %s at key (%c, %d)\n", __func__, index_name, DB_BLOCK_HEIGHT, height); return false; } @@ -340,11 +340,11 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start const CBlockIndex* stop_index, std::vector& results) { if (start_height < 0) { - error("%s: start height (%d) is negative", __func__, start_height); + LogError("%s: start height (%d) is negative\n", __func__, start_height); return false; } if (start_height > stop_index->nHeight) { - error("%s: start height (%d) is greater than stop height (%d)", + LogError("%s: start height (%d) is greater than stop height (%d)\n", __func__, start_height, stop_index->nHeight); return false; } @@ -362,7 +362,7 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start size_t i = static_cast(height - start_height); if (!db_it->GetValue(values[i])) { - error("%s: unable to read value in %s at key (%c, %d)", + LogError("%s: unable to read value in %s at key (%c, %d)\n", __func__, index_name, DB_BLOCK_HEIGHT, height); return false; } @@ -386,7 +386,7 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start } if (!db.Read(DBHashKey(block_hash), results[i])) { - error("%s: unable to read value in %s at key (%c, %s)", + LogError("%s: unable to read value in %s at key (%c, %s)\n", __func__, index_name, DB_BLOCK_HASH, block_hash.ToString()); return false; } diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp index 4c92bb953a..dff8e50a4e 100644 --- a/src/index/coinstatsindex.cpp +++ b/src/index/coinstatsindex.cpp @@ -138,7 +138,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block) read_out.first.ToString(), expected_block_hash.ToString()); if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) { - error("%s: previous block header not found; expected %s", + LogError("%s: previous block header not found; expected %s\n", __func__, expected_block_hash.ToString()); return false; } @@ -246,14 +246,14 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block) for (int height = start_height; height <= stop_height; ++height) { if (!db_it.GetKey(key) || key.height != height) { - error("%s: unexpected key in %s: expected (%c, %d)", + LogError("%s: unexpected key in %s: expected (%c, %d)\n", __func__, index_name, DB_BLOCK_HEIGHT, height); return false; } std::pair value; if (!db_it.GetValue(value)) { - error("%s: unable to read value in %s at key (%c, %d)", + LogError("%s: unable to read value in %s at key (%c, %d)\n", __func__, index_name, DB_BLOCK_HEIGHT, height); return false; } @@ -288,7 +288,7 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const CBlock block; if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *iter_tip)) { - error("%s: Failed to read block %s from disk", + LogError("%s: Failed to read block %s from disk\n", __func__, iter_tip->GetBlockHash().ToString()); return false; } @@ -357,7 +357,7 @@ bool CoinStatsIndex::CustomInit(const std::optional& block // exist. Any other errors indicate database corruption or a disk // failure, and starting the index would cause further corruption. if (m_db->Exists(DB_MUHASH)) { - error("%s: Cannot read current %s state; index may be corrupted", + LogError("%s: Cannot read current %s state; index may be corrupted\n", __func__, GetName()); return false; } @@ -366,7 +366,7 @@ bool CoinStatsIndex::CustomInit(const std::optional& block if (block) { DBVal entry; if (!LookUpOne(*m_db, *block, entry)) { - error("%s: Cannot read current %s state; index may be corrupted", + LogError("%s: Cannot read current %s state; index may be corrupted\n", __func__, GetName()); return false; } @@ -374,7 +374,7 @@ bool CoinStatsIndex::CustomInit(const std::optional& block uint256 out; m_muhash.Finalize(out); if (entry.muhash != out) { - error("%s: Cannot read current %s state; index may be corrupted", + LogError("%s: Cannot read current %s state; index may be corrupted\n", __func__, GetName()); return false; } @@ -429,7 +429,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex read_out.first.ToString(), expected_block_hash.ToString()); if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) { - error("%s: previous block header not found; expected %s", + LogError("%s: previous block header not found; expected %s\n", __func__, expected_block_hash.ToString()); return false; } diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index b95e1362df..80f615ed0e 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -81,23 +81,23 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe AutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)}; if (file.IsNull()) { - error("%s: OpenBlockFile failed", __func__); + LogError("%s: OpenBlockFile failed\n", __func__); return false; } CBlockHeader header; try { file >> header; if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) { - error("%s: fseek(...) failed", __func__); + LogError("%s: fseek(...) failed\n", __func__); return false; } file >> TX_WITH_WITNESS(tx); } catch (const std::exception& e) { - error("%s: Deserialize or I/O error - %s", __func__, e.what()); + LogError("%s: Deserialize or I/O error - %s\n", __func__, e.what()); return false; } if (tx->GetHash() != tx_hash) { - error("%s: txid mismatch", __func__); + LogError("%s: txid mismatch\n", __func__); return false; } block_hash = header.GetHash(); diff --git a/src/kernel/coinstats.cpp b/src/kernel/coinstats.cpp index 1903749674..81c496ab34 100644 --- a/src/kernel/coinstats.cpp +++ b/src/kernel/coinstats.cpp @@ -134,7 +134,7 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c outputs[key.n] = std::move(coin); stats.coins_count++; } else { - error("%s: unable to read value", __func__); + LogError("%s: unable to read value\n", __func__); return false; } pcursor->Next(); diff --git a/src/net.cpp b/src/net.cpp index 7c82f01d75..6701e5cd4e 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -575,7 +575,7 @@ void CNode::SetAddrLocal(const CService& addrLocalIn) { AssertLockNotHeld(m_addr_local_mutex); LOCK(m_addr_local_mutex); if (addrLocal.IsValid()) { - error("Addr local already set for node: %i. Refusing to change from %s to %s", id, addrLocal.ToStringAddrPort(), addrLocalIn.ToStringAddrPort()); + LogError("Addr local already set for node: %i. Refusing to change from %s to %s\n", id, addrLocal.ToStringAddrPort(), addrLocalIn.ToStringAddrPort()); } else { addrLocal = addrLocalIn; } diff --git a/src/netbase.cpp b/src/netbase.cpp index 394278513e..49c334d332 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -338,7 +338,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a IntrRecvError recvr; LogPrint(BCLog::NET, "SOCKS5 connecting %s\n", strDest); if (strDest.size() > 255) { - error("Hostname too long"); + LogError("Hostname too long\n"); return false; } // Construct the version identifier/method selection message @@ -359,7 +359,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a return false; } if (pchRet1[0] != SOCKSVersion::SOCKS5) { - error("Proxy failed to initialize"); + LogError("Proxy failed to initialize\n"); return false; } if (pchRet1[1] == SOCKS5Method::USER_PASS && auth) { @@ -367,7 +367,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a std::vector vAuth; vAuth.push_back(0x01); // Current (and only) version of user/pass subnegotiation if (auth->username.size() > 255 || auth->password.size() > 255) { - error("Proxy username or password too long"); + LogError("Proxy username or password too long\n"); return false; } vAuth.push_back(auth->username.size()); @@ -378,17 +378,17 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a LogPrint(BCLog::PROXY, "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password); uint8_t pchRetA[2]; if (InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) { - error("Error reading proxy authentication response"); + LogError("Error reading proxy authentication response\n"); return false; } if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) { - error("Proxy authentication unsuccessful"); + LogError("Proxy authentication unsuccessful\n"); return false; } } else if (pchRet1[1] == SOCKS5Method::NOAUTH) { // Perform no authentication } else { - error("Proxy requested wrong authentication method %02x", pchRet1[1]); + LogError("Proxy requested wrong authentication method %02x\n", pchRet1[1]); return false; } std::vector vSocks5; @@ -409,12 +409,12 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a * error message. */ return false; } else { - error("Error while reading proxy response"); + LogError("Error while reading proxy response\n"); return false; } } if (pchRet2[0] != SOCKSVersion::SOCKS5) { - error("Proxy failed to accept request"); + LogError("Proxy failed to accept request\n"); return false; } if (pchRet2[1] != SOCKS5Reply::SUCCEEDED) { @@ -423,7 +423,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a return false; } if (pchRet2[2] != 0x00) { // Reserved field must be 0 - error("Error: malformed proxy response"); + LogError("Error: malformed proxy response\n"); return false; } uint8_t pchRet3[256]; @@ -433,7 +433,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a case SOCKS5Atyp::DOMAINNAME: { recvr = InterruptibleRecv(pchRet3, 1, g_socks5_recv_timeout, sock); if (recvr != IntrRecvError::OK) { - error("Error reading from proxy"); + LogError("Error reading from proxy\n"); return false; } int nRecv = pchRet3[0]; @@ -441,22 +441,22 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a break; } default: { - error("Error: malformed proxy response"); + LogError("Error: malformed proxy response\n"); return false; } } if (recvr != IntrRecvError::OK) { - error("Error reading from proxy"); + LogError("Error reading from proxy\n"); return false; } if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) { - error("Error reading from proxy"); + LogError("Error reading from proxy\n"); return false; } LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest); return true; } catch (const std::runtime_error& e) { - error("Error during SOCKS5 proxy handshake: %s", e.what()); + LogError("Error during SOCKS5 proxy handshake: %s\n", e.what()); return false; } } diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index ad1b3acedf..211d557826 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -131,13 +131,13 @@ bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, s pindexNew->nTx = diskindex.nTx; if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) { - error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString()); + LogError("%s: CheckProofOfWork failed: %s\n", __func__, pindexNew->ToString()); return false; } pcursor->Next(); } else { - error("%s: failed to read value", __func__); + LogError("%s: failed to read value\n", __func__); return false; } } else { @@ -434,7 +434,7 @@ bool BlockManager::LoadBlockIndex(const std::optional& snapshot_blockha for (CBlockIndex* pindex : vSortedByHeight) { if (m_interrupt) return false; if (previous_index && pindex->nHeight > previous_index->nHeight + 1) { - error("%s: block index is non-contiguous, index of height %d missing", __func__, previous_index->nHeight + 1); + LogError("%s: block index is non-contiguous, index of height %d missing\n", __func__, previous_index->nHeight + 1); return false; } previous_index = pindex; @@ -674,7 +674,7 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos // Open history file to append AutoFile fileout{OpenUndoFile(pos)}; if (fileout.IsNull()) { - error("%s: OpenUndoFile failed", __func__); + LogError("%s: OpenUndoFile failed\n", __func__); return false; } @@ -685,7 +685,7 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos // Write undo data long fileOutPos = ftell(fileout.Get()); if (fileOutPos < 0) { - error("%s: ftell failed", __func__); + LogError("%s: ftell failed\n", __func__); return false; } pos.nPos = (unsigned int)fileOutPos; @@ -705,14 +705,14 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())}; if (pos.IsNull()) { - error("%s: no undo data available", __func__); + LogError("%s: no undo data available\n", __func__); return false; } // Open history file to read AutoFile filein{OpenUndoFile(pos, true)}; if (filein.IsNull()) { - error("%s: OpenUndoFile failed", __func__); + LogError("%s: OpenUndoFile failed\n", __func__); return false; } @@ -724,13 +724,13 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in verifier >> blockundo; filein >> hashChecksum; } catch (const std::exception& e) { - error("%s: Deserialize or I/O error - %s", __func__, e.what()); + LogError("%s: Deserialize or I/O error - %s\n", __func__, e.what()); return false; } // Verify checksum if (hashChecksum != verifier.GetHash()) { - error("%s: Checksum mismatch", __func__); + LogError("%s: Checksum mismatch\n", __func__); return false; } @@ -974,7 +974,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const // Open history file to append AutoFile fileout{OpenBlockFile(pos)}; if (fileout.IsNull()) { - error("WriteBlockToDisk: OpenBlockFile failed"); + LogError("WriteBlockToDisk: OpenBlockFile failed\n"); return false; } @@ -985,7 +985,7 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const // Write block long fileOutPos = ftell(fileout.Get()); if (fileOutPos < 0) { - error("WriteBlockToDisk: ftell failed"); + LogError("WriteBlockToDisk: ftell failed\n"); return false; } pos.nPos = (unsigned int)fileOutPos; @@ -1004,7 +1004,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid if (block.GetUndoPos().IsNull()) { FlatFilePos _pos; if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) { - error("ConnectBlock(): FindUndoPos failed"); + LogError("ConnectBlock(): FindUndoPos failed\n"); return false; } if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) { @@ -1043,7 +1043,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons // Open history file to read AutoFile filein{OpenBlockFile(pos, true)}; if (filein.IsNull()) { - error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString()); + LogError("ReadBlockFromDisk: OpenBlockFile failed for %s\n", pos.ToString()); return false; } @@ -1051,19 +1051,19 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons try { filein >> TX_WITH_WITNESS(block); } catch (const std::exception& e) { - error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString()); + LogError("%s: Deserialize or I/O error - %s at %s\n", __func__, e.what(), pos.ToString()); return false; } // Check the header if (!CheckProofOfWork(block.GetHash(), block.nBits, GetConsensus())) { - error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); + LogError("ReadBlockFromDisk: Errors in block header at %s\n", pos.ToString()); return false; } // Signet only: check block solution if (GetConsensus().signet_blocks && !CheckSignetBlockSolution(block, GetConsensus())) { - error("ReadBlockFromDisk: Errors in block solution at %s", pos.ToString()); + LogError("ReadBlockFromDisk: Errors in block solution at %s\n", pos.ToString()); return false; } @@ -1078,7 +1078,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co return false; } if (block.GetHash() != index.GetBlockHash()) { - error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s", + LogError("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s\n", index.ToString(), block_pos.ToString()); return false; } @@ -1091,7 +1091,7 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector& block, const FlatF hpos.nPos -= 8; // Seek back 8 bytes for meta header AutoFile filein{OpenBlockFile(hpos, true)}; if (filein.IsNull()) { - error("%s: OpenBlockFile failed for %s", __func__, pos.ToString()); + LogError("%s: OpenBlockFile failed for %s\n", __func__, pos.ToString()); return false; } @@ -1102,14 +1102,14 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector& block, const FlatF filein >> blk_start >> blk_size; if (blk_start != GetParams().MessageStart()) { - error("%s: Block magic mismatch for %s: %s versus expected %s", __func__, pos.ToString(), + LogError("%s: Block magic mismatch for %s: %s versus expected %s\n", __func__, pos.ToString(), HexStr(blk_start), HexStr(GetParams().MessageStart())); return false; } if (blk_size > MAX_SIZE) { - error("%s: Block data is larger than maximum deserialization size for %s: %s versus %s", __func__, pos.ToString(), + LogError("%s: Block data is larger than maximum deserialization size for %s: %s versus %s\n", __func__, pos.ToString(), blk_size, MAX_SIZE); return false; } @@ -1117,7 +1117,7 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector& block, const FlatF block.resize(blk_size); // Zeroing of memory is intentional here filein.read(MakeWritableByteSpan(block)); } catch (const std::exception& e) { - error("%s: Read from block file failed: %s for %s", __func__, e.what(), pos.ToString()); + LogError("%s: Read from block file failed: %s for %s\n", __func__, e.what(), pos.ToString()); return false; } @@ -1138,7 +1138,7 @@ FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, cons nBlockSize += static_cast(BLOCK_SERIALIZATION_HEADER_SIZE); } if (!FindBlockPos(blockPos, nBlockSize, nHeight, block.GetBlockTime(), position_known)) { - error("%s: FindBlockPos failed", __func__); + LogError("%s: FindBlockPos failed\n", __func__); return FlatFilePos(); } if (!position_known) { diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp index 0c30613750..0031f94af1 100644 --- a/src/script/signingprovider.cpp +++ b/src/script/signingprovider.cpp @@ -158,7 +158,7 @@ bool FillableSigningProvider::GetKey(const CKeyID &address, CKey &keyOut) const bool FillableSigningProvider::AddCScript(const CScript& redeemScript) { if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { - error("FillableSigningProvider::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE); + LogError("FillableSigningProvider::AddCScript(): redeemScripts > %i bytes are invalid\n", MAX_SCRIPT_ELEMENT_SIZE); return false; } diff --git a/src/util/fs_helpers.cpp b/src/util/fs_helpers.cpp index 4de8833a3f..f9393c9c13 100644 --- a/src/util/fs_helpers.cpp +++ b/src/util/fs_helpers.cpp @@ -69,7 +69,7 @@ LockResult LockDirectory(const fs::path& directory, const fs::path& lockfile_nam } auto lock = std::make_unique(pathLockFile); if (!lock->TryLock()) { - error("Error while attempting to lock directory %s: %s", fs::PathToString(directory), lock->GetReason()); + LogError("Error while attempting to lock directory %s: %s\n", fs::PathToString(directory), lock->GetReason()); return LockResult::ErrorLock; } if (!probe_only) { diff --git a/src/validation.cpp b/src/validation.cpp index 5a2bf765d0..e3ec208379 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2045,12 +2045,12 @@ DisconnectResult Chainstate::DisconnectBlock(const CBlock& block, const CBlockIn CBlockUndo blockUndo; if (!m_blockman.UndoReadFromDisk(blockUndo, *pindex)) { - error("DisconnectBlock(): failure reading undo data"); + LogError("DisconnectBlock(): failure reading undo data\n"); return DISCONNECT_FAILED; } if (blockUndo.vtxundo.size() + 1 != block.vtx.size()) { - error("DisconnectBlock(): block and undo data inconsistent"); + LogError("DisconnectBlock(): block and undo data inconsistent\n"); return DISCONNECT_FAILED; } @@ -2089,7 +2089,7 @@ DisconnectResult Chainstate::DisconnectBlock(const CBlock& block, const CBlockIn if (i > 0) { // not coinbases CTxUndo &txundo = blockUndo.vtxundo[i-1]; if (txundo.vprevout.size() != tx.vin.size()) { - error("DisconnectBlock(): transaction and undo data inconsistent"); + LogError("DisconnectBlock(): transaction and undo data inconsistent\n"); return DISCONNECT_FAILED; } for (unsigned int j = tx.vin.size(); j > 0;) { @@ -2222,7 +2222,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, // problems. return FatalError(m_chainman.GetNotifications(), state, "Corrupt block found indicating potential hardware failure; shutting down"); } - error("%s: Consensus::CheckBlock: %s", __func__, state.ToString()); + LogError("%s: Consensus::CheckBlock: %s\n", __func__, state.ToString()); return false; } @@ -2409,7 +2409,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, // Any transaction validation failure in ConnectBlock is a block consensus failure state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(), tx_state.GetDebugMessage()); - error("%s: Consensus::CheckTxInputs: %s, %s", __func__, tx.GetHash().ToString(), state.ToString()); + LogError("%s: Consensus::CheckTxInputs: %s, %s\n", __func__, tx.GetHash().ToString(), state.ToString()); return false; } nFees += txfee; @@ -2451,7 +2451,7 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state, // Any transaction validation failure in ConnectBlock is a block consensus failure state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(), tx_state.GetDebugMessage()); - error("ConnectBlock(): CheckInputScripts on %s failed with %s", + LogError("ConnectBlock(): CheckInputScripts on %s failed with %s\n", tx.GetHash().ToString(), state.ToString()); return false; } @@ -2826,7 +2826,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra std::shared_ptr pblock = std::make_shared(); CBlock& block = *pblock; if (!m_blockman.ReadBlockFromDisk(block, *pindexDelete)) { - error("DisconnectTip(): Failed to read block"); + LogError("DisconnectTip(): Failed to read block\n"); return false; } // Apply the block atomically to the chain state. @@ -2835,7 +2835,7 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra CCoinsViewCache view(&CoinsTip()); assert(view.GetBestBlock() == pindexDelete->GetBlockHash()); if (DisconnectBlock(block, pindexDelete, view) != DISCONNECT_OK) { - error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString()); + LogError("DisconnectTip(): DisconnectBlock %s failed\n", pindexDelete->GetBlockHash().ToString()); return false; } bool flushed = view.Flush(); @@ -2966,7 +2966,7 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew, if (!rv) { if (state.IsInvalid()) InvalidBlockFound(pindexNew, state); - error("%s: ConnectBlock %s failed, %s", __func__, pindexNew->GetBlockHash().ToString(), state.ToString()); + LogError("%s: ConnectBlock %s failed, %s\n", __func__, pindexNew->GetBlockHash().ToString(), state.ToString()); return false; } time_3 = SteadyClock::now(); @@ -4250,7 +4250,7 @@ bool ChainstateManager::AcceptBlock(const std::shared_ptr& pblock, pindex->nStatus |= BLOCK_FAILED_VALID; m_blockman.m_dirty_blockindex.insert(pindex); } - error("%s: %s", __func__, state.ToString()); + LogError("%s: %s\n", __func__, state.ToString()); return false; } @@ -4314,7 +4314,7 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr& blo if (m_options.signals) { m_options.signals->BlockChecked(*block, state); } - error("%s: AcceptBlock FAILED (%s)", __func__, state.ToString()); + LogError("%s: AcceptBlock FAILED (%s)\n", __func__, state.ToString()); return false; } } @@ -4323,14 +4323,14 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr& blo BlockValidationState state; // Only used to report errors, not invalidity - ignore it if (!ActiveChainstate().ActivateBestChain(state, block)) { - error("%s: ActivateBestChain failed (%s)", __func__, state.ToString()); + LogError("%s: ActivateBestChain failed (%s)\n", __func__, state.ToString()); return false; } Chainstate* bg_chain{WITH_LOCK(cs_main, return BackgroundSyncInProgress() ? m_ibd_chainstate.get() : nullptr)}; BlockValidationState bg_state; if (bg_chain && !bg_chain->ActivateBestChain(bg_state, block)) { - error("%s: [background] ActivateBestChain failed (%s)", __func__, bg_state.ToString()); + LogError("%s: [background] ActivateBestChain failed (%s)\n", __func__, bg_state.ToString()); return false; } @@ -4370,15 +4370,15 @@ bool TestBlockValidity(BlockValidationState& state, // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, chainstate.m_blockman, chainstate.m_chainman, pindexPrev)) { - error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, state.ToString()); + LogError("%s: Consensus::ContextualCheckBlockHeader: %s\n", __func__, state.ToString()); return false; } if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot)) { - error("%s: Consensus::CheckBlock: %s", __func__, state.ToString()); + LogError("%s: Consensus::CheckBlock: %s\n", __func__, state.ToString()); return false; } if (!ContextualCheckBlock(block, state, chainstate.m_chainman, pindexPrev)) { - error("%s: Consensus::ContextualCheckBlock: %s", __func__, state.ToString()); + LogError("%s: Consensus::ContextualCheckBlock: %s\n", __func__, state.ToString()); return false; } if (!chainstate.ConnectBlock(block, state, &indexDummy, viewNew, true)) { @@ -4584,7 +4584,7 @@ bool Chainstate::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& in // TODO: merge with ConnectBlock CBlock block; if (!m_blockman.ReadBlockFromDisk(block, *pindex)) { - error("ReplayBlock(): ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); + LogError("ReplayBlock(): ReadBlockFromDisk failed at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); return false; } @@ -4610,7 +4610,7 @@ bool Chainstate::ReplayBlocks() std::vector hashHeads = db.GetHeadBlocks(); if (hashHeads.empty()) return true; // We're already in a consistent state. if (hashHeads.size() != 2) { - error("ReplayBlocks(): unknown inconsistent state"); + LogError("ReplayBlocks(): unknown inconsistent state\n"); return false; } @@ -4622,14 +4622,14 @@ bool Chainstate::ReplayBlocks() const CBlockIndex* pindexFork = nullptr; // Latest block common to both the old and the new tip. if (m_blockman.m_block_index.count(hashHeads[0]) == 0) { - error("ReplayBlocks(): reorganization to unknown block requested"); + LogError("ReplayBlocks(): reorganization to unknown block requested\n"); return false; } pindexNew = &(m_blockman.m_block_index[hashHeads[0]]); if (!hashHeads[1].IsNull()) { // The old tip is allowed to be 0, indicating it's the first flush. if (m_blockman.m_block_index.count(hashHeads[1]) == 0) { - error("ReplayBlocks(): reorganization from unknown block requested"); + LogError("ReplayBlocks(): reorganization from unknown block requested\n"); return false; } pindexOld = &(m_blockman.m_block_index[hashHeads[1]]); @@ -4642,13 +4642,13 @@ bool Chainstate::ReplayBlocks() if (pindexOld->nHeight > 0) { // Never disconnect the genesis block. CBlock block; if (!m_blockman.ReadBlockFromDisk(block, *pindexOld)) { - error("RollbackBlock(): ReadBlockFromDisk() failed at %d, hash=%s", pindexOld->nHeight, pindexOld->GetBlockHash().ToString()); + LogError("RollbackBlock(): ReadBlockFromDisk() failed at %d, hash=%s\n", pindexOld->nHeight, pindexOld->GetBlockHash().ToString()); return false; } LogPrintf("Rolling back %s (%i)\n", pindexOld->GetBlockHash().ToString(), pindexOld->nHeight); DisconnectResult res = DisconnectBlock(block, pindexOld, cache); if (res == DISCONNECT_FAILED) { - error("RollbackBlock(): DisconnectBlock failed at %d, hash=%s", pindexOld->nHeight, pindexOld->GetBlockHash().ToString()); + LogError("RollbackBlock(): DisconnectBlock failed at %d, hash=%s\n", pindexOld->nHeight, pindexOld->GetBlockHash().ToString()); return false; } // If DISCONNECT_UNCLEAN is returned, it means a non-existing UTXO was deleted, or an existing UTXO was @@ -4768,13 +4768,13 @@ bool Chainstate::LoadGenesisBlock() const CBlock& block = params.GenesisBlock(); FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, nullptr)}; if (blockPos.IsNull()) { - error("%s: writing genesis block to disk failed", __func__); + LogError("%s: writing genesis block to disk failed\n", __func__); return false; } CBlockIndex* pindex = m_blockman.AddToBlockIndex(block, m_chainman.m_best_header); m_chainman.ReceivedBlockTransactions(block, pindex, blockPos); } catch (const std::runtime_error& e) { - error("%s: failed to write genesis block: %s", __func__, e.what()); + LogError("%s: failed to write genesis block: %s\n", __func__, e.what()); return false; }