From 1034a66b357483b61c368232a4df9fc40ddc45ad Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 19 Apr 2019 19:32:37 -0700 Subject: [PATCH] txscript: Optimize ExtractPkScriptAddr assume non-standard if no success This completes the process of converting the ExtractPkScriptAddr function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this cleans up the final remaining case for non-standard transactions. The method now returns NonStandardTy direclty if no other branch was taken. The following is a before and after comparison of attempting to extract pkscript addrs from a very large, non-standard script. benchmark old ns/op new ns/op delta BenchmarkExtractPkScriptAddrsLarge-8 60713 17.0 -99.97% BenchmarkExtractPkScriptAddrs-8 289 17.0 -94.12% benchmark old allocs new allocs delta BenchmarkExtractPkScriptAddrsLarge-8 1 0 -100.00% BenchmarkExtractPkScriptAddrs-8 1 0 -100.00% benchmark old bytes new bytes delta BenchmarkExtractPkScriptAddrsLarge-8 311299 0 -100.00% BenchmarkExtractPkScriptAddrs-8 768 0 -100.00% --- txscript/standard.go | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/txscript/standard.go b/txscript/standard.go index d9f8a9a3..326d14d8 100644 --- a/txscript/standard.go +++ b/txscript/standard.go @@ -908,23 +908,8 @@ func ExtractPkScriptAddrs(pkScript []byte, chainParams *chaincfg.Params) (Script return WitnessV0ScriptHashTy, addrs, 1, nil } - // Fall back to slow path. Ultimately these are intended to be replaced by - // faster variants based on the unparsed raw scripts. - - var addrs []btcutil.Address - var requiredSigs int - - scriptClass := typeOfScript(scriptVersion, pkScript) - - switch scriptClass { - case NonStandardTy: - // Don't attempt to extract addresses or required signatures for - // nonstandard transactions. - } - - // Don't attempt to extract addresses or required signatures for nonstandard - // transactions. - return scriptClass, addrs, requiredSigs, nil + // If none of the above passed, then the address must be non-standard. + return NonStandardTy, nil, 0, nil } // AtomicSwapDataPushes houses the data pushes found in atomic swap contracts.