mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-15 08:23:46 +00:00
Fixed PR review comments and behavior change
This commit is contained in:
parent
a2e2df461f
commit
47d9118557
2 changed files with 11 additions and 11 deletions
|
|
@ -408,13 +408,13 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
|
||||||
|
|
||||||
if bc.logger != nil {
|
if bc.logger != nil {
|
||||||
if block := bc.CurrentBlock(); block.Number.Uint64() == 0 {
|
if block := bc.CurrentBlock(); block.Number.Uint64() == 0 {
|
||||||
alloc, found, err := getGenesisState(bc.db, block.Hash())
|
alloc, err := getGenesisState(bc.db, block.Hash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get genesis state: %w", err)
|
return nil, fmt.Errorf("failed to get genesis state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if alloc == nil {
|
||||||
return nil, fmt.Errorf("live blockchain tracer requires genesis alloc to be set, use 'geth init' to set it")
|
return nil, fmt.Errorf("live blockchain tracer requires genesis alloc to be set")
|
||||||
}
|
}
|
||||||
|
|
||||||
bc.logger.OnGenesisBlock(bc.genesisBlock, alloc)
|
bc.logger.OnGenesisBlock(bc.genesisBlock, alloc)
|
||||||
|
|
|
||||||
|
|
@ -176,14 +176,14 @@ func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhas
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc GenesisAlloc, found bool, err error) {
|
func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc GenesisAlloc, err error) {
|
||||||
blob := rawdb.ReadGenesisStateSpec(db, blockhash)
|
blob := rawdb.ReadGenesisStateSpec(db, blockhash)
|
||||||
if len(blob) != 0 {
|
if len(blob) != 0 {
|
||||||
if err := alloc.UnmarshalJSON(blob); err != nil {
|
if err := alloc.UnmarshalJSON(blob); err != nil {
|
||||||
return nil, true, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return alloc, true, nil
|
return alloc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Genesis allocation is missing and there are several possibilities:
|
// Genesis allocation is missing and there are several possibilities:
|
||||||
|
|
@ -201,22 +201,22 @@ func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc GenesisAll
|
||||||
genesis = DefaultSepoliaGenesisBlock()
|
genesis = DefaultSepoliaGenesisBlock()
|
||||||
}
|
}
|
||||||
if genesis != nil {
|
if genesis != nil {
|
||||||
return genesis.Alloc, true, nil
|
return genesis.Alloc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, false, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommitGenesisState loads the stored genesis state with the given block
|
// CommitGenesisState loads the stored genesis state with the given block
|
||||||
// hash and commits it into the provided trie database.
|
// hash and commits it into the provided trie database.
|
||||||
func CommitGenesisState(db ethdb.Database, triedb *trie.Database, blockhash common.Hash) error {
|
func CommitGenesisState(db ethdb.Database, triedb *trie.Database, blockhash common.Hash) error {
|
||||||
alloc, found, err := getGenesisState(db, blockhash)
|
alloc, err := getGenesisState(db, blockhash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if alloc == nil {
|
||||||
return nil
|
return errors.New("not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return alloc.flush(db, triedb, blockhash, nil)
|
return alloc.flush(db, triedb, blockhash, nil)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue