-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
btcutil: reuse serialized tx during TxHash #2023
btcutil: reuse serialized tx during TxHash #2023
Conversation
Pull Request Test Coverage Report for Build 7284089562
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the speedup?
The speedup is resulted from the fact that the tx is never serialized. Since we receive it serialized in the block, we just hash those bytes, saving a lot of overhead during txhash calculation. It's a different optimization from #1978 and this speedup is specific to ibd. I tried to show it via cpu profiling but without the utxocache PR #1955, the speedup isn't observable because the utxo i/o is such a big bottleneck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first round to load some context. Can't really add much to the discussion whether to use this PR or #1376, other than I think this code is probably harder to reason about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, I did a once over to see if btcutil.Tx
had any cases where it was modified after using Hash
but couldn't find any. I think somebody else should also double-check just to be safe
Yeah I think that's one advtange: for block validation, things come off the wire, then go into the |
Running a combined branch for a sync test (utxo cache, this PR, and #1978), so far on my machine it's on schedule for a 6-ish hour sync (connected to One thing that still shows up is this hotspot later into the chain with full validation: Currently of the opinion that my attempt in #1376 may not be the best way to go about it, due to unintended consequences (PSBT interactions signing the long sighash, etc). Spending more time with routines like |
btcutil.Block caches the serialized raw bytes of the block during ibd. This serialized block bytes includes the serialized tx. The current tx hash generation will re-serialized the de-serialized tx to create the raw bytes and it'll only then hash that. This commit changes the code so that the re-serialization never happens, saving tons of cpu and memory overhead.
3afc77e
to
83605e4
Compare
Rebased and addressed the review comments. |
Did the final nits in #2081 |
btcutil.Block caches the serialized raw bytes of the block during ibd. This serialized block bytes includes the serialized tx. The current tx hash generation will re-serialized the de-serialized tx to create the raw bytes and it'll only then hash that.
This commit changes the code so that the re-serialization never happens, saving tons of cpu and memory overhead.