aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2024-03-12 09:39:07 +0000
committerfanquake <fanquake@gmail.com>2024-03-12 10:05:06 +0000
commit31be1a47675e4449f856e61beb2b4bfc228ea219 (patch)
treed9ead51b2f7dce87ab4e903730a177b0b274d1ef /src
parente70590988a7b19aca2e3cc2c91d067347b1915ec (diff)
parentfa391513949b7a3b56321436e2015c7e9e6dac2b (diff)
Merge bitcoin/bitcoin#29236: log: Nuke error(...)
fa391513949b7a3b56321436e2015c7e9e6dac2b refactor: Remove unused error() (MarcoFalke) fad0335517096f435d76adce7833e213d3cc23d1 scripted-diff: Replace error() with LogError() (MarcoFalke) fa808fb74972637840675e310f6d4a0f06028d61 refactor: Make error() return type void (MarcoFalke) fa1d62434843866d242bff9f9c55cb838a4f0d83 scripted-diff: return error(...); ==> error(...); return false; (MarcoFalke) fa9a5e80ab86c997102a1c3d4ba017bbe86641d5 refactor: Add missing {} around error() calls (MarcoFalke) Pull request description: `error(...)` has many issues: * It is often used in the context of `return error(...)`, implying that it has a "fancy" type, creating confusion with `util::Result/Error` * `-logsourcelocations` does not work with it, because it will pretend the error happened inside of `logging.h` * The log line contains `ERROR: `, as opposed to `[error]`, like for other errors logged with `LogError`. Fix all issues by removing it. ACKs for top commit: fjahr: re-utACK fa391513949b7a3b56321436e2015c7e9e6dac2b stickies-v: re-ACK fa391513949b7a3b56321436e2015c7e9e6dac2b, no changes since 4a903741b0 ryanofsky: Code review ACK fa391513949b7a3b56321436e2015c7e9e6dac2b. Just rebase since last review Tree-SHA512: ec5bb502ab0d3733fdb14a8a00762638fce0417afd8dd6294ae0d485ce2b7ca5b1efeb50fc2cd7467f6c652e4ed3e99b0f283b08aeca04bbfb7ea4f2c95d283a
Diffstat (limited to 'src')
-rw-r--r--src/addrdb.cpp14
-rw-r--r--src/flatfile.cpp9
-rw-r--r--src/index/base.cpp3
-rw-r--r--src/index/blockfilterindex.cpp38
-rw-r--r--src/index/coinstatsindex.cpp24
-rw-r--r--src/index/txindex.cpp12
-rw-r--r--src/kernel/coinstats.cpp3
-rw-r--r--src/logging.h7
-rw-r--r--src/net.cpp2
-rw-r--r--src/netbase.cpp47
-rw-r--r--src/node/blockstorage.cpp65
-rw-r--r--src/script/signingprovider.cpp6
-rw-r--r--src/util/fs_helpers.cpp2
-rw-r--r--src/validation.cpp83
14 files changed, 205 insertions, 110 deletions
diff --git a/src/addrdb.cpp b/src/addrdb.cpp
index 3f5916560e..f8d4240f3f 100644
--- a/src/addrdb.cpp
+++ b/src/addrdb.cpp
@@ -44,7 +44,8 @@ bool SerializeDB(Stream& stream, const Data& data)
hashwriter << Params().MessageStart() << data;
stream << hashwriter.GetHash();
} catch (const std::exception& e) {
- return 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;
}
return true;
@@ -64,7 +65,8 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
if (fileout.IsNull()) {
fileout.fclose();
remove(pathTmp);
- return 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;
}
// Serialize
@@ -76,14 +78,16 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
if (!FileCommit(fileout.Get())) {
fileout.fclose();
remove(pathTmp);
- return 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();
// replace existing file, if any, with new file
if (!RenameOver(pathTmp, path)) {
remove(pathTmp);
- return error("%s: Rename-into-place failed", __func__);
+ LogError("%s: Rename-into-place failed\n", __func__);
+ return false;
}
return true;
@@ -140,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 59861a08ad..2bff663d8b 100644
--- a/src/flatfile.cpp
+++ b/src/flatfile.cpp
@@ -82,15 +82,18 @@ bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize)
{
FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
if (!file) {
- return 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);
- return 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);
- return 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 2287437f8f..036292cd8a 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -229,7 +229,8 @@ bool BaseIndex::Commit()
}
}
if (!ok) {
- return 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 58f777b326..65993e830e 100644
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -119,8 +119,9 @@ bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& blo
// indicate database corruption or a disk failure, and starting the index would cause
// further corruption.
if (m_db->Exists(DB_FILTER_POS)) {
- return 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;
}
// If the DB_FILTER_POS is not set, then initialize to the first location.
@@ -137,10 +138,12 @@ bool BlockFilterIndex::CustomCommit(CDBBatch& batch)
// Flush current filter file to disk.
AutoFile file{m_filter_fileseq->Open(pos)};
if (file.IsNull()) {
- return 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())) {
- return 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;
}
batch.Write(DB_FILTER_POS, pos);
@@ -159,11 +162,15 @@ bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256&
std::vector<uint8_t> encoded_filter;
try {
filein >> block_hash >> encoded_filter;
- if (Hash(encoded_filter) != hash) return error("Checksum mismatch in filter decode.");
+ if (Hash(encoded_filter) != hash) {
+ 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) {
- return 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;
}
return true;
@@ -235,8 +242,9 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
uint256 expected_block_hash = *Assert(block.prev_hash);
if (read_out.first != expected_block_hash) {
- return 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;
}
prev_header = read_out.second.header;
@@ -270,14 +278,16 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
for (int height = start_height; height <= stop_height; ++height) {
if (!db_it.GetKey(key) || key.height != height) {
- return 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<uint256, DBVal> value;
if (!db_it.GetValue(value)) {
- return 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;
}
batch.Write(DBHashKey(value.first), std::move(value.second));
@@ -330,11 +340,13 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
const CBlockIndex* stop_index, std::vector<DBVal>& results)
{
if (start_height < 0) {
- return 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) {
- return 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;
}
size_t results_size = static_cast<size_t>(stop_index->nHeight - start_height + 1);
@@ -350,8 +362,9 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
size_t i = static_cast<size_t>(height - start_height);
if (!db_it->GetValue(values[i])) {
- return 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;
}
db_it->Next();
@@ -373,8 +386,9 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
}
if (!db.Read(DBHashKey(block_hash), results[i])) {
- return 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 ecd3fd21b5..dff8e50a4e 100644
--- a/src/index/coinstatsindex.cpp
+++ b/src/index/coinstatsindex.cpp
@@ -138,8 +138,9 @@ 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)) {
- return 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;
}
}
@@ -245,14 +246,16 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
for (int height = start_height; height <= stop_height; ++height) {
if (!db_it.GetKey(key) || key.height != height) {
- return 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<uint256, DBVal> value;
if (!db_it.GetValue(value)) {
- return 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;
}
batch.Write(DBHashKey(value.first), std::move(value.second));
@@ -285,8 +288,9 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
CBlock block;
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *iter_tip)) {
- return 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;
}
if (!ReverseBlock(block, iter_tip)) {
@@ -353,23 +357,26 @@ bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockKey>& 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)) {
- return 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;
}
}
if (block) {
DBVal entry;
if (!LookUpOne(*m_db, *block, entry)) {
- return 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;
}
uint256 out;
m_muhash.Finalize(out);
if (entry.muhash != out) {
- return 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;
}
m_transaction_output_count = entry.transaction_output_count;
@@ -422,8 +429,9 @@ 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)) {
- return 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 4983926e68..80f615ed0e 100644
--- a/src/index/txindex.cpp
+++ b/src/index/txindex.cpp
@@ -81,20 +81,24 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
AutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
if (file.IsNull()) {
- return 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)) {
- return error("%s: fseek(...) failed", __func__);
+ LogError("%s: fseek(...) failed\n", __func__);
+ return false;
}
file >> TX_WITH_WITNESS(tx);
} catch (const std::exception& e) {
- return 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) {
- return error("%s: txid mismatch", __func__);
+ LogError("%s: txid mismatch\n", __func__);
+ return false;
}
block_hash = header.GetHash();
return true;
diff --git a/src/kernel/coinstats.cpp b/src/kernel/coinstats.cpp
index ff8a33e804..81c496ab34 100644
--- a/src/kernel/coinstats.cpp
+++ b/src/kernel/coinstats.cpp
@@ -134,7 +134,8 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
outputs[key.n] = std::move(coin);
stats.coins_count++;
} else {
- return error("%s: unable to read value", __func__);
+ LogError("%s: unable to read value\n", __func__);
+ return false;
}
pcursor->Next();
}
diff --git a/src/logging.h b/src/logging.h
index 525e0aec6d..eef70dd20f 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -263,11 +263,4 @@ static inline void LogPrintf_(const std::string& logging_function, const std::st
// Deprecated conditional logging
#define LogPrint(category, ...) LogDebug(category, __VA_ARGS__)
-template <typename... Args>
-bool error(const char* fmt, const Args&... args)
-{
- LogPrintf("ERROR: %s\n", tfm::format(fmt, args...));
- return false;
-}
-
#endif // BITCOIN_LOGGING_H
diff --git a/src/net.cpp b/src/net.cpp
index 2fbfd75261..e8d8f370dd 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -570,7 +570,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 9fbd9f7dea..49c334d332 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -338,7 +338,8 @@ 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) {
- return error("Hostname too long");
+ LogError("Hostname too long\n");
+ return false;
}
// Construct the version identifier/method selection message
std::vector<uint8_t> vSocks5Init;
@@ -358,14 +359,17 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
return false;
}
if (pchRet1[0] != SOCKSVersion::SOCKS5) {
- return error("Proxy failed to initialize");
+ LogError("Proxy failed to initialize\n");
+ return false;
}
if (pchRet1[1] == SOCKS5Method::USER_PASS && auth) {
// Perform username/password authentication (as described in RFC1929)
std::vector<uint8_t> vAuth;
vAuth.push_back(0x01); // Current (and only) version of user/pass subnegotiation
- if (auth->username.size() > 255 || auth->password.size() > 255)
- return error("Proxy username or password too long");
+ if (auth->username.size() > 255 || auth->password.size() > 255) {
+ LogError("Proxy username or password too long\n");
+ return false;
+ }
vAuth.push_back(auth->username.size());
vAuth.insert(vAuth.end(), auth->username.begin(), auth->username.end());
vAuth.push_back(auth->password.size());
@@ -374,15 +378,18 @@ 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) {
- return error("Error reading proxy authentication response");
+ LogError("Error reading proxy authentication response\n");
+ return false;
}
if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) {
- return error("Proxy authentication unsuccessful");
+ LogError("Proxy authentication unsuccessful\n");
+ return false;
}
} else if (pchRet1[1] == SOCKS5Method::NOAUTH) {
// Perform no authentication
} else {
- return error("Proxy requested wrong authentication method %02x", pchRet1[1]);
+ LogError("Proxy requested wrong authentication method %02x\n", pchRet1[1]);
+ return false;
}
std::vector<uint8_t> vSocks5;
vSocks5.push_back(SOCKSVersion::SOCKS5); // VER protocol version
@@ -402,11 +409,13 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
* error message. */
return false;
} else {
- return error("Error while reading proxy response");
+ LogError("Error while reading proxy response\n");
+ return false;
}
}
if (pchRet2[0] != SOCKSVersion::SOCKS5) {
- return error("Proxy failed to accept request");
+ LogError("Proxy failed to accept request\n");
+ return false;
}
if (pchRet2[1] != SOCKS5Reply::SUCCEEDED) {
// Failures to connect to a peer that are not proxy errors
@@ -414,7 +423,8 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
return false;
}
if (pchRet2[2] != 0x00) { // Reserved field must be 0
- return error("Error: malformed proxy response");
+ LogError("Error: malformed proxy response\n");
+ return false;
}
uint8_t pchRet3[256];
switch (pchRet2[3]) {
@@ -423,24 +433,31 @@ 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) {
- return error("Error reading from proxy");
+ LogError("Error reading from proxy\n");
+ return false;
}
int nRecv = pchRet3[0];
recvr = InterruptibleRecv(pchRet3, nRecv, g_socks5_recv_timeout, sock);
break;
}
- default: return error("Error: malformed proxy response");
+ default: {
+ LogError("Error: malformed proxy response\n");
+ return false;
+ }
}
if (recvr != IntrRecvError::OK) {
- return error("Error reading from proxy");
+ LogError("Error reading from proxy\n");
+ return false;
}
if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
- return 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) {
- return 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 c499bbfa6a..211d557826 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -131,12 +131,14 @@ bool BlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, s
pindexNew->nTx = diskindex.nTx;
if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams)) {
- return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
+ LogError("%s: CheckProofOfWork failed: %s\n", __func__, pindexNew->ToString());
+ return false;
}
pcursor->Next();
} else {
- return error("%s: failed to read value", __func__);
+ LogError("%s: failed to read value\n", __func__);
+ return false;
}
} else {
break;
@@ -432,7 +434,8 @@ bool BlockManager::LoadBlockIndex(const std::optional<uint256>& snapshot_blockha
for (CBlockIndex* pindex : vSortedByHeight) {
if (m_interrupt) return false;
if (previous_index && pindex->nHeight > previous_index->nHeight + 1) {
- return 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;
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
@@ -671,7 +674,8 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos
// Open history file to append
AutoFile fileout{OpenUndoFile(pos)};
if (fileout.IsNull()) {
- return error("%s: OpenUndoFile failed", __func__);
+ LogError("%s: OpenUndoFile failed\n", __func__);
+ return false;
}
// Write index header
@@ -681,7 +685,8 @@ bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos
// Write undo data
long fileOutPos = ftell(fileout.Get());
if (fileOutPos < 0) {
- return error("%s: ftell failed", __func__);
+ LogError("%s: ftell failed\n", __func__);
+ return false;
}
pos.nPos = (unsigned int)fileOutPos;
fileout << blockundo;
@@ -700,13 +705,15 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())};
if (pos.IsNull()) {
- return 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()) {
- return error("%s: OpenUndoFile failed", __func__);
+ LogError("%s: OpenUndoFile failed\n", __func__);
+ return false;
}
// Read block
@@ -717,12 +724,14 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
verifier >> blockundo;
filein >> hashChecksum;
} catch (const std::exception& e) {
- return 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()) {
- return error("%s: Checksum mismatch", __func__);
+ LogError("%s: Checksum mismatch\n", __func__);
+ return false;
}
return true;
@@ -965,7 +974,8 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
// Open history file to append
AutoFile fileout{OpenBlockFile(pos)};
if (fileout.IsNull()) {
- return error("WriteBlockToDisk: OpenBlockFile failed");
+ LogError("WriteBlockToDisk: OpenBlockFile failed\n");
+ return false;
}
// Write index header
@@ -975,7 +985,8 @@ bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
// Write block
long fileOutPos = ftell(fileout.Get());
if (fileOutPos < 0) {
- return error("WriteBlockToDisk: ftell failed");
+ LogError("WriteBlockToDisk: ftell failed\n");
+ return false;
}
pos.nPos = (unsigned int)fileOutPos;
fileout << TX_WITH_WITNESS(block);
@@ -993,7 +1004,8 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
if (block.GetUndoPos().IsNull()) {
FlatFilePos _pos;
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo) + 40)) {
- return error("ConnectBlock(): FindUndoPos failed");
+ LogError("ConnectBlock(): FindUndoPos failed\n");
+ return false;
}
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash())) {
return FatalError(m_opts.notifications, state, "Failed to write undo data");
@@ -1031,24 +1043,28 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
// Open history file to read
AutoFile filein{OpenBlockFile(pos, true)};
if (filein.IsNull()) {
- return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
+ LogError("ReadBlockFromDisk: OpenBlockFile failed for %s\n", pos.ToString());
+ return false;
}
// Read block
try {
filein >> TX_WITH_WITNESS(block);
} catch (const std::exception& e) {
- return 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())) {
- return 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())) {
- return error("ReadBlockFromDisk: Errors in block solution at %s", pos.ToString());
+ LogError("ReadBlockFromDisk: Errors in block solution at %s\n", pos.ToString());
+ return false;
}
return true;
@@ -1062,8 +1078,9 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co
return false;
}
if (block.GetHash() != index.GetBlockHash()) {
- return 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;
}
return true;
}
@@ -1074,7 +1091,8 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
hpos.nPos -= 8; // Seek back 8 bytes for meta header
AutoFile filein{OpenBlockFile(hpos, true)};
if (filein.IsNull()) {
- return error("%s: OpenBlockFile failed for %s", __func__, pos.ToString());
+ LogError("%s: OpenBlockFile failed for %s\n", __func__, pos.ToString());
+ return false;
}
try {
@@ -1084,20 +1102,23 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
filein >> blk_start >> blk_size;
if (blk_start != GetParams().MessageStart()) {
- return 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) {
- return 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;
}
block.resize(blk_size); // Zeroing of memory is intentional here
filein.read(MakeWritableByteSpan(block));
} catch (const std::exception& e) {
- return 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;
}
return true;
@@ -1117,7 +1138,7 @@ FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, cons
nBlockSize += static_cast<unsigned int>(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 ff02ab5a12..0031f94af1 100644
--- a/src/script/signingprovider.cpp
+++ b/src/script/signingprovider.cpp
@@ -157,8 +157,10 @@ bool FillableSigningProvider::GetKey(const CKeyID &address, CKey &keyOut) const
bool FillableSigningProvider::AddCScript(const CScript& redeemScript)
{
- if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE)
- return error("FillableSigningProvider::AddCScript(): redeemScripts > %i bytes are invalid", MAX_SCRIPT_ELEMENT_SIZE);
+ if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) {
+ LogError("FillableSigningProvider::AddCScript(): redeemScripts > %i bytes are invalid\n", MAX_SCRIPT_ELEMENT_SIZE);
+ return false;
+ }
LOCK(cs_KeyStore);
mapScripts[CScriptID(redeemScript)] = redeemScript;
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<fsbridge::FileLock>(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 c15e660499..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,8 @@ bool Chainstate::ConnectBlock(const CBlock& block, BlockValidationState& state,
// problems.
return FatalError(m_chainman.GetNotifications(), state, "Corrupt block found indicating potential hardware failure; shutting down");
}
- return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
+ LogError("%s: Consensus::CheckBlock: %s\n", __func__, state.ToString());
+ return false;
}
// verify that the view's current state corresponds to the previous block
@@ -2408,7 +2409,8 @@ 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());
- return 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;
if (!MoneyRange(nFees)) {
@@ -2449,8 +2451,9 @@ 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());
- return error("ConnectBlock(): CheckInputScripts on %s failed with %s",
+ LogError("ConnectBlock(): CheckInputScripts on %s failed with %s\n",
tx.GetHash().ToString(), state.ToString());
+ return false;
}
control.Add(std::move(vChecks));
}
@@ -2823,15 +2826,18 @@ bool Chainstate::DisconnectTip(BlockValidationState& state, DisconnectedBlockTra
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
CBlock& block = *pblock;
if (!m_blockman.ReadBlockFromDisk(block, *pindexDelete)) {
- return error("DisconnectTip(): Failed to read block");
+ LogError("DisconnectTip(): Failed to read block\n");
+ return false;
}
// Apply the block atomically to the chain state.
const auto time_start{SteadyClock::now()};
{
CCoinsViewCache view(&CoinsTip());
assert(view.GetBestBlock() == pindexDelete->GetBlockHash());
- if (DisconnectBlock(block, pindexDelete, view) != DISCONNECT_OK)
- return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
+ if (DisconnectBlock(block, pindexDelete, view) != DISCONNECT_OK) {
+ LogError("DisconnectTip(): DisconnectBlock %s failed\n", pindexDelete->GetBlockHash().ToString());
+ return false;
+ }
bool flushed = view.Flush();
assert(flushed);
}
@@ -2960,7 +2966,8 @@ bool Chainstate::ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew,
if (!rv) {
if (state.IsInvalid())
InvalidBlockFound(pindexNew, state);
- return 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();
time_connect_total += time_3 - time_2;
@@ -4243,7 +4250,8 @@ bool ChainstateManager::AcceptBlock(const std::shared_ptr<const CBlock>& pblock,
pindex->nStatus |= BLOCK_FAILED_VALID;
m_blockman.m_dirty_blockindex.insert(pindex);
}
- return error("%s: %s", __func__, state.ToString());
+ LogError("%s: %s\n", __func__, state.ToString());
+ return false;
}
// Header is valid/has work, merkle tree and segwit merkle tree are good...RELAY NOW
@@ -4306,7 +4314,8 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& blo
if (m_options.signals) {
m_options.signals->BlockChecked(*block, state);
}
- return error("%s: AcceptBlock FAILED (%s)", __func__, state.ToString());
+ LogError("%s: AcceptBlock FAILED (%s)\n", __func__, state.ToString());
+ return false;
}
}
@@ -4314,13 +4323,15 @@ bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& blo
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
if (!ActiveChainstate().ActivateBestChain(state, block)) {
- return 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)) {
- return error("%s: [background] ActivateBestChain failed (%s)", __func__, bg_state.ToString());
+ LogError("%s: [background] ActivateBestChain failed (%s)\n", __func__, bg_state.ToString());
+ return false;
}
return true;
@@ -4358,12 +4369,18 @@ bool TestBlockValidity(BlockValidationState& state,
indexDummy.phashBlock = &block_hash;
// NOTE: CheckBlockHeader is called by CheckBlock
- if (!ContextualCheckBlockHeader(block, state, chainstate.m_blockman, chainstate.m_chainman, pindexPrev))
- return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, state.ToString());
- if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot))
- return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
- if (!ContextualCheckBlock(block, state, chainstate.m_chainman, pindexPrev))
- return error("%s: Consensus::ContextualCheckBlock: %s", __func__, state.ToString());
+ if (!ContextualCheckBlockHeader(block, state, chainstate.m_blockman, chainstate.m_chainman, pindexPrev)) {
+ LogError("%s: Consensus::ContextualCheckBlockHeader: %s\n", __func__, state.ToString());
+ return false;
+ }
+ if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot)) {
+ LogError("%s: Consensus::CheckBlock: %s\n", __func__, state.ToString());
+ return false;
+ }
+ if (!ContextualCheckBlock(block, state, chainstate.m_chainman, pindexPrev)) {
+ LogError("%s: Consensus::ContextualCheckBlock: %s\n", __func__, state.ToString());
+ return false;
+ }
if (!chainstate.ConnectBlock(block, state, &indexDummy, viewNew, true)) {
return false;
}
@@ -4567,7 +4584,8 @@ bool Chainstate::RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& in
// TODO: merge with ConnectBlock
CBlock block;
if (!m_blockman.ReadBlockFromDisk(block, *pindex)) {
- return 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;
}
for (const CTransactionRef& tx : block.vtx) {
@@ -4591,7 +4609,10 @@ bool Chainstate::ReplayBlocks()
std::vector<uint256> hashHeads = db.GetHeadBlocks();
if (hashHeads.empty()) return true; // We're already in a consistent state.
- if (hashHeads.size() != 2) return error("ReplayBlocks(): unknown inconsistent state");
+ if (hashHeads.size() != 2) {
+ LogError("ReplayBlocks(): unknown inconsistent state\n");
+ return false;
+ }
m_chainman.GetNotifications().progress(_("Replaying blocks…"), 0, false);
LogPrintf("Replaying blocks\n");
@@ -4601,13 +4622,15 @@ 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) {
- return 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) {
- return 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]]);
pindexFork = LastCommonAncestor(pindexOld, pindexNew);
@@ -4619,12 +4642,14 @@ bool Chainstate::ReplayBlocks()
if (pindexOld->nHeight > 0) { // Never disconnect the genesis block.
CBlock block;
if (!m_blockman.ReadBlockFromDisk(block, *pindexOld)) {
- return 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) {
- return 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
// overwritten. It corresponds to cases where the block-to-be-disconnect never had all its operations
@@ -4743,12 +4768,14 @@ bool Chainstate::LoadGenesisBlock()
const CBlock& block = params.GenesisBlock();
FlatFilePos blockPos{m_blockman.SaveBlockToDisk(block, 0, nullptr)};
if (blockPos.IsNull()) {
- return 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) {
- return 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;
}
return true;