From b7e37883da1357694a9dd762e9b29b16e9e2db4e Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Wed, 26 Jun 2024 21:55:34 -0400 Subject: [PATCH] wallet, logging: Switch LogInfo to LogWarning/LogError Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors. Suggested by hodlinator in https://github.com/bitcoin/bitcoin/pull/30343#discussion_r1655406670 https://github.com/bitcoin/bitcoin/pull/30343#discussion_r1655407301 https://github.com/bitcoin/bitcoin/pull/30343#discussion_r1655436010 --- src/wallet/rpc/backup.cpp | 4 ++-- src/wallet/scriptpubkeyman.cpp | 2 +- src/wallet/wallet.cpp | 10 +++++----- src/wallet/walletdb.cpp | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 80ae7a0bec5..cbb65ef703b 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -598,7 +598,7 @@ RPCHelpMan importwallet() LogInfo(log, "Importing %s...\n", EncodeDestination(PKHash(keyid))); if (!pwallet->ImportPrivKeys({{keyid, key}}, time)) { - LogInfo(log, "Error importing key for %s\n", EncodeDestination(PKHash(keyid))); + LogError(log, "Error importing key for %s\n", EncodeDestination(PKHash(keyid))); fGood = false; continue; } @@ -613,7 +613,7 @@ RPCHelpMan importwallet() int64_t time = script_pair.second; if (!pwallet->ImportScripts({script}, time)) { - LogInfo(log, "Error importing script %s\n", HexStr(script)); + LogError(log, "Error importing script %s\n", HexStr(script)); fGood = false; continue; } diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 1dfd3d07005..75d054b244f 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -789,7 +789,7 @@ bool LegacyDataSPKM::LoadCScript(const CScript& redeemScript) if (redeemScript.size() > MAX_SCRIPT_ELEMENT_SIZE) { std::string strAddr = EncodeDestination(ScriptHash(redeemScript)); - LogInfo(m_log, "%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr); + LogWarning(m_log, "%s: Warning: This wallet contains a redeemScript of size %i which exceeds maximum size %i thus can never be redeemed. Do not use address %s.\n", __func__, redeemScript.size(), MAX_SCRIPT_ELEMENT_SIZE, strAddr); return true; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d263aae62b1..0b43b2089dd 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2475,11 +2475,11 @@ bool CWallet::SetAddressBookWithDB(WalletBatch& batch, const CTxDestination& add const std::string& encoded_dest = EncodeDestination(address); if (new_purpose && !batch.WritePurpose(encoded_dest, PurposeToString(*new_purpose))) { - LogInfo(m_log, "Error: fail to write address book 'purpose' entry\n"); + LogError(m_log, "Error: fail to write address book 'purpose' entry\n"); return false; } if (!batch.WriteName(encoded_dest, strName)) { - LogInfo(m_log, "Error: fail to write address book 'name' entry\n"); + LogError(m_log, "Error: fail to write address book 'name' entry\n"); return false; } @@ -2517,19 +2517,19 @@ bool CWallet::DelAddressBookWithDB(WalletBatch& batch, const CTxDestination& add } // Delete data rows associated with this address if (!batch.EraseAddressData(address)) { - LogInfo(m_log, "Error: cannot erase address book entry data\n"); + LogError(m_log, "Error: cannot erase address book entry data\n"); return false; } // Delete purpose entry if (!batch.ErasePurpose(dest)) { - LogInfo(m_log, "Error: cannot erase address book entry purpose\n"); + LogError(m_log, "Error: cannot erase address book entry purpose\n"); return false; } // Delete name entry if (!batch.EraseName(dest)) { - LogInfo(m_log, "Error: cannot erase address book entry name\n"); + LogError(m_log, "Error: cannot erase address book entry name\n"); return false; } diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index d165210e10f..9673d7bfbfd 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -485,7 +485,7 @@ static DBErrors LoadWalletFlags(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIV uint64_t flags; if (batch.Read(DBKeys::FLAGS, flags)) { if (!pwallet->LoadWalletFlags(flags)) { - LogInfo(log, "Error reading wallet database: Unknown non-tolerable wallet flags found\n"); + LogError(log, "Error reading wallet database: Unknown non-tolerable wallet flags found\n"); return DBErrors::TOO_NEW; } } @@ -509,7 +509,7 @@ static LoadResult LoadRecords(CWallet* pwallet, DatabaseBatch& batch, const std: Assume(!prefix.empty()); std::unique_ptr cursor = batch.GetNewPrefixCursor(prefix); if (!cursor) { - LogInfo(log, "Error getting database cursor for '%s' records\n", key); + LogError(log, "Error getting database cursor for '%s' records\n", key); result.m_result = DBErrors::CORRUPT; return result; } @@ -519,7 +519,7 @@ static LoadResult LoadRecords(CWallet* pwallet, DatabaseBatch& batch, const std: if (status == DatabaseCursor::Status::DONE) { break; } else if (status == DatabaseCursor::Status::FAIL) { - LogInfo(log, "Error reading next '%s' record for wallet database\n", key); + LogError(log, "Error reading next '%s' record for wallet database\n", key); result.m_result = DBErrors::CORRUPT; return result; } @@ -529,7 +529,7 @@ static LoadResult LoadRecords(CWallet* pwallet, DatabaseBatch& batch, const std: std::string error; DBErrors record_res = load_func(pwallet, ssKey, ssValue, error); if (record_res != DBErrors::LOAD_OK) { - LogInfo(log, "%s\n", error); + LogError(log, "%s\n", error); } result.m_result = std::max(result.m_result, record_res); ++result.m_records; @@ -560,13 +560,13 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch, prefix << type; std::unique_ptr cursor = batch.GetNewPrefixCursor(prefix); if (!cursor) { - LogInfo(log, "Error getting database cursor for '%s' records\n", type); + LogError(log, "Error getting database cursor for '%s' records\n", type); return DBErrors::CORRUPT; } DatabaseCursor::Status status = cursor->Next(key, value); if (status != DatabaseCursor::Status::DONE) { - LogInfo(log, "Error: Unexpected legacy entry found in descriptor wallet %s. The wallet might have been tampered with or created with malicious intent.\n", pwallet->GetName()); + LogError(log, "Error: Unexpected legacy entry found in descriptor wallet %s. The wallet might have been tampered with or created with malicious intent.\n", pwallet->GetName()); return DBErrors::UNEXPECTED_LEGACY_ENTRY; } } @@ -1000,7 +1000,7 @@ static DBErrors LoadAddressBookRecords(CWallet* pwallet, DatabaseBatch& batch) E value >> purpose_str; std::optional purpose{PurposeFromString(purpose_str)}; if (!purpose) { - LogInfo(log, "Warning: nonstandard purpose string '%s' for address '%s'\n", purpose_str, strAddress); + LogWarning(log, "Warning: nonstandard purpose string '%s' for address '%s'\n", purpose_str, strAddress); } pwallet->m_address_book[DecodeDestination(strAddress)].purpose = purpose; return DBErrors::LOAD_OK; @@ -1199,7 +1199,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet) #ifndef ENABLE_EXTERNAL_SIGNER if (pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) { - LogInfo(log, "Error: External signer wallet being loaded without external signer support compiled\n"); + LogError(log, "Error: External signer wallet being loaded without external signer support compiled\n"); return DBErrors::EXTERNAL_SIGNER_SUPPORT_REQUIRED; } #endif