Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Feb 26, 2024

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.
截屏2024-02-27 下午2 58 20

Memory wise, the held memory size is decreased for about 1GB.
截屏2024-02-27 下午3 01 25

More statistics can be found here https://geth-bench.ethdevops.io/d/Jpk-Be5Wk/dual-geth?orgId=1&from=now-12h&to=now

@rjl493456442 rjl493456442 force-pushed the slimdown-pathdb branch 4 times, most recently from be2c678 to 00e4971 Compare February 27, 2024 03:50
@rjl493456442 rjl493456442 marked this pull request as ready for review February 27, 2024 03:50
@rjl493456442
Copy link
Member Author

More performance data is coming:

After running full sync for more than 5 days(142 hours in total), more than 13.5m blocks have been synced.
Master branch is 5 hours ahead, namely this pull request is ~3.5% slower.

截屏2024-03-04 上午10 19 13

Memory usage wise:

  • This pull request constantly uses ~800 megabytes less memory
  • Memory allocation has no difference
  • This pull request has higher GC pause
截屏2024-03-04 上午10 19 47

Copy link
Contributor

@holiman holiman left a 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

core/rawdb/accessors_trie.go Show resolved Hide resolved
Comment on lines +2207 to +2208
blob := rawdb.ReadStorageTrieNode(s.db, accountHash, nil)
if len(blob) != 0 && crypto.Keccak256Hash(blob) == root {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@holiman holiman left a 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

@rjl493456442
Copy link
Member Author

rjl493456442 commented Mar 14, 2024

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

@holiman
Copy link
Contributor

holiman commented Mar 19, 2024

Windows 386 failure

ok  	github.com/ethereum/go-ethereum/eth/protocols/eth	1.166s
--- FAIL: TestSyncNoStorageAndOneCappedPeer (0.43s)
    sync_test.go:1056: accounts: 3000, slots: 0
    sync_test.go:250: Remote side rejected our delivery: proof node (hash 75659376764002ccf460eb80ae7e9070b1defe231e2300e5241d91965adf5f5f) missing
    sync_test.go:1053: sync failed: sync cancelled
FAIL
FAIL	github.com/ethereum/go-ethereum/eth/protocols/snap	145.538s
ok  	github.com/ethereum/go-ethereum/eth/tracers	2.088s

Linux 386 error

 --- FAIL: TestSyncNoStorageAndOneCappedPeer (0.24s)
    sync_test.go:1056: accounts: 3000, slots: 0
    sync_test.go:250: Remote side rejected our delivery: proof node (hash 75659376764002ccf460eb80ae7e9070b1defe231e2300e5241d91965adf5f5f) missing
    sync_test.go:250: Remote side rejected our delivery: proof node (hash f3d5fddd9b908502006b4ea926d4b1146e6034e7e531abc91eccb24c20e5d32e) missing
    sync_test.go:250: Remote side rejected our delivery: proof node (hash 75659376764002ccf460eb80ae7e9070b1defe231e2300e5241d91965adf5f5f) missing
    sync_test.go:1053: sync failed: sync cancelled
--- FAIL: TestSyncBoundaryAccountTrie (0.28s)

Copy link
Contributor

@fjl fjl left a 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.

triedb/pathdb/reader.go Outdated Show resolved Hide resolved
@rjl493456442
Copy link
Member Author

Close it in favor of #29362

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants