-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
core, triedb, trie: don't track node hash in pathdb #29084
Conversation
be2c678
to
00e4971
Compare
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.
I'm not quite finished yet, but have some comments
blob := rawdb.ReadStorageTrieNode(s.db, accountHash, nil) | ||
if len(blob) != 0 && crypto.Keccak256Hash(blob) == root { |
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.
Why did you change from HasStorageTrieNode
into ReadStorageTrieNode
? Seems like you did it to avoid doing a keccak on len(blob)==0
? perhaps then that should be internalized into the rawdb methods?
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.
Originally the HasStorageTrieNode
will compare if the found node is hash-matched with the given hash. In this pull request, the hash comparison in HasStorageTrieNode
is dropped.
We use ReadStorageTrieNode
here to manually compare the hash. The new code should be logic equivalent with the old one.
696f247
to
e265743
Compare
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.
It "looks good". I have not performed any deeper testing though
The failing unit test is interesting. I can also repro it on master, but I believe the test is wrong. Will fix it. EDIT: It's a bug in test and be fixed already |
e265743
to
28badb4
Compare
Windows 386 failure
Linux 386 error
|
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.
LGTM but please figure out the failed test.
14ce134
to
2c6090e
Compare
2c6090e
to
e9be6d8
Compare
Close it in favor of #29362 |
This pull request drops the hash cache of nodes in the pathdb.
Originally, for each node tracked in pathdb, the node hash(32 bytes) is cached as well. As for each node retrieval, the found node is required to be hash-matched. The cached hash can avoid unnecessary hashing(it takes around 400ns on my laptop).
However, the cached hash increases the total memory consumption. If we say the average size of trie node is 100 byte, then the memory overhead is about 24%
32 / (100+32)
. Dropping hash cache allows us to use less memory.Besides, it also benefits for abstraction. As for the upcoming verkle, the slim format(internal node will only store the commitment of children instead of the whole children hash list) is chosen and node hash notion is kind of nuked. This change allows us to better support verkle mode.
But we have to keep in mind that this pr indeed introduces the computation overhead for each node retrieval, which is around 400ns on my laptop). The performance degradation is reflected as below, the average block execution time is increased by ~2m.
Memory wise, the held memory size is decreased for about 1GB.
More statistics can be found here https://geth-bench.ethdevops.io/d/Jpk-Be5Wk/dual-geth?orgId=1&from=now-12h&to=now