From b08a3283c120d7d60bec806901370c0378704f3e Mon Sep 17 00:00:00 2001 From: Jeremy Wei Date: Tue, 16 Jul 2024 17:15:50 -0400 Subject: [PATCH] export, validate, import work locally --- x/wasm/keeper/genesis.go | 27 +++++++++++++++++---------- x/wasm/keeper/keeper.go | 2 ++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/x/wasm/keeper/genesis.go b/x/wasm/keeper/genesis.go index 8204aa2..e75b4dd 100644 --- a/x/wasm/keeper/genesis.go +++ b/x/wasm/keeper/genesis.go @@ -36,6 +36,7 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, staki } } } + fmt.Println("Got maxCodeID = ", maxCodeID) var maxContractID int for i, contract := range data.Contracts { @@ -49,8 +50,11 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, staki } maxContractID = i + 1 // not ideal but max(contractID) is not persisted otherwise } + fmt.Println("maxContractID = ", maxContractID) + fmt.Println("Iterating over data.Sequences = ", data.Sequences) for i, seq := range data.Sequences { + fmt.Println("i = ", i, ", seq = ", seq) err := keeper.importAutoIncrementID(ctx, seq.IDKey, seq.Value) if err != nil { return nil, sdkerrors.Wrapf(err, "sequence number %d", i) @@ -58,7 +62,9 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, staki } // sanity check seq values + fmt.Println("types.KeyLastCodeID = ", string(types.KeyLastCodeID)) seqVal := keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID) + fmt.Println("seqVal = ", seqVal) if seqVal <= maxCodeID { return nil, sdkerrors.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastCodeID), seqVal, maxCodeID) } @@ -138,6 +144,17 @@ func ExportGenesisStream(ctx sdk.Context, keeper *Keeper) <-chan *types.GenesisS genState.Params = keeper.GetParams(ctx) ch <- &genState + // Needs to be first because there are invariant checks when importing that need sequences info + for _, k := range [][]byte{types.KeyLastCodeID, types.KeyLastInstanceID} { + var genState types.GenesisState + genState.Params = keeper.GetParams(ctx) + genState.Sequences = append(genState.Sequences, types.Sequence{ + IDKey: k, + Value: keeper.PeekAutoIncrementID(ctx, k), + }) + ch <- &genState + } + keeper.IterateCodeInfos(ctx, func(codeID uint64, info types.CodeInfo) bool { var genState types.GenesisState genState.Params = keeper.GetParams(ctx) @@ -188,16 +205,6 @@ func ExportGenesisStream(ctx sdk.Context, keeper *Keeper) <-chan *types.GenesisS }) fmt.Println("Done with IterateContractInfo") - for _, k := range [][]byte{types.KeyLastCodeID, types.KeyLastInstanceID} { - var genState types.GenesisState - genState.Params = keeper.GetParams(ctx) - genState.Sequences = append(genState.Sequences, types.Sequence{ - IDKey: k, - Value: keeper.PeekAutoIncrementID(ctx, k), - }) - ch <- &genState - } - close(ch) }() return ch diff --git a/x/wasm/keeper/keeper.go b/x/wasm/keeper/keeper.go index fd4cd12..dbea458 100644 --- a/x/wasm/keeper/keeper.go +++ b/x/wasm/keeper/keeper.go @@ -164,6 +164,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { } func (k Keeper) SetParams(ctx sdk.Context, ps types.Params) { + fmt.Println("In x/wasm, keeper: trying to set params = ", ps) k.paramSpace.SetParamSet(ctx, &ps) } @@ -1000,6 +1001,7 @@ func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 { func (k Keeper) importAutoIncrementID(ctx sdk.Context, lastIDKey []byte, val uint64) error { store := ctx.KVStore(k.storeKey) + fmt.Println("lastIDKey = ", string(lastIDKey)) if store.Has(lastIDKey) { return sdkerrors.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(lastIDKey)) }