Skip to content

Commit

Permalink
limit tx size for create-price, some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed Aug 30, 2024
1 parent 066de47 commit c1c5ba9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 0 additions & 1 deletion app/ante/cosmos/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ func OnlyLegacyAminoSigners(sigData signing.SignatureData) bool {

func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if utils.IsOracleCreatePriceTx(tx) {
// TODO: verify ed25519 signature for create-price message which is signed by consensusKey
sigTx, ok := tx.(authsigning.SigVerifiableTx)
if !ok {
return ctx, sdkerrors.ErrTxDecode.Wrap("invalid transaction type, expected SigVerifiableTx")
Expand Down
4 changes: 4 additions & 0 deletions app/ante/cosmos/txsize_gas.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cosmos

import (
"github.com/ExocoreNetwork/exocore/app/ante/utils"

Check failure on line 4 in app/ante/cosmos/txsize_gas.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ST1019: package "github.com/ExocoreNetwork/exocore/app/ante/utils" is being imported more than once (stylecheck)
anteutils "github.com/ExocoreNetwork/exocore/app/ante/utils"

Check failure on line 5 in app/ante/cosmos/txsize_gas.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

ST1019(related information): other import of "github.com/ExocoreNetwork/exocore/app/ante/utils" (stylecheck)
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
Expand Down Expand Up @@ -39,6 +40,9 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim

// Skip gas consumption if tx is an OracleCreatePriceTx
if anteutils.IsOracleCreatePriceTx(tx) {
if len(ctx.TxBytes()) > utils.TxSizeLimit {
return ctx, sdkerrors.ErrTxTooLarge.Wrapf("oracle create-price tx has exceeds size limit, limit:%d, got:%d", utils.TxSizeLimit, len(ctx.TxBytes()))
}
return next(ctx, tx, simulate)
}

Expand Down
8 changes: 4 additions & 4 deletions app/ante/utils/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const CreatePriceGas = 20000
// TxSizeLimit limits max size of a create-price tx, this is calculated based on one nativeTokenbalance message of worst case(max size), which will need 576 bytes for balance update
const TxSizeLimit = 1000

func IsOracleCreatePriceTx(tx sdk.Tx) bool {
msgs := tx.GetMsgs()
if len(msgs) == 0 {
return false
}
for _, msg := range msgs {
if _, ok := msg.(*oracletypes.MsgCreatePrice); ok {
continue
if _, ok := msg.(*oracletypes.MsgCreatePrice); !ok {
return false
}
return false
}
return true
}
4 changes: 2 additions & 2 deletions x/oracle/keeper/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func (k Keeper) AddNonceItem(ctx sdk.Context, nonce types.ValidatorNonce) {
}

// AddZeroNonceItemForValidators init the nonce of a specific feederID for a set of validators
func (k Keeper) AddZeroNonceItemWithFeederIDForValidators(ctx sdk.Context, feederID uint64, valdiators []string) {
func (k Keeper) AddZeroNonceItemWithFeederIDForValidators(ctx sdk.Context, feederID uint64, validators []string) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.NonceKeyPrefix))
for _, validator := range valdiators {
for _, validator := range validators {
if n, found := k.getNonce(store, validator); found {
found := false
for _, v := range n.NonceList {
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/key_nonce.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

const (
// NonceKeyPrefix is the prefix to retrieve all KeyNonce
// NonceKeyPrefix is used as a prefix for storing key nonces.
NonceKeyPrefix = "KeyNonce/value/"
)

Expand Down

0 comments on commit c1c5ba9

Please sign in to comment.