mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
txscript: Optimize multi sig redeem script func.
This converts the MultisigRedeemScriptFromScriptSig function to make use of the new finalOpcodeData function instead of the far less efficient parseScript thereby significantly optimizing the function. It also deprecates the error return since it really does not make sense given the preconditions of the function. Finally, the comment is modified to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a very large script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------ BenchmarkMultisigRedeemScript 153623 1830 -98.81% benchmark old allocs new allocs delta ------------------------------------------------------------------ BenchmarkMultisigRedeemScript 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------ BenchmarkMultisigRedeemScript 466944 0 -100.00%
This commit is contained in:
parent
b0f5561776
commit
1466a2a72d
@ -860,18 +860,24 @@ func CalcMultiSigStats(script []byte) (int, int, error) {
|
||||
return details.numPubKeys, details.requiredSigs, nil
|
||||
}
|
||||
|
||||
// MultisigRedeemScriptFromScriptSig attempts to extract a multi-
|
||||
// signature redeem script from a P2SH-redeeming input. It returns
|
||||
// nil if the signature script is not a multisignature script.
|
||||
// MultisigRedeemScriptFromScriptSig attempts to extract a multi-signature
|
||||
// redeem script from a P2SH-redeeming input. The script is expected to already
|
||||
// have been checked to be a multisignature script prior to calling this
|
||||
// function. The results are undefined for other script types.
|
||||
//
|
||||
// NOTE: This function is only valid for version 0 scripts. Since the function
|
||||
// does not accept a script version, the results are undefined for other script
|
||||
// versions.
|
||||
//
|
||||
// The error is DEPRECATED and will be removed in the major version bump.
|
||||
func MultisigRedeemScriptFromScriptSig(script []byte) ([]byte, error) {
|
||||
pops, err := parseScript(script)
|
||||
if err != nil {
|
||||
const scriptVersion = 0
|
||||
if err := checkScriptParses(scriptVersion, script); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// The redeemScript is always the last item on the stack of
|
||||
// the script sig.
|
||||
return pops[len(pops)-1].data, nil
|
||||
// The redeemScript is always the last item on the stack of the script sig.
|
||||
return finalOpcodeData(scriptVersion, script), nil
|
||||
}
|
||||
|
||||
// payToPubKeyHashScript creates a new script to pay a transaction
|
||||
|
||||
Loading…
Reference in New Issue
Block a user