Skip to content

Commit

Permalink
release: draft release v0.1.0 (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
randyahx authored Apr 6, 2023
1 parent 1c80b53 commit f6dc18d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
55 changes: 25 additions & 30 deletions x/auth/ante/msg_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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()
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
}
4 changes: 3 additions & 1 deletion x/gashub/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Default parameter values
const (
DefaultMaxTxSize uint64 = 32 * 1024 // 32kb
DefaultMaxTxSize uint64 = 64 * 1024 // 32kb
DefaultMinGasPerByte uint64 = 5
)

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit f6dc18d

Please sign in to comment.