Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gov v1 instead of v1beta1 for new proposals #1269

Merged
merged 13 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ Since: 0.40

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the governance account. |
| `authority` | [string](#string) | | Authority is the address of the governance account. |
| `code_ids` | [uint64](#uint64) | repeated | CodeIDs references the new WASM codes |


Expand Down Expand Up @@ -1545,15 +1545,14 @@ Since: 0.40

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the governance account. |
| `run_as` | [string](#string) | | |
| `authority` | [string](#string) | | Authority is the address of the governance account. |
| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed |
| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply on contract creation, optional |
| `unpin_code` | [bool](#bool) | | UnpinCode code on upload, optional |
| `unpin_code` | [bool](#bool) | | UnpinCode code on upload, optional. As default the uploaded contract is pinned to cache. |
| `admin` | [string](#string) | | Admin is an optional address that can execute migrations |
| `label` | [string](#string) | | Label is optional metadata to be stored with a constract instance. |
| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract on instantiation |
| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred to the contract on instantiation |
| `funds` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | Funds coins that are transferred from the authority account to the contract on instantiation |
| `source` | [string](#string) | | Source is the URL where the code is hosted |
| `builder` | [string](#string) | | Builder is the docker image used to build the code deterministically, used for smart contract verification |
| `code_hash` | [bytes](#bytes) | | CodeHash is the SHA256 sum of the code outputted by builder, used for smart contract verification |
Expand All @@ -1572,6 +1571,12 @@ for executing a MsgStoreAndInstantiateContract message.
Since: 0.40


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | Address is the bech32 address of the new contract instance. |
| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract |





Expand Down Expand Up @@ -1619,7 +1624,7 @@ Since: 0.40

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the governance account. |
| `authority` | [string](#string) | | Authority is the address of the governance account. |
| `contract` | [string](#string) | | Contract is the address of the smart contract |
| `msg` | [bytes](#bytes) | | Msg json encoded message to be passed to the contract as sudo |

Expand All @@ -1637,6 +1642,11 @@ MsgSudoContract message.
Since: 0.40


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `data` | [bytes](#bytes) | | Data contains bytes to returned from the contract |





Expand All @@ -1651,7 +1661,7 @@ Since: 0.40

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the governance account. |
| `authority` | [string](#string) | | Authority is the address of the governance account. |
| `code_ids` | [uint64](#uint64) | repeated | CodeIDs references the WASM codes |


Expand Down Expand Up @@ -1736,7 +1746,7 @@ Since: 0.40

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the governance account. |
| `authority` | [string](#string) | | Authority is the address of the governance account. |
| `params` | [Params](#cosmwasm.wasm.v1.Params) | | params defines the x/wasm parameters to update.

NOTE: All parameters must be supplied. |
Expand Down Expand Up @@ -1783,10 +1793,18 @@ Msg defines the wasm Msg service.
| `UpdateParams` | [MsgUpdateParams](#cosmwasm.wasm.v1.MsgUpdateParams) | [MsgUpdateParamsResponse](#cosmwasm.wasm.v1.MsgUpdateParamsResponse) | UpdateParams defines a governance operation for updating the x/wasm module parameters. The authority is defined in the keeper.

Since: 0.40 | |
| `SudoContract` | [MsgSudoContract](#cosmwasm.wasm.v1.MsgSudoContract) | [MsgSudoContractResponse](#cosmwasm.wasm.v1.MsgSudoContractResponse) | SudoContract calls sudo on a contract. | |
| `PinCodes` | [MsgPinCodes](#cosmwasm.wasm.v1.MsgPinCodes) | [MsgPinCodesResponse](#cosmwasm.wasm.v1.MsgPinCodesResponse) | PinCodes pins a set of code ids in the wasmvm cache. | |
| `UnpinCodes` | [MsgUnpinCodes](#cosmwasm.wasm.v1.MsgUnpinCodes) | [MsgUnpinCodesResponse](#cosmwasm.wasm.v1.MsgUnpinCodesResponse) | UnpinCodes unpins a set of code ids in the wasmvm cache. | |
| `StoreAndInstantiateContract` | [MsgStoreAndInstantiateContract](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContract) | [MsgStoreAndInstantiateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse) | StoreAndInstantiateContract stores and instantiates the contract. | |
| `SudoContract` | [MsgSudoContract](#cosmwasm.wasm.v1.MsgSudoContract) | [MsgSudoContractResponse](#cosmwasm.wasm.v1.MsgSudoContractResponse) | SudoContract defines a governance operation for calling sudo on a contract. The authority is defined in the keeper.

Since: 0.40 | |
| `PinCodes` | [MsgPinCodes](#cosmwasm.wasm.v1.MsgPinCodes) | [MsgPinCodesResponse](#cosmwasm.wasm.v1.MsgPinCodesResponse) | PinCodes defines a governance operation for pinning a set of code ids in the wasmvm cache. The authority is defined in the keeper.

Since: 0.40 | |
| `UnpinCodes` | [MsgUnpinCodes](#cosmwasm.wasm.v1.MsgUnpinCodes) | [MsgUnpinCodesResponse](#cosmwasm.wasm.v1.MsgUnpinCodesResponse) | UnpinCodes defines a governance operation for unpinning a set of code ids in the wasmvm cache. The authority is defined in the keeper.

Since: 0.40 | |
| `StoreAndInstantiateContract` | [MsgStoreAndInstantiateContract](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContract) | [MsgStoreAndInstantiateContractResponse](#cosmwasm.wasm.v1.MsgStoreAndInstantiateContractResponse) | StoreAndInstantiateContract defines a governance operation for storing and instantiating the contract. The authority is defined in the keeper.

Since: 0.40 | |

<!-- end services -->

Expand Down
49 changes: 35 additions & 14 deletions proto/cosmwasm/wasm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,25 @@ service Msg {
//
// Since: 0.40
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
// SudoContract calls sudo on a contract.
// SudoContract defines a governance operation for calling sudo
// on a contract. The authority is defined in the keeper.
//
// Since: 0.40
rpc SudoContract(MsgSudoContract) returns (MsgSudoContractResponse);
// PinCodes pins a set of code ids in the wasmvm cache.
// PinCodes defines a governance operation for pinning a set of
// code ids in the wasmvm cache. The authority is defined in the keeper.
//
// Since: 0.40
rpc PinCodes(MsgPinCodes) returns (MsgPinCodesResponse);
// UnpinCodes unpins a set of code ids in the wasmvm cache.
// UnpinCodes defines a governance operation for unpinning a set of
// code ids in the wasmvm cache. The authority is defined in the keeper.
//
// Since: 0.40
rpc UnpinCodes(MsgUnpinCodes) returns (MsgUnpinCodesResponse);
// StoreAndInstantiateContract stores and instantiates the contract.
// StoreAndInstantiateContract defines a governance operation for storing
// and instantiating the contract. The authority is defined in the keeper.
//
// Since: 0.40
rpc StoreAndInstantiateContract(MsgStoreAndInstantiateContract)
returns (MsgStoreAndInstantiateContractResponse);
}
Expand Down Expand Up @@ -229,7 +241,7 @@ message MsgUpdateInstantiateConfigResponse {}
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
// Authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// params defines the x/wasm parameters to update.
Expand All @@ -250,7 +262,7 @@ message MsgUpdateParamsResponse {}
message MsgSudoContract {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
// Authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Contract is the address of the smart contract
Expand All @@ -263,15 +275,18 @@ message MsgSudoContract {
// MsgSudoContract message.
//
// Since: 0.40
message MsgSudoContractResponse {}
message MsgSudoContractResponse {
// Data contains bytes to returned from the contract
bytes data = 1;
}

// MsgPinCodes is the MsgPinCodes request type.
//
// Since: 0.40
message MsgPinCodes {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
// Authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// CodeIDs references the new WASM codes
repeated uint64 code_ids = 2 [
Expand All @@ -292,7 +307,7 @@ message MsgPinCodesResponse {}
message MsgUnpinCodes {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
// Authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// CodeIDs references the WASM codes
repeated uint64 code_ids = 2 [
Expand All @@ -314,22 +329,23 @@ message MsgUnpinCodesResponse {}
message MsgStoreAndInstantiateContract {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address of the governance account.
// Authority is the address of the governance account.
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string run_as = 2;
// WASMByteCode can be raw or gzip compressed
bytes wasm_byte_code = 3 [ (gogoproto.customname) = "WASMByteCode" ];
// InstantiatePermission to apply on contract creation, optional
AccessConfig instantiate_permission = 4;
// UnpinCode code on upload, optional
// UnpinCode code on upload, optional. As default the uploaded contract is
// pinned to cache.
bool unpin_code = 5;
// Admin is an optional address that can execute migrations
string admin = 6;
// Label is optional metadata to be stored with a constract instance.
string label = 7;
// Msg json encoded message to be passed to the contract on instantiation
bytes msg = 8 [ (gogoproto.casttype) = "RawContractMessage" ];
// Funds coins that are transferred to the contract on instantiation
// Funds coins that are transferred from the authority account to the contract
// on instantiation
repeated cosmos.base.v1beta1.Coin funds = 9 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
Expand All @@ -348,4 +364,9 @@ message MsgStoreAndInstantiateContract {
// for executing a MsgStoreAndInstantiateContract message.
//
// Since: 0.40
message MsgStoreAndInstantiateContractResponse {}
message MsgStoreAndInstantiateContractResponse {
// Address is the bech32 address of the new contract instance.
string address = 1;
// Data contains bytes to returned from the contract
bytes data = 2;
}
96 changes: 96 additions & 0 deletions x/wasm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,99 @@ func (m msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParam

return &types.MsgUpdateParamsResponse{}, nil
}

// PinCodes pins a set of code ids in the wasmvm cache.
func (m msgServer) PinCodes(goCtx context.Context, req *types.MsgPinCodes) (*types.MsgPinCodesResponse, error) {
authority := m.paramStore.GetAuthority()
if authority != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid authority; expected %s, got %s", authority, req.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
for _, codeID := range req.CodeIDs {
if err := m.keeper.PinCode(ctx, codeID); err != nil {
return nil, err
}
}

return &types.MsgPinCodesResponse{}, nil
}

// UnpinCodes unpins a set of code ids in the wasmvm cache.
func (m msgServer) UnpinCodes(goCtx context.Context, req *types.MsgUnpinCodes) (*types.MsgUnpinCodesResponse, error) {
authority := m.paramStore.GetAuthority()
if authority != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid authority; expected %s, got %s", authority, req.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
for _, codeID := range req.CodeIDs {
if err := m.keeper.UnpinCode(ctx, codeID); err != nil {
return nil, err
}
}

return &types.MsgUnpinCodesResponse{}, nil
}

// SudoContract calls sudo on a contract.
func (m msgServer) SudoContract(goCtx context.Context, req *types.MsgSudoContract) (*types.MsgSudoContractResponse, error) {
authority := m.paramStore.GetAuthority()
if authority != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid authority; expected %s, got %s", authority, req.Authority)
}

contractAddr, err := sdk.AccAddressFromBech32(req.Contract)
if err != nil {
return nil, errorsmod.Wrap(err, "contract")
}

ctx := sdk.UnwrapSDKContext(goCtx)
data, err := m.keeper.Sudo(ctx, contractAddr, req.Msg)
if err != nil {
return nil, err
}

return &types.MsgSudoContractResponse{Data: data}, nil
}

// StoreAndInstantiateContract stores and instantiates the contract.
func (m msgServer) StoreAndInstantiateContract(goCtx context.Context, req *types.MsgStoreAndInstantiateContract) (*types.MsgStoreAndInstantiateContractResponse, error) {
authority := m.paramStore.GetAuthority()
if authority != req.Authority {
return nil, errorsmod.Wrapf(types.ErrInvalid, "invalid authority; expected %s, got %s", authority, req.Authority)
}

authorityAddr, err := sdk.AccAddressFromBech32(authority)
if err != nil {
return nil, errorsmod.Wrap(err, "admin")
}

if err = req.ValidateBasic(); err != nil {
return nil, err
}

var adminAddr sdk.AccAddress
if req.Admin != "" {
if adminAddr, err = sdk.AccAddressFromBech32(req.Admin); err != nil {
return nil, errorsmod.Wrap(err, "admin")
}
}

ctx := sdk.UnwrapSDKContext(goCtx)

codeID, _, err := m.keeper.Create(ctx, authorityAddr, req.WASMByteCode, req.InstantiatePermission)
if err != nil {
return nil, err
}

contractAddr, data, err := m.keeper.Instantiate(ctx, codeID, authorityAddr, adminAddr, req.Msg, req.Label, req.Funds)
if err != nil {
return nil, err
}

return &types.MsgStoreAndInstantiateContractResponse{
Address: contractAddr.String(),
Data: data,
}, nil
}
6 changes: 3 additions & 3 deletions x/wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}

// ProposalContents doesn't return any content functions for governance proposals.
func (am AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
return simulation.ProposalContents(am.bankKeeper, am.keeper)
// ProposalMsgs returns msgs used for governance proposals for simulations.
func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg {
return simulation.ProposalMsgs(am.bankKeeper, am.keeper)
}

// RegisterStoreDecoder registers a decoder for supply module's types
Expand Down
1 change: 1 addition & 0 deletions x/wasm/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (

// WasmKeeper is a subset of the wasm keeper used by simulations
type WasmKeeper interface {
GetAuthority() string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

GetParams(ctx sdk.Context) types.Params
IterateCodeInfos(ctx sdk.Context, cb func(uint64, types.CodeInfo) bool)
IterateContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, types.ContractInfo) bool)
Expand Down
Loading