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

Add Ability to Change max-wasm-size via Governance #137

Merged
merged 9 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"os"
"path/filepath"
"strconv"

"github.com/spf13/cast"

Expand Down Expand Up @@ -589,6 +590,12 @@ func NewApp(
panic(err)
}

if maxSize := os.Getenv("MAX_WASM_SIZE"); maxSize != "" {
jim380 marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/CosmWasm/wasmd#compile-time-parameters
val, _ := strconv.ParseInt(maxSize, 10, 32)
wasmtypes.MaxWasmSize = int(val) // default 819200 (800 * 1024)
}

/* =================================================== */
/* TRANSFER STACK */
/* =================================================== */
Expand Down
4 changes: 1 addition & 3 deletions proto/sedachain/randomness/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ import "gogoproto/gogo.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/randomness/types";

message GenesisState {
string seed = 1;
}
message GenesisState { string seed = 1; }
11 changes: 7 additions & 4 deletions proto/sedachain/randomness/v1/randomness.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import "cosmos_proto/cosmos.proto";
option go_package = "github.com/sedaprotocol/seda-chain/x/randomness/types";

message ValidatorVRF {
// operator_address defines the address of the validator's operator; bech encoded in JSON.
string operator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// vrf_pubkey is the public key of the validator's VRF key pair
google.protobuf.Any vrf_pubkey = 2 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
// operator_address defines the address of the validator's operator; bech
// encoded in JSON.
string operator_address = 1
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
// vrf_pubkey is the public key of the validator's VRF key pair
google.protobuf.Any vrf_pubkey = 2
[ (cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey" ];
}
13 changes: 5 additions & 8 deletions proto/sedachain/randomness/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ import "cosmos/msg/v1/msg.proto";

option go_package = "github.com/sedaprotocol/seda-chain/x/randomness/types";

service Msg {
rpc NewSeed(MsgNewSeed)
returns (MsgNewSeedResponse);
}
service Msg { rpc NewSeed(MsgNewSeed) returns (MsgNewSeedResponse); }

message MsgNewSeed {
option (cosmos.msg.v1.signer) = "prover";

string prover = 1; // address of VRF key used to produce proof
string pi = 2; // VRF proof
string beta = 3; // VRF hash
string pi = 2; // VRF proof
string beta = 3; // VRF hash
}

message MsgNewSeedResponse {}
message MsgNewSeedResponse {}
37 changes: 22 additions & 15 deletions proto/sedachain/staking/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,41 @@ service Msg {
// option (cosmos.msg.v1.service) = true;

// CreateValidatorWithVRF defines a method for creating a new validator.
rpc CreateValidatorWithVRF(MsgCreateValidatorWithVRF) returns (MsgCreateValidatorWithVRFResponse);
rpc CreateValidatorWithVRF(MsgCreateValidatorWithVRF)
returns (MsgCreateValidatorWithVRFResponse);
}

// MsgCreateValidator defines a SDK message for creating a new validator.
message MsgCreateValidatorWithVRF {
option (cosmos.msg.v1.signer) = "validator_address";
// option (amino.name) = "cosmos-sdk/MsgCreateValidator";

option (gogoproto.equal) = false;
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

cosmos.staking.v1beta1.Description description = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
cosmos.staking.v1beta1.CommissionRates commission = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
string min_self_delegation = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
cosmos.staking.v1beta1.Description description = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
cosmos.staking.v1beta1.CommissionRates commission = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
string min_self_delegation = 3 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
// Deprecated: Use of Delegator Address in MsgCreateValidator is deprecated.
// The validator address bytes and delegator address bytes refer to the same account while creating validator (defer
// only in bech32 notation).
string delegator_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString", deprecated = true];
string validator_address = 5 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
google.protobuf.Any vrf_pubkey = 8 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];

// The validator address bytes and delegator address bytes refer to the same
// account while creating validator (defer only in bech32 notation).
string delegator_address = 4
[ (cosmos_proto.scalar) = "cosmos.AddressString", deprecated = true ];
string validator_address = 5
[ (cosmos_proto.scalar) = "cosmos.ValidatorAddressString" ];
google.protobuf.Any pubkey = 6
[ (cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey" ];
cosmos.base.v1beta1.Coin value = 7
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
google.protobuf.Any vrf_pubkey = 8
[ (cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey" ];
}

// MsgCreateValidatorResponse defines the Msg/CreateValidator response type.
Expand Down
14 changes: 14 additions & 0 deletions proto/sedachain/wasm_storage/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ service Msg {
rpc InstantiateAndRegisterProxyContract(
MsgInstantiateAndRegisterProxyContract)
returns (MsgInstantiateAndRegisterProxyContractResponse);
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

message MsgStoreDataRequestWasm {
Expand Down Expand Up @@ -61,3 +62,16 @@ message MsgInstantiateAndRegisterProxyContractResponse {
string contract_address = 1
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
}

message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

Params params = 2 [ (gogoproto.nullable) = false ];
}

// no data needs to be returned
message MsgUpdateParamsResponse {}
6 changes: 5 additions & 1 deletion proto/sedachain/wasm_storage/v1/wasm_storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ enum WasmType {
[ (gogoproto.enumvalue_customname) = "WasmTypeRelayer" ];
}

message Params { uint64 max_wasm_size = 1; }
message Params {
option (gogoproto.equal) = true;

uint64 max_wasm_size = 1;
}
5 changes: 2 additions & 3 deletions x/randomness/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions x/randomness/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions x/randomness/types/randomness.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions x/randomness/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions x/staking/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion x/wasm-storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sedaprotocol/seda-chain/x/wasm-storage/types"
)

Expand All @@ -30,6 +29,11 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, authority st
}
}

// GetAuthority returns the module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}

// SetDataRequestWasm stores Data Request Wasm using its hash as the key.
func (k Keeper) SetDataRequestWasm(ctx sdk.Context, wasm *types.Wasm) {
store := ctx.KVStore(k.storeKey)
Expand Down Expand Up @@ -145,3 +149,25 @@ func (k Keeper) GetAllWasms(ctx sdk.Context) []types.Wasm {
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
}

// GetParams returns all the parameters for the module.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
store := ctx.KVStore(k.storeKey)
bz := store.Get([]byte(types.KeyParams))

var params types.Params
k.cdc.MustUnmarshal(bz, &params)
return params
}

// SetParams sets the parameters in the store.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&params)
if err != nil {
return err
}
store.Set([]byte(types.KeyParams), bz)

return nil
}
23 changes: 23 additions & 0 deletions x/wasm-storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,26 @@ func unzipWasm(wasm []byte) ([]byte, error) {
}
return unzipped, nil
}

func (m msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
// validate authority
if _, err := sdk.AccAddressFromBech32(req.Authority); err != nil {
return nil, fmt.Errorf("invalid authority address: %s", err)
}

if m.GetAuthority() != req.Authority {
return nil, fmt.Errorf("invalid authority; expected %s, got %s", m.GetAuthority(), req.Authority)
}

Copy link
Member

Choose a reason for hiding this comment

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

v0.50 recommends that we validate message here

// validate params
if err := req.Params.ValidateBasic(); err != nil {
return nil, err
}

ctx := sdk.UnwrapSDKContext(goCtx)
if err := m.SetParams(ctx, req.Params); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

validate params before setting?

return nil, err
}

return &types.MsgUpdateParamsResponse{}, nil
}
Loading
Loading