Skip to content

Commit

Permalink
fix: delay open trie
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang committed Dec 6, 2024
1 parent 7f8183c commit 5556680
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
18 changes: 9 additions & 9 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
}
return nil
},
func() error {
if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
return consensus.ErrUnknownAncestor
}
return consensus.ErrPrunedAncestor
}
return nil
},
//func() error {
// if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
// if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
// return consensus.ErrUnknownAncestor
// }
// return consensus.ErrPrunedAncestor
// }
// return nil
//},
func() error {
if v.remoteValidator != nil && !v.remoteValidator.AncestorVerified(block.Header()) {
return fmt.Errorf("%w, number: %s, hash: %s", ErrAncestorHasNotBeenVerified, block.Number(), block.Hash())
Expand Down
19 changes: 13 additions & 6 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error)
sdb.snap = sdb.snaps.Snapshot(root)
}

tr, err := db.OpenTrie(root)
if err != nil {
return nil, err
}
_, sdb.noTrie = tr.(*trie.EmptyTrie)
sdb.trie = tr
//tr, err := db.OpenTrie(root)
//if err != nil {
// return nil, err
//}
//_, sdb.noTrie = tr.(*trie.EmptyTrie)
//sdb.trie = tr
return sdb, nil
}

Expand Down Expand Up @@ -1023,6 +1023,13 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
// Finalise all the dirty storage states and write them into the tries
s.Finalise(deleteEmptyObjects)

tr, err := s.db.OpenTrie(s.originalRoot)
if err != nil {
panic("Failed to open state trie")
}
s.trie = tr

s.AccountsIntermediateRoot()
return s.StateIntermediateRoot()
}
Expand Down

0 comments on commit 5556680

Please sign in to comment.