Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]: improve snapshot generation #22465

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4a7becb
eth/protocols: persist received state segments
rjl493456442 Mar 5, 2021
60f57c9
core: initial implementation
rjl493456442 Mar 8, 2021
bf6c7da
core/state/snapshot: add tests
rjl493456442 Mar 9, 2021
fd7cf4b
core, eth: updates
rjl493456442 Mar 9, 2021
8bf2032
eth/protocols/snapshot: count flat state size
rjl493456442 Mar 9, 2021
353804d
core/state: add metrics
rjl493456442 Mar 9, 2021
3a3d341
core/state/snapshot: skip unnecessary deletion
rjl493456442 Mar 9, 2021
f0e822e
core/state/snapshot: rename
rjl493456442 Mar 9, 2021
0b8d5a6
core/state/snapshot: use the global batch
rjl493456442 Mar 9, 2021
a9ea5be
core/state/snapshot: add logs and fix wiping
rjl493456442 Mar 10, 2021
0a2a1a8
core/state/snapshot: fix
rjl493456442 Mar 10, 2021
b6b2aaf
core/state/snapshot: save generation progress even if the batch is empty
rjl493456442 Mar 10, 2021
f64ede8
core/state/snapshot: fixes
rjl493456442 Mar 10, 2021
e848ac9
core/state/snapshot: fix initial account range length
rjl493456442 Mar 10, 2021
f5b9a8f
core/state/snapshot: fix initial account range
rjl493456442 Mar 11, 2021
cc8bffc
eth/protocols/snap: store flat states during the healing
rjl493456442 Mar 11, 2021
475ad07
eth/protocols/snap: print logs
rjl493456442 Mar 12, 2021
955e99d
core/state/snapshot: refactor (#4)
holiman Mar 12, 2021
27c8239
core, eth: fixes
rjl493456442 Mar 12, 2021
a8c419a
core, eth: fix healing writer
rjl493456442 Mar 12, 2021
523e3e4
core, trie, eth: fix paths
rjl493456442 Mar 12, 2021
3f992cf
eth/protocols/snap: fix encoding
rjl493456442 Mar 12, 2021
9f27aae
eth, core: add debug log
rjl493456442 Mar 15, 2021
8344c7c
core/state/generate: release iterator asap (#5)
holiman Mar 15, 2021
e69cde1
core/state/snapshot: optimize stats counter
rjl493456442 Mar 15, 2021
f52d630
core, eth: add metric
rjl493456442 Mar 15, 2021
2dd3d99
core/state/snapshot: update comments
rjl493456442 Mar 15, 2021
b77a7ff
core/state/snapshot: improve tests
rjl493456442 Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions core/state/snapshot/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (dl *diskLayer) genRange(root common.Hash, prefix []byte, kind string, orig
return false, nil, err
}
}
log.Debug("Recovered state range", "kind", kind, "prefix", prefix, "origin", origin, "last", last)
log.Debug("Recovered state range", "kind", kind, "prefix", prefix, "origin", origin, "last", last, "count", len(keys))
return exhausted, last, nil
}
snapFailedRangeProofMeter.Mark(1)
Expand All @@ -288,20 +288,24 @@ func (dl *diskLayer) genRange(root common.Hash, prefix []byte, kind string, orig
}
log.Debug("Wiped currupted state range", "kind", kind, "prefix", prefix, "origin", origin, "limit", limit)
}
iter := trie.NewIterator(tr.NodeIterator(origin))
var (
count int
iter = trie.NewIterator(tr.NodeIterator(origin))
)
for iter.Next() {
if last != nil && bytes.Compare(iter.Key, last) > 0 {
log.Debug("Regenerated state range", "kind", kind, "prefix", prefix, "origin", origin, "last", last)
log.Debug("Regenerated state range", "kind", kind, "prefix", prefix, "root", root, "origin", origin, "last", last, "count", count)
return false, last, nil // Apparently the trie is not exhausted
}
if err := onState(iter.Key, iter.Value, true); err != nil {
return false, nil, err
}
count += 1
}
if iter.Err != nil {
return false, nil, iter.Err
}
log.Debug("Regenerated state range", "kind", kind, "prefix", prefix, "origin", origin, "last", last)
log.Debug("Regenerated state range", "kind", kind, "prefix", prefix, "root", root, "origin", origin, "last", last, "count", count)
return true, nil, nil // The entire trie is exhausted
}

Expand Down Expand Up @@ -417,11 +421,11 @@ func (dl *diskLayer) generate(stats *generatorStats) {
return err
}
if exhausted {
return nil
break
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
}
storeOrigin = increseKey(last)
if storeOrigin == nil {
return nil // special case, the last is 0xffffffff...fff
break // special case, the last is 0xffffffff...fff
}
}
} else {
Expand All @@ -440,6 +444,8 @@ func (dl *diskLayer) generate(stats *generatorStats) {
accMarker = nil
return nil
}

// Global loop for regerating the entire state trie + all layered storage tries.
for {
exhausted, last, err := dl.genRange(dl.root, rawdb.SnapshotAccountPrefix, "account", accOrigin, accountRange, stats, onAccount, FullAccountRLP)
// The procedure it aborted, either by external signal or internal error
Expand Down
2 changes: 1 addition & 1 deletion core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func (t *Tree) Rebuild(root common.Hash) {
case *diskLayer:
// If the base layer is generating, abort it and save
if layer.genAbort != nil {
abort := make(chan *generatorStats)
abort := make(chan *generatorStats, 1) // Discard the stats
layer.genAbort <- abort
}
// Layer should be inactive now, mark it as stale
Expand Down