Skip to content

Commit df303ce

Browse files
committed
Merge #18787: wallet: descriptor wallet release notes and cleanups
ca2a096 Change SetType to SetInternal and remove m_address_type (Andrew Chow) 89b1ce1 Remove unimplemented SetCrypted from DescriptorScriptPubKeyMan (Andrew Chow) b9073c8 rpc: createwallet warning that descriptor wallets are experimental (Andrew Chow) 610030d docs: Add release notes for descriptor wallets (Andrew Chow) Pull request description: Some docs and cleanup following #16528. * Added release notes to explain a bit of motivation for descriptor wallets, what was changed, and how users will be effected by it. Also mentions the caveats regarding multsigs and watchonly that we have discussed on IRC. * Adds a warning to `createwallet` that descriptor wallets are experimental. * Removed unused `SetCrypted` as suggestioned: bitcoin/bitcoin#16528 (comment) * Removed `m_address_type` as mentioned in bitcoin/bitcoin#18782 (comment) ACKs for top commit: Sjors: tACK ca2a096 instagibbs: utACK bitcoin/bitcoin@ca2a096 meshcollider: utACK ca2a096 Tree-SHA512: 987188a912c191430e5d3f89bcef54ba6773692fc2d95b16a3ec11d9007ded210466ed980a3857e8b7196beef6422f07f9c85cc157f996c02d16f4dbde2e7b2a
2 parents ccd85b5 + ca2a096 commit df303ce

File tree

5 files changed

+137
-18
lines changed

5 files changed

+137
-18
lines changed

doc/release-notes-16528.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
Wallet
2+
------
3+
4+
### Experimental Descriptor Wallets
5+
6+
Please note that Descriptor Wallets are still experimental and not all expected functionality
7+
is available. Additionally there may be some bugs and current functions may change in the future.
8+
Bugs and missing functionality can be reported to the [issue tracker](https://github.com/bitcoin/bitcoin/issues).
9+
10+
0.21 introduces a new type of wallet - Descriptor Wallets. Descriptor Wallets store
11+
scriptPubKey information using descriptors. This is in contrast to the Legacy Wallet
12+
structure where keys are used to generate scriptPubKeys and addresses. Because of this
13+
shift to being script based instead of key based, many of the confusing things that Legacy
14+
Wallets do are not possible with Descriptor Wallets. Descriptor Wallets use a definition
15+
of "mine" for scripts which is simpler and more intuitive than that used by Legacy Wallets.
16+
Descriptor Wallets also uses different semantics for watch-only things and imports.
17+
18+
As Descriptor Wallets are a new type of wallet, their introduction does not affect existing wallets.
19+
Users who already have a Bitcoin Core wallet can continue to use it as they did before without
20+
any change in behavior. Newly created Legacy Wallets (which is the default type of wallet) will
21+
behave as they did in previous versions of Bitcoin Core.
22+
23+
The differences between Descriptor Wallets and Legacy Wallets are largely limited to non user facing
24+
things. They are intended to behave similarly except for the import/export and watchonly functionality
25+
as described below.
26+
27+
#### Creating Descriptor Wallets
28+
29+
Descriptor Wallets are not created by default. They must be explicitly created using the
30+
`createwallet` RPC or via the GUI. A `descriptors` option has been added to `createwallet`.
31+
Setting `descriptors` to `true` will create a Descriptor Wallet instead of a Legacy Wallet.
32+
33+
In the GUI, a checkbox has been added to the Create Wallet Dialog to indicate that a
34+
Descriptor Wallet should be created.
35+
36+
Without those options being set, a Legacy Wallet will be created instead. Additionally the
37+
Default Wallet created upon first startup of Bitcoin Core will be a Legacy Wallet.
38+
39+
#### `IsMine` Semantics
40+
41+
`IsMine` refers to the function used to determine whether a script belongs to the wallet.
42+
This is used to determine whether an output belongs to the wallet. `IsMine` in Legacy Wallets
43+
returns true if the wallet would be able to sign an input that spends an output with that script.
44+
Since keys can be involved in a variety of different scripts, this definition for `IsMine` can
45+
lead to many unexpected scripts being considered part of the wallet.
46+
47+
With Descriptor Wallets, descriptors explicitly specify the set of scripts that are owned by
48+
the wallet. Since descriptors are deterministic and easily enumerable, users will know exactly
49+
what scripts the wallet will consider to belong to it. Additionally the implementation of `IsMine`
50+
in Descriptor Wallets is far simpler than for Legacy Wallets. Notably, in Legacy Wallets, `IsMine`
51+
allowed for users to take one type of address (e.g. P2PKH), mutate it into another address type
52+
(e.g. P2WPKH), and the wallet would still detect outputs sending to the new address type
53+
even without that address being requested from the wallet. Descriptor Wallets does not
54+
allow for this and will only watch for the addresses that were explicitly requested from the wallet.
55+
56+
These changes to `IsMine` will make it easier to reason about what scripts the wallet will
57+
actually be watching for in outputs. However for the vast majority of users, this change is
58+
largely transparent and will not have noticeable effect.
59+
60+
#### Imports and Exports
61+
62+
In Legacy Wallets, raw scripts and keys could be imported to the wallet. Those imported scripts
63+
and keys are treated separately from the keys generated by the wallet. This complicates the `IsMine`
64+
logic as it has to distinguish between spendable and watchonly.
65+
66+
Descriptor Wallets handle importing scripts and keys differently. Only complete descriptors can be
67+
imported. These descriptors are then added to the wallet as if it were a descriptor generated by
68+
the wallet itself. This simplifies the `IsMine` logic so that it no longer has to distinguish
69+
between spendable and watchonly. As such, the watchonly model for Descriptor Wallets is also
70+
different and described in more detail in the next section.
71+
72+
To import into a Descriptor Wallet, a new `importdescriptors` RPC has been added that uses a syntax
73+
similar to that of `importmulti`.
74+
75+
As Legacy Wallets and Descriptor Wallets use different mechanisms for storing and importing scripts and keys
76+
the existing import RPCs have been disabled for descriptor wallets.
77+
New export RPCs for Descriptor Wallets have not yet been added.
78+
79+
The following RPCs are disabled for Descriptor Wallets:
80+
81+
* importprivkey
82+
* importpubkey
83+
* importaddress
84+
* importwallet
85+
* dumpprivkey
86+
* dumpwallet
87+
* importmulti
88+
* addmultisigaddress
89+
* sethdseed
90+
91+
#### Watchonly Wallets
92+
93+
A Legacy Wallet contains both private keys and scripts that were being watched.
94+
Those watched scripts would not contribute to your normal balance. In order to see the watchonly
95+
balance and to use watchonly things in transactions, an `include_watchonly` option was added
96+
to many RPCs that would allow users to do that. However it is easy to forget to include this option.
97+
98+
Descriptor Wallets move to a per-wallet watchonly model. Instead an entire wallet is considered to be
99+
watchonly depending on whether it was created with private keys disabled. This eliminates the need
100+
to distinguish between things that are watchonly and things that are not within a wallet itself.
101+
102+
This change does have a caveat. If a Descriptor Wallet with private keys *enabled* has
103+
a multiple key descriptor without all of the private keys (e.g. `multi(...)` with only one private key),
104+
then the wallet will fail to sign and broadcast transactions. Such wallets would need to use the PSBT
105+
workflow but the typical GUI Send, `sendtoaddress`, etc. workflows would still be available, just
106+
non-functional.
107+
108+
This issue is worsened if the wallet contains both single key (e.g. `wpkh(...)`) descriptors and such
109+
multiple key descriptors as some transactions could be signed and broadast and others not. This is
110+
due to some transactions containing only single key inputs, while others would contain both single
111+
key and multiple key inputs, depending on which are available and how the coin selection algorithm
112+
selects inputs. However this is not considered to be a supported use case; multisigs
113+
should be in their own wallets which do not already have descriptors. Although users cannot export
114+
descriptors with private keys for now as explained earlier.
115+
116+
#### BIP 44/49/84 Support
117+
118+
The change to using descriptors changes the default derivation paths used by Bitcoin Core
119+
to adhere to BIP 44/49/84. Descriptors with different derivation paths can be imported without
120+
issue.

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
27262726
}
27272727
if (!request.params[5].isNull() && request.params[5].get_bool()) {
27282728
flags |= WALLET_FLAG_DESCRIPTORS;
2729+
warnings.emplace_back(Untranslated("Wallet is an experimental descriptor wallet"));
27292730
}
27302731

27312732
bilingual_str error;

src/wallet/scriptpubkeyman.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ std::set<CKeyID> LegacyScriptPubKeyMan::GetKeys() const
15771577
return set_address;
15781578
}
15791579

1580-
void LegacyScriptPubKeyMan::SetType(OutputType type, bool internal) {}
1580+
void LegacyScriptPubKeyMan::SetInternal(bool internal) {}
15811581

15821582
bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDestination& dest, std::string& error)
15831583
{
@@ -1589,7 +1589,9 @@ bool DescriptorScriptPubKeyMan::GetNewDestination(const OutputType type, CTxDest
15891589
{
15901590
LOCK(cs_desc_man);
15911591
assert(m_wallet_descriptor.descriptor->IsSingleType()); // This is a combo descriptor which should not be an active descriptor
1592-
if (type != m_address_type) {
1592+
Optional<OutputType> desc_addr_type = m_wallet_descriptor.descriptor->GetOutputType();
1593+
assert(desc_addr_type);
1594+
if (type != *desc_addr_type) {
15931595
throw std::runtime_error(std::string(__func__) + ": Types are inconsistent");
15941596
}
15951597

@@ -1857,7 +1859,7 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const
18571859
}
18581860
}
18591861

1860-
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key)
1862+
bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type)
18611863
{
18621864
LOCK(cs_desc_man);
18631865
assert(m_storage.IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
@@ -1874,7 +1876,7 @@ bool DescriptorScriptPubKeyMan::SetupDescriptorGeneration(const CExtKey& master_
18741876
// Build descriptor string
18751877
std::string desc_prefix;
18761878
std::string desc_suffix = "/*)";
1877-
switch (m_address_type) {
1879+
switch (addr_type) {
18781880
case OutputType::LEGACY: {
18791881
desc_prefix = "pkh(" + xpub + "/44'";
18801882
break;
@@ -2156,9 +2158,8 @@ uint256 DescriptorScriptPubKeyMan::GetID() const
21562158
return id;
21572159
}
21582160

2159-
void DescriptorScriptPubKeyMan::SetType(OutputType type, bool internal)
2161+
void DescriptorScriptPubKeyMan::SetInternal(bool internal)
21602162
{
2161-
this->m_address_type = type;
21622163
this->m_internal = internal;
21632164
}
21642165

src/wallet/scriptpubkeyman.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class ScriptPubKeyMan
237237

238238
virtual uint256 GetID() const { return uint256(); }
239239

240-
virtual void SetType(OutputType type, bool internal) {}
240+
virtual void SetInternal(bool internal) {}
241241

242242
/** Prepends the wallet name in logging output to ease debugging in multi-wallet use cases */
243243
template<typename... Params>
@@ -396,7 +396,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
396396

397397
uint256 GetID() const override;
398398

399-
void SetType(OutputType type, bool internal) override;
399+
void SetInternal(bool internal) override;
400400

401401
// Map from Key ID to key metadata.
402402
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
@@ -524,14 +524,11 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
524524
PubKeyMap m_map_pubkeys GUARDED_BY(cs_desc_man);
525525
int32_t m_max_cached_index = -1;
526526

527-
OutputType m_address_type;
528527
bool m_internal = false;
529528

530529
KeyMap m_map_keys GUARDED_BY(cs_desc_man);
531530
CryptedKeyMap m_map_crypted_keys GUARDED_BY(cs_desc_man);
532531

533-
bool SetCrypted();
534-
535532
//! keeps track of whether Unlock has run a thorough check before
536533
bool m_decryption_thoroughly_checked = false;
537534

@@ -551,9 +548,9 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
551548
: ScriptPubKeyMan(storage),
552549
m_wallet_descriptor(descriptor)
553550
{}
554-
DescriptorScriptPubKeyMan(WalletStorage& storage, OutputType address_type, bool internal)
551+
DescriptorScriptPubKeyMan(WalletStorage& storage, bool internal)
555552
: ScriptPubKeyMan(storage),
556-
m_address_type(address_type), m_internal(internal)
553+
m_internal(internal)
557554
{}
558555

559556
mutable RecursiveMutex cs_desc_man;
@@ -578,7 +575,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
578575
bool IsHDEnabled() const override;
579576

580577
//! Setup descriptors based on the given CExtkey
581-
bool SetupDescriptorGeneration(const CExtKey& master_key);
578+
bool SetupDescriptorGeneration(const CExtKey& master_key, OutputType addr_type);
582579

583580
bool HavePrivateKeys() const override;
584581

@@ -602,7 +599,7 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
602599

603600
uint256 GetID() const override;
604601

605-
void SetType(OutputType type, bool internal) override;
602+
void SetInternal(bool internal) override;
606603

607604
void SetCache(const DescriptorCache& cache);
608605

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4362,7 +4362,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
43624362

43634363
for (bool internal : {false, true}) {
43644364
for (OutputType t : OUTPUT_TYPES) {
4365-
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, t, internal));
4365+
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, internal));
43664366
if (IsCrypted()) {
43674367
if (IsLocked()) {
43684368
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
@@ -4371,7 +4371,7 @@ void CWallet::SetupDescriptorScriptPubKeyMans()
43714371
throw std::runtime_error(std::string(__func__) + ": Could not encrypt new descriptors");
43724372
}
43734373
}
4374-
spk_manager->SetupDescriptorGeneration(master_key);
4374+
spk_manager->SetupDescriptorGeneration(master_key, t);
43754375
uint256 id = spk_manager->GetID();
43764376
m_spk_managers[id] = std::move(spk_manager);
43774377
SetActiveScriptPubKeyMan(id, t, internal);
@@ -4384,7 +4384,7 @@ void CWallet::SetActiveScriptPubKeyMan(uint256 id, OutputType type, bool interna
43844384
WalletLogPrintf("Setting spkMan to active: id = %s, type = %d, internal = %d\n", id.ToString(), static_cast<int>(type), static_cast<int>(internal));
43854385
auto& spk_mans = internal ? m_internal_spk_managers : m_external_spk_managers;
43864386
auto spk_man = m_spk_managers.at(id).get();
4387-
spk_man->SetType(type, internal);
4387+
spk_man->SetInternal(internal);
43884388
spk_mans[type] = spk_man;
43894389

43904390
if (!memonly) {

0 commit comments

Comments
 (0)