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/rawdb: use AncientRange when initializing leveldb from freezer #23612

Merged
merged 2 commits into from Nov 23, 2021

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Sep 20, 2021

When we restore from ancients, we go through them and write the hash->number mapping into leveldb. As of a while back, we now have a methods to read ancients sequentially a lot faster.

This PR can most easily be tested by doing a geth --goerli removedb, and leave ancients intact. Then a geth --goerli --nodiscover --maxpeers 0.

The PR (in draft) contains a little self-validator, which should CRIT if the contents is not correct.

@holiman
Copy link
Contributor Author

holiman commented Sep 21, 2021

Some hands-on testing, initializing 13,178,511 mainnet hashes on my NUC.

Using master :

INFO [09-21|12:22:36.066] Initialising Ethereum protocol           network=1 dbversion=<nil>
INFO [09-21|12:22:37.257] Initializing database from freezer       total=13,178,511 number=308,563 hash=9e513e..009418 elapsed=1.000s
INFO [09-21|12:22:45.297] Initializing database from freezer       total=13,178,511 number=2,048,159 hash=6ee404..4fb8c9 elapsed=9.040s
INFO [09-21|12:22:53.310] Initializing database from freezer       total=13,178,511 number=3,558,677 hash=f17acc..b104ea elapsed=17.052s
INFO [09-21|12:23:01.324] Initializing database from freezer       total=13,178,511 number=4,979,588 hash=8dfe6c..4be0fa elapsed=25.067s
INFO [09-21|12:23:09.335] Initializing database from freezer       total=13,178,511 number=6,349,295 hash=10b6e7..6e23ca elapsed=33.078s
INFO [09-21|12:23:17.363] Initializing database from freezer       total=13,178,511 number=7,654,997 hash=db066d..71d736 elapsed=41.106s
INFO [09-21|12:23:25.363] Initializing database from freezer       total=13,178,511 number=8,954,694 hash=c144bf..c4d4a6 elapsed=49.106s
INFO [09-21|12:23:33.421] Initializing database from freezer       total=13,178,511 number=10,215,197 hash=70eaa0..5f3a9d elapsed=57.164s
INFO [09-21|12:23:41.442] Initializing database from freezer       total=13,178,511 number=11,840,924 hash=3812c0..353338 elapsed=1m5.184s
INFO [09-21|12:23:47.895] Initialized database from freezer        blocks=13,178,511 elapsed=1m11.638s

First run with this PR, with an off-by-one error I unintentionally left in:

INFO [09-21|12:14:19.050] Initialising Ethereum protocol           network=1 dbversion=<nil>
INFO [09-21|12:14:20.279] Initializing database from freezer       total=13,178,511 number=400,003 hash=49b317..801d4d elapsed=1.013s
INFO [09-21|12:14:28.610] Initializing database from freezer       total=13,178,511 number=2,400,023 hash=866b3d..1e92dc elapsed=9.344s
INFO [09-21|12:14:36.735] Initializing database from freezer       total=13,178,511 number=4,100,040 hash=cd3ea6..26b6a1 elapsed=17.469s
INFO [09-21|12:14:44.829] Initializing database from freezer       total=13,178,511 number=5,700,056 hash=ae4303..195c10 elapsed=25.563s
INFO [09-21|12:14:53.189] Initializing database from freezer       total=13,178,511 number=7,300,072 hash=f38cf6..3f48a6 elapsed=33.922s
INFO [09-21|12:15:01.193] Initializing database from freezer       total=13,178,511 number=8,800,087 hash=fc8573..63fa3c elapsed=41.927s
INFO [09-21|12:15:09.441] Initializing database from freezer       total=13,178,511 number=10,300,102 hash=8be843..c32729 elapsed=50.174s
INFO [09-21|12:15:17.598] Initializing database from freezer       total=13,178,511 number=12,400,123 hash=03e38f..dda78c elapsed=58.331s
INFO [09-21|12:15:20.940] Initialized database from freezer        blocks=13,178,511 elapsed=1m1.673s
CRIT [09-21|12:15:22.368] Missing hash->number mapping             number=100,000    err=nil

Second run, with off by one error fixed:

INFO [09-21|12:18:47.528] Initializing database from freezer       total=13,178,511 number=400,000 hash=1e77d8..38ba14 elapsed=1.005s
INFO [09-21|12:18:55.533] Initializing database from freezer       total=13,178,511 number=2,400,000 hash=4abef4..f51865 elapsed=9.009s
INFO [09-21|12:19:04.021] Initializing database from freezer       total=13,178,511 number=4,200,000 hash=bc8b36..a9c2f4 elapsed=17.498s
INFO [09-21|12:19:12.467] Initializing database from freezer       total=13,178,511 number=5,900,000 hash=ce8762..fff70c elapsed=25.944s
INFO [09-21|12:19:20.759] Initializing database from freezer       total=13,178,511 number=7,500,000 hash=6f5243..fa8665 elapsed=34.235s
INFO [09-21|12:19:28.816] Initializing database from freezer       total=13,178,511 number=9,000,000 hash=dbfa2d..bd5a72 elapsed=42.293s
INFO [09-21|12:19:37.024] Initializing database from freezer       total=13,178,511 number=10,500,000 hash=f3a719..76fdc8 elapsed=50.501s
INFO [09-21|12:19:45.192] Initializing database from freezer       total=13,178,511 number=12,700,000 hash=f4b562..b79e1a elapsed=58.669s
INFO [09-21|12:19:47.338] Initialized database from freezer        blocks=13,178,511 elapsed=1m0.815s

So, it seems to work (now), and goes from 70s to 60s.

@holiman holiman marked this pull request as ready for review October 25, 2021 14:30
@holiman
Copy link
Contributor Author

holiman commented Oct 25, 2021

Rebased, PTAL

@ethereum ethereum deleted a comment from HoneyCivik Oct 25, 2021
@holiman
Copy link
Contributor Author

holiman commented Oct 31, 2021

@rjl493456442 could you please take a look at this one?

@holiman
Copy link
Contributor Author

holiman commented Nov 5, 2021

@rjl493456442 a gentle, very soft ping in your general direction...

@holiman holiman closed this Nov 10, 2021
@holiman holiman deleted the faster_iterator branch November 10, 2021 18:32
@holiman holiman restored the faster_iterator branch November 19, 2021 09:08
@holiman
Copy link
Contributor Author

holiman commented Nov 19, 2021

I have no idea why this was closed, I must have been tired and closed/deleted the wrong PR. PTAL

@holiman holiman reopened this Nov 19, 2021
core/rawdb/chain_iterator.go Show resolved Hide resolved
@rjl493456442
Copy link
Member

Sorry, I didn't check the message at all. I will check it.

Copy link
Member

@rjl493456442 rjl493456442 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman added this to the 1.10.13 milestone Nov 23, 2021
@holiman holiman merged commit 347c37b into ethereum:master Nov 23, 2021
sidhujag pushed a commit to syscoin/go-ethereum that referenced this pull request Nov 23, 2021
…thereum#23612)

* core/rawdb: utilize AncientRange when initiating from freezer

* core/rawdb: remove debug sanity check
yongjun925 pushed a commit to DODOEX/go-ethereum that referenced this pull request Dec 3, 2022
…thereum#23612)

* core/rawdb: utilize AncientRange when initiating from freezer

* core/rawdb: remove debug sanity check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants