Merge pull request #1471 from tomt1664/fix/duplicate_solve_data

Removed duplicate solving_data for transaction funding RPCs
This commit is contained in:
Byron Hambly 2025-07-08 13:30:17 +02:00 committed by GitHub
commit 73760bae3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 56 deletions

View file

@ -113,14 +113,12 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "combinerawtransaction", 0, "txs" },
{ "fundrawtransaction", 1, "options" },
{ "fundrawtransaction", 2, "iswitness" },
{ "fundrawtransaction", 3, "solving_data" },
{ "walletcreatefundedpsbt", 0, "inputs" },
{ "walletcreatefundedpsbt", 1, "outputs" },
{ "walletcreatefundedpsbt", 2, "locktime" },
{ "walletcreatefundedpsbt", 3, "options" },
{ "walletcreatefundedpsbt", 4, "bip32derivs" },
{ "walletcreatefundedpsbt", 5, "solving_data" },
{ "walletcreatefundedpsbt", 6, "psbt_version" },
{ "walletcreatefundedpsbt", 5, "psbt_version" },
{ "walletprocesspsbt", 1, "sign" },
{ "walletprocesspsbt", 3, "bip32derivs" },
{ "walletprocesspsbt", 4, "finalize" },

View file

@ -440,7 +440,7 @@ static std::vector<RPCArg> FundTxDoc()
};
}
void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, int& change_position, const UniValue& options, CCoinControl& coinControl, const UniValue& solving_data, bool override_min_fee)
void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out, int& change_position, const UniValue& options, CCoinControl& coinControl, bool override_min_fee)
{
// Make sure the results are valid at least up to the most recent block
// the user could have gotten from another RPC command prior to now
@ -792,25 +792,6 @@ RPCHelpMan fundrawtransaction()
"This boolean should reflect whether the transaction has inputs\n"
"(e.g. fully valid, or on-chain transactions), if known by the caller."
},
{"solving_data", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "Keys and scripts needed for producing a final transaction with a dummy signature. Used for fee estimation during coin selection.\n",
{
{"pubkeys", RPCArg::Type::ARR, RPCArg::DefaultHint{"empty array"}, "A json array of public keys.\n",
{
{"pubkey", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A public key"},
},
},
{"scripts", RPCArg::Type::ARR, RPCArg::DefaultHint{"empty array"}, "A json array of scripts.\n",
{
{"script", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A script"},
},
},
{"descriptors", RPCArg::Type::ARR, RPCArg::DefaultHint{"empty array"}, "A json array of descriptors.\n",
{
{"descriptor", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A descriptor"},
},
}
}
},
},
RPCResult{
RPCResult::Type::OBJ, "", "",
@ -850,7 +831,7 @@ RPCHelpMan fundrawtransaction()
CCoinControl coin_control;
// Automatically select (additional) coins. Can be overridden by options.add_inputs.
coin_control.m_add_inputs = true;
FundTransaction(*pwallet, tx, fee, change_position, request.params[1], coin_control, request.params[3], /* override_min_fee */ true);
FundTransaction(*pwallet, tx, fee, change_position, request.params[1], coin_control, /* override_min_fee */ true);
UniValue result(UniValue::VOBJ);
result.pushKV("hex", EncodeHexTx(CTransaction(tx)));
@ -1293,12 +1274,8 @@ RPCHelpMan send()
// Automatically select coins, unless at least one is manually selected. Can
// be overridden by options.add_inputs.
coin_control.m_add_inputs = rawTx.vin.size() == 0;
UniValue solving_data = NullUniValue;
if (options.exists("solving_data")) {
solving_data = options["solving_data"].get_obj();
}
SetOptionsInputWeights(options["inputs"], options);
FundTransaction(*pwallet, rawTx, fee, change_position, options, coin_control, /* solving_data */ solving_data, /* override_min_fee */ false);
FundTransaction(*pwallet, rawTx, fee, change_position, options, coin_control, /* override_min_fee */ false);
bool add_to_wallet = true;
if (options.exists("add_to_wallet")) {
@ -1530,25 +1507,6 @@ RPCHelpMan walletcreatefundedpsbt()
FundTxDoc()),
"options"},
{"bip32derivs", RPCArg::Type::BOOL, RPCArg::Default{true}, "Include BIP 32 derivation paths for public keys if we know them"},
{"solving_data", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED_NAMED_ARG, "Keys and scripts needed for producing a final transaction with a dummy signature. Used for fee estimation during coin selection.\n",
{
{"pubkeys", RPCArg::Type::ARR, RPCArg::DefaultHint{"empty array"}, "A json array of public keys.\n",
{
{"pubkey", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A public key"},
},
},
{"scripts", RPCArg::Type::ARR, RPCArg::DefaultHint{"empty array"}, "A json array of scripts.\n",
{
{"script", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A script"},
},
},
{"descriptors", RPCArg::Type::ARR, RPCArg::DefaultHint{"empty array"}, "A json array of descriptors.\n",
{
{"descriptor", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A descriptor"},
},
}
}
},
{"psbt_version", RPCArg::Type::NUM, RPCArg::Default{2}, "The PSBT version number to use."},
},
RPCResult{
@ -1605,7 +1563,7 @@ RPCHelpMan walletcreatefundedpsbt()
// Make a blank psbt
uint32_t psbt_version = 2;
if (!request.params[6].isNull()) {
if (!request.params[5].isNull()) {
psbt_version = request.params[6].get_int();
}
if (psbt_version != 2) {
@ -1655,7 +1613,7 @@ RPCHelpMan walletcreatefundedpsbt()
}
}
SetOptionsInputWeights(request.params[0], options);
FundTransaction(wallet, rawTx, fee, change_position, options, coin_control, /* solving_data */ request.params[5], /* override_min_fee */ true);
FundTransaction(wallet, rawTx, fee, change_position, options, coin_control, /* override_min_fee */ true);
// Find an input that is ours
unsigned int blinder_index = 0;
{

View file

@ -132,8 +132,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.test_all_watched_funds()
self.test_option_feerate()
self.test_address_reuse()
# ELEMENTS: FIXME
# self.test_option_subtract_fee_from_outputs()
self.test_option_subtract_fee_from_outputs()
self.test_subtract_fee_with_presets()
self.test_transaction_too_large()
self.test_include_unsafe()
@ -1005,11 +1004,9 @@ class RawTransactionsTest(BitcoinTestFramework):
# An external input without solving data should result in an error
raw_tx = self.nodes[2].createrawtransaction([{"txid": txid, "vout": vout}], [{addr_info['unconfidential']: 20}])
# // ELEMENTS: FIXME or explain why this tx is created without exception
# assert_raises_rpc_error(-4, "Missing solving data for estimating transaction size", self.nodes[2].fundrawtransaction, raw_tx)
# But funding should work when the solving data is provided
funded_tx = self.nodes[2].fundrawtransaction(raw_tx, {}, False, {"pubkeys": [addr_info['pubkey']]})
# But funding should work when the solving data is provided (as part of options)
funded_tx = self.nodes[2].fundrawtransaction(raw_tx, {"solving_data": {"pubkeys": [addr_info['pubkey']]}}, False)
signed_tx = self.nodes[2].signrawtransactionwithwallet(funded_tx['hex'])
assert not signed_tx['complete']
signed_tx = self.nodes[0].signrawtransactionwithwallet(signed_tx['hex'])