Skip to content

Commit 146be9f

Browse files
Merge dashpay#6003: feat: support rpc protx-register for descriptor wallets - part VI
a33dcb3 fix: CheckWalletOwnsScript/CheckWalletOwnsKey to use wallet instead of SPK (Konstantin Akimov) b2ede8b feat: update list of tests that still doesn't support descriptor wallets (Konstantin Akimov) 838d06f feat: enable descriptor wallets for more tests (Konstantin Akimov) 5ab108c feat: implementation of RPC 'protx register' for descriptor wallets (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Many rpc such as `protx register` uses forcely LegacyScriptPubKeyMan instead using CWallet's interface. It causes a failures such as ``` test_framework.authproxy.JSONRPCException: This type of wallet does not support this command (-4) ``` for all functional tests that uses Masternodes/evo nodes. See dashpay/dash-issues#59 to track progress ## What was done? Some direct usages of LegacyScriptPubKeyMan refactored to use CWallet's functionality. There are still 4 functional tests that doesn't work for descriptor wallets: - feature_dip3_deterministicmns.py (no rpc `protx updateregistar`) - feature_governance.py: no rpc for `governance votemany` and `governance votealias` - interface_zmq_dash.py (see governance) That's part I of changes, other changes are not PR-ready yet, WIP. ## How Has This Been Tested? Firstly, the flag `--legacy-wallets` are removed for many functional tests. Secondly, the flag `--descriptors` is inverted in default value: ``` diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 585a6a7..9ad5fd1 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -242,10 +242,10 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): if self.options.descriptors is None: # Prefer BDB unless it isn't available - if self.is_bdb_compiled(): - self.options.descriptors = False - elif self.is_sqlite_compiled(): + if self.is_sqlite_compiled(): self.options.descriptors = True + elif self.is_bdb_compiled(): + self.options.descriptors = False else: # If neither are compiled, tests requiring a wallet will be skipped and the value of self.options.descriptors won't matter # It still needs to exist and be None in order for tests to work however. ``` ## Breaking Changes N/A, descriptor wallets have not been publicly released yet ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: PastaPastaPasta: utACK a33dcb3 Tree-SHA512: 24e22ac91e30a3804d1ac9af864eb9d073208bbb6d1f3326c7f0438f3ccce2b553aa46450989e48cb5c6e0d838ff1c88c6522f195e7aa2bd89342710f3ecef77
2 parents 806fc73 + a33dcb3 commit 146be9f

File tree

2 files changed

+43
-55
lines changed

2 files changed

+43
-55
lines changed

src/rpc/evo.cpp

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -776,18 +776,23 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
776776
ret.pushKV("signMessage", ptx.MakeSignString());
777777
return ret;
778778
} else {
779-
// lets prove we own the collateral
780-
// TODO: make collateral works with Descriptor wallets too
781-
const LegacyScriptPubKeyMan* spk_man = wallet->GetLegacyScriptPubKeyMan();
782-
if (!spk_man) {
783-
throw JSONRPCError(RPC_WALLET_ERROR, "This type of wallet does not support this command");
784-
}
785-
786-
CKey key;
787-
if (!spk_man->GetKey(ToKeyID(*pkhash), key)) {
788-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("collateral key not in wallet: %s", EncodeDestination(txDest)));
789-
}
790-
SignSpecialTxPayloadByString(tx, ptx, key);
779+
{
780+
LOCK(wallet->cs_wallet);
781+
// lets prove we own the collateral
782+
CScript scriptPubKey = GetScriptForDestination(txDest);
783+
std::unique_ptr<SigningProvider> provider = wallet->GetSolvingProvider(scriptPubKey);
784+
785+
std::string signed_payload;
786+
SigningResult err = wallet->SignMessage(ptx.MakeSignString(), *pkhash, signed_payload);
787+
if (err == SigningResult::SIGNING_FAILED) {
788+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, SigningResultString(err));
789+
} else if (err != SigningResult::OK){
790+
throw JSONRPCError(RPC_WALLET_ERROR, SigningResultString(err));
791+
}
792+
bool invalid = false;
793+
ptx.vchSig = DecodeBase64(signed_payload.c_str(), &invalid);
794+
if (invalid) throw JSONRPCError(RPC_INTERNAL_ERROR, "failed to decode base64 ready signature for protx");
795+
} // cs_wallet
791796
SetTxPayload(tx, ptx);
792797
return SignAndSendSpecialTx(request, chain_helper, chainman, tx, fSubmit);
793798
}
@@ -1259,33 +1264,15 @@ static void protx_list_help(const JSONRPCRequest& request)
12591264
}
12601265

12611266
#ifdef ENABLE_WALLET
1262-
static bool CheckWalletOwnsKey(const CWallet* const pwallet, const CKeyID& keyID) {
1263-
if (!pwallet) {
1264-
return false;
1265-
}
1266-
const LegacyScriptPubKeyMan* const spk_man = pwallet->GetLegacyScriptPubKeyMan();
1267-
if (!spk_man) {
1268-
return false;
1269-
}
1270-
return spk_man->HaveKey(keyID);
1271-
}
1272-
12731267
static bool CheckWalletOwnsScript(const CWallet* const pwallet, const CScript& script) {
12741268
if (!pwallet) {
12751269
return false;
12761270
}
1277-
const LegacyScriptPubKeyMan* const spk_man = pwallet->GetLegacyScriptPubKeyMan();
1278-
if (!spk_man) {
1279-
return false;
1280-
}
1271+
return WITH_LOCK(pwallet->cs_wallet, return pwallet->IsMine(script)) == isminetype::ISMINE_SPENDABLE;
1272+
}
12811273

1282-
CTxDestination dest;
1283-
if (ExtractDestination(script, dest)) {
1284-
if ((std::get_if<PKHash>(&dest) && spk_man->HaveKey(ToKeyID(*std::get_if<PKHash>(&dest)))) || (std::get_if<ScriptHash>(&dest) && spk_man->HaveCScript(CScriptID{ScriptHash(*std::get_if<ScriptHash>(&dest))}))) {
1285-
return true;
1286-
}
1287-
}
1288-
return false;
1274+
static bool CheckWalletOwnsKey(const CWallet* const pwallet, const CKeyID& keyID) {
1275+
return CheckWalletOwnsScript(pwallet, GetScriptForDestination(PKHash(keyID)));
12891276
}
12901277
#endif
12911278

test/functional/test_runner.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
# Scripts that are run by default.
9494
# Longest test should go first, to favor running tests in parallel
9595
'feature_dip3_deterministicmns.py --legacy-wallet', # NOTE: needs dash_hash to pass
96-
'feature_llmq_data_recovery.py --legacy-wallet',
96+
'feature_llmq_data_recovery.py',
9797
'wallet_hd.py --legacy-wallet',
9898
'wallet_hd.py --descriptors',
9999
'wallet_backup.py --legacy-wallet',
@@ -105,9 +105,9 @@
105105
'rpc_fundrawtransaction.py --legacy-wallet',
106106
'rpc_fundrawtransaction.py --legacy-wallet --nohd',
107107
'rpc_fundrawtransaction.py --descriptors',
108-
'p2p_quorum_data.py --legacy-wallet',
108+
'p2p_quorum_data.py',
109109
# vv Tests less than 2m vv
110-
'p2p_instantsend.py --legacy-wallet',
110+
'p2p_instantsend.py',
111111
'wallet_basic.py --legacy-wallet',
112112
'wallet_basic.py --descriptors',
113113
'wallet_labels.py --legacy-wallet',
@@ -120,20 +120,20 @@
120120
'wallet_listtransactions.py --legacy-wallet',
121121
'wallet_listtransactions.py --descriptors',
122122
'feature_multikeysporks.py',
123-
'feature_dip3_v19.py --legacy-wallet',
124-
'feature_llmq_signing.py --legacy-wallet', # NOTE: needs dash_hash to pass
125-
'feature_llmq_signing.py --spork21 --legacy-wallet', # NOTE: needs dash_hash to pass
126-
'feature_llmq_chainlocks.py --legacy-wallet', # NOTE: needs dash_hash to pass
127-
'feature_llmq_rotation.py --legacy-wallet', # NOTE: needs dash_hash to pass
128-
'feature_llmq_connections.py --legacy-wallet', # NOTE: needs dash_hash to pass
129-
'feature_llmq_evo.py --legacy-wallet', # NOTE: needs dash_hash to pass
130-
'feature_llmq_simplepose.py --legacy-wallet', # NOTE: needs dash_hash to pass
131-
'feature_llmq_is_cl_conflicts.py --legacy-wallet', # NOTE: needs dash_hash to pass
132-
'feature_llmq_is_retroactive.py --legacy-wallet', # NOTE: needs dash_hash to pass
133-
'feature_llmq_dkgerrors.py --legacy-wallet', # NOTE: needs dash_hash to pass
134-
'feature_dip4_coinbasemerkleroots.py --legacy-wallet', # NOTE: needs dash_hash to pass
135-
'feature_asset_locks.py --legacy-wallet', # NOTE: needs dash_hash to pass
136-
'feature_mnehf.py --legacy-wallet', # NOTE: needs dash_hash to pass
123+
'feature_dip3_v19.py',
124+
'feature_llmq_signing.py', # NOTE: needs dash_hash to pass
125+
'feature_llmq_signing.py --spork21', # NOTE: needs dash_hash to pass
126+
'feature_llmq_chainlocks.py', # NOTE: needs dash_hash to pass
127+
'feature_llmq_rotation.py', # NOTE: needs dash_hash to pass
128+
'feature_llmq_connections.py', # NOTE: needs dash_hash to pass
129+
'feature_llmq_evo.py', # NOTE: needs dash_hash to pass
130+
'feature_llmq_simplepose.py', # NOTE: needs dash_hash to pass
131+
'feature_llmq_is_cl_conflicts.py', # NOTE: needs dash_hash to pass
132+
'feature_llmq_is_retroactive.py', # NOTE: needs dash_hash to pass
133+
'feature_llmq_dkgerrors.py', # NOTE: needs dash_hash to pass
134+
'feature_dip4_coinbasemerkleroots.py', # NOTE: needs dash_hash to pass
135+
'feature_asset_locks.py', # NOTE: needs dash_hash to pass
136+
'feature_mnehf.py', # NOTE: needs dash_hash to pass
137137
# vv Tests less than 60s vv
138138
'p2p_sendheaders.py', # NOTE: needs dash_hash to pass
139139
'p2p_sendheaders_compressed.py', # NOTE: needs dash_hash to pass
@@ -151,6 +151,7 @@
151151
'feature_abortnode.py',
152152
# vv Tests less than 30s vv
153153
'rpc_quorum.py --legacy-wallet',
154+
'rpc_quorum.py --descriptors',
154155
'wallet_keypool_topup.py --legacy-wallet',
155156
'wallet_keypool_topup.py --descriptors',
156157
'feature_fee_estimation.py',
@@ -227,7 +228,7 @@
227228
'feature_backwards_compatibility.py --legacy-wallet',
228229
'feature_backwards_compatibility.py --descriptors',
229230
'wallet_txn_clone.py --mineblock',
230-
'feature_notifications.py --legacy-wallet',
231+
'feature_notifications.py',
231232
'rpc_getblockfilter.py',
232233
'rpc_invalidateblock.py',
233234
'feature_txindex.py',
@@ -290,10 +291,10 @@
290291
'p2p_unrequested_blocks.py', # NOTE: needs dash_hash to pass
291292
'feature_shutdown.py',
292293
'rpc_coinjoin.py',
293-
'rpc_masternode.py --legacy-wallet',
294+
'rpc_masternode.py',
294295
'rpc_mnauth.py',
295-
'rpc_verifyislock.py --legacy-wallet',
296-
'rpc_verifychainlock.py --legacy-wallet',
296+
'rpc_verifyislock.py',
297+
'rpc_verifychainlock.py',
297298
'wallet_create_tx.py --legacy-wallet',
298299
'wallet_send.py --legacy-wallet',
299300
'wallet_send.py --descriptors',

0 commit comments

Comments
 (0)