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: sort evm state by total size #81

Merged
merged 1 commit into from
Jan 2, 2025
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
19 changes: 8 additions & 11 deletions tools/cmd/seidb/operations/state_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,17 @@
return true
})

// Convert map to slice in a deterministic way
var addresses []string
for addr := range contractSizes {
addresses = append(addresses, addr)
}
// Sort the addresses
sort.Strings(addresses)

// Use sorted addresses to build sortedContracts
// Convert map to slice
var sortedContracts []contractSizeEntry
for _, addr := range addresses {
sortedContracts = append(sortedContracts, *contractSizes[addr])
for _, entry := range contractSizes {
sortedContracts = append(sortedContracts, *entry)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism

// Sort by total size in descending order
sort.Slice(sortedContracts, func(i, j int) bool {
return sortedContracts[i].TotalSize > sortedContracts[j].TotalSize
})

fmt.Printf("\nDetailed breakdown for 0x03 prefix (top 20 contracts by total size):\n")
fmt.Printf("%-42s %15s %15s %15s %10s\n", "Contract Address", "Key Size", "Value Size", "Total Size", "Key Count")
fmt.Printf("%s\n", strings.Repeat("-", 100))
Expand Down
Loading