Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txscript: optimize IsUnspendable by removing all allocations #1375

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions txscript/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,14 +847,10 @@ func getWitnessSigOps(pkScript []byte, witness wire.TxWitness) int {
return 0
}

// IsUnspendable returns whether the passed public key script is unspendable, or
// guaranteed to fail at execution. This allows inputs to be pruned instantly
// when entering the UTXO set.
// IsUnspendable returns whether the passed public key script is unspendable,
// or guaranteed to fail at execution. This allows outputs to be pruned
// instantly when entering the UTXO set.
func IsUnspendable(pkScript []byte) bool {
pops, err := parseScript(pkScript)
if err != nil {
return true
}

return len(pops) > 0 && pops[0].opcode.value == OP_RETURN
return (len(pkScript) > 0 && pkScript[0] == OP_RETURN) ||
(len(pkScript) > MaxScriptSize)
}