diff --git a/CHANGELOG.md b/CHANGELOG.md index 43dabac9a1..5c4e376c95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ # Changelog +## v0.1.0 +This is a maintenance release. + +* [\#163](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/163) fix: update DefaultMaxTxSize and gas simulation logic +* [\#155](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/155) feat: add gas config for discontinue object message + ## v0.0.14 This is a hotfix release. diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index c32bf4476d..0c7f026c90 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -582,7 +582,7 @@ func validateBasicTxMsgs(msgs []sdk.Msg) error { return nil } -// GetState returns the applications's deliverState if app is in runTxModeDeliver, +// GetState returns the application's deliverState if app is in runTxModeDeliver, // otherwise it returns the application's checkstate. func (app *BaseApp) getState(mode runTxMode) *state { if mode == runTxModeDeliver { diff --git a/x/auth/ante/msg_gas.go b/x/auth/ante/msg_gas.go index cd914b29e9..60e38b335f 100644 --- a/x/auth/ante/msg_gas.go +++ b/x/auth/ante/msg_gas.go @@ -4,15 +4,19 @@ import ( "fmt" "cosmossdk.io/errors" - "github.com/cosmos/cosmos-sdk/codec/legacy" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/cosmos/cosmos-sdk/x/gashub/types" ) +const ( + // Length of the protobuf encoded bytes + EthSecp256k1PubkeySize = 79 + EthSecp256k1SigSize = 65 + FeeSize = 42 +) + // ValidateTxSizeDecorator will validate tx bytes length given the parameters passed in // If tx is too large decorator returns with error, otherwise call next AnteHandler // @@ -38,7 +42,7 @@ func (vtsd ValidateTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul newCtx := ctx txSize := newCtx.TxSize() - // simulate signatures in simulate mode + // get right tx size in simulate mode if simulate { // in simulate mode, each element should be a nil signature sigs, err := sigTx.GetSignaturesV2() @@ -47,33 +51,20 @@ func (vtsd ValidateTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul } n := len(sigs) - for i, signer := range sigTx.GetSigners() { - // if signature is already filled in, no need to simulate gas cost - if i < n && !isIncompleteSignature(sigs[i].Data) { - continue - } - - var pubkey cryptotypes.PubKey - - acc := vtsd.ak.GetAccount(ctx, signer) - - // use placeholder simSecp256k1Pubkey if sig is nil - if acc == nil || acc.GetPubKey() == nil { - pubkey = simSecp256k1Pubkey + for i := range sigTx.GetSigners() { + if i < n { + if isIncompleteSignature(sigs[i].Data) { + txSize += EthSecp256k1SigSize + } + if sigs[i].PubKey == nil { + txSize += EthSecp256k1PubkeySize + } } else { - pubkey = acc.GetPubKey() - } - - // use stdsignature to mock the size of a full signature - simSig := legacytx.StdSignature{ //nolint:staticcheck // this will be removed when proto is ready - Signature: simSecp256k1Sig[:], - PubKey: pubkey, + txSize += EthSecp256k1SigSize + EthSecp256k1PubkeySize } - - sigBz := legacy.Cdc.MustMarshal(simSig) - txSize = txSize + uint64(len(sigBz)) + 14 } + txSize += FeeSize newCtx = ctx.WithTxSize(txSize) } @@ -113,9 +104,9 @@ func (cmfg ConsumeMsgGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula } if gasByTxSize > gasByMsgType { - ctx.GasMeter().ConsumeGas(gasByTxSize, "tx bytes length") + ctx.GasMeter().ConsumeGas(gasByTxSize, "gas cost by tx bytes length") } else { - ctx.GasMeter().ConsumeGas(gasByMsgType, "msg type") + ctx.GasMeter().ConsumeGas(gasByMsgType, "gas cost by msg type") } return next(ctx, tx, simulate) @@ -140,5 +131,9 @@ func (cmfg ConsumeMsgGasDecorator) getMsgGas(params types.Params, tx sdk.Tx) (ui } func (cmfg ConsumeMsgGasDecorator) getTxSizeGas(params types.Params, ctx sdk.Context) uint64 { - return params.GetMinGasPerByte() * ctx.TxSize() + txSize := ctx.TxSize() + if txSize < params.GetMaxTxSize()/2 { + return 0 + } + return params.GetMinGasPerByte() * txSize } diff --git a/x/gashub/types/params.go b/x/gashub/types/params.go index 9def5940fe..d17eb6ebe0 100644 --- a/x/gashub/types/params.go +++ b/x/gashub/types/params.go @@ -11,7 +11,7 @@ import ( // Default parameter values const ( - DefaultMaxTxSize uint64 = 32 * 1024 // 32kb + DefaultMaxTxSize uint64 = 64 * 1024 // 32kb DefaultMinGasPerByte uint64 = 5 ) @@ -104,6 +104,8 @@ func DefaultParams() Params { NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteObject", 1.2e3), NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCopyObject", 1.2e3), NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCancelCreateObject", 1.2e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDiscontinueObject", 2.4e3), + NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDiscontinueBucket", 2.4e3), NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgCreateGroup", 2.4e3), NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgDeleteGroup", 1.2e3), NewMsgGasParamsWithFixedGas("/bnbchain.greenfield.storage.MsgLeaveGroup", 1.2e3),