Skip to content

Commit 6b56873

Browse files
committed
Merge bitcoin/bitcoin#25784: Wallet: Document expectations for AddWalletFlags (now InitWalletFlags) correctly
0cb6d2a 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 0cb6d2a w0xlt: ACK bitcoin/bitcoin@0cb6d2a ryanofsky: Code review ACK 0cb6d2a. 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
2 parents 0f0508b + 0cb6d2a commit 6b56873

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/wallet/wallet.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,16 +1526,20 @@ bool CWallet::LoadWalletFlags(uint64_t flags)
15261526
return true;
15271527
}
15281528

1529-
bool CWallet::AddWalletFlags(uint64_t flags)
1529+
void CWallet::InitWalletFlags(uint64_t flags)
15301530
{
15311531
LOCK(cs_wallet);
1532+
15321533
// We should never be writing unknown non-tolerable wallet flags
15331534
assert(((flags & KNOWN_WALLET_FLAGS) >> 32) == (flags >> 32));
1535+
// This should only be used once, when creating a new wallet - so current flags are expected to be blank
1536+
assert(m_wallet_flags == 0);
1537+
15341538
if (!WalletBatch(GetDatabase()).WriteWalletFlags(flags)) {
15351539
throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed");
15361540
}
15371541

1538-
return LoadWalletFlags(flags);
1542+
if (!LoadWalletFlags(flags)) assert(false);
15391543
}
15401544

15411545
// 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
28322836
// ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key
28332837
walletInstance->SetMinVersion(FEATURE_LATEST);
28342838

2835-
walletInstance->AddWalletFlags(wallet_creation_flags);
2839+
walletInstance->InitWalletFlags(wallet_creation_flags);
28362840

28372841
// Only create LegacyScriptPubKeyMan when not descriptor wallet
28382842
if (!walletInstance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {

src/wallet/wallet.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,9 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
806806
bool IsWalletFlagSet(uint64_t flag) const override;
807807

808808
/** overwrite all flags by the given uint64_t
809-
returns false if unknown, non-tolerable flags are present */
810-
bool AddWalletFlags(uint64_t flags);
809+
flags must be uninitialised (or 0)
810+
only known flags may be present */
811+
void InitWalletFlags(uint64_t flags);
811812
/** Loads the flags into the wallet. (used by LoadWallet) */
812813
bool LoadWalletFlags(uint64_t flags);
813814

src/wallet/wallettool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void WalletCreate(CWallet* wallet_instance, uint64_t wallet_creation_flag
3434
LOCK(wallet_instance->cs_wallet);
3535

3636
wallet_instance->SetMinVersion(FEATURE_LATEST);
37-
wallet_instance->AddWalletFlags(wallet_creation_flags);
37+
wallet_instance->InitWalletFlags(wallet_creation_flags);
3838

3939
if (!wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) {
4040
auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan();

0 commit comments

Comments
 (0)