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: reduce allocations from sigop count #1380

Closed
wants to merge 4 commits into from

Conversation

cfromknecht
Copy link
Contributor

No description provided.

This commit adds a countOnly flag
to parseScriptTemplate, which will
compute the number of sigops in the
script, without allocating a slice for
parsedOpcodes or slicing data from
the script.

If an error is returned during parsing,
the number of sigops up to that point
is returned. This mimics the existing
behavior where the parsed opcodes
would be returned up to the point of
faliure, from which the sigop count is
then derived.

This reduces the need for large,
single-use memory allocations when
computing sigop counts, which otherwise
increases the gc overhead during block
validation.
Adds a isScriptHashScript which determines if
a given script is a script hash. This is used
to avoid parsing the opcodes when computing
the precise opcode count for non-bip16 p2sh
outputs, and allows us to use the more
efficient zero-alloc sigop count.
This commit adds a helper method
performing zero-alloc sigop counts.
We build on the prior changes by now
parsing the script in countOnly mode,
and returning the number of sigs.

The helper is then used in various
places where the parse opcodes were
simply discarded after getting the
sigop count.
@jakesylvestre
Copy link
Collaborator

@jcvernaleo (as per #1530)

  • Low priority
  • Enhancement

@jakesylvestre
Copy link
Collaborator

@cfromknecht do we have any gobench's related to this method?

@cfromknecht
Copy link
Contributor Author

@jakesyl closing in favor of #1684

@cfromknecht cfromknecht closed this Feb 3, 2021
@cfromknecht cfromknecht deleted the fast-sync-sig-ops branch February 3, 2021 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants