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

core/state/snapshot: detect and clean up dangling storage snapshot in generation #24811

Merged
merged 30 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8604adb
core/state/snapshot: check dangling storages when generating snapshot
rjl493456442 Apr 8, 2022
51f8a0e
core/state/snapshot: polish
rjl493456442 Apr 8, 2022
0ee1ebe
core/state/snapshot: wipe the last part of the dangling storages
rjl493456442 Apr 8, 2022
9b9dba1
core/state/snapshot: fix and add tests
rjl493456442 Apr 8, 2022
617eda9
core/state/snapshot: fix comment
rjl493456442 Apr 8, 2022
bbb6b94
README: remove mentions of fast sync (#24656)
nuoomnoy02 Apr 7, 2022
816f6cb
core, cmd: expose dangling storage detector for wider usage
rjl493456442 Apr 26, 2022
af23c13
core/state/snapshot: rename variable
rjl493456442 Apr 26, 2022
87d8bc3
core, ethdb: use global iterators for snapshot generation
rjl493456442 Apr 28, 2022
f4a489d
core/state/snapshot: polish
rjl493456442 May 4, 2022
5f37c25
cmd, core/state/snapshot: polish
rjl493456442 May 4, 2022
0584fc6
core/state/snapshot: polish
rjl493456442 May 4, 2022
546ce97
Update core/state/snapshot/generate.go
rjl493456442 May 4, 2022
b88d7ac
ethdb: extend db test suite and fix memorydb iterator
rjl493456442 May 5, 2022
e00ff21
ethdb/dbtest: rollback changes
rjl493456442 May 5, 2022
54caa24
ethdb/memorydb: simplify iteration
rjl493456442 May 5, 2022
7fca158
core/state/snapshot: update dangling counter
rjl493456442 May 5, 2022
e178af1
core/state/snapshot: release iterators
rjl493456442 May 7, 2022
3acad8d
core/state/snapshot: update metrics
rjl493456442 May 7, 2022
9a1ccd9
core/state/snapshot: update time metrics
rjl493456442 May 7, 2022
5df1225
metrics/influxdb: temp solution to present counter meaningfully, remo…
rjl493456442 May 7, 2022
d3fb321
add debug log, revert later
rjl493456442 May 7, 2022
83f60af
core/state/snapshot: fix iterator panic
rjl493456442 May 7, 2022
78ed542
all: customized snapshot iterator for backward iteration
rjl493456442 May 7, 2022
254666a
core, ethdb: polish
rjl493456442 May 9, 2022
1f5442d
core/state/snapshot: remove debug log
rjl493456442 May 9, 2022
55577d0
core/state/snapshot: address comments from peter
rjl493456442 May 10, 2022
61dcb92
core/state/snapshot: reopen the iterator at the next position
rjl493456442 May 10, 2022
c80a059
ethdb, core/state/snapshot: address comment from peter
rjl493456442 May 10, 2022
25b0392
core/state/snapshot: reopen exhausted iterators
rjl493456442 May 23, 2022
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
Prev Previous commit
Next Next commit
core/state/snapshot: update metrics
  • Loading branch information
rjl493456442 committed May 9, 2022
commit 3acad8d7d0a90b28361dc2b8ffafef205471686c
8 changes: 7 additions & 1 deletion core/state/snapshot/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ func (ctx *generatorContext) removeStorageBefore(account common.Hash) {
// a step. An error will be returned if the initial position of iterator is not
// in the given account range.
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
func (ctx *generatorContext) removeStorageAt(account common.Hash) error {
var iter = ctx.iterator(snapStorage)
var (
count int64
iter = ctx.iterator(snapStorage)
)
for iter.Next() {
key := iter.Key()
cmp := bytes.Compare(key[1:1+common.HashLength], account.Bytes())
Expand All @@ -192,7 +195,9 @@ func (ctx *generatorContext) removeStorageAt(account common.Hash) error {
break
}
ctx.batch.Delete(key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can grow quite large if a big contract was deleted, imho we should check the batch size and flush if it gets large mid iteration. Also recreate the iterator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. we can flush the batch here. And also in order to simplify the code, we can only flush the batch but without persisting the generation progress marker. We usually do this in checkAndFlush function, but it's fine to not do it here. If panic happens, then we need to redo the generation since the last marker.

count += 1
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
}
snapWipedStorageMeter.Mark(count)
return nil
}

Expand All @@ -208,4 +213,5 @@ func (ctx *generatorContext) removeStorageLeft() {
count += 1
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
}
ctx.stats.dangling += count
snapDanglingStorageMeter.Mark(int64(count))
}
4 changes: 2 additions & 2 deletions core/state/snapshot/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ func (dl *diskLayer) proveRange(ctx *generatorContext, root common.Hash, prefix
}
}
// Update metrics for database iteration and merkle proving
if kind == "storage" {
if kind == snapStorage {
snapStorageSnapReadCounter.Inc(time.Since(start).Nanoseconds())
} else {
snapAccountSnapReadCounter.Inc(time.Since(start).Nanoseconds())
}
defer func(start time.Time) {
if kind == "storage" {
if kind == snapStorage {
snapStorageProveCounter.Inc(time.Since(start).Nanoseconds())
} else {
snapAccountProveCounter.Inc(time.Since(start).Nanoseconds())
Expand Down
1 change: 1 addition & 0 deletions core/state/snapshot/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
snapRecoveredStorageMeter = metrics.NewRegisteredMeter("state/snapshot/generation/storage/recovered", nil)
snapWipedStorageMeter = metrics.NewRegisteredMeter("state/snapshot/generation/storage/wiped", nil)
snapMissallStorageMeter = metrics.NewRegisteredMeter("state/snapshot/generation/storage/missall", nil)
snapDanglingStorageMeter = metrics.NewRegisteredMeter("state/snapshot/generation/storage/dangling", nil)
snapSuccessfulRangeProofMeter = metrics.NewRegisteredMeter("state/snapshot/generation/proof/success", nil)
snapFailedRangeProofMeter = metrics.NewRegisteredMeter("state/snapshot/generation/proof/failure", nil)

Expand Down