diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-08-19 12:02:09 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2022-08-19 12:12:27 -0400 |
commit | 6b56873b41974ced7aad87a4b38abe360c34eed3 (patch) | |
tree | 4d86b4c65b230a341f15a96fe37d6256bde84c15 | |
parent | 0f0508bc72902d1665d73857b5bcffccdaa44958 (diff) | |
parent | 0cb6d2aec63aec76a517b8da621a3c53ab432632 (diff) | |
download | bitcoin-6b56873b41974ced7aad87a4b38abe360c34eed3.tar.xz |
Merge bitcoin/bitcoin#25784: Wallet: Document expectations for AddWalletFlags (now InitWalletFlags) correctly
0cb6d2aec63aec76a517b8da621a3c53ab432632 Bugfix: Wallet: Document expectations for AddWalletFlags (now InitWalletFlags) correctly (Luke Dashjr)
Pull request description:
Includes some slight refactoring (return type changed, current status checked)
ACKs for top commit:
achow101:
ACK 0cb6d2aec63aec76a517b8da621a3c53ab432632
w0xlt:
ACK https://github.com/bitcoin/bitcoin/pull/25784/commits/0cb6d2aec63aec76a517b8da621a3c53ab432632
ryanofsky:
Code review ACK 0cb6d2aec63aec76a517b8da621a3c53ab432632. This is a clarifying change, and should prevent the InitWalletFlags method being called incorrectly. I left a comment suggestion, but feel free to ignore it.
Tree-SHA512: fa18e9471b5e89d35cbc01526e6d4dbe4eee8faa9646847248909af1751b33014a6f9a42fe70a1331c0d73adea79008b8fc3ae2b51a641eba3e36d5c631327f6
-rw-r--r-- | src/wallet/wallet.cpp | 10 | ||||
-rw-r--r-- | src/wallet/wallet.h | 5 | ||||
-rw-r--r-- | src/wallet/wallettool.cpp | 2 |
3 files changed, 11 insertions, 6 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index de787ae421..3d989d90f8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1526,16 +1526,20 @@ bool CWallet::LoadWalletFlags(uint64_t flags) return true; } -bool CWallet::AddWalletFlags(uint64_t flags) +void CWallet::InitWalletFlags(uint64_t flags) { LOCK(cs_wallet); + // We should never be writing unknown non-tolerable wallet flags assert(((flags & KNOWN_WALLET_FLAGS) >> 32) == (flags >> 32)); + // This should only be used once, when creating a new wallet - so current flags are expected to be blank + assert(m_wallet_flags == 0); + if (!WalletBatch(GetDatabase()).WriteWalletFlags(flags)) { throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed"); } - return LoadWalletFlags(flags); + if (!LoadWalletFlags(flags)) assert(false); } // Helper for producing a max-sized low-S low-R signature (eg 71 bytes) @@ -2832,7 +2836,7 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri // ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key walletInstance->SetMinVersion(FEATURE_LATEST); - walletInstance->AddWalletFlags(wallet_creation_flags); + walletInstance->InitWalletFlags(wallet_creation_flags); // Only create LegacyScriptPubKeyMan when not descriptor wallet if (!walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 3a46d0a987..934811dee1 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -806,8 +806,9 @@ public: bool IsWalletFlagSet(uint64_t flag) const override; /** overwrite all flags by the given uint64_t - returns false if unknown, non-tolerable flags are present */ - bool AddWalletFlags(uint64_t flags); + flags must be uninitialised (or 0) + only known flags may be present */ + void InitWalletFlags(uint64_t flags); /** Loads the flags into the wallet. (used by LoadWallet) */ bool LoadWalletFlags(uint64_t flags); diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp index 769175b5a8..e991bc0814 100644 --- a/src/wallet/wallettool.cpp +++ b/src/wallet/wallettool.cpp @@ -34,7 +34,7 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag LOCK(wallet_instance->cs_wallet); wallet_instance->SetMinVersion(FEATURE_LATEST); - wallet_instance->AddWalletFlags(wallet_creation_flags); + wallet_instance->InitWalletFlags(wallet_creation_flags); if (!wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan(); |