Skip to content

Commit

Permalink
add max_callback_gas in param
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 26, 2023
1 parent 629eed9 commit aa55bcd
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func New(
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)
// Since the callbacks middleware itself is an ics4wrapper, it needs to be passed to the ica controller keeper
app.ICAControllerKeeper.WithICS4Wrapper(icaControllerStack.(porttypes.Middleware))
const maxCallbackGas = uint64(1000000)
const maxCallbackGas = uint64(300000)
icaControllerStack = ibccallbacks.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper, app.CronosKeeper, maxCallbackGas)

// Create static IBC router, add transfer route, then set and seal it
Expand Down
9 changes: 9 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ paths:
title: the admin address who can update token mapping
enable_auto_deployment:
type: boolean
max_callback_gas:
type: string
format: uint64
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -43648,6 +43651,9 @@ definitions:
title: the admin address who can update token mapping
enable_auto_deployment:
type: boolean
max_callback_gas:
type: string
format: uint64
description: Params defines the parameters for the cronos module.
cronos.QueryParamsResponse:
type: object
Expand All @@ -43666,6 +43672,9 @@ definitions:
title: the admin address who can update token mapping
enable_auto_deployment:
type: boolean
max_callback_gas:
type: string
format: uint64
description: QueryParamsResponse is the response type for the Query/Params RPC method.
cronos.QueryPermissionsResponse:
type: object
Expand Down
1 change: 1 addition & 0 deletions proto/cronos/cronos.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message Params {
// the admin address who can update token mapping
string cronos_admin = 3;
bool enable_auto_deployment = 4;
uint64 max_callback_gas = 5;
}

// TokenMappingChangeProposal defines a proposal to change one token mapping.
Expand Down
14 changes: 13 additions & 1 deletion x/cronos/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
ibcTimeoutKey = "ibc_timeout"
cronosAdminKey = "cronos_admin"
enableAutoDeploymentKey = "enable_auto_deployment"
maxCallbackGasKey = "max_callback_gas"
)

func GenIbcCroDenom(r *rand.Rand) string {
Expand All @@ -39,6 +40,11 @@ func GenEnableAutoDeployment(r *rand.Rand) bool {
return r.Intn(2) > 0
}

func GenMaxCallbackGas(r *rand.Rand) uint64 {
maxCallbackGas := r.Uint64()
return maxCallbackGas
}

// RandomizedGenState generates a random GenesisState for the cronos module
func RandomizedGenState(simState *module.SimulationState) {
// cronos params
Expand All @@ -47,6 +53,7 @@ func RandomizedGenState(simState *module.SimulationState) {
ibcTimeout uint64
cronosAdmin string
enableAutoDeployment bool
maxCallbackGas uint64
)

simState.AppParams.GetOrGenerate(
Expand All @@ -69,7 +76,12 @@ func RandomizedGenState(simState *module.SimulationState) {
func(r *rand.Rand) { enableAutoDeployment = GenEnableAutoDeployment(r) },
)

params := types.NewParams(ibcCroDenom, ibcTimeout, cronosAdmin, enableAutoDeployment)
simState.AppParams.GetOrGenerate(
simState.Cdc, maxCallbackGasKey, &ibcTimeout, simState.Rand,
func(r *rand.Rand) { maxCallbackGas = GenIbcTimeout(r) },
)

params := types.NewParams(ibcCroDenom, ibcTimeout, cronosAdmin, enableAutoDeployment, maxCallbackGas)
cronosGenesis := &types.GenesisState{
Params: params,
ExternalContracts: nil,
Expand Down
93 changes: 65 additions & 28 deletions x/cronos/types/cronos.pb.go

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

15 changes: 12 additions & 3 deletions x/cronos/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ var (
KeyCronosAdmin = []byte("CronosAdmin")
// KeyEnableAutoDeployment is store's key for the EnableAutoDeployment
KeyEnableAutoDeployment = []byte("EnableAutoDeployment")
// KeyMaxCallbackGas is store's key for the MaxCallbackGas
KeyMaxCallbackGas = []byte("MaxCallbackGas")
)

const (
IbcCroDenomDefaultValue = "ibc/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865"
IbcTimeoutDefaultValue = uint64(86400000000000) // 1 day
IbcCroDenomDefaultValue = "ibc/6B5A664BF0AF4F71B2F0BAA33141E2F1321242FBD5D19762F541EC971ACB0865"
IbcTimeoutDefaultValue = uint64(86400000000000) // 1 day
MaxCallbackGasDefaultValue = uint64(300000)
)

// ParamKeyTable returns the parameter key table.
Expand All @@ -31,12 +34,13 @@ func ParamKeyTable() paramtypes.KeyTable {
}

// NewParams creates a new parameter configuration for the cronos module
func NewParams(ibcCroDenom string, ibcTimeout uint64, cronosAdmin string, enableAutoDeployment bool) Params {
func NewParams(ibcCroDenom string, ibcTimeout uint64, cronosAdmin string, enableAutoDeployment bool, maxCallbackGas uint64) Params {
return Params{
IbcCroDenom: ibcCroDenom,
IbcTimeout: ibcTimeout,
CronosAdmin: cronosAdmin,
EnableAutoDeployment: enableAutoDeployment,
MaxCallbackGas: maxCallbackGas,
}
}

Expand All @@ -47,6 +51,7 @@ func DefaultParams() Params {
IbcTimeout: IbcTimeoutDefaultValue,
CronosAdmin: "",
EnableAutoDeployment: false,
MaxCallbackGas: MaxCallbackGasDefaultValue,
}
}

Expand All @@ -63,6 +68,9 @@ func (p Params) Validate() error {
return err
}
}
if err := validateIsUint64(p.MaxCallbackGas); err != nil {
return err
}
return nil
}

Expand All @@ -79,6 +87,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(KeyIbcTimeout, &p.IbcTimeout, validateIsUint64),
paramtypes.NewParamSetPair(KeyCronosAdmin, &p.CronosAdmin, validateIsAddress),
paramtypes.NewParamSetPair(KeyEnableAutoDeployment, &p.EnableAutoDeployment, validateIsBool),
paramtypes.NewParamSetPair(KeyMaxCallbackGas, &p.MaxCallbackGas, validateIsUint64),
}
}

Expand Down

0 comments on commit aa55bcd

Please sign in to comment.