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: fix race condition #24685

Merged
merged 6 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
3 changes: 3 additions & 0 deletions core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ func (dl *diffLayer) Root() common.Hash {

// Parent returns the subsequent layer of a diff layer.
func (dl *diffLayer) Parent() snapshot {
dl.lock.RLock()
defer dl.lock.RUnlock()

return dl.parent
}

Expand Down
3 changes: 3 additions & 0 deletions eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ func (s *Syncer) loadSyncStatus() {
}
}
}
s.lock.Lock()
defer s.lock.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

This won't fix the issue unfortunately. These fields below are updated throughout the snap sync process locklessly. They were meant to be modified only by the syner loop and not accessed from the outside. Adding a lock everywhere will become super brittle.

Trying to figure out what the best approach would be..

Copy link
Member

Choose a reason for hiding this comment

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

  • Using atomic would mess up the struct internals as they need to be 64 byte aligned not to crach on 32 bit platforms.
  • Using locks everywhere to update these fields are yuck
  • Requesting the progress via the syncer via a channel would lead to arbitrary timings since the syncer might be hanging on some leveldb-compaction write.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy it out onto a second one (intended for external exposure) every once in a while, and use locks on that one?


s.snapped = len(s.tasks) == 0

s.accountSynced = progress.AccountSynced
Expand Down