core/state/snapshot: tiny fixes (#29995)

This commit is contained in:
rjl493456442 2024-06-21 09:51:03 +08:00 committed by GitHub
parent 27654d3022
commit e0e45dbc32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 16 deletions

View File

@ -631,16 +631,10 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
accMarker = nil accMarker = nil
return 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) origin := common.CopyBytes(accMarker)
for { for {
id := trie.StateTrieID(dl.root) id := trie.StateTrieID(dl.root)
exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountRange, onAccount, types.FullAccountRLP) exhausted, last, err := dl.generateRange(ctx, id, rawdb.SnapshotAccountPrefix, snapAccount, origin, accountCheckRange, onAccount, types.FullAccountRLP)
if err != nil { if err != nil {
return err // The procedure it aborted, either by external signal or internal error. return err // The procedure it aborted, either by external signal or internal error.
} }
@ -652,7 +646,6 @@ func generateAccounts(ctx *generatorContext, dl *diskLayer, accMarker []byte) er
ctx.removeStorageLeft() ctx.removeStorageLeft()
break break
} }
accountRange = accountCheckRange
} }
return nil return nil
} }

View File

@ -258,14 +258,6 @@ func (t *Tree) Disable() {
for _, layer := range t.layers { for _, layer := range t.layers {
switch layer := layer.(type) { switch layer := layer.(type) {
case *diskLayer: 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 the base layer is generating, abort it
if layer.genAbort != nil { if layer.genAbort != nil {
abort := make(chan *generatorStats) abort := make(chan *generatorStats)
@ -276,6 +268,7 @@ func (t *Tree) Disable() {
layer.lock.Lock() layer.lock.Lock()
layer.stale = true layer.stale = true
layer.lock.Unlock() layer.lock.Unlock()
layer.Release()
case *diffLayer: case *diffLayer:
// If the layer is a simple diff, simply mark as stale // If the layer is a simple diff, simply mark as stale
@ -740,6 +733,7 @@ func (t *Tree) Rebuild(root common.Hash) {
layer.lock.Lock() layer.lock.Lock()
layer.stale = true layer.stale = true
layer.lock.Unlock() layer.lock.Unlock()
layer.Release()
case *diffLayer: case *diffLayer:
// If the layer is a simple diff, simply mark as stale // If the layer is a simple diff, simply mark as stale