From f9aaacc6c3657c5fff0ebc24ad725214ef9dbc1e Mon Sep 17 00:00:00 2001 From: Roshan <48975233+Pythonberg1997@users.noreply.github.com> Date: Fri, 10 Mar 2023 13:18:33 +0800 Subject: [PATCH] fix: update gashub default params (#118) --- x/auth/ante/ante_test.go | 3 +- x/auth/ante/msg_gas_test.go | 4 +- x/gashub/simulation/params_test.go | 75 ++++++++++++++++++++++++++ x/gashub/types/gas_calculator.go | 9 +--- x/gashub/types/params.go | 87 +++++++++++++++--------------- 5 files changed, 122 insertions(+), 56 deletions(-) diff --git a/x/auth/ante/ante_test.go b/x/auth/ante/ante_test.go index 1c07eaa78d..9e223aab7e 100644 --- a/x/auth/ante/ante_test.go +++ b/x/auth/ante/ante_test.go @@ -1,7 +1,6 @@ package ante_test import ( - "encoding/json" "errors" "fmt" "strings" @@ -1101,7 +1100,7 @@ func (suite *AnteTestSuite) TestAnteHandlerReCheck() { tx, err = suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID()) suite.Require().NoError(err) - txBytes, err := json.Marshal(tx) + txBytes, err := suite.clientCtx.TxConfig.TxEncoder()(tx) suite.Require().Nil(err, "Error marshalling tx: %v", err) suite.ctx = suite.ctx.WithTxBytes(txBytes) diff --git a/x/auth/ante/msg_gas_test.go b/x/auth/ante/msg_gas_test.go index 3f2e201500..ff5e9cc019 100644 --- a/x/auth/ante/msg_gas_test.go +++ b/x/auth/ante/msg_gas_test.go @@ -47,8 +47,8 @@ func (suite *AnteTestSuite) TestMsgGas() { expectedGas uint64 } testCases := []testCase{ - {"MsgSend", msgSend, 100000}, - {"MsgMultiSend", msgMultiSend, 400000}, + {"MsgSend", msgSend, 12000}, + {"MsgMultiSend", msgMultiSend, 32000}, } for _, tc := range testCases { suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // Create new txBuilder for each test diff --git a/x/gashub/simulation/params_test.go b/x/gashub/simulation/params_test.go index 6fcda5cc4b..26422f7c45 100644 --- a/x/gashub/simulation/params_test.go +++ b/x/gashub/simulation/params_test.go @@ -7,6 +7,8 @@ import ( "github.com/stretchr/testify/require" "github.com/cosmos/cosmos-sdk/x/gashub/simulation" + "github.com/cosmos/cosmos-sdk/x/gashub/types" + "fmt" ) func TestParamChanges(t *testing.T) { @@ -33,3 +35,76 @@ func TestParamChanges(t *testing.T) { require.Equal(t, expected[i].subspace, p.Subspace()) } } + +func TestMsgUrl(t *testing.T) { + defaultMsgGasParamsSet := []*types.MsgGasParams{ + types.NewMsgGasParamsWithFixedGas("/cosmos.authz.v1beta1.MsgExec", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.authz.v1beta1.MsgRevoke", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.bank.v1beta1.MsgSend", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgFundCommunityPool", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.feegrant.v1beta1.MsgRevokeAllowance", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgDeposit", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgSubmitProposal", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgVote", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgVoteWeighted", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.oracle.v1.MsgClaim", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.slashing.v1beta1.MsgUnjail", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgBeginRedelegate", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgCreateValidator", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgDelegate", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgEditValidator", 12e3), + types.NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgUndelegate", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.bridge.MsgTransferOut", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.sp.MsgDeposit", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.sp.MsgEditStorageProvider", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCopyObject", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateBucket", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateGroup", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateObject", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteBucket", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteGroup", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgLeaveGroup", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgRejectSealObject", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgSealObject", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgUpdateGroupMember", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgCreatePaymentAccount", 2e6), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgDeposit", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgWithdraw", 12e3), + types.NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgDisableRefund", 12e3), + types.NewMsgGasParamsWithDynamicGas( + "/cosmos.authz.v1beta1.MsgGrant", + &types.MsgGasParams_GrantType{ + GrantType: &types.MsgGasParams_DynamicGasParams{ + FixedGas: 8e3, + GasPerItem: 8e3, + }, + }, + ), + types.NewMsgGasParamsWithDynamicGas( + "/cosmos.bank.v1beta1.MsgMultiSend", + &types.MsgGasParams_MultiSendType{ + MultiSendType: &types.MsgGasParams_DynamicGasParams{ + FixedGas: 8e3, + GasPerItem: 8e3, + }, + }, + ), + types.NewMsgGasParamsWithDynamicGas( + "/cosmos.feegrant.v1beta1.MsgGrantAllowance", + &types.MsgGasParams_GrantAllowanceType{ + GrantAllowanceType: &types.MsgGasParams_DynamicGasParams{ + FixedGas: 8e3, + GasPerItem: 8e3, + }, + }, + ), + } + + for _, param := range defaultMsgGasParamsSet { + fmt.Println(param.MsgTypeUrl) + } +} diff --git a/x/gashub/types/gas_calculator.go b/x/gashub/types/gas_calculator.go index 697936b581..a9902312c4 100644 --- a/x/gashub/types/gas_calculator.go +++ b/x/gashub/types/gas_calculator.go @@ -26,14 +26,7 @@ func RegisterCalculatorGen(msgType string, feeCalcGen GasCalculatorGenerator) { } func GetGasCalculatorGen(msgType string) GasCalculatorGenerator { - res, ok := calculatorsGen[msgType] - // todo: this is a temporary default fee, remove this after all msg types are registered - if !ok { - res = func(params Params) GasCalculator { - return FixedGasCalculator(1e5) - } - } - return res + return calculatorsGen[msgType] } func FixedGasCalculator(amount uint64) GasCalculator { diff --git a/x/gashub/types/params.go b/x/gashub/types/params.go index 886775aed2..9b6af58526 100644 --- a/x/gashub/types/params.go +++ b/x/gashub/types/params.go @@ -11,7 +11,7 @@ import ( // Default parameter values const ( - DefaultMaxTxSize uint64 = 1024 + DefaultMaxTxSize uint64 = 32 * 1024 // 32kb DefaultMinGasPerByte uint64 = 5 ) @@ -69,51 +69,50 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { // DefaultParams returns a default set of parameters. func DefaultParams() Params { defaultMsgGasParamsSet := []*MsgGasParams{ - NewMsgGasParamsWithFixedGas("/cosmos.authz.v1beta1.MsgExec", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.authz.v1beta1.MsgRevoke", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.bank.v1beta1.MsgSend", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgFundCommunityPool", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.feegrant.v1beta1.MsgRevokeAllowance", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgDeposit", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgSubmitProposal", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgVote", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgVoteWeighted", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.oracle.v1.MsgClaim", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.slashing.v1beta1.MsgUnjail", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgBeginRedelegate", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgCreateValidator", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgDelegate", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgEditValidator", 1e5), - NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgUndelegate", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.bridge.MsgTransferOut", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.sp.MsgDeposit", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.sp.MsgEditStorageProvider", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCopyObject", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateBucket", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateGroup", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateObject", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteBucket", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteGroup", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgLeaveGroup", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgRejectSealObject", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgSealObject", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgUpdateGroupMember", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreatePaymentAccount", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeposit", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgWithdraw", 1e5), - NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDisableRefund", 1e5), + NewMsgGasParamsWithFixedGas("/cosmos.authz.v1beta1.MsgExec", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.authz.v1beta1.MsgRevoke", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.bank.v1beta1.MsgSend", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.feegrant.v1beta1.MsgRevokeAllowance", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgDeposit", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgSubmitProposal", 2e8), + NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgVote", 2e7), + NewMsgGasParamsWithFixedGas("/cosmos.gov.v1.MsgVoteWeighted", 2e7), + NewMsgGasParamsWithFixedGas("/cosmos.oracle.v1.MsgClaim", 1e3), + NewMsgGasParamsWithFixedGas("/cosmos.slashing.v1beta1.MsgUnjail", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgBeginRedelegate", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgCreateValidator", 2e8), + NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgDelegate", 12e3), + NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgEditValidator", 2e7), + NewMsgGasParamsWithFixedGas("/cosmos.staking.v1beta1.MsgUndelegate", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.bridge.MsgTransferOut", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.sp.MsgDeposit", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.sp.MsgEditStorageProvider", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCopyObject", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateBucket", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateGroup", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateObject", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteBucket", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteGroup", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgLeaveGroup", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgRejectSealObject", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgSealObject", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgUpdateGroupMember", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgCreatePaymentAccount", 2e6), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgDeposit", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgWithdraw", 12e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.payment.MsgDisableRefund", 12e3), NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.challenge.MsgSubmit", 12e3), NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.challenge.MsgAttest", 1e2), NewMsgGasParamsWithDynamicGas( "/cosmos.authz.v1beta1.MsgGrant", &MsgGasParams_GrantType{ GrantType: &MsgGasParams_DynamicGasParams{ - FixedGas: 1e5, - GasPerItem: 1e5, + FixedGas: 8e3, + GasPerItem: 8e3, }, }, ), @@ -121,8 +120,8 @@ func DefaultParams() Params { "/cosmos.bank.v1beta1.MsgMultiSend", &MsgGasParams_MultiSendType{ MultiSendType: &MsgGasParams_DynamicGasParams{ - FixedGas: 1e5, - GasPerItem: 1e5, + FixedGas: 8e3, + GasPerItem: 8e3, }, }, ), @@ -130,8 +129,8 @@ func DefaultParams() Params { "/cosmos.feegrant.v1beta1.MsgGrantAllowance", &MsgGasParams_GrantAllowanceType{ GrantAllowanceType: &MsgGasParams_DynamicGasParams{ - FixedGas: 1e5, - GasPerItem: 1e5, + FixedGas: 8e3, + GasPerItem: 8e3, }, }, ),