Skip to content

Commit

Permalink
fix: state object trie expire
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang committed Aug 13, 2024
1 parent e8309ad commit d8c3726
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/state/caching_versa_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func (vt *VersaTree) Hash() common.Hash {
hash, err := vt.db.CalcRootHash(vt.handler)
if err != nil {
// TODO:: debug code, will be change to log error
panic(fmt.Sprintf("failed to cacl versa tree hash, error: %s", err.Error()))
panic(fmt.Sprintf("failed to cacl versa tree hash, handler: %d, error: %s", vt.handler, err.Error()))
}
return hash
}
Expand Down
14 changes: 8 additions & 6 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ func (s Storage) Copy() Storage {
// - Account values as well as storages can be accessed and modified through the object.
// - Finally, call commit to return the changes of storage trie and update account data.
type stateObject struct {
db *StateDB
address common.Address // address of ethereum account
addrHash common.Hash // hash of ethereum address of the account
origin *types.StateAccount // Account original data without any change applied, nil means it was not existent
data types.StateAccount // Account data with all mutations applied in the scope of block
db *StateDB
stateRoot common.Hash
address common.Address // address of ethereum account
addrHash common.Hash // hash of ethereum address of the account
origin *types.StateAccount // Account original data without any change applied, nil means it was not existent
data types.StateAccount // Account data with all mutations applied in the scope of block

// Write caches.
trie Trie // storage trie, which becomes non-nil on first access
Expand Down Expand Up @@ -151,7 +152,7 @@ func (s *stateObject) touch() {
// if it's not loaded previously. An error will be returned if trie can't
// be loaded.
func (s *stateObject) getTrie() (Trie, error) {
if s.trie == nil {
if s.trie == nil || s.stateRoot.Cmp(s.db.originalRoot) != 0 {
// Try fetching from prefetcher first
// if s.data.Root != types.EmptyRootHash && s.db.prefetcher != nil {
// When the miner is creating the pending state, there is no prefetcher
Expand All @@ -163,6 +164,7 @@ func (s *stateObject) getTrie() (Trie, error) {
return nil, err
}
s.trie = tr
s.stateRoot = s.db.originalRoot
// }
}
return s.trie, nil
Expand Down

0 comments on commit d8c3726

Please sign in to comment.