Skip to content

Commit 1c2b3a2

Browse files
authored
Remove upgraded IBC state from x/upgrade and the upgrade precompile (#4340)
With the IBC modules gone and #4337 deleting their stores at v6.8, `x/upgrade` still carried the machinery that existed only to serve IBC light-client upgrades: the `upgradedIBCState/<height>/upgradedClient|upgradedConsState` keys and their `SetUpgradedClient`/`GetUpgradedConsensusState`/`ClearIBCState` keeper helpers, the deprecated `Plan.upgraded_client_state` field and its `ValidateBasic` rejection, the `Query/UpgradedConsensusState` gRPC and REST route, and the `upgradedConsensusState` method on the upgrade precompile at 0x1015. None of it has a consumer on Sei, and keeping it means keeping a path that writes IBC state back into the upgrade store. This removes all of it. `ScheduleUpgrade`, `ClearUpgradePlan` and `ApplyUpgrade` no longer touch IBC keys; `Plan` reserves field 5 rather than carrying a dead `Any`; the upgrade query service loses the deprecated rpc and its request/response messages, with `query.pb.go`, `query.pb.gw.go`, `upgrade.pb.go` and the swagger regenerated for just these two proto files. On the EVM side the method is dropped from the current precompile, its ABI and `Upgrade.sol`, and from the not-yet-wired `legacy/v68` archive so it matches the v6.8 code it will freeze. The `legacy/v67` snapshot keeps the selector and returns empty bytes, which is what it always returned: neither pacific-1 (`/store/upgrade/subspace` at height 234051819) nor atlantic-2 (same query at height 274315652) has any `upgradedIBCState` key, and none of the four passed mainnet IBC proposals was an `UpgradeProposal`, so the state was never written. To keep v6.7-era replays gas-identical, the legacy method still charges the gas of the store read it used to perform (`ReadCostFlat` plus `ReadCostPerByte` over the `upgradedIBCState/<h>/upgradedConsState` key), and `TestPrecompile_UpgradedConsensusStateRemoved` pins that charge. The replay is gas-identical rather than byte-identical in every observable: the read no longer reaches the store, so a `debug_trace*` prestate dump of a historical tx that hit this selector would lack one absent-key `upgrade` store read. That is not consensus-relevant and no such tx is known. A tx carrying `Plan.upgraded_client_state` is still rejected, now by the unknown-field check at decode time instead of `ValidateBasic`; neither path touches state. Amino JSON sign bytes are unchanged because the pointer field was `omitempty`. State impact is limited to the v6.8 upgrade already in #4337, whose `pruneUpgradedIBCState` step stays as a defensive no-op on mainnet. The v6.8 `rewriteRetiredIBCProposals` scan from #4337 is also bounded here: it stops at proposal ID 1000 before decoding anything above it, so zero-deposit proposals submitted in the deposit window before the upgrade cannot stretch the upgrade block. IBC proposal types stopped being submittable at v6.7, when the highest proposal ID on any Sei network was 286, and every IBC proposal on pacific-1 and atlantic-2 has an ID at or below 163. Reviewers should look at the v67 legacy path and at `ClearUpgradePlan`, which is now a plain plan delete. Validated with the `x/upgrade` and `precompiles/upgrade` suites, the tagged v6.8 upgrade tests, the offline v6.7→v6.8 migration and `make lint`.
1 parent 51c3f7c commit 1c2b3a2

24 files changed

Lines changed: 247 additions & 1800 deletions

File tree

‎app/testdata/upgrade_v68_offline_source_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func seedV68IBCProposal(t *testing.T, testApp *App, ctx sdk.Context, retained *o
167167
// which v6.8 prunes.
168168
func seedV68UpgradedIBCState(t *testing.T, testApp *App, ctx sdk.Context, retained *offlineUpgradeRetainedState) {
169169
t.Helper()
170-
key := upgradetypes.UpgradedClientKey(ctx.BlockHeight() + 1000)
170+
key := []byte(fmt.Sprintf("upgradedIBCState/%d/upgradedClient", ctx.BlockHeight()+1000))
171171
ctx.KVStore(testApp.GetKey(upgradetypes.StoreKey)).Set(key, []byte("upgraded-client"))
172172
retained.UpgradedIBCStateKey = encodeOfflineUpgradeKey(key)
173173
}

‎app/upgrade_v68_test.go‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12+
"github.com/sei-protocol/sei-chain/app"
1213
"github.com/sei-protocol/sei-chain/app/retiredoracle"
1314
"github.com/sei-protocol/sei-chain/app/retiredvesting"
1415
codectypes "github.com/sei-protocol/sei-chain/sei-cosmos/codec/types"
@@ -431,6 +432,36 @@ func TestV68RewritesRetiredIBCProposals(t *testing.T) {
431432
require.Len(t, app.GovKeeper.GetProposals(ctx), 2)
432433
}
433434

435+
// TestV68RetiredIBCProposalScanIsBounded pins that the v6.8 proposal rewrite
436+
// decodes nothing above app.RetiredIBCProposalIDLimit: a proposal at the limit is
437+
// still rewritten, while bytes stored just above it are neither decoded nor
438+
// touched, even when they would fail to decode.
439+
func TestV68RetiredIBCProposalScanIsBounded(t *testing.T) {
440+
chain := newV68Chain(t)
441+
ctx := chain.Ctx()
442+
text, err := govtypes.NewProposal(
443+
govtypes.NewTextProposal("edge", "at the limit", false), app.RetiredIBCProposalIDLimit, ctx.BlockTime(), ctx.BlockTime().Add(time.Hour), false)
444+
require.NoError(t, err)
445+
text.Content = &codectypes.Any{
446+
TypeUrl: "/ibc.core.client.v1.ClientUpdateProposal",
447+
Value: v68EncodeStrings("edge", "at the limit", "07-tendermint-0", "07-tendermint-1"),
448+
}
449+
store := ctx.KVStore(chain.GetKey(govtypes.StoreKey))
450+
store.Set(govtypes.ProposalKey(text.ProposalId), chain.GovKeeper.MustMarshalProposal(text))
451+
undecodable := []byte{0xff, 0xff, 0xff}
452+
store.Set(govtypes.ProposalKey(app.RetiredIBCProposalIDLimit+1), undecodable)
453+
store.Set(govtypes.ProposalKey(app.RetiredIBCProposalIDLimit+1_000_000), undecodable)
454+
455+
require.NotPanics(t, func() { applyV68(t, chain) })
456+
457+
proposal, found := chain.GovKeeper.GetProposal(ctx, app.RetiredIBCProposalIDLimit)
458+
require.True(t, found)
459+
require.Equal(t, "/cosmos.gov.v1beta1.TextProposal", proposal.Content.TypeUrl)
460+
require.Equal(t, "at the limit", proposal.GetContent().GetDescription())
461+
require.Equal(t, undecodable, store.Get(govtypes.ProposalKey(app.RetiredIBCProposalIDLimit+1)))
462+
require.Equal(t, undecodable, store.Get(govtypes.ProposalKey(app.RetiredIBCProposalIDLimit+1_000_000)))
463+
}
464+
434465
// v68EncodeStrings protobuf-encodes the given values as consecutive string
435466
// fields numbered from 1.
436467
func v68EncodeStrings(values ...string) []byte {

‎app/upgrades.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ var v68DeletedStores = append([]string{retiredoracle.ModuleName}, retiredIBCStor
2828
// whose decoders no longer exist.
2929
const retiredIBCProposalTypeURLPrefix = "/ibc."
3030

31+
// RetiredIBCProposalIDLimit bounds the proposal scan at the v6.8 upgrade. IBC
32+
// proposal content types stopped being submittable at v6.7, when the highest
33+
// proposal ID on any Sei network was below 300, so proposals above this ID
34+
// cannot carry IBC content and are not decoded. The bound keeps the upgrade
35+
// block's work independent of how many proposals are submitted before it.
36+
const RetiredIBCProposalIDLimit uint64 = 1000
37+
3138
// upgradedIBCStateKeyPrefix is the upgrade-store prefix under which the cosmos
3239
// upgrade module recorded planned IBC client state before IBC was retired.
3340
const upgradedIBCStateKeyPrefix = "upgradedIBCState/"
@@ -169,12 +176,16 @@ func (app *App) deleteRetiredModuleVersions(ctx sdk.Context) {
169176
// rewriteRetiredIBCProposals replaces the content of every stored governance
170177
// proposal whose type lives under an IBC protobuf package with a TextProposal
171178
// carrying the original title and description. The proposal record, its
172-
// deposits, votes and tally indexes are left untouched.
179+
// deposits, votes and tally indexes are left untouched. Proposal keys sort by
180+
// big-endian ID, so the scan stops at RetiredIBCProposalIDLimit.
173181
func (app *App) rewriteRetiredIBCProposals(ctx sdk.Context) {
174182
store := ctx.KVStore(app.GetKey(govtypes.StoreKey))
175183
iterator := sdk.KVStorePrefixIterator(store, govtypes.ProposalsKeyPrefix)
176184
var retired []govtypes.Proposal
177185
for ; iterator.Valid(); iterator.Next() {
186+
if govtypes.SplitProposalKey(iterator.Key()) > RetiredIBCProposalIDLimit {
187+
break
188+
}
178189
var proposal govtypes.Proposal
179190
if err := proposal.Unmarshal(iterator.Value()); err != nil {
180191
panic(err)

‎precompiles/upgrade/Upgrade.sol‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ interface IUpgrade {
1717
string memory name
1818
) external view returns (int64 height);
1919

20-
// Returns the upgraded consensus state stored for the given last height,
21-
// or empty bytes if none is stored.
22-
function upgradedConsensusState(
23-
int64 lastHeight
24-
) external view returns (bytes memory consensusState);
25-
2620
// Returns the consensus versions of app modules. An empty moduleName
2721
// returns all modules; a specific moduleName returns just that module.
2822
function moduleVersions(

‎precompiles/upgrade/abi.json‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,5 @@
7878
],
7979
"stateMutability": "view",
8080
"type": "function"
81-
},
82-
{
83-
"inputs": [
84-
{
85-
"internalType": "int64",
86-
"name": "lastHeight",
87-
"type": "int64"
88-
}
89-
],
90-
"name": "upgradedConsensusState",
91-
"outputs": [
92-
{
93-
"internalType": "bytes",
94-
"name": "consensusState",
95-
"type": "bytes"
96-
}
97-
],
98-
"stateMutability": "view",
99-
"type": "function"
10081
}
10182
]

‎precompiles/upgrade/legacy/v67/upgrade.go‎

Lines changed: 9 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎precompiles/upgrade/legacy/v68/abi.json‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,5 @@
7878
],
7979
"stateMutability": "view",
8080
"type": "function"
81-
},
82-
{
83-
"inputs": [
84-
{
85-
"internalType": "int64",
86-
"name": "lastHeight",
87-
"type": "int64"
88-
}
89-
],
90-
"name": "upgradedConsensusState",
91-
"outputs": [
92-
{
93-
"internalType": "bytes",
94-
"name": "consensusState",
95-
"type": "bytes"
96-
}
97-
],
98-
"stateMutability": "view",
99-
"type": "function"
10081
}
10182
]

‎precompiles/upgrade/legacy/v68/upgrade.go‎

Lines changed: 6 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎precompiles/upgrade/upgrade.go‎

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import (
1616
)
1717

1818
const (
19-
CurrentPlanMethod = "currentPlan"
20-
AppliedPlanMethod = "appliedPlan"
21-
UpgradedConsensusStateMethod = "upgradedConsensusState"
22-
ModuleVersionsMethod = "moduleVersions"
19+
CurrentPlanMethod = "currentPlan"
20+
AppliedPlanMethod = "appliedPlan"
21+
ModuleVersionsMethod = "moduleVersions"
2322
)
2423

2524
const (
@@ -35,10 +34,9 @@ type PrecompileExecutor struct {
3534
evmKeeper utils.EVMKeeper
3635
upgradeQuerier utils.UpgradeQuerier
3736

38-
CurrentPlanID []byte
39-
AppliedPlanID []byte
40-
UpgradedConsensusStateID []byte
41-
ModuleVersionsID []byte
37+
CurrentPlanID []byte
38+
AppliedPlanID []byte
39+
ModuleVersionsID []byte
4240
}
4341

4442
func NewPrecompile(keepers utils.Keepers) (*pcommon.DynamicGasPrecompile, error) {
@@ -55,8 +53,6 @@ func NewPrecompile(keepers utils.Keepers) (*pcommon.DynamicGasPrecompile, error)
5553
p.CurrentPlanID = m.ID
5654
case AppliedPlanMethod:
5755
p.AppliedPlanID = m.ID
58-
case UpgradedConsensusStateMethod:
59-
p.UpgradedConsensusStateID = m.ID
6056
case ModuleVersionsMethod:
6157
p.ModuleVersionsID = m.ID
6258
}
@@ -89,8 +85,6 @@ func (p PrecompileExecutor) Execute(ctx sdk.Context, method *abi.Method, caller
8985
return p.currentPlan(ctx, method, args, value)
9086
case AppliedPlanMethod:
9187
return p.appliedPlan(ctx, method, args, value)
92-
case UpgradedConsensusStateMethod:
93-
return p.upgradedConsensusState(ctx, method, args, value)
9488
case ModuleVersionsMethod:
9589
return p.moduleVersions(ctx, method, args, value)
9690
}
@@ -164,32 +158,6 @@ func (p PrecompileExecutor) appliedPlan(ctx sdk.Context, method *abi.Method, arg
164158
return bz, pcommon.GetRemainingGas(ctx, p.evmKeeper), nil
165159
}
166160

167-
func (p PrecompileExecutor) upgradedConsensusState(ctx sdk.Context, method *abi.Method, args []interface{}, value *big.Int) ([]byte, uint64, error) {
168-
if err := pcommon.ValidateNonPayable(value); err != nil {
169-
return nil, 0, err
170-
}
171-
172-
if err := pcommon.ValidateArgsLength(args, 1); err != nil {
173-
return nil, 0, err
174-
}
175-
176-
// The request type is marked deprecated upstream, but it is still the
177-
// wire type of the Query/UpgradedConsensusState rpc this method mirrors.
178-
request := &upgradetypes.QueryUpgradedConsensusStateRequest{ //nolint:staticcheck
179-
LastHeight: args[0].(int64),
180-
}
181-
response, err := p.upgradeQuerier.UpgradedConsensusState(sdk.WrapSDKContext(ctx), request)
182-
if err != nil {
183-
return nil, 0, err
184-
}
185-
186-
bz, err := method.Outputs.Pack(response.UpgradedConsensusState)
187-
if err != nil {
188-
return nil, 0, err
189-
}
190-
return bz, pcommon.GetRemainingGas(ctx, p.evmKeeper), nil
191-
}
192-
193161
func (p PrecompileExecutor) moduleVersions(ctx sdk.Context, method *abi.Method, args []interface{}, value *big.Int) ([]byte, uint64, error) {
194162
if err := pcommon.ValidateNonPayable(value); err != nil {
195163
return nil, 0, err

0 commit comments

Comments
 (0)