Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 3bb26dc

Browse files
committed
Clean up init
1 parent 99b8131 commit 3bb26dc

File tree

4 files changed

+4
-37
lines changed

4 files changed

+4
-37
lines changed

core/blockchain.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,7 @@ func NewBlockChain(
377377
return nil, errCacheConfigNotSpecified
378378
}
379379
// Open trie database with provided config
380-
var stateCache state.Database
381-
triedbConfig := cacheConfig.triedbConfig()
382-
if cacheConfig.StateScheme == customrawdb.FirewoodScheme {
383-
stateCache = state.NewDatabaseWithFirewood(db, triedbConfig)
384-
} else {
385-
stateCache = state.NewDatabaseWithConfig(db, triedbConfig)
386-
}
380+
stateCache := state.NewDatabaseWithConfig(db, cacheConfig.triedbConfig())
387381

388382
// Setup the genesis block, commit the provided genesis specification
389383
// to database if the genesis block is not present yet, or load the

core/genesis.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ func (g *Genesis) trieConfig() *triedb.Config {
230230

231231
// TODO: migrate this function to "flush" for more similarity with upstream.
232232
func (g *Genesis) toBlock(coredb state.Database) *types.Block {
233+
fmt.Println("ToBlock", len(g.Alloc))
233234
statedb, err := state.New(types.EmptyRootHash, coredb, nil)
234235
if err != nil {
235236
panic(err)

core/state/database.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ func NewDatabase(db ethdb.Database) ethstate.Database {
5555
}
5656

5757
func NewDatabaseWithConfig(db ethdb.Database, config *triedb.Config) ethstate.Database {
58-
if config == nil {
59-
return NewDatabase(db)
60-
}
61-
62-
if config.DBOverride == nil {
58+
if config == nil || config.DBOverride == nil {
6359
return ethstate.NewDatabaseWithConfig(db, config)
6460
}
6561

@@ -73,7 +69,6 @@ func NewDatabaseWithConfig(db ethdb.Database, config *triedb.Config) ethstate.Da
7369
return ethstate.NewDatabaseWithConfig(db, config)
7470
}
7571
if innerdb == nil {
76-
fmt.Printf("firewood is nil")
7772
log.Error("firewooddb.Database is nil")
7873
return nil
7974
}
@@ -88,28 +83,6 @@ func NewDatabaseWithNodeDB(db ethdb.Database, triedb *triedb.Database) ethstate.
8883
return ethstate.NewDatabaseWithNodeDB(db, triedb)
8984
}
9085

91-
// Note trieConfig provides a closure here.
92-
func NewDatabaseWithFirewood(db ethdb.Database, trieConfig *triedb.Config) Database {
93-
// I could create my own Config, create the config, and create the triedb.Config
94-
// Don't accept the triedb and create it here
95-
fw, ok := trieConfig.DBOverride(db).(*firewood.Database)
96-
if !ok {
97-
log.Error("Cannot create firewooddb.Database from the provided database")
98-
fmt.Printf("not ok")
99-
return nil
100-
}
101-
if fw == nil {
102-
fmt.Printf("firewood is nil")
103-
log.Error("firewooddb.Database is nil")
104-
return nil
105-
}
106-
107-
return &firewoodAccessorDb{
108-
Database: ethstate.NewDatabaseWithConfig(db, trieConfig),
109-
fw: fw,
110-
}
111-
}
112-
11386
type firewoodAccessorDb struct {
11487
Database
11588
fw *firewood.Database
@@ -132,5 +105,4 @@ func (db *firewoodAccessorDb) OpenStorageTrie(stateRoot common.Hash, address com
132105
// CopyTrie returns an independent copy of the given trie.
133106
func (db *firewoodAccessorDb) CopyTrie(trie Trie) Trie {
134107
panic("CopyTrie not implemented for firewoodAccessorDb")
135-
return nil
136108
}

core/state/database_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestInsert(t *testing.T) {
8282
MetricsPort: 0, // use any open port from OS
8383
}
8484
config.DBOverride = fwCfg.BackendConstructor // BackendConstructor is on the reference to allow closure
85-
fwdb := NewDatabaseWithFirewood(firewoodmemdb, config)
85+
fwdb := NewDatabaseWithConfig(firewoodmemdb, config)
8686

8787
ethRoot := types.EmptyRootHash
8888

0 commit comments

Comments
 (0)