Skip to content

Commit bd0f413

Browse files
committed
Reduce unnecessary hashing in signrawtransaction
1 parent 6ff2c8d commit bd0f413

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
@@ -743,6 +743,9 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
743743
// Script verification errors
744744
UniValue vErrors(UniValue::VARR);
745745

746+
// Use CTransaction for the constant parts of the
747+
// transaction to avoid rehashing.
748+
const CTransaction txConst(mergedTx);
746749
// Sign what we can:
747750
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
748751
CTxIn& txin = mergedTx.vin[i];
@@ -760,10 +763,10 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
760763

761764
// ... and merge in other signatures:
762765
BOOST_FOREACH(const CMutableTransaction& txv, txVariants) {
763-
txin.scriptSig = CombineSignatures(prevPubKey, mergedTx, i, txin.scriptSig, txv.vin[i].scriptSig);
766+
txin.scriptSig = CombineSignatures(prevPubKey, txConst, i, txin.scriptSig, txv.vin[i].scriptSig);
764767
}
765768
ScriptError serror = SCRIPT_ERR_OK;
766-
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, MutableTransactionSignatureChecker(&mergedTx, i), &serror)) {
769+
if (!VerifyScript(txin.scriptSig, prevPubKey, STANDARD_SCRIPT_VERIFY_FLAGS, TransactionSignatureChecker(&txConst, i), &serror)) {
767770
TxInErrorToJSON(txin, vErrors, ScriptErrorString(serror));
768771
}
769772
}

0 commit comments

Comments
 (0)