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

fix(lib/runtime): Remove duplicate keys from storageDiff.clearPrefix #4147

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Changes from all 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
14 changes: 9 additions & 5 deletions lib/runtime/storage/storagediff.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ func (cs *storageDiff) clearPrefixInChild(keyToChild string, prefix []byte,
// optional limit. It returns the number of keys deleted and a boolean
// indicating if all keys with the prefix were removed.
func (cs *storageDiff) clearPrefix(prefix []byte, trieKeys []string, limit int) (deleted uint32, allDeleted bool) {
allKeys := slices.Clone(trieKeys)
newKeys := maps.Keys(cs.upserts)
allKeys = append(allKeys, newKeys...)
keysToClear := maps.Keys(cs.upserts)
for _, k := range trieKeys {
if _, ok := cs.upserts[k]; !ok {
keysToClear = append(keysToClear, k)
}
}

deleted = 0
sort.Strings(allKeys)
for _, k := range allKeys {
sort.Strings(keysToClear)
jimjbrettj marked this conversation as resolved.
Show resolved Hide resolved
for _, k := range keysToClear {
if limit == 0 {
break
}
Expand All @@ -161,7 +165,7 @@ func (cs *storageDiff) clearPrefix(prefix []byte, trieKeys []string, limit int)
}
}

return deleted, deleted == uint32(len(allKeys))
return deleted, deleted == uint32(len(keysToClear))
}

// getFromChild attempts to retrieve a value associated with a specific key
Expand Down
Loading