From 47d9118557d94885f46a12edd2b39484f606f67e Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Wed, 23 Aug 2023 12:11:30 -0400 Subject: [PATCH] Fixed PR review comments and behavior change --- core/blockchain.go | 6 +++--- core/genesis.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index aa263711ad..70418e7624 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -408,13 +408,13 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis if bc.logger != nil { 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 { return nil, fmt.Errorf("failed to get genesis state: %w", err) } - if !found { - return nil, fmt.Errorf("live blockchain tracer requires genesis alloc to be set, use 'geth init' to set it") + if alloc == nil { + return nil, fmt.Errorf("live blockchain tracer requires genesis alloc to be set") } bc.logger.OnGenesisBlock(bc.genesisBlock, alloc) diff --git a/core/genesis.go b/core/genesis.go index 481795166d..54ec15cba4 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -176,14 +176,14 @@ func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhas 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) if len(blob) != 0 { 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: @@ -201,22 +201,22 @@ func getGenesisState(db ethdb.Database, blockhash common.Hash) (alloc GenesisAll genesis = DefaultSepoliaGenesisBlock() } 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 // hash and commits it into the provided trie database. 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 { return err } - if !found { - return nil + if alloc == nil { + return errors.New("not found") } return alloc.flush(db, triedb, blockhash, nil)