Skip to content

Conversation

@jl2012
Copy link
Contributor

@jl2012 jl2012 commented Jan 18, 2017

This saves unnecessary hash caching for non-segwit transactions, but I am not sure if the difference is noticeable.

@sdaftuar
Copy link
Member

sdaftuar commented Jan 18, 2017

Concept ACK (I vaguely recall from when we introduced PrecomputedTransactionData that it was non-negligible performance impact, I can re-check).

I'm not sure about this approach though, because SignatureHash assumes that if the cache passed in is non-NULL, then the precomputed hashes are correct, which will no longer be necessarily true.

In particular, if we wrote signing code that tried to use PrecomputedTransactionData to cache the hashes ahead of time for re-use, then I think this code would break (as the witnesses would all be NULL before the signatures are added, right?) So I think I'd prefer an approach that was easier to reason about...

@jl2012
Copy link
Contributor Author

jl2012 commented Jan 19, 2017

@sdaftuar added a bool to indicate whether the cache is ready so it becomes fail-safe. If we want to use the cache in signing code (which is currently not), an argument could be added to PrecomputedTransactionData::PrecomputedTransactionData to request for that.

@jl2012
Copy link
Contributor Author

jl2012 commented Jan 19, 2017

And I believe it's non-negligible. Assuming a block is full of non-witness txs (which all currently are), around 0.35MB of hashing is needed. For 100,000 blocks that'd be 35GB, which should take a few minutes at least.

@gmaxwell
Copy link
Contributor

Concept ACK. Probably the most important performance measure is connectTip latency at runtime, and I think this could quite possibly dominate that figure.

@sipa
Copy link
Member

sipa commented Apr 9, 2017

utACK 0da49b5

@jl2012
Copy link
Contributor Author

jl2012 commented Sep 25, 2017

@sdaftuar @gmaxwell does it look ok?

@sdaftuar
Copy link
Member

utACK

@TheBlueMatt
Copy link
Contributor

utACK 0da49b5 (in the future we really need to figure out a way to move this into our CTransactionRef stuff so that this gets calculated once upon mempool-add and then not recalculated when we get a block containing the same transaction).

@theuni
Copy link
Member

theuni commented Oct 4, 2017

I'd be a little more comfortable with this if PrecomputedTransactionData were passed around as const, so nobody's tempted to mess with "ready" for some crazy reason. But that can always be done later.

utACK 0da49b5

@laanwj
Copy link
Member

laanwj commented Oct 5, 2017

Looks correct to me, utACK 0da49b5

@laanwj laanwj merged commit 0da49b5 into bitcoin:master Oct 5, 2017
laanwj added a commit that referenced this pull request Oct 5, 2017
0da49b5 Skip precompute sighash for transactions without witness (Johnson Lau)

Pull request description:

  This saves unnecessary hash caching for non-segwit transactions, but I am not sure if the difference is noticeable.

Tree-SHA512: 5cd733a729a52a45781510b3572b26e76837a94155caa14311c6d23a27a12e9613ff278dfc2592e21f640202782f22c5ad00fca85c4de5efacaa617c48ccb08d
@sipa
Copy link
Member

sipa commented Oct 5, 2017

utACK 0da49b5

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants