bsc/core
setunapo 8e74562179
[R4R]: Redesign triePrefetcher to make it thread safe (#972)
* Redesign triePrefetcher to make it thread safe

There are 2 types of triePrefetcher instances:
1.New created triePrefetcher: it is key to do trie prefetch to speed up validation phase.
2.Copied triePrefetcher: it only copy the prefetched trie information, actually it won't do
  prefetch at all, the copied tries are all kept in p.fetches.

Here we try to improve the new created one, to make it concurrent safe, while the copied one's
behavior stay unchanged(its logic is very simple).
As commented in triePrefetcher struct, its APIs are not thread safe. So callers should make sure
the created triePrefetcher should be used within a single routine.
As we are trying to improve triePrefetcher, we would use it concurrently, so it is necessary to
redesign it for concurrent access.

The design is simple:
** start a mainLoop to do all the work, APIs just send channel message.

Others:
** remove the metrics copy, since it is useless for copied triePrefetcher
** for trie(), only get subfetcher through channel to reduce the workload of mainloop

* some code enhancement for triePrefetcher redesign

* some fixup: rename, temporary trie chan for concurrent safe.

* fix review comments

* add some protection in case the trie prefetcher is already stopped

* fix review comments

** make close concurrent safe
** fix potential deadlock

* replace channel by RWMutex for a few triePrefetcher APIs

For APIs like: trie(), copy(), used(), it is simpler and more efficient to
use a RWMutex instead of channel communicaton.
Since the mainLoop would be busy handling trie request, while these trie request
can be processed in parallism.

We would only keep prefetch and close within the mainLoop, since they could update
the fetchers

* add lock for subfecter.used access to make it concurrent safe

* no need to create channel for copied triePrefetcher

* fix trie_prefetcher_test.go

trie prefetcher’s behavior has changed, prefetch() won't create subfetcher immediately.
it is reasonable, but break the UT, to fix the failed UT
2022-07-07 10:00:09 +08:00
..
asm fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
beacon all: separate catalyst package (#24280) 2022-01-31 14:22:35 +02:00
bloombits fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
forkid merge with go-ethereum 1.1.5 2022-02-10 18:48:16 +08:00
rawdb fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
state [R4R]: Redesign triePrefetcher to make it thread safe (#972) 2022-07-07 10:00:09 +08:00
systemcontracts fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
types fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
vm fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
.gitignore
bench_test.go core: fix benchmark tests (#23803) 2021-10-27 13:08:51 +02:00
block_validator_test.go all: core rework for the merge transition (#23761) 2021-11-26 13:23:02 +02:00
block_validator.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
blockchain_diff_test.go fix: asynchronous caching of difflayer causes random errors in tests 2022-07-06 15:43:33 +08:00
blockchain_insert.go core: fix snapshot missing when recovery from crash (#23496) 2021-11-01 14:09:36 +01:00
blockchain_notries_test.go fix: asynchronous caching of difflayer causes random errors in tests 2022-07-06 15:43:33 +08:00
blockchain_reader.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
blockchain_repair_test.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
blockchain_sethead_test.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
blockchain_snapshot_test.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
blockchain_test.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
blockchain.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
blocks.go core: typos and comments improve 2017-05-25 17:14:33 +03:00
bloom_indexer.go eth: move eth.Config to a common package (#22205) 2021-02-05 13:51:15 +01:00
chain_indexer_test.go core: fix potential race in chainIndexerTest (#22346) 2021-03-19 13:32:57 +01:00
chain_indexer.go all: make logs a bit easier on the eye to digest (#22665) 2021-04-15 20:35:00 +03:00
chain_makers_test.go cmd, core, eth: background transaction indexing (#20302) 2020-05-11 18:58:43 +03:00
chain_makers.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
dao_test.go accounts/abi/bind: fix bounded contracts and sim backend for 1559 (#23038) 2021-06-15 13:56:14 +03:00
error.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
events.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
evm.go core/evm: RANDOM opcode (EIP-4399) (#24141) 2022-01-10 09:44:21 +02:00
forkchoice.go all: core rework for the merge transition (#23761) 2021-11-26 13:23:02 +02:00
gaspool.go miner: avoid unnecessary work (#15883) 2018-01-15 12:57:06 +02:00
gen_genesis_account.go tests: update for London (#22976) 2021-06-07 14:37:56 +02:00
gen_genesis.go core: change baseFee into baseFeePerGas in genesis json 2021-06-14 14:04:44 +02:00
genesis_alloc.go cmd/geth: add support for sepolia testnet (#23730) 2021-11-08 13:06:01 +02:00
genesis_test.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
genesis.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
headerchain_test.go all: core rework for the merge transition (#23761) 2021-11-26 13:23:02 +02:00
headerchain.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
mkalloc.go all: add go:build lines (#23468) 2021-08-25 18:46:29 +02:00
receipt_processor.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
remote_state_verifier.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
rlp_test.go core: fix benchmark tests (#23803) 2021-10-27 13:08:51 +02:00
state_prefetcher.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
state_processor_test.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
state_processor.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
state_transition.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
tx_cacher.go Comment error (#18303) 2018-12-14 11:15:31 +01:00
tx_journal.go core: transaction journal should not be executable (#23090) 2021-06-23 07:29:20 +03:00
tx_list_test.go core: fix benchmark tests (#23803) 2021-10-27 13:08:51 +02:00
tx_list.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
tx_noncer.go core: more efficient nonce-update in txpool (#22231) 2021-11-02 18:32:23 +01:00
tx_pool_test.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
tx_pool.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00
types.go fix: code compatibility fixes 2022-07-05 11:14:21 +08:00