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

fix: add gas calculator for msg create validator #94

Merged
merged 1 commit into from
Feb 1, 2023
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
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSw
github.com/ferranbt/fastssz v0.0.0-20210120143747-11b9eff30ea9/go.mod h1:DyEu2iuLBnb/T51BlsiO3yLYdJC6UbGMrIkqK1KmQxM=
github.com/ferranbt/fastssz v0.0.0-20210905181407-59cf6761a7d5 h1:6dVcS0LktRSyEEgldFY4N9J17WjUoiJStttH+RZj0Wo=
github.com/ferranbt/fastssz v0.0.0-20210905181407-59cf6761a7d5/go.mod h1:S8yiDeAXy8f88W4Ul+0dBMPx49S05byYbmZD6Uv94K4=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag=
Expand Down Expand Up @@ -473,9 +472,7 @@ github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx
github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0=
github.com/gogo/gateway v1.1.0/go.mod h1:S7rR8FRQyG3QFESeSv4l2WnsyzlCLG0CzBbUUo/mbic=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog=
github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/gddo v0.0.0-20200528160355-8d077c1d8f4c/go.mod h1:sam69Hju0uq+5uvLJUMDlsKlQ21Vrs1Kd/1YFPNYdOU=
Expand Down Expand Up @@ -626,7 +623,6 @@ github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmv
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down Expand Up @@ -1023,7 +1019,6 @@ github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A=
github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4=
github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -2087,7 +2082,6 @@ gopkg.in/src-d/go-cli.v0 v0.0.0-20181105080154-d492247bbc0d/go.mod h1:z+K8VcOYVY
gopkg.in/src-d/go-log.v1 v1.0.1/go.mod h1:GN34hKP0g305ysm2/hctJ0Y8nWP3zxXXJ8GFabTyABE=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
Expand Down
6 changes: 6 additions & 0 deletions proto/cosmos/gashub/v1alpha1/gashub.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ message Params {
uint64 msg_undelegate_gas = 25 [(gogoproto.customname) = "MsgUndelegateGas"];
uint64 msg_begin_redelegate_gas = 26 [(gogoproto.customname) = "MsgBeginRedelegateGas"];
uint64 msg_cancel_unbonding_delegation_gas = 27 [(gogoproto.customname) = "MsgCancelUnbondingDelegationGas"];
uint64 msg_create_validator_gas = 28 [(gogoproto.customname) = "MsgCreateValidatorGas"];
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
uint64 msg_claim_gas = 29 [(gogoproto.customname) = "MsgClaimGas"];
uint64 msg_transfer_out_gas = 30 [(gogoproto.customname) = "MsgTransferOutGas"];
uint64 msg_create_storage_provider_gas = 31 [(gogoproto.customname) = "MsgCreateStorageProviderGas"];
uint64 msg_edit_storage_provider_gas = 32 [(gogoproto.customname) = "MsgEditStorageProviderGas"];
uint64 msg_sp_deposit_gas = 33 [(gogoproto.customname) = "MsgSpDepositGas"];
}
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func NewSimApp(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

app.GashubKeeper = gashubkeeper.NewGashubKeeper(appCodec, keys[gashubtypes.StoreKey], app.GetSubspace(gashubtypes.ModuleName))
app.GashubKeeper = gashubkeeper.NewKeeper(appCodec, keys[gashubtypes.StoreKey], app.GetSubspace(gashubtypes.ModuleName))

// Register the upgrade keeper
upgradeHandler := map[string]upgradetypes.UpgradeHandler{
Expand Down
16 changes: 8 additions & 8 deletions x/auth/ante/msg_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
// in or empty.
type ValidateTxSizeDecorator struct {
ak AccountKeeper
fhk GashubKeeper
ghk GashubKeeper
}

func NewValidateTxSizeDecorator(ak AccountKeeper, fhk GashubKeeper) ValidateTxSizeDecorator {
func NewValidateTxSizeDecorator(ak AccountKeeper, ghk GashubKeeper) ValidateTxSizeDecorator {
return ValidateTxSizeDecorator{
ak: ak,
fhk: fhk,
ghk: ghk,
}
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func (vtsd ValidateTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
newCtx = ctx.WithTxSize(txSize)
}

params := vtsd.fhk.GetParams(ctx)
params := vtsd.ghk.GetParams(ctx)
if txSize > params.GetMaxTxSize() {
return ctx, errors.Wrapf(sdkerrors.ErrTxTooLarge, "tx length: %d, limit: %d", txSize, params.GetMaxTxSize())
}
Expand All @@ -89,13 +89,13 @@ func (vtsd ValidateTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
// the size of tx and msg type before calling next AnteHandler.
type ConsumeMsgGasDecorator struct {
ak AccountKeeper
fhk GashubKeeper
ghk GashubKeeper
}

func NewConsumeMsgGasDecorator(ak AccountKeeper, fhk GashubKeeper) ConsumeMsgGasDecorator {
func NewConsumeMsgGasDecorator(ak AccountKeeper, ghk GashubKeeper) ConsumeMsgGasDecorator {
return ConsumeMsgGasDecorator{
ak: ak,
fhk: fhk,
ghk: ghk,
}
}

Expand All @@ -105,7 +105,7 @@ func (cmfg ConsumeMsgGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
return ctx, errors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type")
}

params := cmfg.fhk.GetParams(ctx)
params := cmfg.ghk.GetParams(ctx)
gasByTxSize := cmfg.getTxSizeGas(params, ctx)
gasByMsgType, err := cmfg.getMsgGas(params, sigTx)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions x/gashub/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
//
// CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through
// a genesis port script to the new fee collector account
func (fhk Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {
fhk.SetParams(ctx, data.Params)
func (ghk Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {
ghk.SetParams(ctx, data.Params)
}

// ExportGenesis returns a GenesisState for a given context and keeper
func (fhk Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params := fhk.GetParams(ctx)
func (ghk Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
params := ghk.GetParams(ctx)

return types.NewGenesisState(params)
}
4 changes: 2 additions & 2 deletions x/gashub/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
var _ types.QueryServer = Keeper{}

// Params returns parameters of auth module
func (fhk Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
func (ghk Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
params := fhk.GetParams(ctx)
params := ghk.GetParams(ctx)

return &types.QueryParamsResponse{Params: params}, nil
}
8 changes: 4 additions & 4 deletions x/gashub/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type Keeper struct {
paramSubspace paramtypes.Subspace
}

// NewGashubKeeper returns a new gashub keeper
func NewGashubKeeper(
// NewKeeper returns a new gashub keeper
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramstore paramtypes.Subspace,
) Keeper {
// set KeyTable if it has not already been set
Expand All @@ -35,9 +35,9 @@ func NewGashubKeeper(
}

// Logger returns a module-specific logger.
func (fhk Keeper) Logger(ctx sdk.Context) log.Logger {
func (ghk Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}

// GetCodec return codec.Codec object used by the keeper
func (fhk Keeper) GetCodec() codec.BinaryCodec { return fhk.cdc }
func (ghk Keeper) GetCodec() codec.BinaryCodec { return ghk.cdc }
8 changes: 4 additions & 4 deletions x/gashub/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
)

// SetParams sets the auth module's parameters.
func (fhk Keeper) SetParams(ctx sdk.Context, params types.Params) {
fhk.paramSubspace.SetParamSet(ctx, &params)
func (ghk Keeper) SetParams(ctx sdk.Context, params types.Params) {
ghk.paramSubspace.SetParamSet(ctx, &params)
}

// GetParams gets the auth module's parameters.
func (fhk Keeper) GetParams(ctx sdk.Context) (params types.Params) {
fhk.paramSubspace.GetParamSet(ctx, &params)
func (ghk Keeper) GetParams(ctx sdk.Context) (params types.Params) {
ghk.paramSubspace.GetParamSet(ctx, &params)
return
}
2 changes: 1 addition & 1 deletion x/gashub/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func RandomizedGenState(simState *module.SimulationState) {

params := types.NewParams(maxTxSize, minGasPerByte, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas,
msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas,
msgGas, msgGas, msgGas)
msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas, msgGas)

gashubGenesis := types.NewGenesisState(params)

Expand Down
27 changes: 27 additions & 0 deletions x/gashub/types/gas_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
distribution "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
oracletypes "github.com/cosmos/cosmos-sdk/x/oracle/types"
slashing "github.com/cosmos/cosmos-sdk/x/slashing/types"
staking "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand Down Expand Up @@ -201,4 +202,30 @@ func init() {
fixedGas := params.GetMsgCancelUnbondingDelegationGas()
return FixedGasCalculator(fixedGas)
})
RegisterCalculatorGen(types.MsgTypeURL(&staking.MsgCreateValidator{}), func(params Params) GasCalculator {
fixedGas := params.GetMsgCreateValidatorGas()
return FixedGasCalculator(fixedGas)
})
RegisterCalculatorGen(types.MsgTypeURL(&oracletypes.MsgClaim{}), func(params Params) GasCalculator {
fixedGas := params.GetMsgClaimGas()
return FixedGasCalculator(fixedGas)
})

// these msgs are from greenfield, so the msg types need to be hard coded.
RegisterCalculatorGen("/bnbchain.greenfield.bridge.MsgTransferOut", func(params Params) GasCalculator {
fixedGas := params.GetMsgTransferOutGas()
return FixedGasCalculator(fixedGas)
})
RegisterCalculatorGen("/bnbchain.greenfield.sp.MsgCreateStorageProvider", func(params Params) GasCalculator {
fixedGas := params.GetMsgCreateStorageProviderGas()
return FixedGasCalculator(fixedGas)
})
RegisterCalculatorGen("/bnbchain.greenfield.sp.MsgEditStorageProvider", func(params Params) GasCalculator {
fixedGas := params.GetMsgEditStorageProviderGas()
return FixedGasCalculator(fixedGas)
})
RegisterCalculatorGen("/bnbchain.greenfield.sp.MsgDeposit", func(params Params) GasCalculator {
fixedGas := params.GetMsgSpDepositGas()
return FixedGasCalculator(fixedGas)
})
}
Loading