Skip to content

Commit

Permalink
eth/protocols/snap: fix batch writer when resuming an aborted sync (#22)
Browse files Browse the repository at this point in the history
### Description

upstream PR:
[go-ethereum#27842](ethereum/go-ethereum#27842)

Fixes ethereum/go-ethereum#27813.

The closure caused all subtasks to reference the same one batch when
writing, so instead of each subtask of a contract growing and flushing
it's own batch, they all grew the last one's, but flushed their own.

Interestingly however, this should only be an issue if there's also a
lack of peers, otherwise whenever a delivery into the last batch is
made, it should have flushed out everyone else's data too.
  • Loading branch information
0xcb9ff9 committed Sep 4, 2023
1 parent c6888f5 commit 829b516
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ func (s *Syncer) loadSyncStatus() {
}
s.tasks = progress.Tasks
for _, task := range s.tasks {
task := task // closure for task.genBatch in the stacktrie writer callback

task.genBatch = ethdb.HookedBatch{
Batch: s.db.NewBatch(),
OnPut: func(key []byte, value []byte) {
Expand All @@ -746,6 +748,8 @@ func (s *Syncer) loadSyncStatus() {

for _, subtasks := range task.SubTasks {
for _, subtask := range subtasks {
subtask := subtask // closure for subtask.genBatch in the stacktrie writer callback

subtask.genBatch = ethdb.HookedBatch{
Batch: s.db.NewBatch(),
OnPut: func(key []byte, value []byte) {
Expand Down

0 comments on commit 829b516

Please sign in to comment.