Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wallet: Log when Wallet::SetMinVersion sets a different minversion #25896

Merged
merged 1 commit into from
Aug 26, 2022

Conversation

ZenulAbidin
Copy link
Contributor

This change prints a single additional line in the debug.log when bitcoin-cli loads a wallet using loadwallet (not createwallet).

When Bitcoin Core creates a wallet, it's minversion is set to FEATURE_BASE, which is 10500. However, once the wallet is unloaded using unloadwallet or through program termination, and subsequently loaded again, loadwallet updates the minversion in the wallet.dat file to FEATURE_LATEST, currently 169900.

The current logging format prints the very old wallet version during createwallet, and then the actual version in calls to loadwallet. This has confused at least one person (reference - I was the one who asked there if there were plans to change that behavior, and was subsequently redirected here by achow), so it will be very helpful to users to explicitly specify in the logs what the walletdb is doing.

@achow101
Copy link
Member

This is incorrect. loadwallet does not change the wallet version. It occurs during CWallet::Create, which calls WalletBatch::LoadWallet in order to create the db file. The "incorrect" log line occurs during this LoadWallet. We will never change the wallet file version without explicit user action as it is a compatibility breaking change.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 22, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@ZenulAbidin
Copy link
Contributor Author

ZenulAbidin commented Aug 22, 2022

This is incorrect. loadwallet does not change the wallet version. It occurs during CWallet::Create, which calls WalletBatch::LoadWallet in order to create the db file. The "incorrect" log line occurs during this LoadWallet.

Yeah, obviously I had to know that since the section that updates the wallet version is in WalletBatch::LoadWallet. The reason I said it came from loadwallet is because during my testing, calling the loadwallet RPC call eventually triggers WalletBatch::Loadwallet. I was never able to trigger this function from createwallet. Here is part of my debug.log output on regtest to supplement this hypothesis:

2022-08-21T20:52:10Z [rpc] ThreadRPCServer method=createwallet user=notatether                                                                                                                                                                                                
2022-08-21T20:52:10Z Using SQLite Version 3.31.1                                                                                                                                                                                                                              
2022-08-21T20:52:10Z Using wallet /home/zenulabidin/.bitcoin/regtest/wallets/prtest7                                                                                                                                                                                          
2022-08-21T20:52:10Z init message: Loading wallet…                                                                                                                                                                                                                            
2022-08-21T20:52:10Z [prtest7] Wallet file version = 10500, last client version = 239900                                                                                                                                                                                      
2022-08-21T20:52:10Z [prtest7] Keys: 0 plaintext, 0 encrypted, 0 w/ metadata, 0 total. Unknown wallet records: 0                                                                                                                                                              
2022-08-21T20:52:11Z [prtest7] Setting spkMan to active: id = 1e60986d600b86b498d7f5fec0984af074366a234cc825b16e66ef229632b066, type = legacy, internal = false                                                                                                               
2022-08-21T20:52:12Z [prtest7] Setting spkMan to active: id = 8189854c5db714cc58ffc1ab7ae4f1fa340e25d8252f1a9e7f1a20221b96d05c, type = p2sh-segwit, internal = false                                                                                                          
2022-08-21T20:52:12Z [prtest7] Setting spkMan to active: id = efe8901b28b0330fca53a354d32290377c3014f5712faaebd9b552b43cd05a1c, type = bech32, internal = false                                                                                                               
2022-08-21T20:52:13Z [prtest7] Setting spkMan to active: id = 93591c1fd54c434bed79a12d75a36d9cdd9d14f2a503e95d3cbd42699205b83d, type = bech32m, internal = false                                                                                                              
2022-08-21T20:52:14Z [prtest7] Setting spkMan to active: id = 32a04d1773be2f4bf3b9a3fd39b1ac66145d2b7d0dc15424ae1e71cd3ea52203, type = legacy, internal = true                                                                                                                
2022-08-21T20:52:15Z [prtest7] Setting spkMan to active: id = 0093bc4675eb72f188f0729bf2bccdcdf09039d6c51686b9a00edfa51247d293, type = p2sh-segwit, internal = true                                                                                                           
2022-08-21T20:52:16Z [prtest7] Setting spkMan to active: id = b67e3643f790b7e0ba855067b8fa97ba386022aed984cd2b347b7570fcbbd335, type = bech32, internal = true                                                                                                                
2022-08-21T20:52:17Z [prtest7] Setting spkMan to active: id = fa147979b83634d90d47adb6af966a54d7a5f908a081b7dce42da9f8e49c2338, type = bech32m, internal = true                                                                                                               
2022-08-21T20:52:17Z [prtest7] Wallet completed loading in            7325ms                                                                                                                                                                                                  
2022-08-21T20:52:18Z [prtest7] setKeyPool.size() = 8000                                                                                                                                                                                                                       
2022-08-21T20:52:18Z [prtest7] mapWallet.size() = 0                                                                                                                                                                                                                           
2022-08-21T20:52:18Z [prtest7] m_address_book.size() = 0                                                                                                                                                                                                                      
...
2022-08-21T20:52:53Z [rpc] ThreadRPCServer method=unloadwallet user=notatether                                                                                                                                                                                                
2022-08-21T20:52:53Z [prtest7] Releasing wallet                                                                                                                                                                                                                               
2022-08-21T20:53:02Z [rpc] ThreadRPCServer method=loadwallet user=notatether                                                                                                                                                                                                  
2022-08-21T20:53:02Z Using SQLite Version 3.31.1                                                                                                                                                                                                                              
2022-08-21T20:53:02Z Using wallet /home/zenulabidin/.bitcoin/regtest/wallets/prtest7                                                                                                                                                                                          
2022-08-21T20:53:02Z init message: Loading wallet…                                                                                                                                                                                                                            
2022-08-21T20:53:02Z [prtest7] Changing minversion from 10500 to 169900                                                                                                                                                                                                       
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = 1e60986d600b86b498d7f5fec0984af074366a234cc825b16e66ef229632b066, type = legacy, internal = false                                                                                                               
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = 8189854c5db714cc58ffc1ab7ae4f1fa340e25d8252f1a9e7f1a20221b96d05c, type = p2sh-segwit, internal = false                                                                                                          
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = efe8901b28b0330fca53a354d32290377c3014f5712faaebd9b552b43cd05a1c, type = bech32, internal = false                                                                                                               
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = 93591c1fd54c434bed79a12d75a36d9cdd9d14f2a503e95d3cbd42699205b83d, type = bech32m, internal = false                                                                                                              
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = 32a04d1773be2f4bf3b9a3fd39b1ac66145d2b7d0dc15424ae1e71cd3ea52203, type = legacy, internal = true                                                                                                                
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = 0093bc4675eb72f188f0729bf2bccdcdf09039d6c51686b9a00edfa51247d293, type = p2sh-segwit, internal = true                                                                                                           
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = b67e3643f790b7e0ba855067b8fa97ba386022aed984cd2b347b7570fcbbd335, type = bech32, internal = true                                                                                                                
2022-08-21T20:53:02Z [prtest7] Setting spkMan to active: id = fa147979b83634d90d47adb6af966a54d7a5f908a081b7dce42da9f8e49c2338, type = bech32m, internal = true                                                                                                               
2022-08-21T20:53:03Z [prtest7] Wallet file version = 169900, last client version = 239900                                                                                                                                                                                     
2022-08-21T20:53:03Z [prtest7] Keys: 8 plaintext, 0 encrypted, 0 w/ metadata, 8 total. Unknown wallet records: 0                                                                                                                                                              
2022-08-21T20:53:04Z [prtest7] Wallet completed loading in            1068ms                                                                                                                                                                                                  
2022-08-21T20:53:04Z [prtest7] setKeyPool.size() = 8000                                                                                                                                                                                                                       
2022-08-21T20:53:04Z [prtest7] mapWallet.size() = 0                                                                                                                                                                                                                           
2022-08-21T20:53:04Z [prtest7] m_address_book.size() = 0
... # Some time later, I repeated the unloadwallet/loadwallet sequence
2022-08-22T03:48:54Z [rpc] ThreadRPCServer method=unloadwallet user=notatether
2022-08-22T03:48:54Z [prtest7] Releasing wallet
2022-08-22T03:48:56Z [rpc] ThreadRPCServer method=loadwallet user=notatether
2022-08-22T03:48:56Z Using SQLite Version 3.31.1
2022-08-22T03:48:56Z Using wallet /home/zenulabidin/.bitcoin/regtest/wallets/prtest7
2022-08-22T03:48:56Z init message: Loading wallet…
2022-08-22T03:48:56Z [prtest7] Changing minversion from 10500 to 169900
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = 1e60986d600b86b498d7f5fec0984af074366a234cc825b16e66ef229632b066, type = legacy, internal = false
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = 8189854c5db714cc58ffc1ab7ae4f1fa340e25d8252f1a9e7f1a20221b96d05c, type = p2sh-segwit, internal = false
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = efe8901b28b0330fca53a354d32290377c3014f5712faaebd9b552b43cd05a1c, type = bech32, internal = false
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = 93591c1fd54c434bed79a12d75a36d9cdd9d14f2a503e95d3cbd42699205b83d, type = bech32m, internal = false
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = 32a04d1773be2f4bf3b9a3fd39b1ac66145d2b7d0dc15424ae1e71cd3ea52203, type = legacy, internal = true
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = 0093bc4675eb72f188f0729bf2bccdcdf09039d6c51686b9a00edfa51247d293, type = p2sh-segwit, internal = true
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = b67e3643f790b7e0ba855067b8fa97ba386022aed984cd2b347b7570fcbbd335, type = bech32, internal = true
2022-08-22T03:48:56Z [prtest7] Setting spkMan to active: id = fa147979b83634d90d47adb6af966a54d7a5f908a081b7dce42da9f8e49c2338, type = bech32m, internal = true
2022-08-22T03:48:57Z [prtest7] Wallet file version = 169900, last client version = 239900
2022-08-22T03:48:57Z [prtest7] Keys: 8 plaintext, 0 encrypted, 0 w/ metadata, 8 total. Unknown wallet records: 0
2022-08-22T03:48:57Z [prtest7] Wallet completed loading in             997ms
2022-08-22T03:48:58Z [prtest7] setKeyPool.size() = 8000
2022-08-22T03:48:58Z [prtest7] mapWallet.size() = 0
2022-08-22T03:48:58Z [prtest7] m_address_book.size() = 0

Notice how the new message is only printed during an RPC invocation of loadwallet.

@achow101
Copy link
Member

achow101 commented Aug 22, 2022

You misunderstand me.

It is incorrect to have the logline occur during loadwallet. It needs to occur with createwallet because the version is written during creating, not during loading. It is written somewhere in CWallet::Create, after that function has called LoadWallet.

Furthermore, what you have done is log the default value just before the actual minversion is read from the wallet file. This is completely useless information.

@ZenulAbidin
Copy link
Contributor Author

It is incorrect to have the logline occur during loadwallet. It needs to occur with createwallet because the version is written during creating, not during loading. It is written somewhere in CWallet::Create, after that function has called LoadWallet.

Furthermore, what you have done is log the default value just before the actual minversion is read from the wallet file. This is completely useless information.

Changes have been implemented. Now the logging only prints the read minversion.

@achow101
Copy link
Member

achow101 commented Aug 23, 2022

Perhaps it would be better to have the log line in SetMinVersion itself so that it can log everywhere we actually upgrade the minimum version. Of course it should only log if the version is changed.

Please also change the PR title to reflect what the code does.

@ZenulAbidin ZenulAbidin changed the title wallet: Log when loadwallet updates wallet minversion wallet: Log when Wallet::SetMinVersion sets a different minversion Aug 24, 2022
@ZenulAbidin
Copy link
Contributor Author

Perhaps it would be better to have the log line in SetMinVersion itself so that it can log everywhere we actually upgrade the minimum version. Of course it should only log if the version is changed.

Both of these adjustments have been made.

@@ -542,6 +542,7 @@ void CWallet::SetMinVersion(enum WalletFeature nVersion, WalletBatch* batch_in)
LOCK(cs_wallet);
if (nWalletVersion >= nVersion)
return;
this->WalletLogPrintf("Setting minversion to %d\n", nVersion);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this-> is unneeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achow101 I pushed a revision without it (I actually had the patch ready since this afternoon, but I forgot to push it until now).

@achow101
Copy link
Member

Please also update the OP text to reflect the code.

@ZenulAbidin
Copy link
Contributor Author

Just a question, since I haven't done this kind of thing before:

Must I keep rebasing the FETCH_HEAD and force-pushing before this PR can be merged?

I'm asking because apparently other merges are being made and CONTRIBUTING.md says that maintainers might request to rebase the FETCH_HEAD first.

@achow101
Copy link
Member

achow101 commented Aug 26, 2022

@ZenulAbidin No, you do not need to keep rebasing. You only need to rebase if there are conflicts with master. Otherwise you shouldn't rebase as doing so invalidates acks. Other PRs are merged because they are ready - contributors have reviewed those. Of course reviewers can review anything they wish and so it is probable that there are other things that are higher priority that are getting review.

@achow101
Copy link
Member

ACK 835bd27

@achow101 achow101 merged commit 80da4be into bitcoin:master Aug 26, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 26, 2022
…fferent minversion

835bd27 Wallet::SetMinVersion - Log the new minversion (Ali Sherief)

Pull request description:

  This change prints a single additional line in the debug.log when bitcoin-cli loads a wallet using `loadwallet` (*not* `createwallet`).

  When Bitcoin Core creates a wallet, it's `minversion` is set to `FEATURE_BASE`, which is 10500. However, once the wallet is unloaded using `unloadwallet` or through program termination, and subsequently loaded again, `loadwallet` updates the `minversion` in the wallet.dat file to `FEATURE_LATEST`, currently 169900.

  The current logging format prints the very old wallet version during `createwallet`, and then the actual version in calls to `loadwallet`. This has confused at least one person ([reference](https://bitcointalk.org/index.php?topic=5410650.0) - I was the one who asked there if there were plans to change that behavior, and was subsequently redirected here by achow), so it will be very helpful to users to explicitly specify in the logs what the walletdb is doing.

ACKs for top commit:
  achow101:
    ACK 835bd27

Tree-SHA512: 967c8c617e06a84915ddb147378ec3c8b0343e45f43145ec78df9cbc0201867f49c8e11cd068c403eb5ec06e07d38c3c0d3864dad8edc5efbb134a3fb30be41f
@ZenulAbidin ZenulAbidin deleted the wallet-minversion-debugprint branch August 27, 2022 07:44
@bitcoin bitcoin locked and limited conversation to collaborators Aug 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants