Skip to content

Commit

Permalink
wallet, logging: Switch LogInfo to LogWarning/LogError
Browse files Browse the repository at this point in the history
Switch to LogWarning / LogError in obvious places where wallet code is clearly outputting warnings and errors.

Suggested by hodlinator in
bitcoin#30343 (comment)
bitcoin#30343 (comment)
bitcoin#30343 (comment)
  • Loading branch information
ryanofsky committed Jun 27, 2024
1 parent 5c48bfc commit 6b5b235
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/wallet/rpc/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/scriptpubkeyman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ bool LegacyScriptPubKeyMan::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;
}

Expand Down
10 changes: 5 additions & 5 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2440,11 +2440,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;
}

Expand Down Expand Up @@ -2482,19 +2482,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;
}

Expand Down
16 changes: 8 additions & 8 deletions src/wallet/walletdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,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;
}
}
Expand All @@ -493,7 +493,7 @@ static LoadResult LoadRecords(CWallet* pwallet, DatabaseBatch& batch, const std:
Assume(!prefix.empty());
std::unique_ptr<DatabaseCursor> 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;
}
Expand All @@ -503,7 +503,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;
}
Expand All @@ -513,7 +513,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;
Expand Down Expand Up @@ -544,13 +544,13 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
prefix << type;
std::unique_ptr<DatabaseCursor> 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;
}
}
Expand Down Expand Up @@ -984,7 +984,7 @@ static DBErrors LoadAddressBookRecords(CWallet* pwallet, DatabaseBatch& batch) E
value >> purpose_str;
std::optional<AddressPurpose> 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;
Expand Down Expand Up @@ -1175,7 +1175,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
Expand Down

0 comments on commit 6b5b235

Please sign in to comment.