diff --git a/app/app.go b/app/app.go index cb6df3ee9a..44934eae72 100644 --- a/app/app.go +++ b/app/app.go @@ -8,6 +8,7 @@ import ( "path/filepath" "sort" "strings" + "sync" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -27,10 +28,12 @@ import ( ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper" ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" - transfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v8/modules/core" + ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck + ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" @@ -240,6 +243,7 @@ type WasmApp struct { // module configurator configurator module.Configurator + once sync.Once } // NewWasmApp returns a reference to an initialized WasmApp. @@ -920,6 +924,27 @@ func NewWasmApp( return app } +func (app *WasmApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) { + // when skipping sdk 47 for sdk 50, the upgrade handler is called too late in BaseApp + // this is a hack to ensure that the migration is executed when needed and not panics + app.once.Do(func() { + ctx := app.NewUncachedContext(false, tmproto.Header{}) + if _, err := app.ConsensusParamsKeeper.Params(ctx, &consensusparamtypes.QueryParamsRequest{}); err != nil { + // prevents panic: consensus key is nil: collections: not found: key 'no_key' of type github.com/cosmos/gogoproto/tendermint.types.ConsensusParams + // sdk 47: + // Migrate Tendermint consensus parameters from x/params module to a dedicated x/consensus module. + // see https://github.com/cosmos/cosmos-sdk/blob/v0.47.0/simapp/upgrades.go#L66 + baseAppLegacySS := app.GetSubspace(baseapp.Paramspace) + err := baseapp.MigrateParams(sdk.UnwrapSDKContext(ctx), baseAppLegacySS, app.ConsensusParamsKeeper.ParamsStore) + if err != nil { + panic(err) + } + } + }) + + return app.BaseApp.FinalizeBlock(req) +} + func (app *WasmApp) setAnteHandler(txConfig client.TxConfig, wasmConfig wasmtypes.WasmConfig, txCounterStoreKey *storetypes.KVStoreKey) { anteHandler, err := NewAnteHandler( HandlerOptions{ @@ -1174,10 +1199,15 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(slashingtypes.ModuleName) paramsKeeper.Subspace(govtypes.ModuleName) paramsKeeper.Subspace(crisistypes.ModuleName) - paramsKeeper.Subspace(ibctransfertypes.ModuleName) - paramsKeeper.Subspace(ibcexported.ModuleName) - paramsKeeper.Subspace(icahosttypes.SubModuleName) - paramsKeeper.Subspace(icacontrollertypes.SubModuleName) + + // register the IBC key tables for legacy param subspaces + keyTable := ibcclienttypes.ParamKeyTable() + keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}) + paramsKeeper.Subspace(ibcexported.ModuleName).WithKeyTable(keyTable) + paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable()) + paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable()) + paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable()) + paramsKeeper.Subspace(wasmtypes.ModuleName) return paramsKeeper } diff --git a/app/upgrades.go b/app/upgrades.go index f8634ac0f2..2ffaa17b70 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -3,35 +3,49 @@ package app import ( "fmt" - icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" - icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" - ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" - ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck - ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types" - ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" - upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/baseapp" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/CosmWasm/wasmd/app/upgrades" "github.com/CosmWasm/wasmd/app/upgrades/noop" v050 "github.com/CosmWasm/wasmd/app/upgrades/v050" + v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" ) // Upgrades list of chain upgrades var Upgrades = []upgrades.Upgrade{v050.Upgrade} // RegisterUpgradeHandlers registers the chain upgrade handlers -func (app WasmApp) RegisterUpgradeHandlers() { - setupLegacyKeyTables(app.ParamsKeeper) +func (app *WasmApp) RegisterUpgradeHandlers() { + setupLegacyKeyTables(&app.ParamsKeeper) if len(Upgrades) == 0 { // always have a unique upgrade registered for the current version to test in system tests Upgrades = append(Upgrades, noop.NewUpgrade(app.Version())) } - keepers := upgrades.AppKeepers{AccountKeeper: app.AccountKeeper} + keepers := upgrades.AppKeepers{ + AccountKeeper: &app.AccountKeeper, + ParamsKeeper: &app.ParamsKeeper, + ConsensusParamsKeeper: &app.ConsensusParamsKeeper, + CapabilityKeeper: app.CapabilityKeeper, + IBCKeeper: app.IBCKeeper, + Codec: app.appCodec, + GetStoreKey: app.GetKey, + } + app.GetStoreKeys() // register all upgrade handlers for _, upgrade := range Upgrades { app.UpgradeKeeper.SetUpgradeHandler( @@ -62,23 +76,31 @@ func (app WasmApp) RegisterUpgradeHandlers() { } } -func setupLegacyKeyTables(k paramskeeper.Keeper) { - // Set param key table for params module migration +func setupLegacyKeyTables(k *paramskeeper.Keeper) { for _, subspace := range k.GetSubspaces() { subspace := subspace var keyTable paramstypes.KeyTable switch subspace.Name() { - // ibc types - case ibcexported.ModuleName: - keyTable = ibcclienttypes.ParamKeyTable() - keyTable.RegisterParamSet(&ibcconnectiontypes.Params{}) - case ibctransfertypes.ModuleName: - keyTable = ibctransfertypes.ParamKeyTable() - case icahosttypes.SubModuleName: - keyTable = icahosttypes.ParamKeyTable() - case icacontrollertypes.SubModuleName: - keyTable = icacontrollertypes.ParamKeyTable() + case authtypes.ModuleName: + keyTable = authtypes.ParamKeyTable() //nolint:staticcheck + case banktypes.ModuleName: + keyTable = banktypes.ParamKeyTable() //nolint:staticcheck + case stakingtypes.ModuleName: + keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck + case minttypes.ModuleName: + keyTable = minttypes.ParamKeyTable() //nolint:staticcheck + case distrtypes.ModuleName: + keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck + case slashingtypes.ModuleName: + keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck + case govtypes.ModuleName: + keyTable = govv1.ParamKeyTable() //nolint:staticcheck + case crisistypes.ModuleName: + keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck + // wasm + case wasmtypes.ModuleName: + keyTable = v2.ParamKeyTable() //nolint:staticcheck default: continue } @@ -87,4 +109,7 @@ func setupLegacyKeyTables(k paramskeeper.Keeper) { subspace.WithKeyTable(keyTable) } } + // sdk 47 + k.Subspace(baseapp.Paramspace). + WithKeyTable(paramstypes.ConsensusParamsKeyTable()) } diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 2cce0a19b1..2ff71ce631 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -3,15 +3,27 @@ package upgrades import ( "context" + capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" + storetypes "cosmossdk.io/store/types" upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" ) type AppKeepers struct { - authkeeper.AccountKeeper + AccountKeeper *authkeeper.AccountKeeper + ParamsKeeper *paramskeeper.Keeper + ConsensusParamsKeeper *consensusparamkeeper.Keeper + Codec codec.Codec + GetStoreKey func(storeKey string) *storetypes.KVStoreKey + CapabilityKeeper *capabilitykeeper.Keeper + IBCKeeper *ibckeeper.Keeper } type ModuleManager interface { RunMigrations(ctx context.Context, cfg module.Configurator, fromVM module.VersionMap) (module.VersionMap, error) diff --git a/app/upgrades/v050/upgrades.go b/app/upgrades/v050/upgrades.go index 99d39b6db7..091cfe9be8 100644 --- a/app/upgrades/v050/upgrades.go +++ b/app/upgrades/v050/upgrades.go @@ -31,6 +31,7 @@ func CreateUpgradeHandler( configurator module.Configurator, ak *upgrades.AppKeepers, ) upgradetypes.UpgradeHandler { + // sdk 47 to sdk 50 return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { return mm.RunMigrations(ctx, configurator, fromVM) } diff --git a/app/upgrades/v050/upgrades.go_wasmd_33_example.txt b/app/upgrades/v050/upgrades.go_wasmd_33_example.txt new file mode 100644 index 0000000000..e3853b105b --- /dev/null +++ b/app/upgrades/v050/upgrades.go_wasmd_33_example.txt @@ -0,0 +1,73 @@ +package v050 + +import ( + "context" + + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + v6 "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/migrations/v6" + icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" + ibctmmigrations "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint/migrations" + + storetypes "cosmossdk.io/store/types" + circuittypes "cosmossdk.io/x/circuit/types" + "cosmossdk.io/x/nft" + upgradetypes "cosmossdk.io/x/upgrade/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + "github.com/cosmos/cosmos-sdk/x/group" + + "github.com/CosmWasm/wasmd/app/upgrades" +) + +// UpgradeName defines the on-chain upgrade name +const UpgradeName = "v0.50" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: storetypes.StoreUpgrades{ + Added: []string{ + // SDK 46 + group.ModuleName, + nft.ModuleName, + // SDK 47 + crisistypes.ModuleName, + consensusparamtypes.ModuleName, + // SDK 50 + circuittypes.ModuleName, + }, + Deleted: []string{}, + }, +} + +func CreateUpgradeHandler( + mm upgrades.ModuleManager, + configurator module.Configurator, + ak *upgrades.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + // ibc v6 + // NOTE: The moduleName arg of v6.CreateUpgradeHandler refers to the auth module ScopedKeeper name to which the channel capability should be migrated from. + // This should be the same string value provided upon instantiation of the ScopedKeeper with app.CapabilityKeeper.ScopeToModule() + const moduleName = icacontrollertypes.SubModuleName + if err := v6.MigrateICS27ChannelCapability(sdkCtx, ak.Codec, ak.GetStoreKey(capabilitytypes.ModuleName), + ak.CapabilityKeeper, moduleName); err != nil { + return nil, err + } + + // ibc v7 + if _, err := ibctmmigrations.PruneExpiredConsensusStates(sdkCtx, ak.Codec, ak.IBCKeeper.ClientKeeper); err != nil { + return nil, err + } + + // sdk 47 + // consensus params migration is done in app.go FinalizeBlock function to prevent panic + + // sdk 50 + return mm.RunMigrations(ctx, configurator, fromVM) + } +} diff --git a/cmd/wasmd/root.go b/cmd/wasmd/root.go index d2cafcbfd1..6f6022336b 100644 --- a/cmd/wasmd/root.go +++ b/cmd/wasmd/root.go @@ -37,7 +37,7 @@ func NewRootCmd() *cobra.Command { cfg.Seal() // we "pre"-instantiate the application for getting the injected/configured encoding configuration // note, this is not necessary when using app wiring, as depinject can be directly used (see root_v2.go) - tempApp := app.NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir()), []wasmkeeper.Option{}) + tempApp := app.NewWasmApp(log.NewNopLogger(), dbm.NewMemDB(), nil, false, simtestutil.NewAppOptionsWithFlagHome(tempDir()), []wasmkeeper.Option{}) encodingConfig := params.EncodingConfig{ InterfaceRegistry: tempApp.InterfaceRegistry(), Codec: tempApp.AppCodec(), diff --git a/x/wasm/keeper/migrations_integration_test.go b/x/wasm/keeper/migrations_integration_test.go index a2ec8fd329..0962a79977 100644 --- a/x/wasm/keeper/migrations_integration_test.go +++ b/x/wasm/keeper/migrations_integration_test.go @@ -3,20 +3,24 @@ package keeper_test import ( "testing" + "github.com/cometbft/cometbft/libs/rand" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" upgradetypes "cosmossdk.io/x/upgrade/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/module" "github.com/CosmWasm/wasmd/app" + v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2" "github.com/CosmWasm/wasmd/x/wasm/types" ) func TestModuleMigrations(t *testing.T) { wasmApp := app.Setup(t) + myAddress := sdk.AccAddress(rand.Bytes(address.Len)) upgradeHandler := func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { //nolint:unparam return wasmApp.ModuleManager.RunMigrations(ctx, wasmApp.Configurator(), fromVM) @@ -30,15 +34,15 @@ func TestModuleMigrations(t *testing.T) { "with legacy params migrated": { startVersion: 1, setup: func(ctx sdk.Context) { - params := types.Params{ - CodeUploadAccess: types.AllowNobody, - InstantiateDefaultPermission: types.AccessTypeNobody, + params := v2.Params{ + CodeUploadAccess: v2.AccessConfig{Permission: v2.AccessTypeNobody}, + InstantiateDefaultPermission: v2.AccessTypeNobody, } // upgrade code shipped with v0.40 // https://github.com/CosmWasm/wasmd/blob/v0.40.0/app/upgrades.go#L66 sp, _ := wasmApp.ParamsKeeper.GetSubspace(types.ModuleName) - keyTable := types.ParamKeyTable() + keyTable := v2.ParamKeyTable() if !sp.HasKeyTable() { sp.WithKeyTable(keyTable) } @@ -50,6 +54,29 @@ func TestModuleMigrations(t *testing.T) { InstantiateDefaultPermission: types.AccessTypeNobody, }, }, + "with legacy one address type replaced": { + startVersion: 1, + setup: func(ctx sdk.Context) { + params := v2.Params{ + CodeUploadAccess: v2.AccessConfig{Permission: v2.AccessTypeOnlyAddress, Address: myAddress.String()}, + InstantiateDefaultPermission: v2.AccessTypeNobody, + } + + // upgrade code shipped with v0.40 + // https://github.com/CosmWasm/wasmd/blob/v0.40.0/app/upgrades.go#L66 + sp, _ := wasmApp.ParamsKeeper.GetSubspace(types.ModuleName) + keyTable := v2.ParamKeyTable() + if !sp.HasKeyTable() { + sp.WithKeyTable(keyTable) + } + + sp.SetParamSet(ctx, ¶ms) + }, + exp: types.Params{ + CodeUploadAccess: types.AccessTypeAnyOfAddresses.With(myAddress), + InstantiateDefaultPermission: types.AccessTypeNobody, + }, + }, "fresh from genesis": { startVersion: wasmApp.ModuleManager.GetVersionMap()[types.ModuleName], // latest setup: func(ctx sdk.Context) {}, diff --git a/x/wasm/migrations/v2/legacy_types.go b/x/wasm/migrations/v2/legacy_types.go new file mode 100644 index 0000000000..787c28b574 --- /dev/null +++ b/x/wasm/migrations/v2/legacy_types.go @@ -0,0 +1,1219 @@ +package v2 + +import ( + bytes "bytes" + fmt "fmt" + io "io" + math_bits "math/bits" + + proto "github.com/cosmos/gogoproto/proto" + "gopkg.in/yaml.v2" +) + +// AccessType permission types +type AccessType int32 + +const ( + // AccessTypeUnspecified placeholder for empty value + AccessTypeUnspecified AccessType = 0 + // AccessTypeNobody forbidden + AccessTypeNobody AccessType = 1 + // AccessTypeOnlyAddress restricted to a single address + // Deprecated: use AccessTypeAnyOfAddresses instead + AccessTypeOnlyAddress AccessType = 2 + // AccessTypeEverybody unrestricted + AccessTypeEverybody AccessType = 3 + // AccessTypeAnyOfAddresses allow any of the addresses + AccessTypeAnyOfAddresses AccessType = 4 +) + +var AccessType_name = map[int32]string{ + 0: "ACCESS_TYPE_UNSPECIFIED", + 1: "ACCESS_TYPE_NOBODY", + 2: "ACCESS_TYPE_ONLY_ADDRESS", + 3: "ACCESS_TYPE_EVERYBODY", + 4: "ACCESS_TYPE_ANY_OF_ADDRESSES", +} + +var AccessType_value = map[string]int32{ + "ACCESS_TYPE_UNSPECIFIED": 0, + "ACCESS_TYPE_NOBODY": 1, + "ACCESS_TYPE_ONLY_ADDRESS": 2, + "ACCESS_TYPE_EVERYBODY": 3, + "ACCESS_TYPE_ANY_OF_ADDRESSES": 4, +} + +func (AccessType) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_e6155d98fa173e02, []int{0} +} + +// AccessTypeParam +type AccessTypeParam struct { + Value AccessType `protobuf:"varint,1,opt,name=value,proto3,enum=cosmwasm.wasm.v1.AccessType" json:"value,omitempty" yaml:"value"` +} + +func (m *AccessTypeParam) Reset() { *m = AccessTypeParam{} } +func (m *AccessTypeParam) String() string { return proto.CompactTextString(m) } +func (*AccessTypeParam) ProtoMessage() {} +func (*AccessTypeParam) Descriptor() ([]byte, []int) { + return fileDescriptor_e6155d98fa173e02, []int{0} +} + +func (m *AccessTypeParam) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *AccessTypeParam) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AccessTypeParam.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *AccessTypeParam) XXX_Merge(src proto.Message) { + xxx_messageInfo_AccessTypeParam.Merge(m, src) +} + +func (m *AccessTypeParam) XXX_Size() int { + return m.Size() +} + +func (m *AccessTypeParam) XXX_DiscardUnknown() { + xxx_messageInfo_AccessTypeParam.DiscardUnknown(m) +} + +var xxx_messageInfo_AccessTypeParam proto.InternalMessageInfo + +// AccessConfig access control type. +type AccessConfig struct { + Permission AccessType `protobuf:"varint,1,opt,name=permission,proto3,enum=cosmwasm.wasm.v1.AccessType" json:"permission,omitempty" yaml:"permission"` + // Address + // Deprecated: replaced by addresses + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty" yaml:"address"` + Addresses []string `protobuf:"bytes,3,rep,name=addresses,proto3" json:"addresses,omitempty" yaml:"addresses"` +} + +func (m *AccessConfig) Reset() { *m = AccessConfig{} } +func (m *AccessConfig) String() string { return proto.CompactTextString(m) } +func (*AccessConfig) ProtoMessage() {} +func (*AccessConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_e6155d98fa173e02, []int{1} +} + +func (m *AccessConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *AccessConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AccessConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *AccessConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_AccessConfig.Merge(m, src) +} + +func (m *AccessConfig) XXX_Size() int { + return m.Size() +} + +func (m *AccessConfig) XXX_DiscardUnknown() { + xxx_messageInfo_AccessConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_AccessConfig proto.InternalMessageInfo + +// Params defines the set of wasm parameters. +type Params struct { + CodeUploadAccess AccessConfig `protobuf:"bytes,1,opt,name=code_upload_access,json=codeUploadAccess,proto3" json:"code_upload_access" yaml:"code_upload_access"` + InstantiateDefaultPermission AccessType `protobuf:"varint,2,opt,name=instantiate_default_permission,json=instantiateDefaultPermission,proto3,enum=cosmwasm.wasm.v1.AccessType" json:"instantiate_default_permission,omitempty" yaml:"instantiate_default_permission"` +} + +func (p Params) String() string { + out, err := yaml.Marshal(p) + if err != nil { + panic(err) + } + return string(out) +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_e6155d98fa173e02, []int{2} +} + +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} + +func (m *Params) XXX_Size() int { + return m.Size() +} + +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +// CodeInfo is data for the uploaded contract WASM code +type CodeInfo struct { + // CodeHash is the unique identifier created by wasmvm + CodeHash []byte `protobuf:"bytes,1,opt,name=code_hash,json=codeHash,proto3" json:"code_hash,omitempty"` + // Creator address who initially stored the code + Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"` + // InstantiateConfig access control to apply on contract creation, optional + InstantiateConfig AccessConfig `protobuf:"bytes,5,opt,name=instantiate_config,json=instantiateConfig,proto3" json:"instantiate_config"` +} + +func (m *CodeInfo) Reset() { *m = CodeInfo{} } +func (m *CodeInfo) String() string { return proto.CompactTextString(m) } +func (*CodeInfo) ProtoMessage() {} +func (*CodeInfo) Descriptor() ([]byte, []int) { + return fileDescriptor_e6155d98fa173e02, []int{3} +} + +func (m *CodeInfo) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} + +func (m *CodeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CodeInfo.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} + +func (m *CodeInfo) XXX_Merge(src proto.Message) { + xxx_messageInfo_CodeInfo.Merge(m, src) +} + +func (m *CodeInfo) XXX_Size() int { + return m.Size() +} + +func (m *CodeInfo) XXX_DiscardUnknown() { + xxx_messageInfo_CodeInfo.DiscardUnknown(m) +} + +var xxx_messageInfo_CodeInfo proto.InternalMessageInfo + +var fileDescriptor_e6155d98fa173e02 = []byte{ + // 1201 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xcf, 0x8f, 0xdb, 0xc4, + 0x17, 0x8f, 0x93, 0xec, 0x8f, 0x4c, 0xf7, 0xdb, 0xaf, 0x3b, 0x6c, 0x69, 0x36, 0xac, 0x92, 0x60, + 0x4a, 0xd9, 0x6e, 0xdb, 0xa4, 0x5d, 0x10, 0x48, 0x3d, 0x54, 0xca, 0x0f, 0xb7, 0xeb, 0x8a, 0x4d, + 0xa2, 0x49, 0x4a, 0x59, 0xa4, 0x62, 0x39, 0xf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28, 0x2b, 0xfd, 0x7e, 0x94, 0x95, 0xbe, 0x78, + 0x92, 0x8d, 0x3d, 0x7e, 0x92, 0x8d, 0xfd, 0xf6, 0x24, 0x1b, 0xfb, 0xe4, 0x42, 0xe4, 0x0d, 0x55, + 0x08, 0xed, 0xdf, 0x0d, 0x7e, 0xc4, 0xac, 0xe2, 0x48, 0xfc, 0x90, 0xf1, 0xbf, 0xb1, 0xf6, 0x32, + 0x1f, 0x91, 0xef, 0xfe, 0x13, 0x00, 0x00, 0xff, 0xff, 0x69, 0x83, 0x28, 0x71, 0xae, 0x09, 0x00, + 0x00, +} + +func (m *AccessTypeParam) Equal(that interface{}) bool { + if that == nil { + return m == nil + } + + that1, ok := that.(*AccessTypeParam) + if !ok { + that2, ok := that.(AccessTypeParam) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return m == nil + } else if m == nil { + return false + } + if m.Value != that1.Value { + return false + } + return true +} + +func (m *AccessConfig) Equal(that interface{}) bool { + if that == nil { + return m == nil + } + + that1, ok := that.(*AccessConfig) + if !ok { + that2, ok := that.(AccessConfig) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return m == nil + } else if m == nil { + return false + } + if m.Permission != that1.Permission { + return false + } + if m.Address != that1.Address { + return false + } + if len(m.Addresses) != len(that1.Addresses) { + return false + } + for i := range m.Addresses { + if m.Addresses[i] != that1.Addresses[i] { + return false + } + } + return true +} + +func (m *Params) Equal(that interface{}) bool { + if that == nil { + return m == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return m == nil + } else if m == nil { + return false + } + if !m.CodeUploadAccess.Equal(&that1.CodeUploadAccess) { + return false + } + if m.InstantiateDefaultPermission != that1.InstantiateDefaultPermission { + return false + } + return true +} + +func (m *CodeInfo) Equal(that interface{}) bool { + if that == nil { + return m == nil + } + + that1, ok := that.(*CodeInfo) + if !ok { + that2, ok := that.(CodeInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return m == nil + } else if m == nil { + return false + } + if !bytes.Equal(m.CodeHash, that1.CodeHash) { + return false + } + if m.Creator != that1.Creator { + return false + } + if !m.InstantiateConfig.Equal(&that1.InstantiateConfig) { + return false + } + return true +} + +func (m *AccessTypeParam) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AccessTypeParam) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AccessTypeParam) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Value != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Value)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *AccessConfig) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AccessConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AccessConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if m.Permission != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Permission)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.InstantiateDefaultPermission != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.InstantiateDefaultPermission)) + i-- + dAtA[i] = 0x10 + } + { + size, err := m.CodeUploadAccess.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *CodeInfo) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CodeInfo) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CodeInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.InstantiateConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0x12 + } + if len(m.CodeHash) > 0 { + i -= len(m.CodeHash) + copy(dAtA[i:], m.CodeHash) + i = encodeVarintTypes(dAtA, i, uint64(len(m.CodeHash))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} + +func (m *AccessTypeParam) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Value != 0 { + n += 1 + sovTypes(uint64(m.Value)) + } + return n +} + +func (m *AccessConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Permission != 0 { + n += 1 + sovTypes(uint64(m.Permission)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + if len(m.Addresses) > 0 { + for _, s := range m.Addresses { + l = len(s) + n += 1 + l + sovTypes(uint64(l)) + } + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.CodeUploadAccess.Size() + n += 1 + l + sovTypes(uint64(l)) + if m.InstantiateDefaultPermission != 0 { + n += 1 + sovTypes(uint64(m.InstantiateDefaultPermission)) + } + return n +} + +func (m *CodeInfo) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CodeHash) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.InstantiateConfig.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} + +func (m *AccessTypeParam) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AccessTypeParam: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AccessTypeParam: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + m.Value = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Value |= AccessType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *AccessConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AccessConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AccessConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Permission", wireType) + } + m.Permission = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Permission |= AccessType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeUploadAccess", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.CodeUploadAccess.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field InstantiateDefaultPermission", wireType) + } + m.InstantiateDefaultPermission = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.InstantiateDefaultPermission |= AccessType(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func (m *CodeInfo) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CodeInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CodeInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CodeHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CodeHash = append(m.CodeHash[:0], dAtA[iNdEx:postIndex]...) + if m.CodeHash == nil { + m.CodeHash = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field InstantiateConfig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.InstantiateConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} + +func skipTypes(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTypes + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/wasm/migrations/v2/params_legacy.go b/x/wasm/migrations/v2/params_legacy.go new file mode 100644 index 0000000000..d4fad0bdef --- /dev/null +++ b/x/wasm/migrations/v2/params_legacy.go @@ -0,0 +1,142 @@ +/* +NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov +controlled execution of MsgUpdateParams messages. These types remains solely +for migration purposes and will be removed in a future release. +*/ +package v2 + +import ( + "encoding/json" + "fmt" + + "github.com/cosmos/gogoproto/jsonpb" + + errorsmod "cosmossdk.io/errors" + + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/CosmWasm/wasmd/x/wasm/types" +) + +var ( + ParamStoreKeyUploadAccess = []byte("uploadAccess") + ParamStoreKeyInstantiateAccess = []byte("instantiateAccess") +) + +// Deprecated: Type declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// ParamSetPairs returns the parameter set pairs. +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(ParamStoreKeyUploadAccess, &p.CodeUploadAccess, validateAccessConfig), + paramtypes.NewParamSetPair(ParamStoreKeyInstantiateAccess, &p.InstantiateDefaultPermission, validateAccessType), + } +} + +func validateAccessConfig(i interface{}) error { + v, ok := i.(AccessConfig) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return v.ValidateBasic() +} + +var AllAccessTypes = []AccessType{ + AccessTypeNobody, + AccessTypeOnlyAddress, + AccessTypeAnyOfAddresses, + AccessTypeEverybody, +} + +func validateAccessType(i interface{}) error { + a, ok := i.(AccessType) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if a == AccessTypeUnspecified { + return errorsmod.Wrap(types.ErrEmpty, "type") + } + for _, v := range AllAccessTypes { + if v == a { + return nil + } + } + return errorsmod.Wrapf(types.ErrInvalid, "unknown type: %q", a) +} + +func (a AccessConfig) ValidateBasic() error { + switch a.Permission { + case AccessTypeUnspecified: + return errorsmod.Wrap(types.ErrEmpty, "type") + case AccessTypeNobody, AccessTypeEverybody: + return nil + case AccessTypeOnlyAddress: + _, err := sdk.AccAddressFromBech32(a.Address) + return errorsmod.Wrap(err, "only address") + case AccessTypeAnyOfAddresses: + return errorsmod.Wrap(assertValidAddresses(a.Addresses), "addresses") + } + return errorsmod.Wrapf(types.ErrInvalid, "unknown type: %q", a.Permission) +} + +func assertValidAddresses(addrs []string) error { + if len(addrs) == 0 { + return types.ErrEmpty + } + idx := make(map[string]struct{}, len(addrs)) + for _, a := range addrs { + if _, err := sdk.AccAddressFromBech32(a); err != nil { + return errorsmod.Wrapf(err, "address: %s", a) + } + if _, exists := idx[a]; exists { + return types.ErrDuplicate.Wrapf("address: %s", a) + } + idx[a] = struct{}{} + } + return nil +} + +func (a AccessType) String() string { + switch a { + case AccessTypeNobody: + return "Nobody" + case AccessTypeOnlyAddress: + return "OnlyAddress" + case AccessTypeEverybody: + return "Everybody" + case AccessTypeAnyOfAddresses: + return "AnyOfAddresses" + } + return "Unspecified" +} + +func (a *AccessType) UnmarshalText(text []byte) error { + for _, v := range AllAccessTypes { + if v.String() == string(text) { + *a = v + return nil + } + } + *a = AccessTypeUnspecified + return nil +} + +func (a AccessType) MarshalText() ([]byte, error) { + return []byte(a.String()), nil +} + +func (a *AccessType) MarshalJSONPB(_ *jsonpb.Marshaler) ([]byte, error) { + return json.Marshal(a) +} + +func (a *AccessType) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, data []byte) error { + return json.Unmarshal(data, a) +} + +func (a AccessConfig) Equals(o AccessConfig) bool { + return a.Permission == o.Permission && a.Address == o.Address +} diff --git a/x/wasm/migrations/v2/params_legacy_test.go b/x/wasm/migrations/v2/params_legacy_test.go new file mode 100644 index 0000000000..d405b0b368 --- /dev/null +++ b/x/wasm/migrations/v2/params_legacy_test.go @@ -0,0 +1,89 @@ +package v2 + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/codec" +) + +func TestAccessTypeMarshalJson(t *testing.T) { + specs := map[string]struct { + src AccessType + exp string + }{ + "Unspecified": {src: AccessTypeUnspecified, exp: `"Unspecified"`}, + "Nobody": {src: AccessTypeNobody, exp: `"Nobody"`}, + "OnlyAddress": {src: AccessTypeOnlyAddress, exp: `"OnlyAddress"`}, + "AccessTypeAnyOfAddresses": {src: AccessTypeAnyOfAddresses, exp: `"AnyOfAddresses"`}, + "Everybody": {src: AccessTypeEverybody, exp: `"Everybody"`}, + "unknown": {src: 999, exp: `"Unspecified"`}, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + got, err := json.Marshal(spec.src) + require.NoError(t, err) + assert.Equal(t, []byte(spec.exp), got) + }) + } +} + +func TestAccessTypeUnmarshalJson(t *testing.T) { + specs := map[string]struct { + src string + exp AccessType + }{ + "Unspecified": {src: `"Unspecified"`, exp: AccessTypeUnspecified}, + "Nobody": {src: `"Nobody"`, exp: AccessTypeNobody}, + "OnlyAddress": {src: `"OnlyAddress"`, exp: AccessTypeOnlyAddress}, + "AnyOfAddresses": {src: `"AnyOfAddresses"`, exp: AccessTypeAnyOfAddresses}, + "Everybody": {src: `"Everybody"`, exp: AccessTypeEverybody}, + "unknown": {src: `""`, exp: AccessTypeUnspecified}, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + var got AccessType + err := json.Unmarshal([]byte(spec.src), &got) + require.NoError(t, err) + assert.Equal(t, spec.exp, got) + }) + } +} + +func TestParamsUnmarshalJson(t *testing.T) { + specs := map[string]struct { + src string + exp Params + }{ + "defaults": { + src: `{"code_upload_access": {"permission": "Everybody"}, + "instantiate_default_permission": "Everybody"}`, + exp: Params{ + CodeUploadAccess: AccessConfig{Permission: AccessTypeEverybody}, + InstantiateDefaultPermission: AccessTypeEverybody, + }, + }, + "legacy type": { + src: `{"code_upload_access": {"permission": "OnlyAddress", "address": "wasm1lq3q55r9sqwqyrfmlp6xy8ufhayt96lmcttthz", "addresses": [] }, + "instantiate_default_permission": "Nobody"}`, + exp: Params{ + CodeUploadAccess: AccessConfig{ + Permission: AccessTypeOnlyAddress, Address: "wasm1lq3q55r9sqwqyrfmlp6xy8ufhayt96lmcttthz", Addresses: nil, + }, + InstantiateDefaultPermission: AccessTypeNobody, + }, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + var val Params + marshaler := codec.NewLegacyAmino() + err := marshaler.UnmarshalJSON([]byte(spec.src), &val) + require.NoError(t, err) + assert.Equal(t, spec.exp, val) + }) + } +} diff --git a/x/wasm/migrations/v2/store.go b/x/wasm/migrations/v2/store.go index de1490dbca..481ef6865c 100644 --- a/x/wasm/migrations/v2/store.go +++ b/x/wasm/migrations/v2/store.go @@ -16,13 +16,8 @@ import ( // module state. func MigrateStore(ctx sdk.Context, storeService corestoretypes.KVStoreService, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error { store := storeService.OpenKVStore(ctx) - var currParams types.Params + var currParams Params legacySubspace.GetParamSet(ctx, &currParams) - - if err := currParams.ValidateBasic(); err != nil { - return err - } - bz, err := cdc.Marshal(&currParams) if err != nil { return err diff --git a/x/wasm/migrations/v2/store_test.go b/x/wasm/migrations/v2/store_test.go index df52ef3686..f087e6f42f 100644 --- a/x/wasm/migrations/v2/store_test.go +++ b/x/wasm/migrations/v2/store_test.go @@ -3,6 +3,8 @@ package v2_test import ( "testing" + "github.com/cometbft/cometbft/libs/rand" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" storetypes "cosmossdk.io/store/types" @@ -10,38 +12,90 @@ import ( "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/CosmWasm/wasmd/x/wasm" - "github.com/CosmWasm/wasmd/x/wasm/exported" v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2" "github.com/CosmWasm/wasmd/x/wasm/types" ) -type mockSubspace struct { - ps types.Params -} +func TestMigrate(t *testing.T) { + cfg := moduletestutil.MakeTestEncodingConfig(wasm.AppModuleBasic{}) + cdc := cfg.Codec + var ( + wasmStoreKey = storetypes.NewKVStoreKey(types.StoreKey) + paramsStoreKey = storetypes.NewKVStoreKey(paramstypes.StoreKey) + paramsTStoreKey = storetypes.NewTransientStoreKey(paramstypes.TStoreKey) + myAddress = sdk.AccAddress(rand.Bytes(address.Len)) + ) + specs := map[string]struct { + src v2.Params + }{ + "one address": { + src: v2.Params{ + CodeUploadAccess: v2.AccessConfig{ + Permission: v2.AccessTypeOnlyAddress, + Address: myAddress.String(), + }, + InstantiateDefaultPermission: v2.AccessTypeNobody, + }, + }, + "multiple addresses": { + src: v2.Params{ + CodeUploadAccess: v2.AccessConfig{ + Permission: v2.AccessTypeAnyOfAddresses, + Addresses: []string{myAddress.String(), sdk.AccAddress(rand.Bytes(address.Len)).String()}, + }, + InstantiateDefaultPermission: v2.AccessTypeEverybody, + }, + }, + "everybody": { + src: v2.Params{ + CodeUploadAccess: v2.AccessConfig{ + Permission: v2.AccessTypeEverybody, + }, + InstantiateDefaultPermission: v2.AccessTypeEverybody, + }, + }, + "nobody": { + src: v2.Params{ + CodeUploadAccess: v2.AccessConfig{ + Permission: v2.AccessTypeNobody, + }, + InstantiateDefaultPermission: v2.AccessTypeNobody, + }, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + paramsKeeper := paramskeeper.NewKeeper(cdc, cfg.Amino, paramsStoreKey, paramsTStoreKey) + ctx := testutil.DefaultContextWithKeys( + map[string]*storetypes.KVStoreKey{ + paramstypes.StoreKey: paramsStoreKey, + types.StoreKey: wasmStoreKey, + }, + map[string]*storetypes.TransientStoreKey{ + paramstypes.TStoreKey: paramsTStoreKey, + }, + nil, + ) -func newMockSubspace(ps types.Params) mockSubspace { - return mockSubspace{ps: ps} -} + // register legacy parameters + params := spec.src + subspace := paramsKeeper.Subspace(types.ModuleName) + subspace.WithKeyTable(v2.ParamKeyTable()) + subspace.SetParamSet(ctx, ¶ms) -func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { - *ps.(*types.Params) = ms.ps -} + // when + require.NoError(t, v2.MigrateStore(ctx, runtime.NewKVStoreService(wasmStoreKey), subspace, cdc)) -func TestMigrate(t *testing.T) { - cdc := moduletestutil.MakeTestEncodingConfig(wasm.AppModuleBasic{}).Codec - storeKey := storetypes.NewKVStoreKey(types.StoreKey) - tKey := storetypes.NewTransientStoreKey("transient_test") - ctx := testutil.DefaultContext(storeKey, tKey) - store := ctx.KVStore(storeKey) - - legacySubspace := newMockSubspace(types.DefaultParams()) - require.NoError(t, v2.MigrateStore(ctx, runtime.NewKVStoreService(storeKey), legacySubspace, cdc)) - - var res types.Params - bz := store.Get(types.ParamsKey) - require.NoError(t, cdc.Unmarshal(bz, &res)) - require.Equal(t, legacySubspace.ps, res) + var res v2.Params + bz := ctx.KVStore(wasmStoreKey).Get(types.ParamsKey) + require.NoError(t, cdc.Unmarshal(bz, &res)) + assert.Equal(t, params, res) + }) + } } diff --git a/x/wasm/module_test.go b/x/wasm/module_test.go index a68c1d9dc8..c08ab1455e 100644 --- a/x/wasm/module_test.go +++ b/x/wasm/module_test.go @@ -27,19 +27,20 @@ import ( "github.com/CosmWasm/wasmd/x/wasm/exported" "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/testdata" + v2 "github.com/CosmWasm/wasmd/x/wasm/migrations/v2" "github.com/CosmWasm/wasmd/x/wasm/types" ) type mockSubspace struct { - ps types.Params + ps v2.Params } -func newMockSubspace(ps types.Params) mockSubspace { +func newMockSubspace(ps v2.Params) mockSubspace { return mockSubspace{ps: ps} } func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) { - *ps.(*types.Params) = ms.ps + *ps.(*v2.Params) = ms.ps } type testData struct { @@ -57,6 +58,11 @@ type testData struct { func setupTest(t *testing.T) testData { t.Helper() + DefaultParams := v2.Params{ + CodeUploadAccess: v2.AccessConfig{Permission: v2.AccessTypeEverybody}, + InstantiateDefaultPermission: v2.AccessTypeEverybody, + } + ctx, keepers := keeper.CreateTestInput(t, false, "iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4") encConf := keeper.MakeEncodingConfig(t) queryRouter := baseapp.NewGRPCQueryRouter() @@ -64,7 +70,7 @@ func setupTest(t *testing.T) testData { queryRouter.SetInterfaceRegistry(encConf.InterfaceRegistry) serviceRouter.SetInterfaceRegistry(encConf.InterfaceRegistry) data := testData{ - module: NewAppModule(encConf.Codec, keepers.WasmKeeper, keepers.StakingKeeper, keepers.AccountKeeper, keepers.BankKeeper, nil, newMockSubspace(types.DefaultParams())), + module: NewAppModule(encConf.Codec, keepers.WasmKeeper, keepers.StakingKeeper, keepers.AccountKeeper, keepers.BankKeeper, nil, newMockSubspace(DefaultParams)), ctx: ctx, acctKeeper: keepers.AccountKeeper, keeper: *keepers.WasmKeeper, diff --git a/x/wasm/types/params.go b/x/wasm/types/params.go index 9793ee68a0..4b923b1bd3 100644 --- a/x/wasm/types/params.go +++ b/x/wasm/types/params.go @@ -2,7 +2,6 @@ package types import ( "encoding/json" - "fmt" "github.com/cosmos/gogoproto/jsonpb" "github.com/pkg/errors" @@ -104,25 +103,13 @@ func (p Params) ValidateBasic() error { if err := validateAccessType(p.InstantiateDefaultPermission); err != nil { return errors.Wrap(err, "instantiate default permission") } - if err := validateAccessConfig(p.CodeUploadAccess); err != nil { + if err := p.CodeUploadAccess.ValidateBasic(); err != nil { return errors.Wrap(err, "upload access") } return nil } -func validateAccessConfig(i interface{}) error { - v, ok := i.(AccessConfig) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - return v.ValidateBasic() -} - -func validateAccessType(i interface{}) error { - a, ok := i.(AccessType) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } +func validateAccessType(a AccessType) error { if a == AccessTypeUnspecified { return errorsmod.Wrap(ErrEmpty, "type") } diff --git a/x/wasm/types/params_legacy.go b/x/wasm/types/params_legacy.go deleted file mode 100644 index db38cb8bee..0000000000 --- a/x/wasm/types/params_legacy.go +++ /dev/null @@ -1,26 +0,0 @@ -/* -NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov -controlled execution of MsgUpdateParams messages. These types remains solely -for migration purposes and will be removed in a future release. -*/ -package types - -import paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - -var ( - ParamStoreKeyUploadAccess = []byte("uploadAccess") - ParamStoreKeyInstantiateAccess = []byte("instantiateAccess") -) - -// Deprecated: Type declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - -// ParamSetPairs returns the parameter set pairs. -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(ParamStoreKeyUploadAccess, &p.CodeUploadAccess, validateAccessConfig), - paramtypes.NewParamSetPair(ParamStoreKeyInstantiateAccess, &p.InstantiateDefaultPermission, validateAccessType), - } -}