Bugfix: Wallet: Document expectations for AddWalletFlags (now InitWalletFlags) correctly

This commit is contained in:
Luke Dashjr committed 2022-08-05 02:54:15 +00:00
1 parent 30308cc380
commit 0cb6d2aec6
3 files changed
+11 -6

No files matched your search

+7 -3
View File
@@ -1479,16 +1479,20 @@ bool CWallet::LoadWalletFlags(uint64_t flags)
return true; return true;
} }
bool CWallet::AddWalletFlags(uint64_t flags) void CWallet::InitWalletFlags(uint64_t flags)
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
// We should never be writing unknown non-tolerable wallet flags // We should never be writing unknown non-tolerable wallet flags
assert(((flags & KNOWN_WALLET_FLAGS) >> 32) == (flags >> 32)); 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)) { if (!WalletBatch(GetDatabase()).WriteWalletFlags(flags)) {
throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed"); 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) // Helper for producing a max-sized low-S low-R signature (eg 71 bytes)
@@ -2721,7 +2725,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 // 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->SetMinVersion(FEATURE_LATEST);
walletInstance->AddWalletFlags(wallet_creation_flags); walletInstance->InitWalletFlags(wallet_creation_flags);
// Only create LegacyScriptPubKeyMan when not descriptor wallet // Only create LegacyScriptPubKeyMan when not descriptor wallet
if (!walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { if (!walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
+3 -2
View File
@@ -781,8 +781,9 @@ public:
bool IsWalletFlagSet(uint64_t flag) const override; bool IsWalletFlagSet(uint64_t flag) const override;
/** overwrite all flags by the given uint64_t /** overwrite all flags by the given uint64_t
returns false if unknown, non-tolerable flags are present */ flags must be uninitialised (or 0)
bool AddWalletFlags(uint64_t flags); only known flags may be present */
void InitWalletFlags(uint64_t flags);
/** Loads the flags into the wallet. (used by LoadWallet) */ /** Loads the flags into the wallet. (used by LoadWallet) */
bool LoadWalletFlags(uint64_t flags); bool LoadWalletFlags(uint64_t flags);
+1 -1
View File
@@ -34,7 +34,7 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
LOCK(wallet_instance->cs_wallet); LOCK(wallet_instance->cs_wallet);
wallet_instance->SetMinVersion(FEATURE_LATEST); wallet_instance->SetMinVersion(FEATURE_LATEST);
wallet_instance->AddWalletFlags(wallet_creation_flags); wallet_instance->InitWalletFlags(wallet_creation_flags);
if (!wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { if (!wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan(); auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan();