Skip to content

Commit

Permalink
Revert "core/state/snapshot: tiny fixes" (#30039)
Browse files Browse the repository at this point in the history
Revert "core/state/snapshot: tiny fixes (#29995)"

This reverts commit e0e45db.
  • Loading branch information
rjl493456442 authored Jun 21, 2024
1 parent e0e45db commit c10ac4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion core/state/snapshot/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,16 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
accMarker = nil
return nil
}
// Always reset the initial account range as 1 whenever recover from the
// interruption. TODO(rjl493456442) can we remove it?
var accountRange = accountCheckRange
if len(accMarker) > 0 {
accountRange = 1
}
origin := common.CopyBytes(accMarker)
for {
id := trie.StateTrieID(dl.root)
exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountCheckRange, onAccount, types.FullAccountRLP)
exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountRange, onAccount, types.FullAccountRLP)
if err != nil {
return err // The procedure it aborted, either by external signal or internal error.
}
Expand All @@ -646,6 +652,7 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
ctx.removeStorageLeft()
break
}
accountRange = accountCheckRange
}
return nil
}
Expand Down
10 changes: 8 additions & 2 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ func (t *Tree) Disable() {
for _, layer := range t.layers {
switch layer := layer.(type) {
case *diskLayer:

layer.lock.RLock()
generating := layer.genMarker != nil
layer.lock.RUnlock()
if !generating {
// Generator is already aborted or finished
break
}
// If the base layer is generating, abort it
if layer.genAbort != nil {
abort := make(chan *generatorStats)
Expand All @@ -268,7 +276,6 @@ func (t *Tree) Disable() {
layer.lock.Lock()
layer.stale = true
layer.lock.Unlock()
layer.Release()

case *diffLayer:
// If the layer is a simple diff, simply mark as stale
Expand Down Expand Up @@ -733,7 +740,6 @@ func (t *Tree) Rebuild(root common.Hash) {
layer.lock.Lock()
layer.stale = true
layer.lock.Unlock()
layer.Release()

case *diffLayer:
// If the layer is a simple diff, simply mark as stale
Expand Down

0 comments on commit c10ac4f

Please sign in to comment.