-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Pure HashAndNibblize
function
#13453
Conversation
erigon-lib/commitment/commitment.go
Outdated
@@ -138,7 +138,7 @@ func InitializeTrieAndUpdates(tv TrieVariant, mode Mode, tmpdir string) (Trie, * | |||
default: | |||
|
|||
trie := NewHexPatriciaHashed(length.Addr, nil, tmpdir) | |||
tree := NewUpdates(mode, tmpdir, trie.HashAndNibblizeKey) | |||
tree := NewUpdates(mode, tmpdir, HashAndNibblizeKey) |
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.
Lets specify count of nibbles per byte. Since this is for hex trie, it should be 2.
HashKeyToNibbles2
or HashKeyForHexTrie
so we could have different HashKeyFor*
. usage of this exact function is strictly bounded to preparing hex trie paths from plain keys
erigon-lib/commitment/utils.go
Outdated
@@ -0,0 +1,138 @@ | |||
package commitment |
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.
contents of file is not kind of utils but around plain key encoding back and forth. Keys.go or nibbles.go would better reflect it's contents.
erigon-lib/commitment/utils.go
Outdated
ecrypto "github.com/erigontech/erigon-lib/crypto" | ||
) | ||
|
||
// Hash the account or storage key and return the resulting hashed key in the nibblized form |
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.
update comment that this
- expects plain key
- splits each byte onto 2 nibbles => hex patricia only
erigon-lib/commitment/utils.go
Outdated
// Hash the account or storage key and return the resulting hashed key in the nibblized form | ||
func HashAndNibblizeKey(key []byte) []byte { | ||
keyLen := length.Addr | ||
if len(key) < length.Addr { |
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.
keyLen = min(a, b)
erigon-lib/commitment/utils.go
Outdated
if len(key) < length.Addr { | ||
keyLen = len(key) | ||
} | ||
compactedHashKey := ecrypto.Keccak256(key[:keyLen]) |
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.
its not compacted, it's hashedKey of address part
This PR extracts
HashAndNibblize
as a utility function, not dependent onHexPatriciaTrieHashed
.Doing some benchmark comparisons this change doesn't impact performance (in fact it looks to make an improvement).
These are the comparisons:
For 25 million keys:
hph.HashAndNibblizeKey
: 136.664sHashAndNibblizeKey
: 108.215sFor 35 million keys:
hph.HashAndNibblizeKey
: 351.598sHashAndNibblizeKey
: 326.218sFor 50 million keys:
hph.HashAndNibblizeKey
: 1055.217sHashAndNibblizeKey
: 568.075s