• Martin Holst Swende's avatar
    core, eth: improve delivery speed on header requests (#23105) · db03faa1
    Martin Holst Swende authored
    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: 's avatarFelix Lange <fjl@twurst.com>
    db03faa1
Name
Last commit
Last update
.github Loading commit data...
accounts Loading commit data...
build Loading commit data...
cmd Loading commit data...
common Loading commit data...
consensus Loading commit data...
console Loading commit data...
contracts/checkpointoracle Loading commit data...
core Loading commit data...
crypto Loading commit data...
docs Loading commit data...
eth Loading commit data...
ethclient Loading commit data...
ethdb Loading commit data...
ethstats Loading commit data...
event Loading commit data...
graphql Loading commit data...
internal Loading commit data...
les Loading commit data...
light Loading commit data...
log Loading commit data...
metrics Loading commit data...
miner Loading commit data...
mobile Loading commit data...
node Loading commit data...
p2p Loading commit data...
params Loading commit data...
rlp Loading commit data...
rpc Loading commit data...
signer Loading commit data...
swarm Loading commit data...
tests Loading commit data...
trie Loading commit data...
.dockerignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.golangci.yml Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
COPYING Loading commit data...
COPYING.LESSER Loading commit data...
Dockerfile Loading commit data...
Dockerfile.alltools Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
SECURITY.md Loading commit data...
appveyor.yml Loading commit data...
circle.yml Loading commit data...
go.mod Loading commit data...
go.sum Loading commit data...
interfaces.go Loading commit data...
oss-fuzz.sh Loading commit data...