Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Export state analysis data to DynamoDB#101

Merged
yzang2019 merged 9 commits intomainfrom
yzang/state-analysis-data
Aug 29, 2025
Merged

Export state analysis data to DynamoDB#101
yzang2019 merged 9 commits intomainfrom
yzang/state-analysis-data

Conversation

@yzang2019
Copy link
Copy Markdown
Collaborator

@yzang2019 yzang2019 commented Aug 28, 2025

Describe your changes and provide context

This PR is add support to export state size result to DynamoDB so that we can later expose metrics to do more offline analysis

Testing performed to validate your change

Tested and validated on DynamoDB

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.67%. Comparing base (4a62f83) to head (4c49813).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #101      +/-   ##
==========================================
+ Coverage   63.60%   63.67%   +0.07%     
==========================================
  Files          28       28              
  Lines        4047     4047              
==========================================
+ Hits         2574     2577       +3     
+ Misses       1173     1171       -2     
+ Partials      300      299       -1     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +143 to +145
for _, contract := range contracts {
contractSlice = append(contractSlice, *contract)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +219 to +223
for _, result := range moduleResults {
// Create analysis object directly from raw data
analysis := createStateSizeAnalysis(height, result.ModuleName, result)
analyses = append(analyses, analysis)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +259 to +261
for _, entry := range result.ContractSizes {
contractSlice = append(contractSlice, *entry)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment on lines +291 to +293
for _, contract := range result.ContractSizes {
contractSlice = append(contractSlice, *contract)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
Comment thread tools/cmd/seidb/operations/state_size.go Fixed
ValueSizeByPrefix: make(map[string]int64),
TotalSizeByPrefix: make(map[string]int64),
NumKeysByPrefix: make(map[string]int64),
ContractSizes: make(map[string]*utils.ContractSizeEntry),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Questions:

  • How big can these maps get in terms of memory footprint?
  • do we need the exact prefix values or simply their distribution? If latter, hash them to cap the maximum memory footprint?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These maps are pretty small, there are usually less than 10 different key prefix. Each key prefix is like 2 bytes. We need the exact prefix values, since are pretty small, shouldn't be a big concern, but yeah, this is a good point to think about

@yzang2019 yzang2019 requested a review from philipsu522 August 28, 2025 21:35
Comment on lines +226 to +264
for moduleName, result := range moduleResults {
fmt.Printf("Module %s total numKeys:%d, total keySize:%d, total valueSize:%d, totalSize: %d \n",
result.ModuleName, result.TotalNumKeys, result.TotalKeySize, result.TotalValueSize, result.TotalSize)

prefixKeyResult, _ := json.MarshalIndent(result.PrefixSizes[moduleName].KeySize, "", " ")
fmt.Printf("Module %s prefix key size breakdown (bytes): %s \n", result.ModuleName, prefixKeyResult)

prefixValueResult, _ := json.MarshalIndent(result.PrefixSizes[moduleName].ValueSize, "", " ")
fmt.Printf("Module %s prefix value size breakdown (bytes): %s \n", result.ModuleName, prefixValueResult)

totalSizeResult, _ := json.MarshalIndent(result.PrefixSizes[moduleName].TotalSize, "", " ")
fmt.Printf("Module %s prefix total size breakdown (bytes): %s \n", result.ModuleName, totalSizeResult)

numKeysResult, _ := json.MarshalIndent(result.PrefixSizes[moduleName].KeyCount, "", " ")
fmt.Printf("Module %s prefix num of keys breakdown: %s \n", result.ModuleName, numKeysResult)

// Display top contracts (already limited to top 100)
fmt.Printf("\nDetailed breakdown for 0x03 prefix (top %d contracts by total size):\n", len(result.ContractSizes))
fmt.Printf("%-42s %15s %10s\n", "Contract Address", "Total Size", "Key Count")
fmt.Printf("%s\n", strings.Repeat("-", 70))

// Convert to slice for display
var contractSlice []utils.ContractSizeEntry
for _, entry := range result.ContractSizes {
contractSlice = append(contractSlice, *entry)
}

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

for _, contract := range contractSlice {
fmt.Printf("0x%-40s %15d %10d\n",
contract.Address,
contract.TotalSize,
contract.KeyCount)
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
@yzang2019 yzang2019 merged commit 2533953 into main Aug 29, 2025
7 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants