db03faa10d
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> |
||
---|---|---|
.. | ||
asm | ||
bloombits | ||
forkid | ||
rawdb | ||
state | ||
types | ||
vm | ||
.gitignore | ||
bench_test.go | ||
block_validator_test.go | ||
block_validator.go | ||
blockchain_insert.go | ||
blockchain_reader.go | ||
blockchain_repair_test.go | ||
blockchain_sethead_test.go | ||
blockchain_snapshot_test.go | ||
blockchain_test.go | ||
blockchain.go | ||
blocks.go | ||
bloom_indexer.go | ||
chain_indexer_test.go | ||
chain_indexer.go | ||
chain_makers_test.go | ||
chain_makers.go | ||
dao_test.go | ||
error.go | ||
events.go | ||
evm.go | ||
forkchoice.go | ||
gaspool.go | ||
gen_genesis_account.go | ||
gen_genesis.go | ||
genesis_alloc.go | ||
genesis_test.go | ||
genesis.go | ||
headerchain_test.go | ||
headerchain.go | ||
mkalloc.go | ||
rlp_test.go | ||
state_prefetcher.go | ||
state_processor_test.go | ||
state_processor.go | ||
state_transition.go | ||
tx_cacher.go | ||
tx_journal.go | ||
tx_list_test.go | ||
tx_list.go | ||
tx_noncer.go | ||
tx_pool_test.go | ||
tx_pool.go | ||
types.go |