From 77157c53b2d384ea5f94e70920d4a342e3687c09 Mon Sep 17 00:00:00 2001 From: Pino' Surace Date: Wed, 26 Jul 2023 16:07:47 +0200 Subject: [PATCH] Make tests pass --- app/app.go | 21 +- cmd/tgrade/genwasm.go | 21 -- cmd/tgrade/root.go | 1 - docs/proto/proto-docs.md | 2 +- proto/confio/twasm/v1beta1/genesis.proto | 10 +- .../proto/cosmwasm/wasm/v1/authz.proto | 118 ++++++++++ .../proto/cosmwasm/wasm/v1/genesis.proto | 20 +- third_party/proto/cosmwasm/wasm/v1/ibc.proto | 6 + .../proto/cosmwasm/wasm/v1/proposal.proto | 98 ++++++++ .../proto/cosmwasm/wasm/v1/query.proto | 25 ++ third_party/proto/cosmwasm/wasm/v1/tx.proto | 20 +- .../proto/cosmwasm/wasm/v1/types.proto | 5 +- x/poe/keeper/test_common.go | 2 +- x/twasm/client/cli/genesisio.go | 28 ++- x/twasm/keeper/genesis.go | 15 +- x/twasm/keeper/genesis_test.go | 61 ++--- x/twasm/keeper/keeper.go | 1 + x/twasm/keeper/privileged_test.go | 6 +- x/twasm/keeper/test_common.go | 2 +- x/twasm/module.go | 2 +- x/twasm/simulation/genesis.go | 1 - x/twasm/types/genesis.go | 16 +- x/twasm/types/genesis.pb.go | 213 +++++++++--------- x/twasm/types/test_fixtures.go | 24 +- 24 files changed, 471 insertions(+), 247 deletions(-) create mode 100644 third_party/proto/cosmwasm/wasm/v1/authz.proto diff --git a/app/app.go b/app/app.go index 8d3132b4..dd9f0d6f 100644 --- a/app/app.go +++ b/app/app.go @@ -62,6 +62,8 @@ import ( icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types" + ibcfeekeeper "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/keeper" + ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v4/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" @@ -151,6 +153,7 @@ var ( maccPerms = map[string][]string{ ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, icatypes.ModuleName: nil, + ibcfeetypes.ModuleName: nil, twasm.ModuleName: {authtypes.Minter, authtypes.Burner}, poetypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, } @@ -185,6 +188,7 @@ type TgradeApp struct { upgradeKeeper upgradekeeper.Keeper paramsKeeper paramskeeper.Keeper ibcKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + ibcFeeKeeper ibcfeekeeper.Keeper transferKeeper ibctransferkeeper.Keeper icaHostKeeper icahostkeeper.Keeper feeGrantKeeper feegrantkeeper.Keeper @@ -233,7 +237,7 @@ func NewTgradeApp( authtypes.StoreKey, banktypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, - feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, poe.StoreKey, icahosttypes.StoreKey, + feegrant.StoreKey, authzkeeper.StoreKey, wasm.StoreKey, poe.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -330,6 +334,14 @@ func NewTgradeApp( AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.upgradeKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper)) + // IBC Fee Module keeper + app.ibcFeeKeeper = ibcfeekeeper.NewKeeper( + appCodec, keys[ibcfeetypes.StoreKey], app.getSubspace(ibcfeetypes.ModuleName), + app.ibcKeeper.ChannelKeeper, // may be replaced with IBC middleware + app.ibcKeeper.ChannelKeeper, + &app.ibcKeeper.PortKeeper, app.accountKeeper, app.bankKeeper, + ) + // Create Transfer Keepers app.transferKeeper = ibctransferkeeper.NewKeeper( appCodec, @@ -366,7 +378,7 @@ func NewTgradeApp( // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks - availableCapabilities := "staking,stargate,iterator,tgrade,cosmwasm_1_1" + availableCapabilities := "staking,stargate,iterator,tgrade,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3" wasmOpts = append(SetupWasmHandlers(appCodec, app.bankKeeper, govRouter, &app.twasmKeeper, &app.poeKeeper, app), wasmOpts...) @@ -397,7 +409,7 @@ func NewTgradeApp( // Create static IBC router, add app routes, then set and seal it ibcRouter := porttypes.NewRouter() ibcRouter. - AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.twasmKeeper, app.ibcKeeper.ChannelKeeper)). + AddRoute(wasm.ModuleName, wasm.NewIBCHandler(app.twasmKeeper, app.ibcKeeper.ChannelKeeper, app.ibcFeeKeeper)). AddRoute(ibctransfertypes.ModuleName, transferIBCModule). AddRoute(icahosttypes.SubModuleName, icaHostIBCModule) app.ibcKeeper.SetRouter(ibcRouter) @@ -462,6 +474,7 @@ func NewTgradeApp( ibctransfertypes.ModuleName, ibchost.ModuleName, icatypes.ModuleName, + ibcfeetypes.ModuleName, poe.ModuleName, twasm.ModuleName, globalfee.ModuleName, @@ -480,6 +493,7 @@ func NewTgradeApp( ibctransfertypes.ModuleName, ibchost.ModuleName, icatypes.ModuleName, + ibcfeetypes.ModuleName, globalfee.ModuleName, twasm.ModuleName, poe.ModuleName, // poe after twasm to have valset update at the end @@ -506,6 +520,7 @@ func NewTgradeApp( ibctransfertypes.ModuleName, ibchost.ModuleName, icatypes.ModuleName, + ibcfeetypes.ModuleName, // wasm after ibc transfer twasm.ModuleName, // poe after wasm contract instantiation diff --git a/cmd/tgrade/genwasm.go b/cmd/tgrade/genwasm.go index cb69bf4e..ad6143ba 100644 --- a/cmd/tgrade/genwasm.go +++ b/cmd/tgrade/genwasm.go @@ -1,33 +1,12 @@ package main import ( - wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli" "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" "github.com/confio/tgrade/x/twasm/client/cli" ) -func AddGenesisWasmMsgCmd(defaultNodeHome string) *cobra.Command { - txCmd := &cobra.Command{ - Use: "wasm-genesis-message", - Short: "Wasm genesis message subcommands", - Aliases: []string{"wasm-genesis-msg", "wasm-genesis-messages", "add-wasm-genesis-message"}, - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - genIO := cli.NewGenesisIO() - txCmd.AddCommand( - wasmcli.GenesisStoreCodeCmd(defaultNodeHome, genIO), - wasmcli.GenesisInstantiateContractCmd(defaultNodeHome, genIO), - wasmcli.GenesisExecuteContractCmd(defaultNodeHome, genIO), - wasmcli.GenesisListContractsCmd(defaultNodeHome, genIO), - wasmcli.GenesisListCodesCmd(defaultNodeHome, genIO), - ) - return txCmd -} - func GenesisWasmFlagsCmd(defaultNodeHome string) *cobra.Command { txCmd := &cobra.Command{ Use: "wasm-genesis-flags", diff --git a/cmd/tgrade/root.go b/cmd/tgrade/root.go index d66986cd..fafd2a68 100644 --- a/cmd/tgrade/root.go +++ b/cmd/tgrade/root.go @@ -110,7 +110,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig appparams.EncodingConfig cli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome), genutilcli.ValidateGenesisCmd(app.ModuleBasics), AddGenesisAccountCmd(app.DefaultNodeHome), - AddGenesisWasmMsgCmd(app.DefaultNodeHome), GenesisWasmFlagsCmd(app.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}), diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 1c56a0ad..f993848b 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -968,6 +968,7 @@ Contract struct encompasses ContractAddress, ContractInfo, and ContractState | `contract_info` | [cosmwasm.wasm.v1.ContractInfo](#cosmwasm.wasm.v1.ContractInfo) | | | | `kv_model` | [KVModel](#confio.twasm.v1beta1.KVModel) | | | | `custom_model` | [CustomModel](#confio.twasm.v1beta1.CustomModel) | | | +| `contract_code_history` | [cosmwasm.wasm.v1.ContractCodeHistoryEntry](#cosmwasm.wasm.v1.ContractCodeHistoryEntry) | repeated | | @@ -1002,7 +1003,6 @@ import | `codes` | [cosmwasm.wasm.v1.Code](#cosmwasm.wasm.v1.Code) | repeated | Codes has all stored wasm codes and metadata | | `contracts` | [Contract](#confio.twasm.v1beta1.Contract) | repeated | Contracts contains all instantiated contracts, state and metadata | | `sequences` | [cosmwasm.wasm.v1.Sequence](#cosmwasm.wasm.v1.Sequence) | repeated | Sequences names and values | -| `gen_msgs` | [cosmwasm.wasm.v1.GenesisState.GenMsgs](#cosmwasm.wasm.v1.GenesisState.GenMsgs) | repeated | GenMsgs has wasmd sdk type messages to execute in the genesis phase | | `privileged_contract_addresses` | [string](#string) | repeated | PrivilegedContractAddresses is a list of contract addresses that can have special permissions | | `pinned_code_ids` | [uint64](#uint64) | repeated | PinnedCodeIDs has codeInfo ids for wasm codes that are pinned in cache | diff --git a/proto/confio/twasm/v1beta1/genesis.proto b/proto/confio/twasm/v1beta1/genesis.proto index 643d6c46..63d53d0c 100644 --- a/proto/confio/twasm/v1beta1/genesis.proto +++ b/proto/confio/twasm/v1beta1/genesis.proto @@ -30,11 +30,8 @@ message GenesisState { (gogoproto.jsontag) = "sequences,omitempty" ]; - // GenMsgs has wasmd sdk type messages to execute in the genesis phase - repeated cosmwasm.wasm.v1.GenesisState.GenMsgs gen_msgs = 5 [ - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "gen_msgs,omitempty" - ]; + // was "gen_msgs" + reserved 5; // PrivilegedContractAddresses is a list of contract addresses that can have // special permissions @@ -59,6 +56,9 @@ message Contract { KVModel kv_model = 3; CustomModel custom_model = 4; } + + repeated cosmwasm.wasm.v1.ContractCodeHistoryEntry contract_code_history = 5 + [ (gogoproto.nullable) = false ]; } // KVModel is a wrapper around the wasmd default key value model. diff --git a/third_party/proto/cosmwasm/wasm/v1/authz.proto b/third_party/proto/cosmwasm/wasm/v1/authz.proto new file mode 100644 index 00000000..97a82275 --- /dev/null +++ b/third_party/proto/cosmwasm/wasm/v1/authz.proto @@ -0,0 +1,118 @@ +syntax = "proto3"; +package cosmwasm.wasm.v1; + +import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "google/protobuf/any.proto"; + +option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; +option (gogoproto.goproto_getters_all) = false; + +// ContractExecutionAuthorization defines authorization for wasm execute. +// Since: wasmd 0.30 +message ContractExecutionAuthorization { + option (cosmos_proto.implements_interface) = + "cosmos.authz.v1beta1.Authorization"; + + // Grants for contract executions + repeated ContractGrant grants = 1 [ (gogoproto.nullable) = false ]; +} + +// ContractMigrationAuthorization defines authorization for wasm contract +// migration. Since: wasmd 0.30 +message ContractMigrationAuthorization { + option (cosmos_proto.implements_interface) = + "cosmos.authz.v1beta1.Authorization"; + + // Grants for contract migrations + repeated ContractGrant grants = 1 [ (gogoproto.nullable) = false ]; +} + +// ContractGrant a granted permission for a single contract +// Since: wasmd 0.30 +message ContractGrant { + // Contract is the bech32 address of the smart contract + string contract = 1; + + // Limit defines execution limits that are enforced and updated when the grant + // is applied. When the limit lapsed the grant is removed. + google.protobuf.Any limit = 2 [ (cosmos_proto.accepts_interface) = + "cosmwasm.wasm.v1.ContractAuthzLimitX" ]; + + // Filter define more fine-grained control on the message payload passed + // to the contract in the operation. When no filter applies on execution, the + // operation is prohibited. + google.protobuf.Any filter = 3 + [ (cosmos_proto.accepts_interface) = + "cosmwasm.wasm.v1.ContractAuthzFilterX" ]; +} + +// MaxCallsLimit limited number of calls to the contract. No funds transferable. +// Since: wasmd 0.30 +message MaxCallsLimit { + option (cosmos_proto.implements_interface) = + "cosmwasm.wasm.v1.ContractAuthzLimitX"; + + // Remaining number that is decremented on each execution + uint64 remaining = 1; +} + +// MaxFundsLimit defines the maximal amounts that can be sent to the contract. +// Since: wasmd 0.30 +message MaxFundsLimit { + option (cosmos_proto.implements_interface) = + "cosmwasm.wasm.v1.ContractAuthzLimitX"; + + // Amounts is the maximal amount of tokens transferable to the contract. + repeated cosmos.base.v1beta1.Coin amounts = 1 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// CombinedLimit defines the maximal amounts that can be sent to a contract and +// the maximal number of calls executable. Both need to remain >0 to be valid. +// Since: wasmd 0.30 +message CombinedLimit { + option (cosmos_proto.implements_interface) = + "cosmwasm.wasm.v1.ContractAuthzLimitX"; + + // Remaining number that is decremented on each execution + uint64 calls_remaining = 1; + // Amounts is the maximal amount of tokens transferable to the contract. + repeated cosmos.base.v1beta1.Coin amounts = 2 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// AllowAllMessagesFilter is a wildcard to allow any type of contract payload +// message. +// Since: wasmd 0.30 +message AllowAllMessagesFilter { + option (cosmos_proto.implements_interface) = + "cosmwasm.wasm.v1.ContractAuthzFilterX"; +} + +// AcceptedMessageKeysFilter accept only the specific contract message keys in +// the json object to be executed. +// Since: wasmd 0.30 +message AcceptedMessageKeysFilter { + option (cosmos_proto.implements_interface) = + "cosmwasm.wasm.v1.ContractAuthzFilterX"; + + // Messages is the list of unique keys + repeated string keys = 1; +} + +// AcceptedMessagesFilter accept only the specific raw contract messages to be +// executed. +// Since: wasmd 0.30 +message AcceptedMessagesFilter { + option (cosmos_proto.implements_interface) = + "cosmwasm.wasm.v1.ContractAuthzFilterX"; + + // Messages is the list of raw contract messages + repeated bytes messages = 1 [ (gogoproto.casttype) = "RawContractMessage" ]; +} diff --git a/third_party/proto/cosmwasm/wasm/v1/genesis.proto b/third_party/proto/cosmwasm/wasm/v1/genesis.proto index 87373e18..4e728ff4 100644 --- a/third_party/proto/cosmwasm/wasm/v1/genesis.proto +++ b/third_party/proto/cosmwasm/wasm/v1/genesis.proto @@ -3,7 +3,6 @@ package cosmwasm.wasm.v1; import "gogoproto/gogo.proto"; import "cosmwasm/wasm/v1/types.proto"; -import "cosmwasm/wasm/v1/tx.proto"; option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; @@ -20,23 +19,6 @@ message GenesisState { (gogoproto.nullable) = false, (gogoproto.jsontag) = "sequences,omitempty" ]; - repeated GenMsgs gen_msgs = 5 [ - (gogoproto.nullable) = false, - (gogoproto.jsontag) = "gen_msgs,omitempty" - ]; - - // GenMsgs define the messages that can be executed during genesis phase in - // order. The intention is to have more human readable data that is auditable. - message GenMsgs { - // sum is a single message - oneof sum { - MsgStoreCode store_code = 1; - MsgInstantiateContract instantiate_contract = 2; - MsgExecuteContract execute_contract = 3; - // MsgInstantiateContract2 intentionally not supported - // see https://github.com/CosmWasm/wasmd/issues/987 - } - } } // Code struct encompasses CodeInfo and CodeBytes @@ -53,6 +35,8 @@ message Contract { string contract_address = 1; ContractInfo contract_info = 2 [ (gogoproto.nullable) = false ]; repeated Model contract_state = 3 [ (gogoproto.nullable) = false ]; + repeated ContractCodeHistoryEntry contract_code_history = 4 + [ (gogoproto.nullable) = false ]; } // Sequence key and value of an id generation counter diff --git a/third_party/proto/cosmwasm/wasm/v1/ibc.proto b/third_party/proto/cosmwasm/wasm/v1/ibc.proto index d880a707..feaad293 100644 --- a/third_party/proto/cosmwasm/wasm/v1/ibc.proto +++ b/third_party/proto/cosmwasm/wasm/v1/ibc.proto @@ -25,6 +25,12 @@ message MsgIBCSend { bytes data = 6; } +// MsgIBCSendResponse +message MsgIBCSendResponse { + // Sequence number of the IBC packet sent + uint64 sequence = 1; +} + // MsgIBCCloseChannel port and channel need to be owned by the contract message MsgIBCCloseChannel { string channel = 2 [ (gogoproto.moretags) = "yaml:\"source_channel\"" ]; diff --git a/third_party/proto/cosmwasm/wasm/v1/proposal.proto b/third_party/proto/cosmwasm/wasm/v1/proposal.proto index 25bf2700..b1c484bc 100644 --- a/third_party/proto/cosmwasm/wasm/v1/proposal.proto +++ b/third_party/proto/cosmwasm/wasm/v1/proposal.proto @@ -2,6 +2,7 @@ syntax = "proto3"; package cosmwasm.wasm.v1; import "gogoproto/gogo.proto"; +import "cosmos_proto/cosmos.proto"; import "cosmos/base/v1beta1/coin.proto"; import "cosmwasm/wasm/v1/types.proto"; @@ -12,6 +13,8 @@ option (gogoproto.equal_all) = true; // StoreCodeProposal gov proposal content type to submit WASM code to the system message StoreCodeProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1; // Description is a human readable text @@ -26,11 +29,21 @@ message StoreCodeProposal { AccessConfig instantiate_permission = 7; // UnpinCode code on upload, optional bool unpin_code = 8; + // Source is the URL where the code is hosted + string source = 9; + // Builder is the docker image used to build the code deterministically, used + // for smart contract verification + string builder = 10; + // CodeHash is the SHA256 sum of the code outputted by builder, used for smart + // contract verification + bytes code_hash = 11; } // InstantiateContractProposal gov proposal content type to instantiate a // contract. message InstantiateContractProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1; // Description is a human readable text @@ -52,8 +65,41 @@ message InstantiateContractProposal { ]; } +// InstantiateContract2Proposal gov proposal content type to instantiate +// contract 2 +message InstantiateContract2Proposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // RunAs is the address that is passed to the contract's enviroment as sender + string run_as = 3; + // Admin is an optional address that can execute migrations + string admin = 4; + // CodeID is the reference to the stored WASM code + uint64 code_id = 5 [ (gogoproto.customname) = "CodeID" ]; + // Label is optional metadata to be stored with a constract instance. + string label = 6; + // Msg json encode message to be passed to the contract on instantiation + bytes msg = 7 [ (gogoproto.casttype) = "RawContractMessage" ]; + // Funds coins that are transferred to the contract on instantiation + repeated cosmos.base.v1beta1.Coin funds = 8 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + // Salt is an arbitrary value provided by the sender. Size can be 1 to 64. + bytes salt = 9; + // FixMsg include the msg value into the hash for the predictable address. + // Default is false + bool fix_msg = 10; +} + // MigrateContractProposal gov proposal content type to migrate a contract. message MigrateContractProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1; // Description is a human readable text @@ -70,6 +116,8 @@ message MigrateContractProposal { // SudoContractProposal gov proposal content type to call sudo on a contract. message SudoContractProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1; // Description is a human readable text @@ -83,6 +131,8 @@ message SudoContractProposal { // ExecuteContractProposal gov proposal content type to call execute on a // contract. message ExecuteContractProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1; // Description is a human readable text @@ -102,6 +152,8 @@ message ExecuteContractProposal { // UpdateAdminProposal gov proposal content type to set an admin for a contract. message UpdateAdminProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1; // Description is a human readable text @@ -115,6 +167,8 @@ message UpdateAdminProposal { // ClearAdminProposal gov proposal content type to clear the admin of a // contract. message ClearAdminProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1; // Description is a human readable text @@ -126,6 +180,8 @@ message ClearAdminProposal { // PinCodesProposal gov proposal content type to pin a set of code ids in the // wasmvm cache. message PinCodesProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; // Description is a human readable text @@ -140,6 +196,8 @@ message PinCodesProposal { // UnpinCodesProposal gov proposal content type to unpin a set of code ids in // the wasmvm cache. message UnpinCodesProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; // Description is a human readable text @@ -163,6 +221,8 @@ message AccessConfigUpdate { // UpdateInstantiateConfigProposal gov proposal content type to update // instantiate config to a set of code ids. message UpdateInstantiateConfigProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + // Title is a short summary string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; // Description is a human readable text @@ -172,3 +232,41 @@ message UpdateInstantiateConfigProposal { repeated AccessConfigUpdate access_config_updates = 3 [ (gogoproto.nullable) = false ]; } + +// StoreAndInstantiateContractProposal gov proposal content type to store +// and instantiate the contract. +message StoreAndInstantiateContractProposal { + option (cosmos_proto.implements_interface) = "cosmos.gov.v1beta1.Content"; + + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // RunAs is the address that is passed to the contract's environment as sender + string run_as = 3; + // WASMByteCode can be raw or gzip compressed + bytes wasm_byte_code = 4 [ (gogoproto.customname) = "WASMByteCode" ]; + // InstantiatePermission to apply on contract creation, optional + AccessConfig instantiate_permission = 5; + // UnpinCode code on upload, optional + bool unpin_code = 6; + // Admin is an optional address that can execute migrations + string admin = 7; + // Label is optional metadata to be stored with a constract instance. + string label = 8; + // Msg json encoded message to be passed to the contract on instantiation + bytes msg = 9 [ (gogoproto.casttype) = "RawContractMessage" ]; + // Funds coins that are transferred to the contract on instantiation + repeated cosmos.base.v1beta1.Coin funds = 10 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; + // Source is the URL where the code is hosted + string source = 11; + // Builder is the docker image used to build the code deterministically, used + // for smart contract verification + string builder = 12; + // CodeHash is the SHA256 sum of the code outputted by builder, used for smart + // contract verification + bytes code_hash = 13; +} diff --git a/third_party/proto/cosmwasm/wasm/v1/query.proto b/third_party/proto/cosmwasm/wasm/v1/query.proto index 41d959d8..ffe48d24 100644 --- a/third_party/proto/cosmwasm/wasm/v1/query.proto +++ b/third_party/proto/cosmwasm/wasm/v1/query.proto @@ -63,6 +63,13 @@ service Query { rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { option (google.api.http).get = "/cosmwasm/wasm/v1/codes/params"; } + + // ContractsByCreator gets the contracts by creator + rpc ContractsByCreator(QueryContractsByCreatorRequest) + returns (QueryContractsByCreatorResponse) { + option (google.api.http).get = + "/cosmwasm/wasm/v1/contracts/creator/{creator_address}"; + } } // QueryContractInfoRequest is the request type for the Query/ContractInfo RPC @@ -236,3 +243,21 @@ message QueryParamsResponse { // params defines the parameters of the module. Params params = 1 [ (gogoproto.nullable) = false ]; } + +// QueryContractsByCreatorRequest is the request type for the +// Query/ContractsByCreator RPC method. +message QueryContractsByCreatorRequest { + // CreatorAddress is the address of contract creator + string creator_address = 1; + // Pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 2; +} + +// QueryContractsByCreatorResponse is the response type for the +// Query/ContractsByCreator RPC method. +message QueryContractsByCreatorResponse { + // ContractAddresses result set + repeated string contract_addresses = 1; + // Pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} \ No newline at end of file diff --git a/third_party/proto/cosmwasm/wasm/v1/tx.proto b/third_party/proto/cosmwasm/wasm/v1/tx.proto index 04acc8ef..741fbc49 100644 --- a/third_party/proto/cosmwasm/wasm/v1/tx.proto +++ b/third_party/proto/cosmwasm/wasm/v1/tx.proto @@ -28,11 +28,14 @@ service Msg { rpc UpdateAdmin(MsgUpdateAdmin) returns (MsgUpdateAdminResponse); // ClearAdmin removes any admin stored for a smart contract rpc ClearAdmin(MsgClearAdmin) returns (MsgClearAdminResponse); + // UpdateInstantiateConfig updates instantiate config for a smart contract + rpc UpdateInstantiateConfig(MsgUpdateInstantiateConfig) + returns (MsgUpdateInstantiateConfigResponse); } // MsgStoreCode submit Wasm code to the system message MsgStoreCode { - // Sender is the that actor that signed the messages + // Sender is the actor that signed the messages string sender = 1; // WASMByteCode can be raw or gzip compressed bytes wasm_byte_code = 2 [ (gogoproto.customname) = "WASMByteCode" ]; @@ -166,7 +169,7 @@ message MsgUpdateAdminResponse {} // MsgClearAdmin removes any admin stored for a smart contract message MsgClearAdmin { - // Sender is the that actor that signed the messages + // Sender is the actor that signed the messages string sender = 1; // Contract is the address of the smart contract string contract = 3; @@ -174,3 +177,16 @@ message MsgClearAdmin { // MsgClearAdminResponse returns empty data message MsgClearAdminResponse {} + +// MsgUpdateInstantiateConfig updates instantiate config for a smart contract +message MsgUpdateInstantiateConfig { + // Sender is the that actor that signed the messages + string sender = 1; + // CodeID references the stored WASM code + uint64 code_id = 2 [ (gogoproto.customname) = "CodeID" ]; + // NewInstantiatePermission is the new access control + AccessConfig new_instantiate_permission = 3; +} + +// MsgUpdateInstantiateConfigResponse returns empty data +message MsgUpdateInstantiateConfigResponse {} \ No newline at end of file diff --git a/third_party/proto/cosmwasm/wasm/v1/types.proto b/third_party/proto/cosmwasm/wasm/v1/types.proto index 8d140248..b68179e2 100644 --- a/third_party/proto/cosmwasm/wasm/v1/types.proto +++ b/third_party/proto/cosmwasm/wasm/v1/types.proto @@ -84,15 +84,14 @@ message ContractInfo { // Label is optional metadata to be stored with a contract instance. string label = 4; // Created Tx position when the contract was instantiated. - // This data should kept internal and not be exposed via query results. Just - // use for sorting AbsoluteTxPosition created = 5; string ibc_port_id = 6 [ (gogoproto.customname) = "IBCPortID" ]; // Extension is an extension point to store custom metadata within the // persistence model. google.protobuf.Any extension = 7 - [ (cosmos_proto.accepts_interface) = "ContractInfoExtension" ]; + [ (cosmos_proto.accepts_interface) = + "cosmwasm.wasm.v1.ContractInfoExtension" ]; } // ContractCodeHistoryOperationType actions that caused a code change diff --git a/x/poe/keeper/test_common.go b/x/poe/keeper/test_common.go index a19bbe55..9d32b19a 100644 --- a/x/poe/keeper/test_common.go +++ b/x/poe/keeper/test_common.go @@ -331,7 +331,7 @@ func createTestInput( // NewWasmVMMock creates a new WasmerEngine mock with basic ops for create/instantiation set to noops. func NewWasmVMMock(mutators ...func(*wasmtesting.MockWasmer)) *wasmtesting.MockWasmer { mock := &wasmtesting.MockWasmer{ - CreateFn: wasmtesting.HashOnlyCreateFn, + StoreCodeFn: wasmtesting.HashOnlyStoreCodeFn, InstantiateFn: wasmtesting.NoOpInstantiateFn, AnalyzeCodeFn: wasmtesting.HasIBCAnalyzeFn, } diff --git a/x/twasm/client/cli/genesisio.go b/x/twasm/client/cli/genesisio.go index dc0600af..e46bb668 100644 --- a/x/twasm/client/cli/genesisio.go +++ b/x/twasm/client/cli/genesisio.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" - wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli" "github.com/cosmos/cosmos-sdk/server" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" @@ -15,10 +14,9 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/genutil" "github.com/spf13/cobra" + tmtypes "github.com/tendermint/tendermint/types" ) -var _ wasmcli.GenesisMutator = GenesisIO{} - // GenesisIO to alter the genesis state for this module. To be used with the wasm cli extension point. type GenesisIO struct { GenesisReader @@ -38,8 +36,6 @@ func (x GenesisIO) AlterWasmModuleState(cmd *cobra.Command, callback func(state if err := callback(&wasmState, appState); err != nil { return err } - // update genesis messages as they can be modified - state.GenMsgs = wasmState.GenMsgs return nil }) } @@ -77,14 +73,12 @@ func (x GenesisIO) AlterTWasmModuleState(cmd *cobra.Command, callback func(state return genutil.ExportGenesisFile(g.GenDoc, g.GenesisFile) } -// TWasmGenesisData extends the wasmcli GenesisData for this module state. +// TWasmGenesisData extends the GenesisData for this module state. type TWasmGenesisData struct { - *wasmcli.GenesisData + *GenesisData twasmModuleState types.GenesisState } -var _ wasmcli.GenesisReader = GenesisReader{} - // GenesisReader reads the genesis data for this module. To be used with the wasm cli extension point type GenesisReader struct{} @@ -106,7 +100,7 @@ func (d GenesisReader) ReadTWasmGenesis(cmd *cobra.Command) (*TWasmGenesisData, } wasmState := twasmGenesisState.RawWasmState() return &TWasmGenesisData{ - GenesisData: wasmcli.NewGenesisData( + GenesisData: NewGenesisData( genFile, genDoc, appState, @@ -116,10 +110,22 @@ func (d GenesisReader) ReadTWasmGenesis(cmd *cobra.Command) (*TWasmGenesisData, }, nil } -func (d GenesisReader) ReadWasmGenesis(cmd *cobra.Command) (*wasmcli.GenesisData, error) { +func (d GenesisReader) ReadWasmGenesis(cmd *cobra.Command) (*GenesisData, error) { r, err := d.ReadTWasmGenesis(cmd) if err != nil { return nil, err } return r.GenesisData, nil } + +// GenesisData contains raw and unmarshalled data from the genesis file +type GenesisData struct { + GenesisFile string + GenDoc *tmtypes.GenesisDoc + AppState map[string]json.RawMessage + WasmModuleState *wasmtypes.GenesisState +} + +func NewGenesisData(genesisFile string, genDoc *tmtypes.GenesisDoc, appState map[string]json.RawMessage, wasmModuleState *wasmtypes.GenesisState) *GenesisData { + return &GenesisData{GenesisFile: genesisFile, GenDoc: genDoc, AppState: appState, WasmModuleState: wasmModuleState} +} diff --git a/x/twasm/keeper/genesis.go b/x/twasm/keeper/genesis.go index da85798a..39816f16 100644 --- a/x/twasm/keeper/genesis.go +++ b/x/twasm/keeper/genesis.go @@ -15,12 +15,6 @@ import ( "github.com/confio/tgrade/x/twasm/types" ) -type noopValsetUpdater struct{} - -func (n noopValsetUpdater) ApplyAndReturnValidatorSetUpdates(context sdk.Context) (updates []abci.ValidatorUpdate, err error) { - return nil, nil -} - // InitGenesis sets supply information for genesis. // // CONTRACT: all types of accounts must have been already initialized/created @@ -28,9 +22,8 @@ func InitGenesis( ctx sdk.Context, keeper *Keeper, data types.GenesisState, - msgHandler sdk.Handler, ) ([]abci.ValidatorUpdate, error) { - result, err := wasmkeeper.InitGenesis(ctx, &keeper.Keeper, data.RawWasmState(), noopValsetUpdater{}, msgHandler) + result, err := wasmkeeper.InitGenesis(ctx, &keeper.Keeper, data.RawWasmState()) if err != nil { return nil, sdkerrors.Wrap(err, "wasm") } @@ -97,8 +90,9 @@ func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState { contracts := make([]types.Contract, len(wasmState.Contracts)) for i, v := range wasmState.Contracts { contracts[i] = types.Contract{ - ContractAddress: v.ContractAddress, - ContractInfo: v.ContractInfo, + ContractAddress: v.ContractAddress, + ContractInfo: v.ContractInfo, + ContractCodeHistory: v.ContractCodeHistory, } var details types.TgradeContractDetails @@ -128,7 +122,6 @@ func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState { Codes: wasmState.Codes, Contracts: contracts, Sequences: wasmState.Sequences, - GenMsgs: wasmState.GenMsgs, } // pinned is stored in code info diff --git a/x/twasm/keeper/genesis_test.go b/x/twasm/keeper/genesis_test.go index cb6b7220..efb6bfa5 100644 --- a/x/twasm/keeper/genesis_test.go +++ b/x/twasm/keeper/genesis_test.go @@ -2,23 +2,20 @@ package keeper import ( "crypto/sha256" - "encoding/json" "errors" "testing" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - - "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" "github.com/CosmWasm/wasmd/x/wasm/keeper/wasmtesting" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" cosmwasm "github.com/CosmWasm/wasmvm" + wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/confio/tgrade/x/twasm/contract" "github.com/confio/tgrade/x/twasm/types" ) @@ -32,6 +29,9 @@ func TestInitGenesis(t *testing.T) { m.SudoFn = func(codeID cosmwasm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store cosmwasm.KVStore, goapi cosmwasm.GoAPI, querier cosmwasm.Querier, gasMeter cosmwasm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{}, 0, nil } + m.StoreCodeUncheckedFn = func(codeID cosmwasm.WasmCode) (cosmwasm.Checksum, error) { + return wasmvm.CreateChecksum(codeID) + } }) type registeredCallback struct { @@ -90,35 +90,6 @@ func TestInitGenesis(t *testing.T) { wasmvm: noopMock, expCallbackReg: []registeredCallback{{pos: 1, cbt: types.PrivilegeTypeBeginBlock, addr: genContractAddress(2, 2)}}, }, - "privilege set for gen msg contract": { - state: types.GenesisStateFixture(t, func(state *types.GenesisState) { - state.PrivilegedContractAddresses = []string{genContractAddress(2, 1).String()} - state.Contracts = nil - state.Sequences = []wasmtypes.Sequence{{IDKey: wasmtypes.KeyLastCodeID, Value: 3}} - state.GenMsgs = []wasmtypes.GenesisState_GenMsgs{ - {Sum: &wasmtypes.GenesisState_GenMsgs_InstantiateContract{ - InstantiateContract: wasmtypes.MsgInstantiateContractFixture( - func(msg *wasmtypes.MsgInstantiateContract) { - msg.CodeID = 2 - msg.Funds = nil - }), - }}, - } - }), - wasmvm: NewWasmVMMock(func(m *wasmtesting.MockWasmer) { - // callback registers for end block on sudo call - m.PinFn = func(checksum cosmwasm.Checksum) error { return nil } - m.SudoFn = func(codeID cosmwasm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store cosmwasm.KVStore, goapi cosmwasm.GoAPI, querier cosmwasm.Querier, gasMeter cosmwasm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { - tradeMsg := contract.TgradeMsg{Privilege: &contract.PrivilegeMsg{Request: types.PrivilegeTypeEndBlock}} - msgBz, err := json.Marshal(&tradeMsg) - require.NoError(t, err) - return &wasmvmtypes.Response{ - Messages: []wasmvmtypes.SubMsg{{ReplyOn: wasmvmtypes.ReplyNever, Msg: wasmvmtypes.CosmosMsg{Custom: msgBz}}}, - }, 0, nil - } - }), - expCallbackReg: []registeredCallback{{pos: 1, cbt: types.PrivilegeTypeEndBlock, addr: genContractAddress(2, 1)}}, - }, "privileges set from dump": { state: types.GenesisStateFixture(t, func(state *types.GenesisState) { state.PrivilegedContractAddresses = nil @@ -165,6 +136,9 @@ func TestInitGenesis(t *testing.T) { m.SudoFn = func(codeID cosmwasm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store cosmwasm.KVStore, goapi cosmwasm.GoAPI, querier cosmwasm.Querier, gasMeter cosmwasm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{}, 0, nil } + m.StoreCodeUncheckedFn = func(codeID cosmwasm.WasmCode) (cosmwasm.Checksum, error) { + return wasmvm.CreateChecksum(codeID) + } }), expCallbackReg: []registeredCallback{{pos: 1, cbt: types.PrivilegeStateExporterImporter, addr: genContractAddress(2, 2)}}, }, @@ -197,6 +171,9 @@ func TestInitGenesis(t *testing.T) { m.SudoFn = func(codeID cosmwasm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store cosmwasm.KVStore, goapi cosmwasm.GoAPI, querier cosmwasm.Querier, gasMeter cosmwasm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { return &wasmvmtypes.Response{}, 0, errors.New("testing error") } + m.StoreCodeUncheckedFn = func(codeID cosmwasm.WasmCode) (cosmwasm.Checksum, error) { + return wasmvm.CreateChecksum(codeID) + } }), expErr: true, }, @@ -207,8 +184,7 @@ func TestInitGenesis(t *testing.T) { k := keepers.TWasmKeeper // when - msgHandler := wasm.NewHandler(wasmkeeper.NewDefaultPermissionKeeper(k)) - valset, gotErr := InitGenesis(ctx, k, spec.state, msgHandler) + valset, gotErr := InitGenesis(ctx, k, spec.state) // then if spec.expErr { @@ -248,7 +224,7 @@ func TestInitGenesis(t *testing.T) { func TestExportGenesis(t *testing.T) { wasmCodes := make(map[string]cosmwasm.WasmCode) noopVMMock := NewWasmVMMock(func(m *wasmtesting.MockWasmer) { - m.CreateFn = func(code cosmwasm.WasmCode) (cosmwasm.Checksum, error) { + m.StoreCodeFn = func(code cosmwasm.WasmCode) (cosmwasm.Checksum, error) { hash := sha256.Sum256(code) wasmCodes[string(hash[:])] = code return hash[:], nil @@ -262,6 +238,11 @@ func TestExportGenesis(t *testing.T) { require.True(t, ok) return r, nil } + m.StoreCodeUncheckedFn = func(codeID wasmvm.WasmCode) (wasmvm.Checksum, error) { + hash := sha256.Sum256(codeID) + wasmCodes[string(hash[:])] = codeID + return hash[:], nil + } }) specs := map[string]struct { @@ -306,7 +287,8 @@ func TestExportGenesis(t *testing.T) { setContractPrivilege(t, ctx, keepers, genContractAddress(1, 1), priv) }, mockVM: NewWasmVMMock(func(m *wasmtesting.MockWasmer) { - m.CreateFn = noopVMMock.CreateFn + m.StoreCodeUncheckedFn = noopVMMock.StoreCodeUnchecked + m.StoreCodeFn = noopVMMock.StoreCode m.PinFn = noopVMMock.PinFn m.GetCodeFn = noopVMMock.GetCodeFn m.SudoFn = func(codeID cosmwasm.Checksum, env wasmvmtypes.Env, sudoMsg []byte, store cosmwasm.KVStore, goapi cosmwasm.GoAPI, querier cosmwasm.Querier, gasMeter cosmwasm.GasMeter, gasLimit uint64, deserCost wasmvmtypes.UFraction) (*wasmvmtypes.Response, uint64, error) { @@ -332,8 +314,7 @@ func TestExportGenesis(t *testing.T) { ctx, keepers := CreateDefaultTestInput(t, wasmkeeper.WithWasmEngine(spec.mockVM)) k := keepers.TWasmKeeper - msgHandler := wasm.NewHandler(wasmkeeper.NewDefaultPermissionKeeper(k)) - _, err := InitGenesis(ctx, k, spec.srcState, msgHandler) + _, err := InitGenesis(ctx, k, spec.srcState) require.NoError(t, err) if spec.alterState != nil { diff --git a/x/twasm/keeper/keeper.go b/x/twasm/keeper/keeper.go index 15ae09f8..aab66e2e 100644 --- a/x/twasm/keeper/keeper.go +++ b/x/twasm/keeper/keeper.go @@ -59,6 +59,7 @@ func NewKeeper( bankKeeper, stakingKeeper, distKeeper, + nil, channelKeeper, portKeeper, capabilityKeeper, diff --git a/x/twasm/keeper/privileged_test.go b/x/twasm/keeper/privileged_test.go index a29905df..82de22a8 100644 --- a/x/twasm/keeper/privileged_test.go +++ b/x/twasm/keeper/privileged_test.go @@ -22,6 +22,10 @@ import ( "github.com/confio/tgrade/x/twasm/types" ) +// magic number for Wasm is "\0asm" +// See https://webassembly.github.io/spec/core/binary/modules.html#binary-module +var wasmIdent = []byte("\x00\x61\x73\x6D") + func TestSetPrivileged(t *testing.T) { var ( capturedPinChecksum *cosmwasm.Checksum @@ -418,7 +422,7 @@ func TestRemovePrivilegedContractRegistration(t *testing.T) { func seedTestContract(t *testing.T, ctx sdk.Context, k *Keeper) (uint64, sdk.AccAddress) { t.Helper() creatorAddr := rand.Bytes(address.Len) - codeID, _, err := k.contractKeeper.Create(ctx, creatorAddr, []byte{}, nil) + codeID, _, err := k.contractKeeper.Create(ctx, creatorAddr, append(wasmIdent, bytes.Repeat([]byte{byte(1)}, 20)...), nil) require.NoError(t, err) contractAddr, _, err := k.contractKeeper.Instantiate(ctx, codeID, creatorAddr, creatorAddr, nil, "", nil) require.NoError(t, err) diff --git a/x/twasm/keeper/test_common.go b/x/twasm/keeper/test_common.go index 67d8a779..06e93fea 100644 --- a/x/twasm/keeper/test_common.go +++ b/x/twasm/keeper/test_common.go @@ -309,7 +309,7 @@ func createTestInput( // NewWasmVMMock creates a new WasmerEngine mock with basic ops for create/instantiation set to noops. func NewWasmVMMock(mutators ...func(*wasmtesting.MockWasmer)) *wasmtesting.MockWasmer { mock := &wasmtesting.MockWasmer{ - CreateFn: wasmtesting.HashOnlyCreateFn, + StoreCodeFn: wasmtesting.HashOnlyStoreCodeFn, InstantiateFn: wasmtesting.NoOpInstantiateFn, AnalyzeCodeFn: wasmtesting.HasIBCAnalyzeFn, } diff --git a/x/twasm/module.go b/x/twasm/module.go index 08d83e0c..f64b1650 100644 --- a/x/twasm/module.go +++ b/x/twasm/module.go @@ -151,7 +151,7 @@ func (AppModule) QuerierRoute() string { func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - validators, err := keeper.InitGenesis(ctx, am.keeper, genesisState, am.Route().Handler()) + validators, err := keeper.InitGenesis(ctx, am.keeper, genesisState) if err != nil { panic(err) } diff --git a/x/twasm/simulation/genesis.go b/x/twasm/simulation/genesis.go index 3fe2c32f..2b77156c 100644 --- a/x/twasm/simulation/genesis.go +++ b/x/twasm/simulation/genesis.go @@ -16,7 +16,6 @@ func RandomizedGenState(simstate *module.SimulationState) { Codes: nil, Contracts: nil, Sequences: nil, - GenMsgs: nil, PrivilegedContractAddresses: nil, PinnedCodeIDs: nil, } diff --git a/x/twasm/types/genesis.go b/x/twasm/types/genesis.go index 7fc24546..6f50092b 100644 --- a/x/twasm/types/genesis.go +++ b/x/twasm/types/genesis.go @@ -1,7 +1,6 @@ package types import ( - wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -43,16 +42,13 @@ func (g GenesisState) ValidateBasic() error { uniquePinnedCodeIDs[code] = struct{}{} } - genesisCodes := wasmcli.GetAllCodes(&wasmState) - for _, code := range genesisCodes { + for _, code := range wasmState.GetCodes() { delete(uniquePinnedCodeIDs, code.CodeID) } if len(uniquePinnedCodeIDs) > 0 { return sdkerrors.Wrapf(wasmtypes.ErrInvalidGenesis, "%d pinned codeIDs not found in genesis codeIDs", len(uniquePinnedCodeIDs)) } - - genesisContracts := wasmcli.GetAllContracts(&wasmState) - for _, contract := range genesisContracts { + for _, contract := range wasmState.Contracts { delete(uniqueAddr, contract.ContractAddress) } if len(uniqueAddr) > 0 { @@ -72,9 +68,10 @@ func (g GenesisState) RawWasmState() wasmtypes.GenesisState { s = m.Models } contracts[i] = wasmtypes.Contract{ - ContractAddress: v.ContractAddress, - ContractInfo: v.ContractInfo, - ContractState: s, + ContractAddress: v.ContractAddress, + ContractInfo: v.ContractInfo, + ContractState: s, + ContractCodeHistory: v.ContractCodeHistory, } } return wasmtypes.GenesisState{ @@ -82,7 +79,6 @@ func (g GenesisState) RawWasmState() wasmtypes.GenesisState { Codes: g.Codes, Contracts: contracts, Sequences: g.Sequences, - GenMsgs: g.GenMsgs, } } diff --git a/x/twasm/types/genesis.pb.go b/x/twasm/types/genesis.pb.go index 9555d7dc..66665e8c 100644 --- a/x/twasm/types/genesis.pb.go +++ b/x/twasm/types/genesis.pb.go @@ -39,8 +39,6 @@ type GenesisState struct { Contracts []Contract `protobuf:"bytes,3,rep,name=contracts,proto3" json:"contracts,omitempty"` // Sequences names and values Sequences []types.Sequence `protobuf:"bytes,4,rep,name=sequences,proto3" json:"sequences,omitempty"` - // GenMsgs has wasmd sdk type messages to execute in the genesis phase - GenMsgs []types.GenesisState_GenMsgs `protobuf:"bytes,5,rep,name=gen_msgs,json=genMsgs,proto3" json:"gen_msgs,omitempty"` // PrivilegedContractAddresses is a list of contract addresses that can have // special permissions PrivilegedContractAddresses []string `protobuf:"bytes,6,rep,name=privileged_contract_addresses,json=privilegedContractAddresses,proto3" json:"privileged_contract_addresses,omitempty"` @@ -114,13 +112,6 @@ func (m *GenesisState) GetSequences() []types.Sequence { return nil } -func (m *GenesisState) GetGenMsgs() []types.GenesisState_GenMsgs { - if m != nil { - return m.GenMsgs - } - return nil -} - func (m *GenesisState) GetPrivilegedContractAddresses() []string { if m != nil { return m.PrivilegedContractAddresses @@ -144,7 +135,8 @@ type Contract struct { // Types that are valid to be assigned to ContractState: // *Contract_KvModel // *Contract_CustomModel - ContractState isContract_ContractState `protobuf_oneof:"contract_state"` + ContractState isContract_ContractState `protobuf_oneof:"contract_state"` + ContractCodeHistory []types.ContractCodeHistoryEntry `protobuf:"bytes,5,rep,name=contract_code_history,json=contractCodeHistory,proto3" json:"contract_code_history"` } func (m *Contract) Reset() { *m = Contract{} } @@ -236,6 +228,13 @@ func (m *Contract) GetCustomModel() *CustomModel { return nil } +func (m *Contract) GetContractCodeHistory() []types.ContractCodeHistoryEntry { + if m != nil { + return m.ContractCodeHistory + } + return nil +} + // XXX_OneofWrappers is for the internal use of the proto package. func (*Contract) XXX_OneofWrappers() []interface{} { return []interface{}{ @@ -358,49 +357,49 @@ func init() { } var fileDescriptor_89c4cd47eb0533ed = []byte{ - // 659 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x94, 0x5f, 0x4f, 0xd3, 0x50, - 0x14, 0xc0, 0x37, 0x36, 0x36, 0x76, 0x37, 0x84, 0x5c, 0x89, 0x94, 0x21, 0xdd, 0xdc, 0x03, 0xce, - 0x68, 0xda, 0x80, 0xd1, 0x44, 0x13, 0x13, 0x2c, 0xfe, 0x23, 0x86, 0x48, 0x46, 0xc4, 0x68, 0xa2, - 0x4b, 0x77, 0x7b, 0xb9, 0x36, 0xd0, 0xde, 0xba, 0x73, 0x19, 0xf0, 0x2d, 0x7c, 0xf2, 0x33, 0xf1, - 0xc8, 0xa3, 0x4f, 0x8b, 0x19, 0x0f, 0x26, 0x7c, 0x04, 0x9f, 0x4c, 0x6f, 0x6f, 0xbb, 0x42, 0xa7, - 0x6f, 0x6d, 0xcf, 0xef, 0xfc, 0xce, 0xbd, 0x67, 0x67, 0x07, 0xb5, 0x08, 0xf7, 0xf7, 0x5d, 0x6e, - 0x8a, 0x63, 0x1b, 0x3c, 0x73, 0xb0, 0xd6, 0xa3, 0xc2, 0x5e, 0x33, 0x19, 0xf5, 0x29, 0xb8, 0x60, - 0x04, 0x7d, 0x2e, 0x38, 0x5e, 0x88, 0x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x10, 0x7a, 0x93, 0xeb, 0x94, 0x0f, 0x06, 0xf2, 0x11, 0xbf, 0x42, 0x35, 0x72, - 0x04, 0x82, 0x7b, 0x2a, 0xbf, 0x28, 0xf3, 0xef, 0xfc, 0x63, 0x36, 0x25, 0x19, 0x3b, 0xaa, 0x64, - 0xfc, 0x6a, 0xcd, 0xa3, 0x1b, 0xc9, 0x75, 0x20, 0x1c, 0x87, 0xd6, 0x06, 0x2a, 0xab, 0x7a, 0xf8, - 0x11, 0x2a, 0x49, 0x7b, 0xd8, 0x8c, 0x70, 0x92, 0x16, 0xb3, 0x97, 0x8c, 0x2c, 0xea, 0xbf, 0x17, - 0xc1, 0xad, 0x2f, 0xa8, 0x9a, 0xaa, 0x88, 0xdf, 0xa1, 0x82, 0x07, 0x4c, 0x9b, 0x6e, 0xe6, 0xdb, - 0x35, 0xeb, 0xd9, 0x9f, 0x61, 0xe3, 0x09, 0x73, 0xc5, 0xd7, 0xa3, 0x9e, 0x41, 0xb8, 0x67, 0x6e, - 0x72, 0xf0, 0x3e, 0xc4, 0xab, 0xc0, 0x31, 0x4f, 0xa2, 0x95, 0x10, 0x6d, 0x8b, 0x8e, 0x7d, 0x1c, - 0xf7, 0x70, 0x9b, 0x02, 0xd8, 0x8c, 0x76, 0x42, 0x93, 0xb5, 0x71, 0x36, 0xd2, 0xf3, 0xe7, 0x23, - 0x3d, 0xff, 0x6b, 0xa4, 0xe7, 0xbf, 0x5f, 0xe8, 0xb9, 0xf3, 0x0b, 0x3d, 0xf7, 0xf3, 0x42, 0xcf, - 0x7d, 0x5a, 0x4d, 0x99, 0xe3, 0x95, 0xc8, 0xfa, 0xb6, 0x43, 0xcd, 0x13, 0xb5, 0x1b, 0xa5, 0xb9, - 0x57, 0x92, 0xdb, 0xe6, 0xe1, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x74, 0x37, 0x09, 0x76, 0x38, - 0x05, 0x00, 0x00, + // 667 bytes of a gzipped FileDescriptorProto + 0x1f, 0x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x80, 0xc9, 0x8f, 0x18, 0xc3, 0xad, 0xaf, 0xa8, 0x9a, 0xc9, 0x85, 0x3f, + 0xa0, 0x82, 0x0b, 0xb6, 0x52, 0x6a, 0xe6, 0xdb, 0x35, 0xe3, 0xe5, 0xef, 0xb0, 0xf1, 0xdc, 0x76, + 0xf8, 0xfe, 0x51, 0x4f, 0xb3, 0x98, 0xab, 0xaf, 0x31, 0x70, 0x3f, 0x25, 0x7b, 0x81, 0xe8, 0x27, + 0xf1, 0x7e, 0x88, 0x57, 0x47, 0xc7, 0x3c, 0x4e, 0x22, 0x6d, 0x51, 0x00, 0xd3, 0xa6, 0x9d, 0x48, + 0xc9, 0x58, 0x3d, 0x1d, 0xaa, 0xf9, 0xb3, 0xa1, 0x9a, 0xff, 0x35, 0x54, 0xf3, 0x3f, 0xce, 0xd5, + 0xdc, 0xd9, 0xb9, 0x9a, 0xfb, 0x79, 0xae, 0xe6, 0xbe, 0xdc, 0xcb, 0x28, 0x27, 0xfb, 0xd1, 0x0e, + 0x4c, 0x42, 0xf5, 0x13, 0xb9, 0x28, 0x85, 0x72, 0xaf, 0x2c, 0x56, 0xcf, 0x93, 0xbf, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x9f, 0x96, 0x5c, 0x41, 0x45, 0x05, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -450,20 +449,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x32 } } - if len(m.GenMsgs) > 0 { - for iNdEx := len(m.GenMsgs) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.GenMsgs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - } - } if len(m.Sequences) > 0 { for iNdEx := len(m.Sequences) - 1; iNdEx >= 0; iNdEx-- { { @@ -539,6 +524,20 @@ func (m *Contract) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.ContractCodeHistory) > 0 { + for iNdEx := len(m.ContractCodeHistory) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ContractCodeHistory[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + } + } if m.ContractState != nil { { size := m.ContractState.Size() @@ -717,12 +716,6 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } - if len(m.GenMsgs) > 0 { - for _, e := range m.GenMsgs { - l = e.Size() - n += 1 + l + sovGenesis(uint64(l)) - } - } if len(m.PrivilegedContractAddresses) > 0 { for _, s := range m.PrivilegedContractAddresses { l = len(s) @@ -754,6 +747,12 @@ func (m *Contract) Size() (n int) { if m.ContractState != nil { n += m.ContractState.Size() } + if len(m.ContractCodeHistory) > 0 { + for _, e := range m.ContractCodeHistory { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -983,40 +982,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field GenMsgs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.GenMsgs = append(m.GenMsgs, types.GenesisState_GenMsgs{}) - if err := m.GenMsgs[len(m.GenMsgs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PrivilegedContractAddresses", wireType) @@ -1311,6 +1276,40 @@ func (m *Contract) Unmarshal(dAtA []byte) error { } m.ContractState = &Contract_CustomModel{v} iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ContractCodeHistory", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ContractCodeHistory = append(m.ContractCodeHistory, types.ContractCodeHistoryEntry{}) + if err := m.ContractCodeHistory[len(m.ContractCodeHistory)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/twasm/types/test_fixtures.go b/x/twasm/types/test_fixtures.go index 37511531..9360b024 100644 --- a/x/twasm/types/test_fixtures.go +++ b/x/twasm/types/test_fixtures.go @@ -12,6 +12,10 @@ import ( "github.com/tendermint/tendermint/libs/rand" ) +// magic number for Wasm is "\0asm" +// See https://webassembly.github.io/spec/core/binary/modules.html#binary-module +var wasmIdent = []byte("\x00\x61\x73\x6D") + func PromoteProposalFixture(mutators ...func(*PromoteToPrivilegedContractProposal)) *PromoteToPrivilegedContractProposal { const anyAddress = "cosmos1qyqszqgpqyqszqgpqyqszqgpqyqszqgpjnp7du" p := &PromoteToPrivilegedContractProposal{ @@ -43,9 +47,11 @@ func DeterministicGenesisStateFixture(t *testing.T, mutators ...func(*GenesisSta genesisState := GenesisStateFixture(t) for i := range genesisState.Contracts { genesisState.Contracts[i].ContractAddress = wasmkeeper.BuildContractAddressClassic(uint64(i), uint64(i)).String() + genesisState.Contracts[i].ContractCodeHistory = []wasmtypes.ContractCodeHistoryEntry{wasmtypes.ContractCodeHistoryEntryFixture()} + genesisState.Contracts[i].ContractInfo.Created = genesisState.Contracts[i].ContractCodeHistory[0].Updated } for i := range genesisState.Codes { - wasmCode := bytes.Repeat([]byte{byte(i)}, 20) + wasmCode := append(wasmIdent, bytes.Repeat([]byte{byte(i)}, 20)...) genesisState.Codes[i].CodeInfo = wasmtypes.CodeInfoFixture(wasmtypes.WithSHA256CodeHash(wasmCode)) genesisState.Codes[i].CodeBytes = wasmCode } @@ -72,14 +78,14 @@ func GenesisStateFixture(t *testing.T, mutators ...func(*GenesisState)) GenesisS {IDKey: wasmtypes.KeyLastCodeID, Value: 10}, {IDKey: wasmtypes.KeyLastInstanceID, Value: 11}, } - state.GenMsgs = nil }) contracts := make([]Contract, len(wasmState.Contracts)) for i, v := range wasmState.Contracts { contracts[i] = Contract{ - ContractAddress: v.ContractAddress, - ContractInfo: v.ContractInfo, - ContractState: &Contract_KvModel{&KVModel{v.ContractState}}, + ContractAddress: v.ContractAddress, + ContractInfo: v.ContractInfo, + ContractState: &Contract_KvModel{&KVModel{v.ContractState}}, + ContractCodeHistory: v.ContractCodeHistory, } } genesisState := GenesisState{ @@ -87,7 +93,6 @@ func GenesisStateFixture(t *testing.T, mutators ...func(*GenesisState)) GenesisS Codes: wasmState.Codes, Contracts: contracts, Sequences: wasmState.Sequences, - GenMsgs: wasmState.GenMsgs, PrivilegedContractAddresses: []string{anyContractAddr}, } for _, m := range mutators { @@ -101,9 +106,10 @@ func ContractFixture(t *testing.T, mutators ...func(contract *Contract)) Contrac t.Helper() wasmContract := wasmtypes.ContractFixture() c := Contract{ - ContractAddress: wasmContract.ContractAddress, - ContractInfo: wasmContract.ContractInfo, - ContractState: &Contract_KvModel{&KVModel{wasmContract.ContractState}}, + ContractAddress: wasmContract.ContractAddress, + ContractInfo: wasmContract.ContractInfo, + ContractState: &Contract_KvModel{&KVModel{wasmContract.ContractState}}, + ContractCodeHistory: wasmContract.ContractCodeHistory, } for _, m := range mutators { m(&c)