mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-29 15:29:14 +01:00
Merge #16528: Native Descriptor Wallets using DescriptorScriptPubKeyMan
223588b1bbAdd a --descriptors option to various tests (Andrew Chow)869f7ab30atests: Add RPCOverloadWrapper which overloads some disabled RPCs (Andrew Chow)cf06062859Correctly check for default wallet (Andrew Chow)886e0d75f5Implement CWallet::IsSpentKey for non-LegacySPKMans (Andrew Chow)3c19fdd2a2Return error when no ScriptPubKeyMan is available for specified type (Andrew Chow)388ba94231Change wallet_encryption.py to use signmessage instead of dumpprivkey (Andrew Chow)1346e14831Functional tests for descriptor wallets (Andrew Chow)f193ea889dadd importdescriptors RPC and tests for native descriptor wallets (Hugo Nguyen)ce24a94494Add IsLegacy to CWallet so that the GUI knows whether to show watchonly (Andrew Chow)1cb42b22b1Generate new descriptors when encrypting (Andrew Chow)82ae02b165Be able to create new wallets with DescriptorScriptPubKeyMans as backing (Andrew Chow)b713baa75aImplement GetMetadata in DescriptorScriptPubKeyMan (Andrew Chow)8b9603bd0bChange GetMetadata to use unique_ptr<CKeyMetadata> (Andrew Chow)72a9540df9Implement FillPSBT in DescriptorScriptPubKeyMan (Andrew Chow)84b4978c02Implement SignMessage for descriptor wallets (Andrew Chow)bde7c9fa38Implement SignTransaction in DescriptorScriptPubKeyMan (Andrew Chow)d50c8ddd41Implement GetSolvingProvider for DescriptorScriptPubKeyMan (Andrew Chow)f1ca5feb4aImplement GetKeypoolOldestTime and only display it if greater than 0 (Andrew Chow)586b57a9a6Implement ReturnDestination in DescriptorScriptPubKeyMan (Andrew Chow)f866957979Implement GetReservedDestination in DescriptorScriptPubKeyMan (Andrew Chow)a775f7c7fdImplement Unlock and Encrypt in DescriptorScriptPubKeyMan (Andrew Chow)bfdd073486Implement GetNewDestination for DescriptorScriptPubKeyMan (Andrew Chow)58c7651821Implement TopUp in DescriptorScriptPubKeyMan (Andrew Chow)e014886a34Implement SetupGeneration for DescriptorScriptPubKeyMan (Andrew Chow)46dfb99768Implement writing descriptorkeys, descriptorckeys, and descriptors to wallet file (Andrew Chow)4cb9b69be0Implement several simple functions in DescriptorScriptPubKeyMan (Andrew Chow)d1ec3e4f19Add IsSingleType to Descriptors (Andrew Chow)953feb3d27Implement loading of keys for DescriptorScriptPubKeyMan (Andrew Chow)2363e9fcaaLoad the descriptor cache from the wallet file (Andrew Chow)46c46aebb7Implement GetID for DescriptorScriptPubKeyMan (Andrew Chow)ec2f9e1178Implement IsHDEnabled in DescriptorScriptPubKeyMan (Andrew Chow)741122d4c1Implement MarkUnusedAddresses in DescriptorScriptPubKeyMan (Andrew Chow)2db7ca765cImplement IsMine for DescriptorScriptPubKeyMan (Andrew Chow)db7177af8cAdd LoadDescriptorScriptPubKeyMan and SetActiveScriptPubKeyMan to CWallet (Andrew Chow)78f8a92910Implement SetType in DescriptorScriptPubKeyMan (Andrew Chow)834de0300cStore WalletDescriptor in DescriptorScriptPubKeyMan (Andrew Chow)d8132669e1Add a lock cs_desc_man for DescriptorScriptPubKeyMan (Andrew Chow)3194a7f88aIntroduce WalletDescriptor class (Andrew Chow)6b13cd3fa8Create LegacyScriptPubKeyMan when not a descriptor wallet (Andrew Chow)aeac157c9dReturn nullptr from GetLegacyScriptPubKeyMan if descriptor wallet (Andrew Chow)96accc73f0Add WALLET_FLAG_DESCRIPTORS (Andrew Chow)6b8119af53Introduce DescriptorScriptPubKeyMan as a dummy class (Andrew Chow)06620302c7Introduce SetType function to tell ScriptPubKeyMans the type and internal-ness of it (Andrew Chow) Pull request description: Introducing the wallet of the glorious future (again): native descriptor wallets. With native descriptor wallets, addresses are generated from descriptors. Instead of generating keys and deriving addresses from keys, addresses come from the scriptPubKeys produced by a descriptor. Native descriptor wallets will be optional for now and can only be created by using `createwallet`. Descriptor wallets will store descriptors, master keys from the descriptor, and descriptor cache entries. Keys are derived from descriptors on the fly. In order to allow choosing different address types, 6 descriptors are needed for normal use. There is a pair of primary and change descriptors for each of the 3 address types. With the default keypool size of 1000, each descriptor has 1000 scriptPubKeys and descriptor cache entries pregenerated. This has a side effect of making wallets large since 6000 pubkeys are written to the wallet by default, instead of the current 2000. scriptPubKeys are kept only in memory and are generated every time a descriptor is loaded. By default, we use the standard BIP 44, 49, 84 derivation paths with an external and internal derivation chain for each. Descriptors can also be imported with a new `importdescriptors` RPC. Native descriptor wallets use the `ScriptPubKeyMan` interface introduced in #16341 to add a `DescriptorScriptPubKeyMan`. This defines a different IsMine which uses the simpler model of "does this scriptPubKey exist in this wallet". Furthermore, `DescriptorScriptPubKeyMan` does not have watchonly, so with native descriptor wallets, it is not possible to have a wallet with both watchonly and non-watchonly things. Rather a wallet with `disable_private_keys` needs to be used for watchonly things. A `--descriptor` option was added to some tests (`wallet_basic.py`, `wallet_encryption.py`, `wallet_keypool.py`, `wallet_keypool_topup.py`, and `wallet_labels.py`) to allow for these tests to use descriptor wallets. Additionally, several RPCs are disabled for descriptor wallets (`importprivkey`, `importpubkey`, `importaddress`, `importmulti`, `addmultisigaddress`, `dumpprivkey`, `dumpwallet`, `importwallet`, and `sethdseed`). ACKs for top commit: Sjors: utACK223588b1bb(rebased, nits addressed) jonatack: Code review re-ACK223588b1bb. fjahr: re-ACK223588b1bbinstagibbs: light re-ACK223588bmeshcollider: Code review ACK223588b1bbTree-SHA512: 59bc52aeddbb769ed5f420d5d240d8137847ac821b588eb616b34461253510c1717d6a70bab8765631738747336ae06f45ba39603ccd17f483843e5ed9a90986
This commit is contained in:
@@ -22,6 +22,7 @@ import shlex
|
||||
import sys
|
||||
|
||||
from .authproxy import JSONRPCException
|
||||
from .descriptors import descsum_create
|
||||
from .util import (
|
||||
MAX_NODES,
|
||||
append_config,
|
||||
@@ -61,7 +62,7 @@ class TestNode():
|
||||
To make things easier for the test writer, any unrecognised messages will
|
||||
be dispatched to the RPC connection."""
|
||||
|
||||
def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None):
|
||||
def __init__(self, i, datadir, *, chain, rpchost, timewait, bitcoind, bitcoin_cli, coverage_dir, cwd, extra_conf=None, extra_args=None, use_cli=False, start_perf=False, use_valgrind=False, version=None, descriptors=False):
|
||||
"""
|
||||
Kwargs:
|
||||
start_perf (bool): If True, begin profiling the node with `perf` as soon as
|
||||
@@ -79,6 +80,7 @@ class TestNode():
|
||||
self.binary = bitcoind
|
||||
self.coverage_dir = coverage_dir
|
||||
self.cwd = cwd
|
||||
self.descriptors = descriptors
|
||||
if extra_conf is not None:
|
||||
append_config(datadir, extra_conf)
|
||||
# Most callers will just need to add extra args to the standard list below.
|
||||
@@ -170,10 +172,10 @@ class TestNode():
|
||||
def __getattr__(self, name):
|
||||
"""Dispatches any unrecognised messages to the RPC connection or a CLI instance."""
|
||||
if self.use_cli:
|
||||
return getattr(self.cli, name)
|
||||
return getattr(RPCOverloadWrapper(self.cli, True, self.descriptors), name)
|
||||
else:
|
||||
assert self.rpc_connected and self.rpc is not None, self._node_msg("Error: no RPC connection")
|
||||
return getattr(self.rpc, name)
|
||||
return getattr(RPCOverloadWrapper(self.rpc, descriptors=self.descriptors), name)
|
||||
|
||||
def start(self, extra_args=None, *, cwd=None, stdout=None, stderr=None, **kwargs):
|
||||
"""Start the node."""
|
||||
@@ -265,11 +267,11 @@ class TestNode():
|
||||
|
||||
def get_wallet_rpc(self, wallet_name):
|
||||
if self.use_cli:
|
||||
return self.cli("-rpcwallet={}".format(wallet_name))
|
||||
return RPCOverloadWrapper(self.cli("-rpcwallet={}".format(wallet_name)), True, self.descriptors)
|
||||
else:
|
||||
assert self.rpc_connected and self.rpc, self._node_msg("RPC not connected")
|
||||
wallet_path = "wallet/{}".format(urllib.parse.quote(wallet_name))
|
||||
return self.rpc / wallet_path
|
||||
return RPCOverloadWrapper(self.rpc / wallet_path, descriptors=self.descriptors)
|
||||
|
||||
def stop_node(self, expected_stderr='', wait=0):
|
||||
"""Stop the node."""
|
||||
@@ -595,3 +597,118 @@ class TestNodeCLI():
|
||||
return json.loads(cli_stdout, parse_float=decimal.Decimal)
|
||||
except json.JSONDecodeError:
|
||||
return cli_stdout.rstrip("\n")
|
||||
|
||||
class RPCOverloadWrapper():
|
||||
def __init__(self, rpc, cli=False, descriptors=False):
|
||||
self.rpc = rpc
|
||||
self.is_cli = cli
|
||||
self.descriptors = descriptors
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.rpc, name)
|
||||
|
||||
def createwallet(self, wallet_name, disable_private_keys=None, blank=None, passphrase=None, avoid_reuse=None, descriptors=None):
|
||||
if self.is_cli:
|
||||
if disable_private_keys is None:
|
||||
disable_private_keys = 'null'
|
||||
if blank is None:
|
||||
blank = 'null'
|
||||
if passphrase is None:
|
||||
passphrase = ''
|
||||
if avoid_reuse is None:
|
||||
avoid_reuse = 'null'
|
||||
if descriptors is None:
|
||||
descriptors = self.descriptors
|
||||
return self.__getattr__('createwallet')(wallet_name, disable_private_keys, blank, passphrase, avoid_reuse, descriptors)
|
||||
|
||||
def importprivkey(self, privkey, label=None, rescan=None):
|
||||
wallet_info = self.getwalletinfo()
|
||||
if self.is_cli:
|
||||
if label is None:
|
||||
label = 'null'
|
||||
if rescan is None:
|
||||
rescan = 'null'
|
||||
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
|
||||
return self.__getattr__('importprivkey')(privkey, label, rescan)
|
||||
desc = descsum_create('combo(' + privkey + ')')
|
||||
req = [{
|
||||
'desc': desc,
|
||||
'timestamp': 0 if rescan else 'now',
|
||||
'label': label if label else ''
|
||||
}]
|
||||
import_res = self.importdescriptors(req)
|
||||
if not import_res[0]['success']:
|
||||
raise JSONRPCException(import_res[0]['error'])
|
||||
|
||||
def addmultisigaddress(self, nrequired, keys, label=None, address_type=None):
|
||||
wallet_info = self.getwalletinfo()
|
||||
if self.is_cli:
|
||||
if label is None:
|
||||
label = 'null'
|
||||
if address_type is None:
|
||||
address_type = 'null'
|
||||
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
|
||||
return self.__getattr__('addmultisigaddress')(nrequired, keys, label, address_type)
|
||||
cms = self.createmultisig(nrequired, keys, address_type)
|
||||
req = [{
|
||||
'desc': cms['descriptor'],
|
||||
'timestamp': 0,
|
||||
'label': label if label else ''
|
||||
}]
|
||||
import_res = self.importdescriptors(req)
|
||||
if not import_res[0]['success']:
|
||||
raise JSONRPCException(import_res[0]['error'])
|
||||
return cms
|
||||
|
||||
def importpubkey(self, pubkey, label=None, rescan=None):
|
||||
wallet_info = self.getwalletinfo()
|
||||
if self.is_cli:
|
||||
if label is None:
|
||||
label = 'null'
|
||||
if rescan is None:
|
||||
rescan = 'null'
|
||||
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
|
||||
return self.__getattr__('importpubkey')(pubkey, label, rescan)
|
||||
desc = descsum_create('combo(' + pubkey + ')')
|
||||
req = [{
|
||||
'desc': desc,
|
||||
'timestamp': 0 if rescan else 'now',
|
||||
'label': label if label else ''
|
||||
}]
|
||||
import_res = self.importdescriptors(req)
|
||||
if not import_res[0]['success']:
|
||||
raise JSONRPCException(import_res[0]['error'])
|
||||
|
||||
def importaddress(self, address, label=None, rescan=None, p2sh=None):
|
||||
wallet_info = self.getwalletinfo()
|
||||
if self.is_cli:
|
||||
if label is None:
|
||||
label = 'null'
|
||||
if rescan is None:
|
||||
rescan = 'null'
|
||||
if p2sh is None:
|
||||
p2sh = 'null'
|
||||
if 'descriptors' not in wallet_info or ('descriptors' in wallet_info and not wallet_info['descriptors']):
|
||||
return self.__getattr__('importaddress')(address, label, rescan, p2sh)
|
||||
is_hex = False
|
||||
try:
|
||||
int(address ,16)
|
||||
is_hex = True
|
||||
desc = descsum_create('raw(' + address + ')')
|
||||
except:
|
||||
desc = descsum_create('addr(' + address + ')')
|
||||
reqs = [{
|
||||
'desc': desc,
|
||||
'timestamp': 0 if rescan else 'now',
|
||||
'label': label if label else ''
|
||||
}]
|
||||
if is_hex and p2sh:
|
||||
reqs.append({
|
||||
'desc': descsum_create('p2sh(raw(' + address + '))'),
|
||||
'timestamp': 0 if rescan else 'now',
|
||||
'label': label if label else ''
|
||||
})
|
||||
import_res = self.importdescriptors(reqs)
|
||||
for res in import_res:
|
||||
if not res['success']:
|
||||
raise JSONRPCException(res['error'])
|
||||
|
||||
Reference in New Issue
Block a user