From aa55bcd5a55476bd5fea82081ac26d04c1d74a9f Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 26 Sep 2023 15:02:15 +0800 Subject: [PATCH] add max_callback_gas in param --- app/app.go | 2 +- client/docs/swagger-ui/swagger.yaml | 9 +++ proto/cronos/cronos.proto | 1 + x/cronos/simulation/genesis.go | 14 ++++- x/cronos/types/cronos.pb.go | 93 ++++++++++++++++++++--------- x/cronos/types/params.go | 15 ++++- 6 files changed, 101 insertions(+), 33 deletions(-) diff --git a/app/app.go b/app/app.go index 5d11554ce0..5a90a379ee 100644 --- a/app/app.go +++ b/app/app.go @@ -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 diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index ead7dc06aa..d1a7de27d8 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -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. @@ -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 @@ -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 diff --git a/proto/cronos/cronos.proto b/proto/cronos/cronos.proto index ccfbf53d1e..06172ad52b 100644 --- a/proto/cronos/cronos.proto +++ b/proto/cronos/cronos.proto @@ -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. diff --git a/x/cronos/simulation/genesis.go b/x/cronos/simulation/genesis.go index 413f8f63a1..a63467f277 100644 --- a/x/cronos/simulation/genesis.go +++ b/x/cronos/simulation/genesis.go @@ -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 { @@ -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 @@ -47,6 +53,7 @@ func RandomizedGenState(simState *module.SimulationState) { ibcTimeout uint64 cronosAdmin string enableAutoDeployment bool + maxCallbackGas uint64 ) simState.AppParams.GetOrGenerate( @@ -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, diff --git a/x/cronos/types/cronos.pb.go b/x/cronos/types/cronos.pb.go index fbafdecb6c..12324030f2 100644 --- a/x/cronos/types/cronos.pb.go +++ b/x/cronos/types/cronos.pb.go @@ -30,6 +30,7 @@ type Params struct { // the admin address who can update token mapping CronosAdmin string `protobuf:"bytes,3,opt,name=cronos_admin,json=cronosAdmin,proto3" json:"cronos_admin,omitempty"` EnableAutoDeployment bool `protobuf:"varint,4,opt,name=enable_auto_deployment,json=enableAutoDeployment,proto3" json:"enable_auto_deployment,omitempty"` + MaxCallbackGas uint64 `protobuf:"varint,5,opt,name=max_callback_gas,json=maxCallbackGas,proto3" json:"max_callback_gas,omitempty"` } func (m *Params) Reset() { *m = Params{} } @@ -92,6 +93,13 @@ func (m *Params) GetEnableAutoDeployment() bool { return false } +func (m *Params) GetMaxCallbackGas() uint64 { + if m != nil { + return m.MaxCallbackGas + } + return 0 +} + // TokenMappingChangeProposal defines a proposal to change one token mapping. type TokenMappingChangeProposal struct { Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` @@ -197,34 +205,36 @@ func init() { func init() { proto.RegisterFile("cronos/cronos.proto", fileDescriptor_8bc54992a93db2d2) } var fileDescriptor_8bc54992a93db2d2 = []byte{ - // 422 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xbd, 0x6e, 0xdb, 0x30, - 0x14, 0x85, 0xc5, 0xd4, 0x51, 0x6d, 0x3a, 0x59, 0x58, 0x23, 0x10, 0x3c, 0xc8, 0xaa, 0x26, 0x0f, - 0x4d, 0x04, 0xb4, 0x99, 0x3c, 0x35, 0x3f, 0xe8, 0xd6, 0x22, 0x20, 0x32, 0x75, 0x11, 0x28, 0x8a, - 0x90, 0x89, 0x8a, 0xbc, 0x04, 0x45, 0x15, 0xd5, 0x1b, 0x74, 0xec, 0xd8, 0x31, 0xcf, 0xd2, 0xa9, - 0xa3, 0xc7, 0x4e, 0x45, 0x61, 0xbf, 0x41, 0x9f, 0xa0, 0x90, 0x98, 0xa4, 0xc9, 0x90, 0x49, 0xf7, - 0x3b, 0x07, 0xc2, 0x39, 0x97, 0xb8, 0xf8, 0x05, 0xb7, 0xa0, 0xa1, 0xc9, 0xfc, 0xe7, 0xc4, 0x58, - 0x70, 0x40, 0x42, 0x4f, 0xf3, 0x59, 0x05, 0x15, 0x0c, 0x52, 0xd6, 0x4f, 0xde, 0x4d, 0x37, 0x08, - 0x87, 0x57, 0xcc, 0x32, 0xd5, 0x90, 0x77, 0xf8, 0x50, 0x16, 0x3c, 0xe7, 0x16, 0xf2, 0x52, 0x68, - 0x50, 0x11, 0x4a, 0xd0, 0x72, 0x72, 0x9e, 0xfe, 0xfd, 0xbd, 0x88, 0x3b, 0xa6, 0xea, 0x55, 0xfa, - 0xc8, 0x7e, 0x05, 0x4a, 0x3a, 0xa1, 0x8c, 0xeb, 0x52, 0x3a, 0x95, 0x05, 0xbf, 0xb0, 0x70, 0xd9, - 0xeb, 0x64, 0x81, 0x7b, 0xcc, 0x9d, 0x54, 0x02, 0x5a, 0x17, 0xed, 0x25, 0x68, 0x39, 0xa2, 0x58, - 0x16, 0xfc, 0xda, 0x2b, 0xe4, 0x25, 0x3e, 0xf0, 0x9d, 0x72, 0x56, 0x2a, 0xa9, 0xa3, 0x67, 0x7d, - 0x0e, 0x9d, 0x7a, 0xed, 0xac, 0x97, 0xc8, 0x29, 0x3e, 0x12, 0x9a, 0x15, 0xb5, 0xc8, 0x59, 0xeb, - 0xfa, 0x40, 0x53, 0x43, 0xa7, 0x84, 0x76, 0xd1, 0x28, 0x41, 0xcb, 0x31, 0x9d, 0x79, 0xf7, 0xac, - 0x75, 0x70, 0x79, 0xef, 0xad, 0x46, 0xdf, 0x6f, 0x16, 0x41, 0xfa, 0x03, 0xe1, 0xf9, 0x35, 0x7c, - 0x12, 0xfa, 0x3d, 0x33, 0x46, 0xea, 0xea, 0x62, 0xcd, 0x74, 0x25, 0xae, 0x2c, 0x18, 0x68, 0x58, - 0x4d, 0x66, 0x78, 0xdf, 0x49, 0x57, 0x0b, 0xbf, 0x1e, 0xf5, 0x40, 0x12, 0x3c, 0x2d, 0x45, 0xc3, - 0xad, 0x34, 0x4e, 0x82, 0x1e, 0x4a, 0x4f, 0xe8, 0x43, 0xa9, 0xff, 0xcf, 0x3f, 0x8b, 0xaf, 0xeb, - 0x81, 0xcc, 0xf1, 0x98, 0x83, 0x76, 0x96, 0x71, 0x5f, 0x6d, 0x42, 0xef, 0x99, 0x1c, 0xe1, 0xb0, - 0xe9, 0x54, 0x01, 0x75, 0xb4, 0x3f, 0x38, 0xb7, 0x44, 0x22, 0xfc, 0xbc, 0x14, 0x5c, 0x2a, 0x56, - 0x47, 0x61, 0x82, 0x96, 0x87, 0xf4, 0x0e, 0x57, 0xe3, 0xaf, 0x37, 0x8b, 0x60, 0x58, 0xe2, 0x2d, - 0x3e, 0x78, 0xb8, 0xc3, 0xff, 0x74, 0xf4, 0x54, 0xfa, 0xde, 0xe3, 0xf4, 0xf3, 0x0f, 0x3f, 0xb7, - 0x31, 0xda, 0x6c, 0x63, 0xf4, 0x67, 0x1b, 0xa3, 0x6f, 0xbb, 0x38, 0xd8, 0xec, 0xe2, 0xe0, 0xd7, - 0x2e, 0x0e, 0x3e, 0x9e, 0x56, 0xd2, 0xad, 0xdb, 0xe2, 0x84, 0x83, 0xca, 0xb8, 0xed, 0x8c, 0x83, - 0x63, 0xb0, 0xd5, 0x31, 0x5f, 0x33, 0xa9, 0x6f, 0x6f, 0x27, 0xfb, 0xfc, 0x3a, 0xfb, 0x72, 0x37, - 0xbb, 0xce, 0x88, 0xa6, 0x08, 0x87, 0x83, 0x79, 0xf3, 0x2f, 0x00, 0x00, 0xff, 0xff, 0x3d, 0x74, - 0x94, 0x69, 0x65, 0x02, 0x00, 0x00, + // 451 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xb1, 0x6f, 0xd3, 0x40, + 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10, 0xdd, 0xae, + 0x43, 0xf4, 0x7b, 0x1d, 0xa2, 0xaf, 0x9b, 0xd0, 0xbb, 0xdd, 0x84, 0xde, 0xcf, 0x4d, 0xe8, 0x7d, + 0x3a, 0x2d, 0x85, 0x5d, 0x2c, 0x8b, 0x13, 0x06, 0x32, 0x65, 0xa6, 0xd1, 0x16, 0x8e, 0xc1, 0x94, + 0xc7, 0x6c, 0x41, 0x85, 0xda, 0x5e, 0x59, 0xfa, 0xf9, 0x75, 0xba, 0xba, 0x7b, 0xdb, 0x46, 0xf3, + 0xba, 0xf0, 0xbb, 0xd3, 0x7a, 0xf3, 0x2f, 0x00, 0x00, 0xff, 0xff, 0xad, 0x72, 0x13, 0x5e, 0x8f, + 0x02, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -247,6 +257,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MaxCallbackGas != 0 { + i = encodeVarintCronos(dAtA, i, uint64(m.MaxCallbackGas)) + i-- + dAtA[i] = 0x28 + } if m.EnableAutoDeployment { i-- if m.EnableAutoDeployment { @@ -410,6 +425,9 @@ func (m *Params) Size() (n int) { if m.EnableAutoDeployment { n += 2 } + if m.MaxCallbackGas != 0 { + n += 1 + sovCronos(uint64(m.MaxCallbackGas)) + } return n } @@ -600,6 +618,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { } } m.EnableAutoDeployment = bool(v != 0) + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxCallbackGas", wireType) + } + m.MaxCallbackGas = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCronos + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxCallbackGas |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipCronos(dAtA[iNdEx:]) diff --git a/x/cronos/types/params.go b/x/cronos/types/params.go index c99ff0dbc1..fe88d43bc6 100644 --- a/x/cronos/types/params.go +++ b/x/cronos/types/params.go @@ -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. @@ -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, } } @@ -47,6 +51,7 @@ func DefaultParams() Params { IbcTimeout: IbcTimeoutDefaultValue, CronosAdmin: "", EnableAutoDeployment: false, + MaxCallbackGas: MaxCallbackGasDefaultValue, } } @@ -63,6 +68,9 @@ func (p Params) Validate() error { return err } } + if err := validateIsUint64(p.MaxCallbackGas); err != nil { + return err + } return nil } @@ -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), } }