Skip to content

Commit cbb5f3a

Browse files
committed
Merge #19836: rpc: Properly deserialize txs with witness before signing
3333077 rpc: Adjust witness-tx deserialize error message (MarcoFalke) cccc752 rpc: Properly deserialize txs with witness before signing (MarcoFalke) Pull request description: Signing a transaction can only happen when the transaction has inputs. A transaction with inputs can always be deserialized as witness-transaction. If `try_no_witness` decoding is attempted, this will lead to rare intermittent failures. Fixes #18803 ACKs for top commit: achow101: ACK 3333077 ajtowns: ACK 3333077 Tree-SHA512: 73f8a5cdfe03fb0e68908d2fa09752c346406f455694a020ec0dd1267ef8f0a583b8e84063ea74aac127106dd193b72623ca6d81469a94b3f5b3c766ebf2c42b
2 parents 9ad7cd2 + 3333077 commit cbb5f3a

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

src/rpc/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static RPCHelpMan generateblock()
352352
txs.push_back(MakeTransactionRef(std::move(mtx)));
353353

354354
} else {
355-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("Transaction decode failed for %s", str));
355+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("Transaction decode failed for %s. Make sure the tx has at least one input.", str));
356356
}
357357
}
358358

src/rpc/rawtransaction.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,8 @@ static RPCHelpMan combinerawtransaction()
656656
std::vector<CMutableTransaction> txVariants(txs.size());
657657

658658
for (unsigned int idx = 0; idx < txs.size(); idx++) {
659-
if (!DecodeHexTx(txVariants[idx], txs[idx].get_str(), true)) {
660-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed for tx %d", idx));
659+
if (!DecodeHexTx(txVariants[idx], txs[idx].get_str())) {
660+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed for tx %d. Make sure the tx has at least one input.", idx));
661661
}
662662
}
663663

@@ -780,8 +780,8 @@ static RPCHelpMan signrawtransactionwithkey()
780780
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VARR, UniValue::VSTR}, true);
781781

782782
CMutableTransaction mtx;
783-
if (!DecodeHexTx(mtx, request.params[0].get_str(), true)) {
784-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
783+
if (!DecodeHexTx(mtx, request.params[0].get_str())) {
784+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
785785
}
786786

787787
FillableSigningProvider keystore;
@@ -847,10 +847,10 @@ static RPCHelpMan sendrawtransaction()
847847
UniValueType(), // VNUM or VSTR, checked inside AmountFromValue()
848848
});
849849

850-
// parse hex string from parameter
851850
CMutableTransaction mtx;
852-
if (!DecodeHexTx(mtx, request.params[0].get_str()))
853-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
851+
if (!DecodeHexTx(mtx, request.params[0].get_str())) {
852+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
853+
}
854854
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
855855

856856
const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
@@ -928,7 +928,7 @@ static RPCHelpMan testmempoolaccept()
928928

929929
CMutableTransaction mtx;
930930
if (!DecodeHexTx(mtx, request.params[0].get_array()[0].get_str())) {
931-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
931+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
932932
}
933933
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
934934
const uint256& tx_hash = tx->GetHash();

src/wallet/rpcdump.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ RPCHelpMan importprunedfunds()
340340
CWallet* const pwallet = wallet.get();
341341

342342
CMutableTransaction tx;
343-
if (!DecodeHexTx(tx, request.params[0].get_str()))
344-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
343+
if (!DecodeHexTx(tx, request.params[0].get_str())) {
344+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
345+
}
345346
uint256 hashTx = tx.GetHash();
346347

347348
CDataStream ssMB(ParseHexV(request.params[1], "proof"), SER_NETWORK, PROTOCOL_VERSION);

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,8 +3331,8 @@ RPCHelpMan signrawtransactionwithwallet()
33313331
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true);
33323332

33333333
CMutableTransaction mtx;
3334-
if (!DecodeHexTx(mtx, request.params[0].get_str(), true)) {
3335-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
3334+
if (!DecodeHexTx(mtx, request.params[0].get_str())) {
3335+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
33363336
}
33373337

33383338
// Sign the transaction

0 commit comments

Comments
 (0)