Skip to content

Commit

Permalink
Merge pull request #81 from sei-protocol/yiren/fix-evm-state
Browse files Browse the repository at this point in the history
fix: sort evm state by total size
  • Loading branch information
blindchaser authored Jan 2, 2025
2 parents 06d922a + 91aeee6 commit 77c7807
Showing 1 changed file with 8 additions and 11 deletions.
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 @@ func PrintStateSize(module string, db *memiavl.DB) error {
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)
}

// 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

0 comments on commit 77c7807

Please sign in to comment.