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

Profile and optimize new VM.validate_header() #910

Closed
gsalgado opened this issue Jun 13, 2018 · 8 comments
Closed

Profile and optimize new VM.validate_header() #910

gsalgado opened this issue Jun 13, 2018 · 8 comments

Comments

@gsalgado
Copy link
Contributor

That method takes 1.4s to complete when I call it passing the DAO fork header (1920000). If it takes as long to validate any header, that will be a huge problem for the light client and fast-sync

Need to profile it and optimize. Unless, of course, it's only when validating the DAO fork header that it takes that long

@carver
Copy link
Contributor

carver commented Jun 13, 2018

If 1.4s is the time to run only one test, it might be the cache generation for the PoW check. I would want to see the average time over a bunch of runs.

@gsalgado
Copy link
Contributor Author

This is some profiling data I gathered from importing ropsten blocks around 107178. Header validation (mainly pow checking) consumes a significant amount of time, but doesn't seem to be a huge deal on that range of blocks. It'd be interesting to do the same on recent blocks, with higher TD. If anybody has a fully synced light DB, this is the code I used to profile just the header importing: https://gist.github.com/gsalgado/e8e6d3e28ad7fa3db84040be551b6bce

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   398513    5.311    0.000  243.677    0.001 base_events.py:1336(_run_once)
   782090    2.972    0.000  148.824    0.000 events.py:143(_run)
    49536    0.049    0.000  119.393    0.002 lightchain.py:159(_process_announcements)
    49536    0.041    0.000  119.343    0.002 lightchain.py:230(process_announcement)
    49536    0.649    0.000  119.303    0.002 lightchain.py:246(_import_headers_from_peer)
    49536    0.327    0.000  114.036    0.002 lightchain.py:275(_validate_header)
    24768    0.268    0.000  110.345    0.004 base.py:676(validate_header)
    24768    0.194    0.000  109.906    0.004 base.py:703(validate_seal)
    24768    0.586    0.000  102.144    0.004 pow.py:55(check_pow)
    24768   98.904    0.004   98.904    0.004 {built-in method pyethash.hashimoto_light}

@carver
Copy link
Contributor

carver commented Jun 18, 2018

I heard a rumor that geth doesn't check the PoW on every header. Would be worth checking out how they do that safely.

@gsalgado
Copy link
Contributor Author

gsalgado commented Jun 20, 2018

Indeed it doesn't; I describe their approach in #330 (comment). Filed #932 for it

@gsalgado
Copy link
Contributor Author

So, as shown by the profiling data above, doing PoW validation makes light sync much slower, but it's mainly because of pyethash.hashimoto_light, which I imagine won't be easy to optimize, so I think our best bet is #932

@carver
Copy link
Contributor

carver commented Jul 10, 2018

Should we:

  1. move this issue to the following milestone, or
  2. add kth header validation to Grace Hopper

I'm currently pro 1

@gsalgado
Copy link
Contributor Author

I guess we could do both. 2 is already on its way (#1010)

@carver
Copy link
Contributor

carver commented Jul 13, 2018

With #1010 merged, this issue seems done enough to close.

@carver carver closed this as completed Jul 13, 2018
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

No branches or pull requests

2 participants