From fc853ca3448fc006a979b7443ca81f786084d003 Mon Sep 17 00:00:00 2001 From: Rahul Ghangas Date: Fri, 11 Nov 2022 22:00:10 +0530 Subject: [PATCH] feat: add param for gas per message byte (#965) Adds `gasPerMsgByte` as params to the payment module. Defines relevant stores and queries Relevant changes in `proto/payment/*` `x/payment/keeper*` `x/payment/types/*` - [x] finished 1st part of #949 Note: To be merged after #893 and constants for default values can be defined in a cumulative PR --- proto/blob/params.proto | 1 + x/blob/keeper/keeper.go | 8 ++--- x/blob/keeper/params.go | 7 +++++ x/blob/keeper/params_test.go | 1 + x/blob/types/genesis_test.go | 5 +-- x/blob/types/params.go | 27 ++++++++++++++-- x/blob/types/params.pb.go | 60 +++++++++++++++++++++++++++++------- 7 files changed, 90 insertions(+), 19 deletions(-) diff --git a/proto/blob/params.proto b/proto/blob/params.proto index 64ce258108..b5300a0801 100644 --- a/proto/blob/params.proto +++ b/proto/blob/params.proto @@ -11,4 +11,5 @@ message Params { uint32 min_square_size = 1 [(gogoproto.moretags) = "yaml:\"min_square_size\""]; uint32 max_square_size = 2 [(gogoproto.moretags) = "yaml:\"max_square_size\""]; + uint32 gas_per_blob_byte = 3 [(gogoproto.moretags) = "yaml:\"gas_per_blob_byte\""]; } diff --git a/x/blob/keeper/keeper.go b/x/blob/keeper/keeper.go index 17ea87ab9b..6cc55c5ccb 100644 --- a/x/blob/keeper/keeper.go +++ b/x/blob/keeper/keeper.go @@ -18,10 +18,10 @@ import ( const ( payForBlobGasDescriptor = "pay for data" - // GasPerMsgByte is the amount of gas to charge per byte of message data. - // TODO: extract GasPerMsgByte as a parameter to this module. - GasPerMsgByte = 8 - GasPerMsgShare = appconsts.ShareSize * GasPerMsgByte + // GasPerBlobByte is the amount of gas to charge per byte of message data. + // TODO: extract GasPerBlobByte as a parameter to this module. + GasPerBlobByte = 8 + GasPerMsgShare = appconsts.ShareSize * GasPerBlobByte ) // Keeper handles all the state changes for the blob module. diff --git a/x/blob/keeper/params.go b/x/blob/keeper/params.go index 2fa1c3e065..62ef08be64 100644 --- a/x/blob/keeper/params.go +++ b/x/blob/keeper/params.go @@ -10,6 +10,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { return types.NewParams( k.MinSquareSize(ctx), k.MaxSquareSize(ctx), + k.GasPerBlobByte(ctx), ) } @@ -29,3 +30,9 @@ func (k Keeper) MaxSquareSize(ctx sdk.Context) (res uint32) { k.paramStore.Get(ctx, types.KeyMaxSquareSize, &res) return } + +// GasPerBlobByte returns the GasPerBlobByte param +func (k Keeper) GasPerBlobByte(ctx sdk.Context) (res uint32) { + k.paramStore.Get(ctx, types.KeyGasPerBlobByte, &res) + return +} diff --git a/x/blob/keeper/params_test.go b/x/blob/keeper/params_test.go index e8d29f4857..bdf557863d 100644 --- a/x/blob/keeper/params_test.go +++ b/x/blob/keeper/params_test.go @@ -17,4 +17,5 @@ func TestGetParams(t *testing.T) { require.EqualValues(t, params, k.GetParams(ctx)) require.EqualValues(t, params.MinSquareSize, k.MinSquareSize(ctx)) require.EqualValues(t, params.MaxSquareSize, k.MaxSquareSize(ctx)) + require.EqualValues(t, params.GasPerBlobByte, k.GasPerBlobByte(ctx)) } diff --git a/x/blob/types/genesis_test.go b/x/blob/types/genesis_test.go index a6e123ecbd..e04f062198 100644 --- a/x/blob/types/genesis_test.go +++ b/x/blob/types/genesis_test.go @@ -22,8 +22,9 @@ func TestGenesisState_Validate(t *testing.T) { desc: "valid genesis state", genState: &types.GenesisState{ Params: types.Params{ - MinSquareSize: 512, - MaxSquareSize: 1024, + MinSquareSize: 512, + MaxSquareSize: 1024, + GasPerBlobByte: 20, }, }, valid: true, diff --git a/x/blob/types/params.go b/x/blob/types/params.go index 600f33c859..325b57a941 100644 --- a/x/blob/types/params.go +++ b/x/blob/types/params.go @@ -19,6 +19,11 @@ var ( DefaultMaxSquareSize uint32 = 128 ) +var ( + KeyGasPerBlobByte = []byte("GasPerBlobByte") + DefaultGasPerBlobByte uint32 = 8 +) + // ParamKeyTable returns the param key table for the blob module func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) @@ -28,10 +33,12 @@ func ParamKeyTable() paramtypes.KeyTable { func NewParams( minSquareSize uint32, maxSquareSize uint32, + GasPerBlobByte uint32, ) Params { return Params{ - MinSquareSize: minSquareSize, - MaxSquareSize: maxSquareSize, + MinSquareSize: minSquareSize, + MaxSquareSize: maxSquareSize, + GasPerBlobByte: GasPerBlobByte, } } @@ -40,6 +47,7 @@ func DefaultParams() Params { return NewParams( DefaultMinSquareSize, DefaultMaxSquareSize, + DefaultGasPerBlobByte, ) } @@ -48,6 +56,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyMinSquareSize, &p.MinSquareSize, validateMinSquareSize), paramtypes.NewParamSetPair(KeyMaxSquareSize, &p.MaxSquareSize, validateMaxSquareSize), + paramtypes.NewParamSetPair(KeyGasPerBlobByte, &p.GasPerBlobByte, validateGasPerBlobByte), } } @@ -108,3 +117,17 @@ func validateMinMaxSquareSizeOrder(minSquareSize, maxSquareSize uint32) error { } return nil } + +// validateGasPerBlobByte validates the GasPerBlobByte param +func validateGasPerBlobByte(v interface{}) error { + GasPerBlobByte, ok := v.(uint32) + if !ok { + return fmt.Errorf("invalid parameter type: %T", v) + } + + if GasPerBlobByte == 0 { + return fmt.Errorf("gas per blob byte cannot be 0") + } + + return nil +} diff --git a/x/blob/types/params.pb.go b/x/blob/types/params.pb.go index 3cb9954c93..358501540b 100644 --- a/x/blob/types/params.pb.go +++ b/x/blob/types/params.pb.go @@ -25,8 +25,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { - MinSquareSize uint32 `protobuf:"varint,1,opt,name=min_square_size,json=minSquareSize,proto3" json:"min_square_size,omitempty" yaml:"min_square_size"` - MaxSquareSize uint32 `protobuf:"varint,2,opt,name=max_square_size,json=maxSquareSize,proto3" json:"max_square_size,omitempty" yaml:"max_square_size"` + MinSquareSize uint32 `protobuf:"varint,1,opt,name=min_square_size,json=minSquareSize,proto3" json:"min_square_size,omitempty" yaml:"min_square_size"` + MaxSquareSize uint32 `protobuf:"varint,2,opt,name=max_square_size,json=maxSquareSize,proto3" json:"max_square_size,omitempty" yaml:"max_square_size"` + GasPerBlobByte uint32 `protobuf:"varint,3,opt,name=gas_per_blob_byte,json=gasPerBlobByte,proto3" json:"gas_per_blob_byte,omitempty" yaml:"gas_per_blob_byte"` } func (m *Params) Reset() { *m = Params{} } @@ -75,6 +76,13 @@ func (m *Params) GetMaxSquareSize() uint32 { return 0 } +func (m *Params) GetGasPerBlobByte() uint32 { + if m != nil { + return m.GasPerBlobByte + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "blob.Params") } @@ -82,21 +90,24 @@ func init() { func init() { proto.RegisterFile("blob/params.proto", fileDescriptor_6eb7255e25c6327c) } var fileDescriptor_6eb7255e25c6327c = []byte{ - // 217 bytes of a gzipped FileDescriptorProto + // 266 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0xca, 0xc9, 0x4f, 0xd2, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x01, - 0x09, 0x49, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x05, 0xf4, 0x41, 0x2c, 0x88, 0x9c, 0xd2, 0x34, + 0x09, 0x49, 0x89, 0xa4, 0xe7, 0xa7, 0xe7, 0x83, 0x05, 0xf4, 0x41, 0x2c, 0x88, 0x9c, 0xd2, 0x7d, 0x46, 0x2e, 0xb6, 0x00, 0xb0, 0x62, 0x21, 0x27, 0x2e, 0xfe, 0xdc, 0xcc, 0xbc, 0xf8, 0xe2, 0xc2, 0xd2, 0xc4, 0xa2, 0xd4, 0xf8, 0xe2, 0xcc, 0xaa, 0x54, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x5e, 0x27, 0xa9, 0x4f, 0xf7, 0xe4, 0xc5, 0x2a, 0x13, 0x73, 0x73, 0xac, 0x94, 0xd0, 0x14, 0x28, 0x05, 0xf1, 0xe6, 0x66, 0xe6, 0x05, 0x83, 0x05, 0x82, 0x33, 0xab, 0x52, 0xc1, 0x66, 0x24, 0x56, 0xa0, 0x98, - 0xc1, 0x84, 0x61, 0x06, 0xaa, 0x02, 0x90, 0x19, 0x89, 0x15, 0x08, 0x33, 0xac, 0x58, 0x66, 0x2c, - 0x90, 0x67, 0x70, 0xf2, 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, - 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0x83, - 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe4, 0xd4, 0x9c, 0xd4, 0xe2, - 0x92, 0xcc, 0xc4, 0xfc, 0xa2, 0x74, 0x38, 0x5b, 0x37, 0xb1, 0xa0, 0x40, 0xbf, 0x42, 0x1f, 0x1c, - 0x0e, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0xbf, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, - 0xff, 0x5c, 0x4f, 0x18, 0x6e, 0x1c, 0x01, 0x00, 0x00, + 0xc1, 0x84, 0x61, 0x06, 0xaa, 0x02, 0x90, 0x19, 0x89, 0x15, 0x48, 0x66, 0xb8, 0x73, 0x09, 0xa6, + 0x27, 0x16, 0xc7, 0x17, 0xa4, 0x16, 0xc5, 0x83, 0x1c, 0x1e, 0x9f, 0x54, 0x59, 0x92, 0x2a, 0xc1, + 0x0c, 0x36, 0x45, 0xe6, 0xd3, 0x3d, 0x79, 0x09, 0x88, 0x29, 0x18, 0x4a, 0x94, 0x82, 0xf8, 0xd2, + 0x13, 0x8b, 0x03, 0x52, 0x8b, 0x9c, 0x72, 0xf2, 0x93, 0x9c, 0x2a, 0x4b, 0x52, 0xad, 0x58, 0x66, + 0x2c, 0x90, 0x67, 0x70, 0xf2, 0x3a, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, + 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, + 0x83, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe4, 0xd4, 0x9c, 0xd4, + 0xe2, 0x92, 0xcc, 0xc4, 0xfc, 0xa2, 0x74, 0x38, 0x5b, 0x37, 0xb1, 0xa0, 0x40, 0xbf, 0x42, 0x1f, + 0x1c, 0xa0, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x40, 0x33, 0x06, 0x04, 0x00, 0x00, + 0xff, 0xff, 0xee, 0xed, 0xe4, 0x71, 0x65, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -119,6 +130,11 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.GasPerBlobByte != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.GasPerBlobByte)) + i-- + dAtA[i] = 0x18 + } if m.MaxSquareSize != 0 { i = encodeVarintParams(dAtA, i, uint64(m.MaxSquareSize)) i-- @@ -155,6 +171,9 @@ func (m *Params) Size() (n int) { if m.MaxSquareSize != 0 { n += 1 + sovParams(uint64(m.MaxSquareSize)) } + if m.GasPerBlobByte != 0 { + n += 1 + sovParams(uint64(m.GasPerBlobByte)) + } return n } @@ -231,6 +250,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { break } } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasPerBlobByte", wireType) + } + m.GasPerBlobByte = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasPerBlobByte |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])