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

consensus/clique: cache block signatures for fast checks #14545

Merged
merged 1 commit into from May 30, 2017

Conversation

Projects
None yet
3 participants
@karalabe
Member

karalabe commented May 29, 2017

Generating the signer of a clique block is non negligible as it entails an ecrecover operation. As such, it's useful to cache the recently seen block's signers to avoid paying this cost, especially when importing large batches where concurrent processing means recovering the same signer multiple times concurrently.

The original code had a cache for the signatures, but it seems it was never finished as it was left unused. This PR adds the missing piece of actually caching recovered addresses and attempting to pick the signer out from the cache before doing a heavy ecrecover.

The end result on a Nexus 5X:

E/GoLog: INFO [05-29|18:56:45] Imported new block headers   count=192 elapsed=1.206s   number=192  hash=8c570c…ba360c ignored=0
E/GoLog: INFO [05-29|18:56:46] Imported new block headers   count=192 elapsed=1.151s   number=384  hash=6d95fa…a59e49 ignored=0
E/GoLog: INFO [05-29|18:56:54] Imported new block headers   count=1344 elapsed=8.154s  number=1728 hash=7eff72…2707a2 ignored=0
E/GoLog: INFO [05-29|18:57:07] Imported new block headers   count=2048 elapsed=12.361s number=3776 hash=60862f…3bf36d ignored=0
E/GoLog: INFO [05-29|18:57:10] Imported new block headers   count=448  elapsed=2.879s  number=4224 hash=c591be…e85d53 ignored=0
E/GoLog: INFO [05-29|18:57:22] Imported new block headers   count=2048 elapsed=12.411s number=6272 hash=4d5b3a…8df378 ignored=0

old vs. new

E/GoLog: INFO [05-29|19:02:02] Imported new block headers   count=192 elapsed=632.786ms  number=192   hash=8c570c…ba360c ignored=0
E/GoLog: INFO [05-29|19:02:02] Imported new block headers   count=192 elapsed=656.589ms  number=384   hash=6d95fa…a59e49 ignored=0
E/GoLog: INFO [05-29|19:02:05] Imported new block headers   count=768 elapsed=2.519s     number=1152  hash=9d3964…5b5a49 ignored=0
E/GoLog: INFO [05-29|19:02:08] Imported new block headers   count=960 elapsed=3.219s     number=2112  hash=cc3a9a…11d37c ignored=0
E/GoLog: INFO [05-29|19:02:16] Imported new block headers   count=2048 elapsed=7.433s    number=4160  hash=9104d6…600671 ignored=0
E/GoLog: INFO [05-29|19:02:23] Imported new block headers   count=2048 elapsed=7.049s    number=6208  hash=b55e40…482572 ignored=0
E/GoLog: INFO [05-29|19:02:28] Imported new block headers   count=1280 elapsed=4.402s    number=7488  hash=add5a8…599711 ignored=0
E/GoLog: INFO [05-29|19:02:35] Imported new block headers   count=2048 elapsed=7.016s    number=9536  hash=f21589…d35ebc ignored=0

On a Zenbook Pro, a light sync from 0 to head takes about 3:20 vs 2:05 with this change.

This one's for you @ligi (I was annoyed that Walleth syncs too much :P).

@karalabe karalabe added this to the 1.6.2 milestone May 29, 2017

@ligi

This comment has been minimized.

Show comment
Hide comment
@ligi

ligi May 29, 2017

Member

YAY cool @karalabe - thanks so much!

Member

ligi commented May 29, 2017

YAY cool @karalabe - thanks so much!

@holiman

LGTM

@karalabe karalabe merged commit b0f30b0 into ethereum:master May 30, 2017

3 checks passed

commit-message-check/gitcop All commit messages are valid
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment