wallet: remove `DBErrors::NEED_REWRITE` enum value
What changed, and why it matters
This commit removes an old wallet-loading code path called NEED_REWRITE that was used to automatically rewrite certain very old Berkeley DB (BDB) wallets from Bitcoin versions 0.4.0 and 0.5.0. The change is described as cleanup because those wallets can no longer be loaded outside of migration, and migration already rewrites the database. There is no direct evidence in the commit of a security vulnerability being fixed.
No immediate action required. Treat as routine refactoring. If maintaining older wallet support, verify that wallet migration still correctly handles the previously NEED_REWRITE cases and that no load path remains that could silently skip the rewrite.
Security signals we found
Removal of legacy wallet rewrite path for ancient BDB wallet versions (0.4.0 / 0.5.0)
No new input validation, bounds checks, or cryptographic changes introduced
No mention of security, vulnerability, bug, crash, or exploit in commit message or diff
Change is framed as code cleanup following a PR review comment
Evidence from the diff
The patch deletes the DBErrors::NEED_REWRITE enum value and all handling of it. Previously, loading a legacy encrypted wallet whose last client version was 40000 or 50000 would return NEED_REWRITE, triggering a database rewrite and a user-facing restart message. The removal is justified by the fact that such BDB wallets cannot be loaded anymore except during wallet migration, which performs its own rewrite. The change is purely subtractive and does not add new logic.
Changed components
src/wallet/wallet.cppsrc/wallet/walletdb.cppsrc/wallet/walletdb.hInspect captured patch +0 / −13
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index e1e0d307..fe074a3a 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2357,9 +2357,6 @@ DBErrors CWallet::PopulateWalletFromDB(bilingual_str& error, std::vector<bilingu
Assert(m_spk_managers.empty());
Assert(m_wallet_flags == 0);
DBErrors nLoadWalletRet = WalletBatch(GetDatabase()).LoadWallet(this);
- if (nLoadWalletRet == DBErrors::NEED_REWRITE) {
- GetDatabase().Rewrite();
- }
if (m_spk_managers.empty()) {
assert(m_external_spk_managers.empty());
@@ -2388,9 +2385,6 @@ DBErrors CWallet::PopulateWalletFromDB(bilingual_str& error, std::vector<bilingu
case DBErrors::EXTERNAL_SIGNER_SUPPORT_REQUIRED:
error = strprintf(_("Error loading %s: External signer wallet being loaded without external signer support compiled"), wallet_file);
break;
- case DBErrors::NEED_REWRITE:
- error = strprintf(_("Wallet needed to be rewritten: restart %s to complete"), CLIENT_NAME);
- break;
case DBErrors::UNKNOWN_DESCRIPTOR:
error = strprintf(_("Unrecognized descriptor found. Loading wallet %s\n\n"
"The wallet might have been created on a newer version.\n"
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index 4e168112..64d9617a 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -593,12 +593,6 @@ static DBErrors LoadLegacyWalletRecords(CWallet* pwallet, DatabaseBatch& batch,
});
result = std::max(result, script_res.m_result);
- // Check whether rewrite is needed
- if (ckey_res.m_records > 0) {
- // Rewrite encrypted wallets of versions 0.4.0 and 0.5.0rc:
- if (last_client == 40000 || last_client == 50000) result = std::max(result, DBErrors::NEED_REWRITE);
- }
-
// Load keymeta
std::map<uint160, CHDChain> hd_chains;
LoadResult keymeta_res = LoadRecords(pwallet, batch, DBKeys::KEYMETA,
diff --git a/src/wallet/walletdb.h b/src/wallet/walletdb.h
index 65ff8c0b..455fc745 100644
--- a/src/wallet/walletdb.h
+++ b/src/wallet/walletdb.h
@@ -44,7 +44,6 @@ enum class DBErrors : int
{
LOAD_OK = 0,
NEED_RESCAN = 1,
- NEED_REWRITE = 2,
EXTERNAL_SIGNER_SUPPORT_REQUIRED = 3,
NONCRITICAL_ERROR = 4,
TOO_NEW = 5,
Why this scored 19/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.