Skip to content

Commit

Permalink
revert min gas price config
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Feb 14, 2023
1 parent b7d9789 commit 9b7ca1e
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 146 deletions.
3 changes: 1 addition & 2 deletions proto/cosmos/gashub/v1alpha1/gashub.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ message Params {

uint64 max_tx_size = 1 [(gogoproto.customname) = "MaxTxSize"];
uint64 min_gas_per_byte = 2 [(gogoproto.customname) = "MinGasPerByte"];
string min_gas_price = 3 [(gogoproto.customname) = "MinGasPrice"];

repeated MsgGasParams msg_gas_params_set = 4 [(gogoproto.customname) = "MsgGasParamsSet"];
repeated MsgGasParams msg_gas_params_set = 3 [(gogoproto.customname) = "MsgGasParamsSet"];
}

// MsgGasParams defines gas for a msg type
Expand Down
3 changes: 1 addition & 2 deletions x/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type HandlerOptions struct {
FeegrantKeeper FeegrantKeeper
SignModeHandler authsigning.SignModeHandler
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params types.Params) error
GashubKeeper GashubKeeper
TxFeeChecker TxFeeChecker
}

Expand All @@ -43,7 +42,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
NewTxTimeoutHeightDecorator(),
NewValidateMemoDecorator(options.AccountKeeper),
NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.GashubKeeper, options.TxFeeChecker),
NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
NewValidateSigCountDecorator(options.AccountKeeper),
NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
Expand Down
8 changes: 3 additions & 5 deletions x/auth/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// TxFeeChecker check if the provided fee is enough and returns the effective fee and tx priority,
// the effective fee should be deducted later, and the priority should be returned in abci response.
type TxFeeChecker func(ctx sdk.Context, ghk GashubKeeper, tx sdk.Tx) (sdk.Coins, int64, error)
type TxFeeChecker func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error)

// DeductFeeDecorator deducts fees from the first signer of the tx
// If the first signer does not have the funds to pay for the fees, return with InsufficientFunds error
Expand All @@ -21,10 +21,9 @@ type DeductFeeDecorator struct {
bankKeeper types.BankKeeper
feegrantKeeper FeegrantKeeper
txFeeChecker TxFeeChecker
gashubKeeper GashubKeeper
}

func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper, fk FeegrantKeeper, ghk GashubKeeper, tfc TxFeeChecker) DeductFeeDecorator {
func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper, fk FeegrantKeeper, tfc TxFeeChecker) DeductFeeDecorator {
if tfc == nil {
tfc = checkTxFeeWithValidatorMinGasPrices
}
Expand All @@ -34,7 +33,6 @@ func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper, fk FeegrantKee
bankKeeper: bk,
feegrantKeeper: fk,
txFeeChecker: tfc,
gashubKeeper: ghk,
}
}

Expand All @@ -55,7 +53,7 @@ func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bo

fee := feeTx.GetFee()
if !simulate {
fee, priority, err = dfd.txFeeChecker(ctx, dfd.gashubKeeper, tx)
fee, priority, err = dfd.txFeeChecker(ctx, tx)
if err != nil {
return ctx, err
}
Expand Down
6 changes: 3 additions & 3 deletions x/auth/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (s *AnteTestSuite) TestDeductFeeDecorator_ZeroGas() {
s.SetupTest(true) // setup
s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder()

mfd := ante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.GashubKeeper, nil)
mfd := ante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, nil)
antehandler := sdk.ChainAnteDecorators(mfd)

// keys and addresses
Expand Down Expand Up @@ -46,7 +46,7 @@ func (s *AnteTestSuite) TestEnsureMempoolFees() {
s.SetupTest(true) // setup
s.txBuilder = s.clientCtx.TxConfig.NewTxBuilder()

mfd := ante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, s.app.GashubKeeper, nil)
mfd := ante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, s.app.FeeGrantKeeper, nil)
antehandler := sdk.ChainAnteDecorators(mfd)

// keys and addresses
Expand Down Expand Up @@ -130,7 +130,7 @@ func (s *AnteTestSuite) TestDeductFees() {
err = testutil.FundAccount(s.app.BankKeeper, s.ctx, addr1, coins)
s.Require().NoError(err)

dfd := ante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, nil, s.app.GashubKeeper, nil)
dfd := ante.NewDeductFeeDecorator(s.app.AccountKeeper, s.app.BankKeeper, nil, nil)
antehandler := sdk.ChainAnteDecorators(dfd)

_, err = antehandler(s.ctx, tx, false)
Expand Down
2 changes: 1 addition & 1 deletion x/auth/ante/feegrant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (suite *AnteTestSuite) TestDeductFeesNoDelegation() {
protoTxCfg := tx.NewTxConfig(codec.NewProtoCodec(app.InterfaceRegistry()), tx.DefaultSignModes)

// this just tests our handler
dfd := ante.NewDeductFeeDecorator(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.GashubKeeper, nil)
dfd := ante.NewDeductFeeDecorator(app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, nil)
feeAnteHandler := sdk.ChainAnteDecorators(dfd)

// this tests the whole stack
Expand Down
8 changes: 4 additions & 4 deletions x/auth/ante/validator_tx_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// checkTxFeeWithValidatorMinGasPrices implements the default fee logic, where the minimum price per
// unit of gas is fixed and set by each validator, can the tx priority is computed from the gas price.
func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, ghk GashubKeeper, tx sdk.Tx) (sdk.Coins, int64, error) {
func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return nil, 0, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
Expand Down Expand Up @@ -40,15 +40,15 @@ func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, ghk GashubKeeper, tx s
}
}

priority := GetTxPriority(feeCoins, int64(gas))
priority := getTxPriority(feeCoins, int64(gas))
return feeCoins, priority, nil
}

// GetTxPriority returns a naive tx priority based on the amount of the smallest denomination of the gas price
// getTxPriority returns a naive tx priority based on the amount of the smallest denomination of the gas price
// provided in a transaction.
// NOTE: This implementation should be used with a great consideration as it opens potential attack vectors
// where txs with multiple coins could not be prioritize as expected.
func GetTxPriority(fee sdk.Coins, gas int64) int64 {
func getTxPriority(fee sdk.Coins, gas int64) int64 {
var priority int64
for _, c := range fee {
p := int64(math.MaxInt64)
Expand Down
16 changes: 1 addition & 15 deletions x/gashub/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package simulation
import (
"fmt"
"math/rand"
"strconv"

"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/simulation"
Expand All @@ -15,7 +14,6 @@ import (
const (
MaxTxSize = "max_tx_size"
MinGasPerByte = "min_gas_per_byte"
MinGasPrice = "min_gas_price"
MsgGas = "msg_gas"
)

Expand All @@ -29,12 +27,6 @@ func GenMinGasPerByte(r *rand.Rand) uint64 {
return uint64(simulation.RandIntBetween(r, 5, 50))
}

// GenMinGasPrice randomized MinGasPrice
func GenMinGasPrice(r *rand.Rand) string {
amount := simulation.RandIntBetween(r, 1, 10)
return strconv.FormatInt(int64(amount), 10) + "gweibnb"
}

// GenMsgGasParams randomized msg gas consumption
func GenMsgGasParams(r *rand.Rand) *types.MsgGasParams {
msgTypeUrl := simulation.RandStringOfLength(r, 12)
Expand All @@ -56,19 +48,13 @@ func RandomizedGenState(simState *module.SimulationState) {
func(r *rand.Rand) { minGasPerByte = GenMinGasPerByte(r) },
)

var minGasPrice string
simState.AppParams.GetOrGenerate(
simState.Cdc, MinGasPrice, &minGasPrice, simState.Rand,
func(r *rand.Rand) { minGasPrice = GenMinGasPrice(r) },
)

var msgGasParams *types.MsgGasParams
simState.AppParams.GetOrGenerate(
simState.Cdc, MsgGas, &msgGasParams, simState.Rand,
func(r *rand.Rand) { msgGasParams = GenMsgGasParams(r) },
)

params := types.NewParams(maxTxSize, minGasPerByte, minGasPrice, []*types.MsgGasParams{msgGasParams})
params := types.NewParams(maxTxSize, minGasPerByte, []*types.MsgGasParams{msgGasParams})

gashubGenesis := types.NewGenesisState(params)

Expand Down
3 changes: 1 addition & 2 deletions x/gashub/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func TestRandomizedGenState(t *testing.T) {

require.Equal(t, uint64(2540), gashubGenesis.Params.MaxTxSize)
require.Equal(t, uint64(36), gashubGenesis.Params.MinGasPerByte)
require.Equal(t, "7gweibnb", gashubGenesis.Params.MinGasPrice)

gas := gashubGenesis.Params.MsgGasParamsSet[0].GasParams.(*types.MsgGasParams_FixedType)
require.Equal(t, uint64(4828162), gas.FixedType.FixedGas)
require.Equal(t, uint64(4978511), gas.FixedType.FixedGas)
}
120 changes: 32 additions & 88 deletions x/gashub/types/gashub.pb.go

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

Loading

0 comments on commit 9b7ca1e

Please sign in to comment.