Move genesis initialization logic to NewBlockChain:
Current flow: backend.New() calls SetupGenesisBlockWithOverride, which does open Trie.db for initializing. Then, it calls NewBlockChain, which also opens Trie.db for progressing the chain.
This is acceptable for now, since Trie.db can be opened multiple times. However, later in PBSS, Trie.db contains diff freezer, which is a singleton that can only be open once (and thus must be closed before reopening). Moving all the use of Trie.db in the same component makes it easier for closing logic.
New flow: SetupGenesisBlockWithOverride is called inside NewBlockChain.
Later PRs will open Trie.db once within the BlockChain component, and then close it in BlockChain.Close().
Note that the later Trie.db that contains diff freezer will be reworked (and thus renamed), we just use its current name here for convenience.
Reference: https://github.com/ethereum/go-ethereum/pull/25523/commits
Move genesis initialization logic to
NewBlockChain
:backend.New()
callsSetupGenesisBlockWithOverride
, which does openTrie.db
for initializing. Then, it callsNewBlockChain
, which also opensTrie.db
for progressing the chain.Trie.db
can be opened multiple times. However, later in PBSS,Trie.db
contains diff freezer, which is a singleton that can only be open once (and thus must be closed before reopening). Moving all the use ofTrie.db
in the same component makes it easier for closing logic.SetupGenesisBlockWithOverride
is called insideNewBlockChain
.Trie.db
once within theBlockChain
component, and then close it inBlockChain.Close()
.Note that the later
Trie.db
that contains diff freezer will be reworked (and thus renamed), we just use its current name here for convenience.