-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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
eth/protocols/snap: speed up hash checks #22023
Conversation
eth/protocols/snap/sync.go
Outdated
hasher := sha3.NewLegacyKeccak256() | ||
|
||
hasher := sha3.NewLegacyKeccak256().(crypto.KeccakState) | ||
var hash = make([]byte, 32) |
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.
hash := make([]byte, 32)
, Go usually either uses var
for the default value or :=
for non defaults. Pls also add a newline after this.
Pls update the others too.
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.
Squashfixed
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.
SGTM
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.
formatting change; lgtm
This PR optimises the hashing a bit during the snap response verification. We use a
hash
only temporarily, to verify against the request, and can thus reuse the same buffer, and avoid an alloc and copy. We can also use thekeccatState
to avoid a second alloc+copy viaRead
instead ofSum
.Benchmark for checking
10K
items with 100 bytes of data each: