Skip to content

Commit

Permalink
Merge pull request cosmos#564 from CosmWasm/540-trim-code-info
Browse files Browse the repository at this point in the history
Trim code info
  • Loading branch information
ethanfrey authored Jul 28, 2021
2 parents 6f684d5 + 18741cb commit 267643f
Show file tree
Hide file tree
Showing 40 changed files with 300 additions and 942 deletions.
8 changes: 0 additions & 8 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ CodeInfo is data for the uploaded contract WASM code
| ----- | ---- | ----- | ----------- |
| `code_hash` | [bytes](#bytes) | | CodeHash is the unique identifier created by wasmvm |
| `creator` | [string](#string) | | Creator address who initially stored the code |
| `source` | [string](#string) | | Source is a valid absolute HTTPS URI to the contract's source code, optional |
| `builder` | [string](#string) | | Builder is a valid docker image name with tag, optional |
| `instantiate_config` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiateConfig access control to apply on contract creation, optional |


Expand Down Expand Up @@ -407,8 +405,6 @@ MsgStoreCode submit Wasm code to the system
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | Sender is the that actor that signed the messages |
| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed |
| `source` | [string](#string) | | Source is a valid absolute HTTPS URI to the contract's source code, optional |
| `builder` | [string](#string) | | Builder is a valid docker image name with tag, optional |
| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission access control to apply on contract creation, optional |


Expand Down Expand Up @@ -733,8 +729,6 @@ StoreCodeProposal gov proposal content type to submit WASM code to the system
| `description` | [string](#string) | | Description is a human readable text |
| `run_as` | [string](#string) | | RunAs is the address that is passed to the contract's environment as sender |
| `wasm_byte_code` | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed |
| `source` | [string](#string) | | Source is a valid absolute HTTPS URI to the contract's source code, optional |
| `builder` | [string](#string) | | Builder is a valid docker image name with tag, optional |
| `instantiate_permission` | [AccessConfig](#cosmwasm.wasm.v1.AccessConfig) | | InstantiatePermission to apply on contract creation, optional |


Expand Down Expand Up @@ -805,8 +799,6 @@ CodeInfoResponse contains code meta data from CodeInfo
| `code_id` | [uint64](#uint64) | | id for legacy support |
| `creator` | [string](#string) | | |
| `data_hash` | [bytes](#bytes) | | |
| `source` | [string](#string) | | |
| `builder` | [string](#string) | | |



Expand Down
7 changes: 2 additions & 5 deletions proto/cosmwasm/wasm/v1/proposal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ message StoreCodeProposal {
string run_as = 3;
// WASMByteCode can be raw or gzip compressed
bytes wasm_byte_code = 4 [ (gogoproto.customname) = "WASMByteCode" ];
// Source is a valid absolute HTTPS URI to the contract's source code,
// optional
string source = 5;
// Builder is a valid docker image name with tag, optional
string builder = 6;
// Used in v1beta1
reserved 5, 6;
// InstantiatePermission to apply on contract creation, optional
AccessConfig instantiate_permission = 7;
}
Expand Down
4 changes: 2 additions & 2 deletions proto/cosmwasm/wasm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ message CodeInfoResponse {
bytes data_hash = 3
[ (gogoproto.casttype) =
"github.com/tendermint/tendermint/libs/bytes.HexBytes" ];
string source = 4;
string builder = 5;
// Used in v1beta1
reserved 4, 5;
}

// QueryCodeResponse is the response type for the Query/Code RPC method
Expand Down
7 changes: 2 additions & 5 deletions proto/cosmwasm/wasm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ message MsgStoreCode {
string sender = 1;
// WASMByteCode can be raw or gzip compressed
bytes wasm_byte_code = 2 [ (gogoproto.customname) = "WASMByteCode" ];
// Source is a valid absolute HTTPS URI to the contract's source code,
// optional
string source = 3;
// Builder is a valid docker image name with tag, optional
string builder = 4;
// Used in v1beta1
reserved 3, 4;
// InstantiatePermission access control to apply on contract creation,
// optional
AccessConfig instantiate_permission = 5;
Expand Down
7 changes: 2 additions & 5 deletions proto/cosmwasm/wasm/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ message CodeInfo {
bytes code_hash = 1;
// Creator address who initially stored the code
string creator = 2;
// Source is a valid absolute HTTPS URI to the contract's source code,
// optional
string source = 3;
// Builder is a valid docker image name with tag, optional
string builder = 4;
// Used in v1beta1
reserved 3, 4;
// InstantiateConfig access control to apply on contract creation, optional
AccessConfig instantiate_config = 5 [ (gogoproto.nullable) = false ];
}
Expand Down
2 changes: 0 additions & 2 deletions x/wasm/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const (
RouterKey = types.RouterKey
MaxWasmSize = types.MaxWasmSize
MaxLabelSize = types.MaxLabelSize
BuildTagRegexp = types.BuildTagRegexp
MaxBuildTagSize = types.MaxBuildTagSize
WasmModuleEventType = types.WasmModuleEventType
AttributeKeyContractAddr = types.AttributeKeyContractAddr
ProposalTypeStoreCode = types.ProposalTypeStoreCode
Expand Down
4 changes: 0 additions & 4 deletions x/wasm/client/cli/genesis_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ func GenesisStoreCodeCmd(defaultNodeHome string, genesisMutator GenesisMutator)
})
},
}
cmd.Flags().String(flagSource, "", "A valid URI reference to the contract's source code, optional")
cmd.Flags().String(flagBuilder, "", "A valid docker tag for the build system, optional")
cmd.Flags().String(flagRunAs, "", "The address that is stored as code creator")
cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateByAddress, "", "Only this address can instantiate a contract instance from the code, optional")
Expand Down Expand Up @@ -289,8 +287,6 @@ func getAllCodes(state *types.GenesisState) ([]codeMeta, error) {
Info: types.CodeInfo{
CodeHash: hash[:],
Creator: msg.Sender,
Source: msg.Source,
Builder: msg.Builder,
InstantiateConfig: accessConfig,
},
})
Expand Down
13 changes: 0 additions & 13 deletions x/wasm/client/cli/genesis_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestGenesisStoreCodeCmd(t *testing.T) {
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{anyValidWasmFile.Name()})
flagSet := cmd.Flags()
flagSet.Set("source", "https://foo.bar")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
},
},
Expand All @@ -80,18 +79,6 @@ func TestGenesisStoreCodeCmd(t *testing.T) {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{anyValidWasmFile.Name()})
flagSet := cmd.Flags()
flagSet.Set("source", "https://foo.bar")
},
expError: true,
},
"invalid msg data should fail": {
srcGenesis: minimalWasmGenesis,
mutator: func(cmd *cobra.Command) {
cmd.SetArgs([]string{anyValidWasmFile.Name()})
flagSet := cmd.Flags()
flagSet.Set("source", "not an url")
flagSet.Set("run-as", keeper.RandomBech32AccountAddress(t))
},
expError: true,
},
Expand Down
4 changes: 0 additions & 4 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func ProposalStoreCodeCmd() *cobra.Command {
Description: proposalDescr,
RunAs: runAs,
WASMByteCode: src.WASMByteCode,
Source: src.Source,
Builder: src.Builder,
InstantiatePermission: src.InstantiatePermission,
}

Expand All @@ -74,8 +72,6 @@ func ProposalStoreCodeCmd() *cobra.Command {
},
}

cmd.Flags().String(flagSource, "", "A valid URI reference to the contract's source code, optional")
cmd.Flags().String(flagBuilder, "", "A valid docker tag for the build system, optional")
cmd.Flags().String(flagRunAs, "", "The address that is stored as code creator")
cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateByAddress, "", "Only this address can instantiate a contract instance from the code, optional")
Expand Down
16 changes: 0 additions & 16 deletions x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (

const (
flagAmount = "amount"
flagSource = "source"
flagBuilder = "builder"
flagLabel = "label"
flagAdmin = "admin"
flagRunAs = "run-as"
Expand Down Expand Up @@ -69,8 +67,6 @@ func StoreCodeCmd() *cobra.Command {
},
}

cmd.Flags().String(flagSource, "", "A valid URI reference to the contract's source code, optional")
cmd.Flags().String(flagBuilder, "", "A valid docker tag for the build system, optional")
cmd.Flags().String(flagInstantiateByEverybody, "", "Everybody can instantiate a contract from the code, optional")
cmd.Flags().String(flagInstantiateByAddress, "", "Only this address can instantiate a contract instance from the code, optional")
flags.AddTxFlagsToCmd(cmd)
Expand Down Expand Up @@ -122,21 +118,9 @@ func parseStoreCodeArgs(file string, sender sdk.AccAddress, flags *flag.FlagSet)
}
}

// build and sign the transaction, then broadcast to Tendermint
source, err := flags.GetString(flagSource)
if err != nil {
return types.MsgStoreCode{}, fmt.Errorf("source: %s", err)
}
builder, err := flags.GetString(flagBuilder)
if err != nil {
return types.MsgStoreCode{}, fmt.Errorf("builder: %s", err)
}

msg := types.MsgStoreCode{
Sender: sender.String(),
WASMByteCode: wasm,
Source: source,
Builder: builder,
InstantiatePermission: perm,
}
return msg, nil
Expand Down
6 changes: 0 additions & 6 deletions x/wasm/client/rest/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ type StoreCodeProposalJsonReq struct {
RunAs string `json:"run_as" yaml:"run_as"`
// WASMByteCode can be raw or gzip compressed
WASMByteCode []byte `json:"wasm_byte_code" yaml:"wasm_byte_code"`
// Source is a valid absolute HTTPS URI to the contract's source code, optional
Source string `json:"source" yaml:"source"`
// Builder is a valid docker image name with tag, optional
Builder string `json:"builder" yaml:"builder"`
// InstantiatePermission to apply on contract creation, optional
InstantiatePermission *types.AccessConfig `json:"instantiate_permission" yaml:"instantiate_permission"`
}
Expand All @@ -38,8 +34,6 @@ func (s StoreCodeProposalJsonReq) Content() govtypes.Content {
Description: s.Description,
RunAs: s.RunAs,
WASMByteCode: s.WASMByteCode,
Source: s.Source,
Builder: s.Builder,
InstantiatePermission: s.InstantiatePermission,
}
}
Expand Down
2 changes: 0 additions & 2 deletions x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func TestInitGenesis(t *testing.T) {
msg := MsgStoreCode{
Sender: creator.String(),
WASMByteCode: testContract,
Source: "https://github.com/CosmWasm/wasmd/blob/master/x/wasm/testdata/hackatom.wasm",
Builder: "confio/cosmwasm-opt:0.7.0",
}
err := msg.ValidateBasic()
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/keeper/contract_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var _ types.ContractOpsKeeper = PermissionedKeeper{}

// decoratedKeeper contains a subset of the wasm keeper that are already or can be guarded by an authorization policy in the future
type decoratedKeeper interface {
create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, source string, builder string, instantiateAccess *types.AccessConfig, authZ AuthorizationPolicy) (codeID uint64, err error)
create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *types.AccessConfig, authZ AuthorizationPolicy) (codeID uint64, err error)
instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins, authZ AuthorizationPolicy) (sdk.AccAddress, []byte, error)
migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newCodeID uint64, msg []byte, authZ AuthorizationPolicy) ([]byte, error)
setContractAdmin(ctx sdk.Context, contractAddress, caller, newAdmin sdk.AccAddress, authZ AuthorizationPolicy) error
Expand All @@ -36,8 +36,8 @@ func NewDefaultPermissionKeeper(nested decoratedKeeper) *PermissionedKeeper {
return NewPermissionedKeeper(nested, DefaultAuthorizationPolicy{})
}

func (p PermissionedKeeper) Create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, source string, builder string, instantiateAccess *types.AccessConfig) (codeID uint64, err error) {
return p.nested.create(ctx, creator, wasmCode, source, builder, instantiateAccess, p.authZPolicy)
func (p PermissionedKeeper) Create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *types.AccessConfig) (codeID uint64, err error) {
return p.nested.create(ctx, creator, wasmCode, instantiateAccess, p.authZPolicy)
}

func (p PermissionedKeeper) Instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins) (sdk.AccAddress, []byte, error) {
Expand Down
6 changes: 1 addition & 5 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestGenesisExportImport(t *testing.T) {

creatorAddr, err := sdk.AccAddressFromBech32(codeInfo.Creator)
require.NoError(t, err)
codeID, err := contractKeeper.Create(srcCtx, creatorAddr, wasmCode, codeInfo.Source, codeInfo.Builder, &codeInfo.InstantiateConfig)
codeID, err := contractKeeper.Create(srcCtx, creatorAddr, wasmCode, &codeInfo.InstantiateConfig)
require.NoError(t, err)
if pinned {
contractKeeper.PinCode(srcCtx, codeID)
Expand Down Expand Up @@ -462,8 +462,6 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
"code_info": {
"code_hash": %q,
"creator": "cosmos1qtu5n0cnhfkjj6l2rq97hmky9fd89gwca9yarx",
"source": "https://example.com",
"builder": "foo/bar:tag",
"instantiate_config": {
"permission": "OnlyAddress",
"address": "cosmos1qtu5n0cnhfkjj6l2rq97hmky9fd89gwca9yarx"
Expand Down Expand Up @@ -523,8 +521,6 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
expCodeInfo := types.CodeInfo{
CodeHash: wasmCodeHash[:],
Creator: codeCreatorAddr,
Source: "https://example.com",
Builder: "foo/bar:tag",
InstantiateConfig: wasmTypes.AccessConfig{
Permission: types.AccessTypeOnlyAddress,
Address: codeCreatorAddr,
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (k Keeper) setParams(ctx sdk.Context, ps types.Params) {
k.paramSpace.SetParamSet(ctx, &ps)
}

func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, source string, builder string, instantiateAccess *types.AccessConfig, authZ AuthorizationPolicy) (codeID uint64, err error) {
func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte, instantiateAccess *types.AccessConfig, authZ AuthorizationPolicy) (codeID uint64, err error) {
if !authZ.CanCreateCode(k.getUploadAccessConfig(ctx), creator) {
return 0, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not create code")
}
Expand All @@ -172,7 +172,7 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte,
defaultAccessConfig := k.getInstantiateAccessConfig(ctx).With(creator)
instantiateAccess = &defaultAccessConfig
}
codeInfo := types.NewCodeInfo(codeHash, creator, source, builder, *instantiateAccess)
codeInfo := types.NewCodeInfo(codeHash, creator, *instantiateAccess)
k.storeCodeInfo(ctx, codeID, codeInfo)
return codeID, nil
}
Expand Down
Loading

0 comments on commit 267643f

Please sign in to comment.