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

eth/protocols/snap: fix the flaws in the snap sync #22553

Merged
merged 10 commits into from
Mar 24, 2021
16 changes: 16 additions & 0 deletions eth/protocols/snap/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,12 @@ func (s *Syncer) processAccountResponse(res *accountResponse) {
// Ensure that the response doesn't overflow into the subsequent task
last := res.task.Last.Big()
for i, hash := range res.hashes {
// Mark the range complete if the last is already included.
// Keep iteration to delete the extra states if exists.
if hash.Big().Cmp(last) == 0 {
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
res.cont = false
continue
}
if hash.Big().Cmp(last) > 0 {
// Chunk overflown, cut off excess, but also update the boundary nodes
for j := i; j < len(res.hashes); j++ {
Expand Down Expand Up @@ -1761,6 +1767,12 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
// Ensure the response doesn't overflow into the subsequent task
last := res.subTask.Last.Big()
for k, hash := range res.hashes[i] {
// Mark the range complete if the last is already included.
// Keep iteration to delete the extra states if exists.
if hash.Big().Cmp(last) == 0 {
res.cont = false
continue
}
rjl493456442 marked this conversation as resolved.
Show resolved Hide resolved
if hash.Big().Cmp(last) > 0 {
// Chunk overflown, cut off excess, but also update the boundary
for l := k; l < len(res.hashes[i]); l++ {
Expand Down Expand Up @@ -1793,6 +1805,10 @@ func (s *Syncer) processStorageResponse(res *storageResponse) {
skipped++
continue
}
if _, err := res.overflow.Get(it.Key()); err == nil {
skipped++
continue
}
}
// Node is not a boundary, persist to disk
batch.Put(it.Key(), it.Value())
Expand Down
Loading