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

Waste less memory if sighash optimizations are on #171

Merged
merged 1 commit into from May 16, 2016

Conversation

cjepson
Copy link
Contributor

@cjepson cjepson commented May 13, 2016

Legacy transaction deep copy code mandated by the Bitcoin protocol
caused large amounts of data to be copied needlessly. If the
optimization for SigHashAll is set in chaincfg/params.go, these
extra copies are avoided by directly writing the pkScript and
decorations to a buffer and then hashing to get a witness hash,
while using the cached hash for the prefix.

Fixes #126.

@alexlyp
Copy link
Member

alexlyp commented May 16, 2016

tACK on simnet

tx *wire.MsgTx, idx int) (chainhash.Hash, error) {
var buf bytes.Buffer
if hashType&sigHashMask != SigHashAllValue {
binary.Write(&buf, binary.LittleEndian,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid binary.Write, especially since this is supposed to be an optimized hot path. Call the methods on binary.LittleEndian instead.

@cjepson
Copy link
Contributor Author

cjepson commented May 16, 2016

@alexlyp Please turn on the optimization in chaincfg/params.go and then sync mainnet and testnet too

@alexlyp
Copy link
Member

alexlyp commented May 16, 2016

with optimization = true sync on testnet and mainnet went fine

Legacy transaction deep copy code mandated by the Bitcoin protocol
caused large amounts of data to be copied needlessly. If the
optimization for SigHashAll is set in chaincfg/params.go, these
extra copies are avoided by directly writing the pkScript and
decorations to a buffer and then hashing to get a witness hash,
while using the cached hash for the prefix.

Fixes btcsuite#126.
@alexlyp alexlyp merged commit 653e13d into decred:master May 16, 2016
@jcvernaleo jcvernaleo added this to the v0.1.4 milestone May 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skip the extra tx.Copy() when calculating the signature hash
4 participants