Skip to content

Commit

Permalink
debug no lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Jul 14, 2021
1 parent 5427bde commit 90863ac
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
if parent == nil {
parent = bc.GetHeader(block.ParentHash(), block.NumberU64()-1)
}
statedb, err := state.LazyNew(parent.Root, bc.stateCache, bc.snaps)
statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps)
if err != nil {
return it.index, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/state/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
codeSizeCacheSize = 100000

// Number of state trie in cache
accountTrieCacheSize = 11
accountTrieCacheSize = 32

// Number of storage Trie in cache
storageTrieCacheSize = 2000
Expand Down
22 changes: 7 additions & 15 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,10 @@ type StateDB struct {

// New creates a new state from a given trie.
func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) {
return newStateDB(root, db, snaps, false)
return newStateDB(root, db, snaps)
}

// New creates a new state, but do not open the trie tree at first.
func LazyNew(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) {
return newStateDB(root, db, snaps, true)
}

func newStateDB(root common.Hash, db Database, snaps *snapshot.Tree, lazy bool) (*StateDB, error) {
func newStateDB(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) {
sdb := &StateDB{
db: db,
originalRoot: root,
Expand All @@ -151,21 +146,18 @@ func newStateDB(root common.Hash, db Database, snaps *snapshot.Tree, lazy bool)
journal: newJournal(),
hasher: crypto.NewKeccakState(),
}
tr, err := db.OpenTrie(root)
if err != nil {
return nil, err
}
sdb.trie = tr
if sdb.snaps != nil {
if sdb.snap = sdb.snaps.Snapshot(root); sdb.snap != nil {
sdb.snapDestructs = make(map[common.Hash]struct{})
sdb.snapAccounts = make(map[common.Hash][]byte)
sdb.snapStorage = make(map[common.Hash]map[common.Hash][]byte)
}
}
// if without snaps, still init with trie tree
if !lazy || sdb.snap == nil {
tr, err := db.OpenTrie(root)
if err != nil {
return nil, err
}
sdb.trie = tr
}
return sdb, nil
}

Expand Down

0 comments on commit 90863ac

Please sign in to comment.