Skip to content

Commit

Permalink
core: set path mode as default
Browse files Browse the repository at this point in the history
  • Loading branch information
VM committed Feb 28, 2024
1 parent b7b64da commit 362ce7c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
6 changes: 4 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ var defaultCacheConfig = &CacheConfig{
SnapshotLimit: 256,
TriesInMemory: 128,
SnapshotWait: true,
StateScheme: rawdb.HashScheme,
StateHistory: params.FullImmutabilityThreshold,
StateScheme: rawdb.PathScheme,
PathSyncFlush: false,
}

// DefaultCacheConfigWithScheme returns a deep copied default cache config with
Expand Down Expand Up @@ -2035,7 +2037,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
go throwaway.TriePrefetchInAdvance(block, signer)
}

//Process block using the parent state as reference point
// Process block using the parent state as reference point
if bc.pipeCommit {
statedb.EnablePipeCommit()
}
Expand Down
6 changes: 4 additions & 2 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
)

// BlockGen creates blocks for testing.
Expand Down Expand Up @@ -339,8 +340,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
}
return nil, nil
}
// Forcibly use hash-based state scheme for retaining all nodes in disk.
triedb := trie.NewDatabase(db, trie.HashDefaults)

// Forcibly use path-based state scheme for retaining all nodes in disk.
triedb := trie.NewDatabase(db, &trie.Config{PathDB: pathdb.Defaults})
defer triedb.Close()

for i := 0; i < n; i++ {
Expand Down
8 changes: 4 additions & 4 deletions core/rawdb/accessors_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ func ParseStateScheme(provided string, disk ethdb.Database) (string, error) {
stored := ReadStateScheme(disk)
if provided == "" {
if stored == "" {
// use default scheme for empty database, flip it when
// path mode is chosen as default
log.Info("State scheme set to default", "scheme", "hash")
return HashScheme, nil
// use default scheme for empty database, now path mode
// is chosen as default
log.Info("State scheme set to default", "scheme", PathScheme)
return PathScheme, nil
}
log.Info("State scheme set to already existing disk db", "scheme", stored)
return stored, nil // reuse scheme of persistent scheme
Expand Down
1 change: 1 addition & 0 deletions core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {
}
tr, err := trie.NewStateTrie(trie.StateTrieID(root), db.triedb)
if err != nil {
fmt.Println("Failed to open trie: ", err)
return nil, err
}
return tr, nil
Expand Down
28 changes: 13 additions & 15 deletions trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,17 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
// Sanitize the config and use the default one if it's not specified.
dbScheme := rawdb.ReadStateScheme(diskdb)
if config == nil {
if dbScheme == rawdb.PathScheme {
config = &Config{
PathDB: pathdb.Defaults,
}
} else {
if dbScheme == rawdb.HashScheme {
config = HashDefaults
} else {
config = &Config{PathDB: pathdb.Defaults}
}
}
if config.PathDB == nil && config.HashDB == nil {
if dbScheme == rawdb.PathScheme {
config.PathDB = pathdb.Defaults
} else {
if dbScheme == rawdb.HashScheme {
config.HashDB = hashdb.Defaults
} else {
config.PathDB = pathdb.Defaults
}
}
var preimages *preimageStore
Expand All @@ -136,7 +134,7 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
/*
* 1. First, initialize db according to the user config
* 2. Second, initialize the db according to the scheme already used by db
* 3. Last, use the default scheme, namely hash scheme
* 3. Last, use the default scheme, namely path scheme
*/
if config.HashDB != nil {
if rawdb.ReadStateScheme(diskdb) == rawdb.PathScheme {
Expand All @@ -148,16 +146,16 @@ func NewDatabase(diskdb ethdb.Database, config *Config) *Database {
log.Warn("incompatible state scheme", "old", rawdb.HashScheme, "new", rawdb.PathScheme)
}
db.backend = pathdb.New(diskdb, config.PathDB)
} else if strings.Compare(dbScheme, rawdb.PathScheme) == 0 {
if config.PathDB == nil {
config.PathDB = pathdb.Defaults
}
db.backend = pathdb.New(diskdb, config.PathDB)
} else {
} else if strings.Compare(dbScheme, rawdb.HashScheme) == 0 {
if config.HashDB == nil {
config.HashDB = hashdb.Defaults
}
db.backend = hashdb.New(diskdb, config.HashDB, mptResolver{})
} else {
if config.PathDB == nil {
config.PathDB = pathdb.Defaults
}
db.backend = pathdb.New(diskdb, config.PathDB)
}
return db
}
Expand Down

0 comments on commit 362ce7c

Please sign in to comment.