Skip to content

Commit

Permalink
add UpdateInstantiateConfig gov proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
jhernandezb committed May 3, 2022
1 parent 23c75b1 commit fde825b
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SIMAPP = ./app

# for dockerized protobuf tools
DOCKER := $(shell which docker)
BUF_IMAGE=bufbuild/buf@sha256:3cb1f8a4b48bd5ad8f09168f10f607ddc318af202f5c057d52a45216793d85e5 #v1.4.0
BUF_IMAGE=bufbuild/buf:1.0.0-rc8
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(BUF_IMAGE)
HTTPS_GIT := https://github.com/CosmWasm/wasmd.git

Expand Down
20 changes: 20 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- [SudoContractProposal](#cosmwasm.wasm.v1.SudoContractProposal)
- [UnpinCodesProposal](#cosmwasm.wasm.v1.UnpinCodesProposal)
- [UpdateAdminProposal](#cosmwasm.wasm.v1.UpdateAdminProposal)
- [UpdateInstantiateConfigProposal](#cosmwasm.wasm.v1.UpdateInstantiateConfigProposal)

- [cosmwasm/wasm/v1/query.proto](#cosmwasm/wasm/v1/query.proto)
- [CodeInfoResponse](#cosmwasm.wasm.v1.CodeInfoResponse)
Expand Down Expand Up @@ -814,6 +815,25 @@ UpdateAdminProposal gov proposal content type to set an admin for a contract.




<a name="cosmwasm.wasm.v1.UpdateInstantiateConfigProposal"></a>

### UpdateInstantiateConfigProposal
UpdateInstantiateConfigProposal gov proposal content type to update
instantiate config to a set of code ids.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `title` | [string](#string) | | Title is a short summary |
| `description` | [string](#string) | | Description is a human readable text |
| `code_ids` | [uint64](#uint64) | repeated | CodeIDs references the WASM codes |
| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply to the set of code ids |





<!-- end messages -->

<!-- end enums -->
Expand Down
16 changes: 16 additions & 0 deletions proto/cosmwasm/wasm/v1/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,19 @@ message UnpinCodesProposal {
(gogoproto.moretags) = "yaml:\"code_ids\""
];
}

// UpdateInstantiateConfigProposal gov proposal content type to update
// instantiate config to a set of code ids.
message UpdateInstantiateConfigProposal {
// Title is a short summary
string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ];
// Description is a human readable text
string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ];
// CodeIDs references the WASM codes
repeated uint64 code_ids = 3 [
(gogoproto.customname) = "CodeIDs",
(gogoproto.moretags) = "yaml:\"code_ids\""
];
// InstantiatePermission to apply to the set of code ids
AccessConfig instantiate_permission = 4 [ (gogoproto.nullable) = false ];
}
6 changes: 6 additions & 0 deletions x/wasm/keeper/contract_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type decoratedKeeper interface {
execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, msg []byte, coins sdk.Coins) ([]byte, error)
Sudo(ctx sdk.Context, contractAddress sdk.AccAddress, msg []byte) ([]byte, error)
setContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error
setAccessConfig(ctx sdk.Context, codeID uint64, config types.AccessConfig) error
}

type PermissionedKeeper struct {
Expand Down Expand Up @@ -78,3 +79,8 @@ func (p PermissionedKeeper) UnpinCode(ctx sdk.Context, codeID uint64) error {
func (p PermissionedKeeper) SetContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra types.ContractInfoExtension) error {
return p.nested.setContractInfoExtension(ctx, contract, extra)
}

// SetAccessConfig updates the access config of a code id.
func (p PermissionedKeeper) SetAccessConfig(ctx sdk.Context, codeID uint64, config types.AccessConfig) error {
return p.nested.setAccessConfig(ctx, codeID, config)
}
11 changes: 11 additions & 0 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,17 @@ func (k Keeper) setContractInfoExtension(ctx sdk.Context, contractAddr sdk.AccAd
return nil
}

// setAccessConfig updates the access config of a code id.
func (k Keeper) setAccessConfig(ctx sdk.Context, codeID uint64, config types.AccessConfig) error {
info := k.GetCodeInfo(ctx, codeID)
if info == nil {
return sdkerrors.Wrap(types.ErrNotFound, "code info")
}
info.InstantiateConfig = config
k.storeCodeInfo(ctx, codeID, *info)
return nil
}

// handleContractResponse processes the contract response data by emitting events and sending sub-/messages.
func (k *Keeper) handleContractResponse(
ctx sdk.Context,
Expand Down
14 changes: 14 additions & 0 deletions x/wasm/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func NewWasmProposalHandlerX(k types.ContractOpsKeeper, enabledProposalTypes []t
return handlePinCodesProposal(ctx, k, *c)
case *types.UnpinCodesProposal:
return handleUnpinCodesProposal(ctx, k, *c)
case *types.UpdateInstantiateConfigProposal:
return handleUpdateInstantiateConfigProposal(ctx, k, *c)
default:
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized wasm proposal content type: %T", c)
}
Expand Down Expand Up @@ -221,3 +223,15 @@ func handleUnpinCodesProposal(ctx sdk.Context, k types.ContractOpsKeeper, p type
}
return nil
}

func handleUpdateInstantiateConfigProposal(ctx sdk.Context, k types.ContractOpsKeeper, p types.UpdateInstantiateConfigProposal) error {
if err := p.ValidateBasic(); err != nil {
return err
}
for _, v := range p.CodeIDs {
if err := k.SetAccessConfig(ctx, v, p.InstantiatePermission); err != nil {
return sdkerrors.Wrapf(err, "code id: %d", v)
}
}
return nil
}
2 changes: 2 additions & 0 deletions x/wasm/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { //nolint:staticcheck
cdc.RegisterConcrete(&ExecuteContractProposal{}, "wasm/ExecuteContractProposal", nil)
cdc.RegisterConcrete(&UpdateAdminProposal{}, "wasm/UpdateAdminProposal", nil)
cdc.RegisterConcrete(&ClearAdminProposal{}, "wasm/ClearAdminProposal", nil)
cdc.RegisterConcrete(&UpdateInstantiateConfigProposal{}, "wasm/UpdateInstantiateConfigProposal", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
Expand All @@ -52,6 +53,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&ClearAdminProposal{},
&PinCodesProposal{},
&UnpinCodesProposal{},
&UpdateInstantiateConfigProposal{},
)

registry.RegisterInterface("ContractInfoExtension", (*ContractInfoExtension)(nil))
Expand Down
3 changes: 3 additions & 0 deletions x/wasm/types/exported_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type ContractOpsKeeper interface {

// SetContractInfoExtension updates the extension point data that is stored with the contract info
SetContractInfoExtension(ctx sdk.Context, contract sdk.AccAddress, extra ContractInfoExtension) error

// SetAccessConfig updates the access config of a code id.
SetAccessConfig(ctx sdk.Context, codeID uint64, config AccessConfig) error
}

// IBCContractKeeper IBC lifecycle event handler
Expand Down
58 changes: 49 additions & 9 deletions x/wasm/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import (
type ProposalType string

const (
ProposalTypeStoreCode ProposalType = "StoreCode"
ProposalTypeInstantiateContract ProposalType = "InstantiateContract"
ProposalTypeMigrateContract ProposalType = "MigrateContract"
ProposalTypeSudoContract ProposalType = "SudoContract"
ProposalTypeExecuteContract ProposalType = "ExecuteContract"
ProposalTypeUpdateAdmin ProposalType = "UpdateAdmin"
ProposalTypeClearAdmin ProposalType = "ClearAdmin"
ProposalTypePinCodes ProposalType = "PinCodes"
ProposalTypeUnpinCodes ProposalType = "UnpinCodes"
ProposalTypeStoreCode ProposalType = "StoreCode"
ProposalTypeInstantiateContract ProposalType = "InstantiateContract"
ProposalTypeMigrateContract ProposalType = "MigrateContract"
ProposalTypeSudoContract ProposalType = "SudoContract"
ProposalTypeExecuteContract ProposalType = "ExecuteContract"
ProposalTypeUpdateAdmin ProposalType = "UpdateAdmin"
ProposalTypeClearAdmin ProposalType = "ClearAdmin"
ProposalTypePinCodes ProposalType = "PinCodes"
ProposalTypeUnpinCodes ProposalType = "UnpinCodes"
ProposalTypeUpdateInstantiateConfig ProposalType = "UpdateInstantiateConfig"
)

// DisableAllProposals contains no wasm gov types.
Expand Down Expand Up @@ -77,6 +78,7 @@ func init() { // register new content types with the sdk
govtypes.RegisterProposalTypeCodec(&ClearAdminProposal{}, "wasm/ClearAdminProposal")
govtypes.RegisterProposalTypeCodec(&PinCodesProposal{}, "wasm/PinCodesProposal")
govtypes.RegisterProposalTypeCodec(&UnpinCodesProposal{}, "wasm/UnpinCodesProposal")
govtypes.RegisterProposalTypeCodec(&UpdateInstantiateConfigProposal{}, "wasm/UpdateInstantiateConfigProposal")
}

// ProposalRoute returns the routing key of a parameter change proposal.
Expand Down Expand Up @@ -546,3 +548,41 @@ func validateProposalCommons(title, description string) error {
}
return nil
}

// ProposalRoute returns the routing key of a parameter change proposal.
func (p UpdateInstantiateConfigProposal) ProposalRoute() string { return RouterKey }

// GetTitle returns the title of the proposal
func (p *UpdateInstantiateConfigProposal) GetTitle() string { return p.Title }

// GetDescription returns the human readable description of the proposal
func (p UpdateInstantiateConfigProposal) GetDescription() string { return p.Description }

// ProposalType returns the type
func (p UpdateInstantiateConfigProposal) ProposalType() string {
return string(ProposalTypeUpdateInstantiateConfig)
}

// ValidateBasic validates the proposal
func (p UpdateInstantiateConfigProposal) ValidateBasic() error {
if err := validateProposalCommons(p.Title, p.Description); err != nil {
return err
}
if len(p.CodeIDs) == 0 {
return sdkerrors.Wrap(ErrEmpty, "code ids")
}
if err := p.InstantiatePermission.ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "instantiate permission")
}
return nil
}

// String implements the Stringer interface.
func (p UpdateInstantiateConfigProposal) String() string {
return fmt.Sprintf(`Update Instantiate Config Proposal:
Title: %s
Description: %s
Codes: %v
InstantiatePermission: %v
`, p.Title, p.Description, p.CodeIDs, p.InstantiatePermission)
}
Loading

0 comments on commit fde825b

Please sign in to comment.