Skip to content

plt-224 memoize GetDoneHeight in upgrade keeper to avoid repeated KV reads#3130

Open
amir-deris wants to merge 3 commits intomainfrom
amir/plt-224-cache-memoize-getdoneheight-in-upgrade-keeper
Open

plt-224 memoize GetDoneHeight in upgrade keeper to avoid repeated KV reads#3130
amir-deris wants to merge 3 commits intomainfrom
amir/plt-224-cache-memoize-getdoneheight-in-upgrade-keeper

Conversation

@amir-deris
Copy link
Copy Markdown

@amir-deris amir-deris commented Mar 27, 2026

Summary

GetDoneHeight performs a raw KV store read on every invocation. Under normal operation, this function is called on every eth_sendRawTransaction.

In addition, GetCustomPrecompilesVersions calls GetDoneHeight in a loop over every upgrade version of every precompile, which also runs during gas estimation.

Because upgrade done-heights are written exactly once when an upgrade executes and never change afterward, these repeated KV reads always return the same value.

Fix

Add an in-memory map[string]int64 cache to the upgrade keeper.

  • On the first call for a given upgrade name, read the done-height from the KV store and store it in the cache.
  • On subsequent calls, return the cached value directly.
  • The cache is safe for the lifetime of the process because done-heights are immutable once set.

Expected Impact

This removes the KV store read from the gas-estimation hot path and from the precompile version-resolution loop, reducing CPU time for eth_sendRawTransaction.

Benchmark Results

BenchmarkGetDoneHeightCached-10    17.25 ns/op
BenchmarkGetDoneHeightUncached-10  5840 ns/op

@amir-deris amir-deris self-assigned this Mar 27, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 29, 2026, 2:00 AM

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.75%. Comparing base (82751c6) to head (04e83ee).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3130   +/-   ##
=======================================
  Coverage   58.75%   58.75%           
=======================================
  Files        2094     2094           
  Lines      173084   173090    +6     
=======================================
+ Hits       101696   101702    +6     
  Misses      62333    62333           
  Partials     9055     9055           
Flag Coverage Δ
sei-chain-pr 81.33% <100.00%> (?)
sei-db 70.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-cosmos/x/upgrade/keeper/keeper.go 92.88% <100.00%> (+0.18%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@amir-deris amir-deris force-pushed the amir/plt-224-cache-memoize-getdoneheight-in-upgrade-keeper branch from 35147a6 to 04e83ee Compare March 29, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant