Skip to content

Commit afb8f35

Browse files
fanquakePastaPastaPasta
authored andcommitted
Merge bitcoin#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 bitcoin#18803 ACKs for top commit: achow101: ACK 3333077 ajtowns: ACK 3333077 Tree-SHA512: 73f8a5cdfe03fb0e68908d2fa09752c346406f455694a020ec0dd1267ef8f0a583b8e84063ea74aac127106dd193b72623ca6d81469a94b3f5b3c766ebf2c42b
1 parent 1bd4d8d commit afb8f35

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
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 UniValue generateblock(const JSONRPCRequest& request)
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static UniValue combinerawtransaction(const JSONRPCRequest& request)
636636

637637
for (unsigned int idx = 0; idx < txs.size(); idx++) {
638638
if (!DecodeHexTx(txVariants[idx], txs[idx].get_str())) {
639-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed for tx %d", idx));
639+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, strprintf("TX decode failed for tx %d. Make sure the tx has at least one input.", idx));
640640
}
641641
}
642642

@@ -757,7 +757,7 @@ static UniValue signrawtransactionwithkey(const JSONRPCRequest& request)
757757

758758
CMutableTransaction mtx;
759759
if (!DecodeHexTx(mtx, request.params[0].get_str())) {
760-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
760+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
761761
}
762762

763763
FillableSigningProvider keystore;
@@ -823,10 +823,10 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
823823
UniValue::VBOOL
824824
});
825825

826-
// parse hex string from parameter
827826
CMutableTransaction mtx;
828-
if (!DecodeHexTx(mtx, request.params[0].get_str()))
829-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
827+
if (!DecodeHexTx(mtx, request.params[0].get_str())) {
828+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
829+
}
830830
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
831831

832832
const CFeeRate max_raw_tx_fee_rate = request.params[1].isNull() ?
@@ -898,7 +898,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
898898

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

src/wallet/rpcdump.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
298298
CWallet* const pwallet = wallet.get();
299299

300300
CMutableTransaction tx;
301-
if (!DecodeHexTx(tx, request.params[0].get_str()))
302-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
301+
if (!DecodeHexTx(tx, request.params[0].get_str())) {
302+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
303+
}
303304
uint256 hashTx = tx.GetHash();
304305
CWalletTx wtx(pwallet, MakeTransactionRef(std::move(tx)));
305306

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3464,7 +3464,7 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
34643464

34653465
CMutableTransaction mtx;
34663466
if (!DecodeHexTx(mtx, request.params[0].get_str())) {
3467-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
3467+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
34683468
}
34693469

34703470
// Sign the transaction

0 commit comments

Comments
 (0)