bsc/eth/downloader
Martin Holst Swende db03faa10d
core, eth: improve delivery speed on header requests (#23105)
This PR reduces the amount of work we do when answering header queries, e.g. when a peer
is syncing from us.

For some items, e.g block bodies, when we read the rlp-data from database, we plug it
directly into the response package. We didn't do that for headers, but instead read
headers-rlp, decode to types.Header, and re-encode to rlp. This PR changes that to keep it
in RLP-form as much as possible. When a node is syncing from us, it typically requests 192
contiguous headers. On master it has the following effect:

- For headers not in ancient: 2 db lookups. One for translating hash->number (even though
  the request is by number), and another for reading by hash (this latter one is sometimes
  cached).
  
- For headers in ancient: 1 file lookup/syscall for translating hash->number (even though
  the request is by number), and another for reading the header itself. After this, it
  also performes a hashing of the header, to ensure that the hash is what it expected. In
  this PR, I instead move the logic for "give me a sequence of blocks" into the lower
  layers, where the database can determine how and what to read from leveldb and/or
  ancients.

There are basically four types of requests; three of them are improved this way. The
fourth, by hash going backwards, is more tricky to optimize. However, since we know that
the gap is 0, we can look up by the parentHash, and stlil shave off all the number->hash
lookups.

The gapped collection can be optimized similarly, as a follow-up, at least in three out of
four cases.

Co-authored-by: Felix Lange <fjl@twurst.com>
2021-12-07 17:50:58 +01:00
..
api.go all: remove redundant conversions and import names (#21903) 2020-11-25 21:00:23 +01:00
downloader_test.go core, eth: improve delivery speed on header requests (#23105) 2021-12-07 17:50:58 +01:00
downloader.go core, eth, les, trie: remove the sync bloom, used by fast sync 2021-12-03 12:32:41 +02:00
events.go cmd,eth: 16400 Add an option to stop geth once in sync. WIP for light mode (#17321) 2019-01-30 08:40:36 +01:00
fetchers_concurrent_bodies.go eth: pre-process downloader responses on the peer reader thread 2021-12-01 20:18:12 +02:00
fetchers_concurrent_headers.go eth: pre-process downloader responses on the peer reader thread 2021-12-01 20:18:12 +02:00
fetchers_concurrent_receipts.go eth: pre-process downloader responses on the peer reader thread 2021-12-01 20:18:12 +02:00
fetchers_concurrent.go eth: request id dispatcher and direct req/reply APIs (#23576) 2021-11-26 13:26:03 +02:00
fetchers.go eth: pre-process downloader responses on the peer reader thread 2021-12-01 20:18:12 +02:00
metrics.go eth: request id dispatcher and direct req/reply APIs (#23576) 2021-11-26 13:26:03 +02:00
modes.go eth: request id dispatcher and direct req/reply APIs (#23576) 2021-11-26 13:26:03 +02:00
peer.go eth: request id dispatcher and direct req/reply APIs (#23576) 2021-11-26 13:26:03 +02:00
queue_test.go eth: pre-process downloader responses on the peer reader thread 2021-12-01 20:18:12 +02:00
queue.go eth: pre-process downloader responses on the peer reader thread 2021-12-01 20:18:12 +02:00
resultstore.go eth/downloader: refactor downloader + queue (#21263) 2020-07-24 10:46:26 +03:00
statesync.go eth: request id dispatcher and direct req/reply APIs (#23576) 2021-11-26 13:26:03 +02:00
testchain_test.go eth: request id dispatcher and direct req/reply APIs (#23576) 2021-11-26 13:26:03 +02:00