txscript: Optimize GetWitnessSigOpCount

This converts the GetWitnessSigOpCount function to use a combination of
raw script analysis and the new tokenizer instead of the far less
efficeint parseScript, thereby significantly optimizing the funciton.

In particular, it use the recently added countSigOpsv0 in precise mode
to avoid calling paseScript.
This commit is contained in:
Conner Fromknecht 2021-02-04 14:14:53 -08:00 committed by Olaoluwa Osuntokun
parent 26d63c61dc
commit 77863f5649
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -955,8 +955,7 @@ func getWitnessSigOps(pkScript []byte, witness wire.TxWitness) int {
len(witness) > 0:
witnessScript := witness[len(witness)-1]
pops, _ := parseScript(witnessScript)
return getSigOpCount(pops, true)
return countSigOpsV0(witnessScript, true)
}
}