Skip to content

Commit daf044a

Browse files
committed
Reduce unnecessary hashing in signrawtransaction
Coming from btc@bd0f41387783ee91623d7fac15e89e57db37df82
1 parent 5fcad0c commit daf044a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,9 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
734734
// Script verification errors
735735
UniValue vErrors(UniValue::VARR);
736736

737+
// Use CTransaction for the constant parts of the
738+
// transaction to avoid rehashing.
739+
const CTransaction txConst(mergedTx);
737740
// Sign what we can:
738741
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
739742
CTxIn& txin = mergedTx.vin[i];
@@ -767,10 +770,10 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
767770

768771
// ... and merge in other signatures:
769772
for (const CMutableTransaction& txv : txVariants) {
770-
txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
773+
txin.scriptSig = CombineSignatures(prevPubKey, txConst, i, txin.scriptSig, txv.vin[i].scriptSig);
771774
}
772775
ScriptError serror = SCRIPT_ERR_OK;
773-
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker(&mergedTx, i), &serror)) {
776+
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i), &serror)) {
774777
TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror));
775778
}
776779
}

0 commit comments

Comments
 (0)