From 359ecd3704993422eb53e3da2a7d0bea2f575ab0 Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Sun, 18 May 2025 11:39:51 -0700 Subject: [PATCH 1/3] walletdb: Log the wallet version after it has been read from disk Logging the wallet version before anything has been read from disk results in the wrong version being logged. Also split the last client version logging as it may not always be present to be logged. --- src/wallet/walletdb.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 590f94def87..3bb5db71f5e 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -447,6 +447,7 @@ static DBErrors LoadMinVersion(CWallet* pwallet, DatabaseBatch& batch) EXCLUSIVE AssertLockHeld(pwallet->cs_wallet); int nMinVersion = 0; if (batch.Read(DBKeys::MINVERSION, nMinVersion)) { + pwallet->WalletLogPrintf("Wallet file version = %d\n", nMinVersion); if (nMinVersion > FEATURE_LATEST) return DBErrors::TOO_NEW; pwallet->LoadMinVersion(nMinVersion); @@ -1156,7 +1157,7 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet) // Last client version to open this wallet int last_client = CLIENT_VERSION; bool has_last_client = m_batch->Read(DBKeys::VERSION, last_client); - pwallet->WalletLogPrintf("Wallet file version = %d, last client version = %d\n", pwallet->GetVersion(), last_client); + if (has_last_client) pwallet->WalletLogPrintf("Last client version = %d\n", last_client); try { if ((result = LoadMinVersion(pwallet, *m_batch)) != DBErrors::LOAD_OK) return result; From 39a483c8e9dcfe8ec243fa72269e1df9e75059ab Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Sun, 18 May 2025 11:55:18 -0700 Subject: [PATCH 2/3] test: Check that the correct versions are logged on wallet load --- test/functional/wallet_createwallet.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/functional/wallet_createwallet.py b/test/functional/wallet_createwallet.py index 1f86b265e8d..de48967b532 100755 --- a/test/functional/wallet_createwallet.py +++ b/test/functional/wallet_createwallet.py @@ -165,6 +165,18 @@ class CreateWalletTest(BitcoinTestFramework): self.log.info("Test that legacy wallets cannot be created") assert_raises_rpc_error(-4, 'descriptors argument must be set to "true"; it is no longer possible to create a legacy wallet.', self.nodes[0].createwallet, wallet_name="legacy", descriptors=False) + self.log.info("Check that the version number is being logged correctly") + node.createwallet("version_check") + wallet = node.get_wallet_rpc("version_check") + wallet_version = wallet.getwalletinfo()["walletversion"] + client_version = node.getnetworkinfo()["version"] + wallet.unloadwallet() + with node.assert_debug_log( + expected_msgs=[f"Last client version = {client_version}", f"Wallet file version = {wallet_version}"], + unexpected_msgs=["Wallet file version = 10500"] + ): + node.loadwallet("version_check") + if __name__ == '__main__': CreateWalletTest(__file__).main() From 4b2cd0b41ff4800c8801f2c44883eaec60a035fa Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Sun, 18 May 2025 11:58:40 -0700 Subject: [PATCH 3/3] test: check that creating a wallet does not log version info --- test/functional/wallet_createwallet.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functional/wallet_createwallet.py b/test/functional/wallet_createwallet.py index de48967b532..312d22fce48 100755 --- a/test/functional/wallet_createwallet.py +++ b/test/functional/wallet_createwallet.py @@ -166,7 +166,8 @@ class CreateWalletTest(BitcoinTestFramework): assert_raises_rpc_error(-4, 'descriptors argument must be set to "true"; it is no longer possible to create a legacy wallet.', self.nodes[0].createwallet, wallet_name="legacy", descriptors=False) self.log.info("Check that the version number is being logged correctly") - node.createwallet("version_check") + with node.assert_debug_log(expected_msgs=[], unexpected_msgs=["Last client version = ", "Wallet file version = "]): + node.createwallet("version_check") wallet = node.get_wallet_rpc("version_check") wallet_version = wallet.getwalletinfo()["walletversion"] client_version = node.getnetworkinfo()["version"]