Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migration to Cosmos SDK v0.46 #1217

Merged
merged 114 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 90 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
213ee73
go.mod cosmos-sdk bump
robert-zaremba Jun 1, 2022
4c10078
update migrations
robert-zaremba Jun 3, 2022
fe8adc3
cleanups
robert-zaremba Jun 3, 2022
16f3bbd
commenting out gov proposal handlers
robert-zaremba Jun 3, 2022
09491fa
solve tendermint incompatibilities
robert-zaremba Jun 3, 2022
89b2f67
fix go.mod grpc imports
robert-zaremba Jun 3, 2022
9448569
use latest cosmos sdk
robert-zaremba Jun 7, 2022
211d5a7
bump cosmos-sdk
robert-zaremba Jun 16, 2022
ad5d49c
Merge branch 'main' into robert/cosmos-046
robert-zaremba Jul 13, 2022
a4d64f6
fix price feeder go.mod
robert-zaremba Jul 13, 2022
c4ba09e
bump tendermint
robert-zaremba Jul 13, 2022
80a3573
fix iavl version
robert-zaremba Jul 13, 2022
ffd3745
update sdk and IAVL
robert-zaremba Jul 14, 2022
10a0cd4
adding go.sum
robert-zaremba Jul 15, 2022
1214c0c
remove ibc-go/v2
robert-zaremba Jul 20, 2022
aec412c
Merge remote-tracking branch 'origin/main' into robert/cosmos-046
robert-zaremba Jul 26, 2022
b25670e
main go.mod tidy
robert-zaremba Jul 26, 2022
8b7e2de
price-feeder go.mod fix
robert-zaremba Jul 26, 2022
2c6760e
Merge remote-tracking branch 'origin/main' into robert/cosmos-046
robert-zaremba Jul 26, 2022
07e24fa
bump Cosmos SDK
robert-zaremba Jul 26, 2022
145cbd1
migration p1
robert-zaremba Jul 27, 2022
67fafcb
migrate ibctransfer module
robert-zaremba Jul 29, 2022
1710610
update ante handler
robert-zaremba Aug 3, 2022
33757fc
Merge remote-tracking branch 'origin/main' into robert/cosmos-046
robert-zaremba Aug 4, 2022
85c3c32
Merge branch 'main' into robert/cosmos-046
robert-zaremba Aug 4, 2022
5111bc3
fix ante build
robert-zaremba Aug 4, 2022
8e02bbb
api fix
robert-zaremba Aug 4, 2022
d769641
fix oracle simulations
robert-zaremba Aug 4, 2022
a7cf4c3
migrate app.go + upgrades
robert-zaremba Aug 4, 2022
0cc0495
enable nft
robert-zaremba Aug 4, 2022
f566ea7
fixes
robert-zaremba Aug 4, 2022
6b0c2dc
fix leverage proposal handler
robert-zaremba Aug 4, 2022
70e5c85
fix app export
robert-zaremba Aug 4, 2022
c1ad2d8
fix modules
robert-zaremba Aug 4, 2022
29e33c7
fix test_helpers and EncodingConfig
robert-zaremba Aug 4, 2022
e616635
fix cmd modules
robert-zaremba Aug 5, 2022
0d59e35
update changelog
robert-zaremba Aug 5, 2022
d8fbdaa
update comments in oracle keeper
robert-zaremba Aug 5, 2022
ef094f5
use cosmos-sdk fork
robert-zaremba Aug 5, 2022
06d352e
use cosmos-sdk umee release
robert-zaremba Aug 5, 2022
7778331
update cmd root and flags
robert-zaremba Aug 6, 2022
7c91bb2
review comments
robert-zaremba Aug 6, 2022
6bb84b6
review
robert-zaremba Aug 8, 2022
db50d91
update oracle tests
robert-zaremba Aug 8, 2022
c907c1e
fix oracle tests
RafilxTenfen Aug 10, 2022
e14dafc
update sdk.Int to sdkmath.Int
RafilxTenfen Aug 10, 2022
c4a9c20
moved sdk.StoreKey to storetypes.StoreKey
RafilxTenfen Aug 10, 2022
3fa90ea
fix leverage tests by making sure the addr size is 20
RafilxTenfen Aug 10, 2022
fd1d4af
add missing param to SetupWithGenesisValSet
RafilxTenfen Aug 10, 2022
1f256ff
fix lint
RafilxTenfen Aug 10, 2022
573548b
update GetStakingKeeper to return object
robert-zaremba Aug 11, 2022
b34e903
remove custom Gentx module
robert-zaremba Aug 12, 2022
13deafb
migrate price-feeder for umee v3 compatibility
robert-zaremba Aug 15, 2022
86ca7b8
add commit tag to umee-network/cosmos-sdk
RafilxTenfen Aug 15, 2022
b613916
add commit tag to umee-network/ibc-go
RafilxTenfen Aug 15, 2022
666d869
add commit tag to umee-network/bech32-ibc
RafilxTenfen Aug 15, 2022
cca32bf
add commit tag to umee-network/Gravity-Bridge
RafilxTenfen Aug 15, 2022
fd8d4d7
add commit tag to price-feeder
RafilxTenfen Aug 15, 2022
d80912a
add gowork files
RafilxTenfen Aug 16, 2022
67818aa
add verification to conversionRates
RafilxTenfen Aug 16, 2022
41fe910
add line to go.work - note that go mod verify still errors
toteki Aug 17, 2022
80ad03f
Merge branch 'main' into robert/cosmos-046
toteki Aug 17, 2022
4d37944
make go-mod-tidy
toteki Aug 17, 2022
a9d3fc2
Merge remote-tracking branch 'origin/main' into robert/cosmos-046
robert-zaremba Aug 17, 2022
15df53c
remove deprecated grpc.WithInsecure
RafilxTenfen Aug 17, 2022
94be114
Merge branch 'main' into robert/cosmos-046
toteki Aug 17, 2022
859b557
fix sims - initial stake
adamewozniak Aug 17, 2022
01ceed7
e2e keyring migrations
adamewozniak Aug 17, 2022
2b44bca
use p2p instead of tmtypes in e2e
adamewozniak Aug 17, 2022
1a8d91c
review
robert-zaremba Aug 17, 2022
f01f14f
update ante tests
robert-zaremba Aug 17, 2022
ee98933
remove unnecesassary SetupTest call
robert-zaremba Aug 17, 2022
353f848
import whitespace convention
toteki Aug 18, 2022
787202e
lint++
toteki Aug 18, 2022
54bee0c
Merge branch 'main' into robert/cosmos-046
toteki Aug 18, 2022
ccdb5ba
remove duplicated import in ibctransfer
toteki Aug 18, 2022
b823dd1
Merge branch 'robert/cosmos-046' of github.com:umee-network/umee into…
toteki Aug 18, 2022
b004766
Merge remote-tracking branch 'origin/main' into robert/cosmos-046
robert-zaremba Aug 18, 2022
66eadd2
Use ignite cli fork for liveness test
adamewozniak Aug 18, 2022
e1ed15d
fix test names which stop expected tests
adamewozniak Aug 18, 2022
0f9e697
fix liveness go.work issue
adamewozniak Aug 19, 2022
95918de
improving ante handler fee tests
robert-zaremba Aug 19, 2022
f7c2554
modify verification of fee and priority
RafilxTenfen Aug 19, 2022
204fe27
review update: use require.Equal for Int
robert-zaremba Aug 19, 2022
3f8f194
fix sim test
robert-zaremba Aug 19, 2022
b1e4314
fix sim test
robert-zaremba Aug 19, 2022
98df69e
revoked to 100000 MaxMsgGasUsage
RafilxTenfen Aug 19, 2022
b10ee2d
add Gravity msgs check of FeeAndPriority
RafilxTenfen Aug 19, 2022
9488a6f
cosmetics
robert-zaremba Aug 19, 2022
3a5196e
reduce free GB messages
robert-zaremba Aug 19, 2022
a986c7b
Update ante/fee_test.go
toteki Aug 19, 2022
935f90d
fix int equality check
robert-zaremba Aug 19, 2022
69d7b99
fix nil pointer panic
robert-zaremba Aug 19, 2022
3d2cb3b
change group config
robert-zaremba Aug 19, 2022
c96dd5b
fix: remove not compatible VerifyAddressFormat for sdk.Config
robert-zaremba Aug 19, 2022
5a7c751
Merge branch 'main' into robert/cosmos-046
robert-zaremba Aug 19, 2022
8047d8f
fix debug cmd
robert-zaremba Aug 19, 2022
33045fd
fix e2e createMemoryKeyFromMnemonic
robert-zaremba Aug 19, 2022
46ca4fe
remove excessive config log
toteki Aug 20, 2022
6f2ce61
Merge branch 'main' into robert/cosmos-046
toteki Aug 20, 2022
58aeff2
add fix of output json
RafilxTenfen Aug 21, 2022
388b8ce
add verification of err
RafilxTenfen Aug 21, 2022
49391cf
remove deprecated ioutil
RafilxTenfen Aug 21, 2022
82dfa95
removed unused field/functions
RafilxTenfen Aug 21, 2022
c8ca043
simplified gas price
RafilxTenfen Aug 21, 2022
cdddd5e
add count to check amount of tokens instead of hardcoding it
RafilxTenfen Aug 21, 2022
e9bf1fe
add mock provider to peggo
RafilxTenfen Aug 21, 2022
aec5dea
add function to check balances when sending
RafilxTenfen Aug 21, 2022
1a9fe0b
simplified e2e testing sendFromEthToUmee
RafilxTenfen Aug 21, 2022
ee96db1
simplified e2e testing sendFromUmeeToEth
RafilxTenfen Aug 21, 2022
3f71c5f
test: disable ibctransfer TestTrackMetadata
robert-zaremba Aug 22, 2022
c6abbae
skip 2
robert-zaremba Aug 22, 2022
ff4a3ea
update skip statement
robert-zaremba Aug 22, 2022
704be66
remove go.work
robert-zaremba Aug 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ jobs:
- name: Install Starport
if: env.GIT_DIFF
run: |
curl https://get.ignite.com/cli! | bash
cd ../
git clone https://github.com/umee-network/cli --depth=1
cd cli && make install
cd ../umee
- name: Start Local Network via Starport
if: env.GIT_DIFF
run: |
/usr/local/bin/ignite chain serve --reset-once -v -c ./starport.ci.yml &
~/go/bin/ignite chain serve --reset-once -v -c ./starport.ci.yml &
- name: Test Local Network Liveness
if: env.GIT_DIFF
run: |
sleep 1m
./contrib/scripts/test_localnet_liveness.sh 40 5 50 localhost
./contrib/scripts/test_localnet_liveness.sh 50 5 50 localhost
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1188](https://github.com/umee-network/umee/pull/1188) Add `liquidity`, `maximum_borrow`, `maximum_collateral`, `minimum_liquidity`, `available_withdraw`, `available_collateralize`, and `utoken_supply` fields to market summary.
- [1203](https://github.com/umee-network/umee/pull/1203) Add Swagger docs.
- [1212](https://github.com/umee-network/umee/pull/1212) Add `util/checkers` utility package providing common check / validation functions.
- [1217](https://github.com/umee-network/umee/pull/1217) Integrated Cosmos SDK v0.46
- Adding Cosmos SDK x/group module.
- Increased Gov `MaxMetadataLen` from 255 to 800 characters.
- [1220](https://github.com/umee-network/umee/pull/1220) Submit oracle prevotes / vote txs via the CLI.
- [1222](https://github.com/umee-network/umee/pull/1222) Liquidation reward_denom can now be either token or uToken.
- [1238](https://github.com/umee-network/umee/pull/1238) Added bad debts query.
Expand Down
25 changes: 8 additions & 17 deletions ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,31 @@ type HandlerOptions struct {
// signer.
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
return nil, sdkerrors.ErrLogic.Wrap("account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
return nil, sdkerrors.ErrLogic.Wrap("bank keeper is required for ante builder")
}

if options.OracleKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder")
return nil, sdkerrors.ErrLogic.Wrap("oracle keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = cosmosante.DefaultSigVerificationGasConsumer
return nil, sdkerrors.ErrLogic.Wrap("sign mode handler is required for ante builder")
}

return sdk.ChainAnteDecorators(
cosmosante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
cosmosante.NewRejectExtensionOptionsDecorator(),
NewMempoolFeeDecorator(), // mempool fee validation
cosmosante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
cosmosante.NewExtensionOptionsDecorator(nil), // nil=reject extensions
NewSpamPreventionDecorator(options.OracleKeeper), // spam prevention
cosmosante.NewValidateBasicDecorator(),
cosmosante.NewTxTimeoutHeightDecorator(),
cosmosante.NewValidateMemoDecorator(options.AccountKeeper),
cosmosante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, FeeAndPriority),
// SetPubKeyDecorator must be called before all signature verification decorators
cosmosante.NewSetPubKeyDecorator(options.AccountKeeper),
cosmosante.NewValidateSigCountDecorator(options.AccountKeeper),
cosmosante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
cosmosante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
cosmosante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
cosmosante.NewIncrementSequenceDecorator(options.AccountKeeper),
), nil
Expand Down
97 changes: 60 additions & 37 deletions ante/fee.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
package ante

import (
"math"

gbtypes "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

oracletypes "github.com/umee-network/umee/v2/x/oracle/types"
)

// MaxOracleMsgGasUsage defines the maximum gas allowed for an oracle transaction.
const MaxOracleMsgGasUsage = uint64(100000)

// MempoolFeeDecorator defines a custom Umee AnteHandler decorator that is
// responsible for allowing oracle transactions from oracle feeders to bypass
// the minimum fee CheckTx check. However, if an oracle transaction's gas limit
// is beyond the accepted threshold, the minimum fee check is still applied.
//
// For non-oracle transactions, the minimum fee check is applied.
type MempoolFeeDecorator struct{}

func NewMempoolFeeDecorator() MempoolFeeDecorator {
return MempoolFeeDecorator{}
}
// MaxMsgGasUsage defines the maximum gas allowed for an oracle transaction.
const MaxMsgGasUsage = uint64(100000)

func (mfd MempoolFeeDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (newCtx sdk.Context, err error) {
// FeeAndPriority ensures tx has enough fee coins to pay for the gas at the CheckTx time
// to early remove transactions from the mempool without enough attached fee.
// The validator min fee check is ignored if the tx contains only oracle messages and
// tx gas limit is <= MaxOracleMsgGasUsage. Essentially, validators can provide price
// transactison for free as long as the gas per message is in the MaxOracleMsgGasUsage limit.
func FeeAndPriority(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
return nil, 0, sdkerrors.ErrTxDecode.Wrap("Tx must be a FeeTx")
}

feeCoins := feeTx.GetFee()
gas := feeTx.GetGas()
msgs := feeTx.GetMsgs()
isOracleOrGravity := IsOracleOrGravityTx(msgs)
chargeFees := !isOracleOrGravity || gas > uint64(len(msgs))*MaxMsgGasUsage

// Only check for minimum fees if the execution mode is CheckTx and the tx does
// not contain oracle messages. If the tx does contain oracle messages, it's
// total gas must be less than or equal to a constant, otherwise minimum fees
// are checked.
if ctx.IsCheckTx() && !simulate &&
!(isOracleTx(msgs) && gas <= uint64(len(msgs))*MaxOracleMsgGasUsage) {
if ctx.IsCheckTx() && chargeFees {
minGasPrices := ctx.MinGasPrices()
if !minGasPrices.IsZero() {
requiredFees := make(sdk.Coins, len(minGasPrices))
Expand All @@ -56,26 +44,38 @@ func (mfd MempoolFeeDecorator) AnteHandle(
}

if !feeCoins.IsAnyGTE(requiredFees) {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInsufficientFee,
"insufficient fees; got: %s required: %s",
feeCoins,
requiredFees,
)
return nil, 0, sdkerrors.ErrInsufficientFee.Wrapf(
"insufficient fees; got: %s required: %s", feeCoins, requiredFees)
}
}
}

return next(ctx, tx, simulate)
priority := getTxPriority(feeCoins, isOracleOrGravity)
if !chargeFees {
return sdk.Coins{}, priority, nil
}
return feeCoins, priority, nil
}

func isOracleTx(msgs []sdk.Msg) bool {
// IsOracleOrGravityTx checks if all messages are oracle messages
func IsOracleOrGravityTx(msgs []sdk.Msg) bool {
for _, msg := range msgs {
switch msg.(type) {
case *oracletypes.MsgAggregateExchangeRatePrevote:
case *oracletypes.MsgAggregateExchangeRatePrevote,
*oracletypes.MsgAggregateExchangeRateVote:
continue

case *oracletypes.MsgAggregateExchangeRateVote:
case *gbtypes.MsgValsetConfirm,
*gbtypes.MsgRequestBatch,
*gbtypes.MsgConfirmBatch,
*gbtypes.MsgERC20DeployedClaim,
*gbtypes.MsgConfirmLogicCall,
*gbtypes.MsgLogicCallExecutedClaim,
*gbtypes.MsgSendToCosmosClaim,
*gbtypes.MsgExecuteIbcAutoForwards,
*gbtypes.MsgBatchSendToEthClaim,
*gbtypes.MsgValsetUpdatedClaim,
*gbtypes.MsgSubmitBadSignatureEvidence:
continue

default:
Expand All @@ -85,3 +85,26 @@ func isOracleTx(msgs []sdk.Msg) bool {

return true
}

// getTxPriority returns naive tx priority based on the lowest fee amount (regardless of the
// denom) and oracle tx check.
func getTxPriority(fee sdk.Coins, isOracleOrGravity bool) int64 {
var priority int64
for _, c := range fee {
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
// TODO: we should better compare amounts
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
// https://github.com/umee-network/umee/issues/510
p := int64(math.MaxInt64)
if c.Amount.IsInt64() {
p = c.Amount.Int64()
}
if priority == 0 || p < priority {
priority = p
}
}
if isOracleOrGravity {
// TODO: this is a naive version.
// Proper solution will be implemented in https://github.com/umee-network/umee/issues/510
priority += 100000
}
return priority
}
86 changes: 48 additions & 38 deletions ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,71 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/umee-network/umee/v2/ante"
oracletypes "github.com/umee-network/umee/v2/x/oracle/types"
)

func (suite *IntegrationTestSuite) TestMempoolFee() {
suite.SetupTest()
func (suite *IntegrationTestSuite) TestFeeAndPriority() {
require := suite.Require()
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

mfd := ante.NewMempoolFeeDecorator()
antehandler := sdk.ChainAnteDecorators(mfd)
priv1, _, addr1 := testdata.KeyTestPubAddr()
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}

msg := testdata.NewTestMsg(addr1)
feeAmount := testdata.NewTestFeeAmount()
gasLimit := testdata.NewTestGasLimit()
suite.Require().NoError(suite.txBuilder.SetMsgs(msg))
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)
msgs := testdata.NewTestMsg(addr1)
require.NoError(suite.txBuilder.SetMsgs(msgs))
fee := sdk.NewCoins(sdk.NewInt64Coin("atom", 150))
gasLimit := 200000
suite.txBuilder.SetFeeAmount(fee)
suite.txBuilder.SetGasLimit(uint64(gasLimit))

privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
// Test1: validator min gas price check
// Ante should fail when validator min gas price is above the transaction gas limit
minGasPrice := sdk.NewDecCoinFromDec("atom", sdk.NewDecFromInt(fee[0].Amount).QuoInt64(int64(gasLimit/2)))
ctx := suite.ctx.
WithMinGasPrices([]sdk.DecCoin{minGasPrice}).
WithIsCheckTx(true)
tx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
suite.Require().NoError(err)
require.NoError(err)
_, _, err = ante.FeeAndPriority(ctx, tx)
require.ErrorIs(sdkerrors.ErrInsufficientFee, err)

// Set high gas price so standard test fee fails
atomPrice := sdk.NewDecCoinFromDec("atom", sdk.NewDec(200).Quo(sdk.NewDec(100000)))
highGasPrice := []sdk.DecCoin{atomPrice}
suite.ctx = suite.ctx.WithMinGasPrices(highGasPrice)
// Test2: min gas price not checked in DeliverTx
ctx = suite.ctx.WithIsCheckTx(false)
suite.checkFeeAnte(tx, fee, ctx)

suite.ctx = suite.ctx.WithIsCheckTx(true)
// Test3: should not error when min gas price is same or lower than the fee
ctx = ctx.WithMinGasPrices(sdk.NewDecCoinsFromCoins(fee...))
suite.checkFeeAnte(tx, fee, ctx)

// antehandler errors with insufficient fees
_, err = antehandler(suite.ctx, tx, false)
suite.Require().Error(err, "Decorator should have errored on too low fee for local gasPrice")
ctx = ctx.WithMinGasPrices([]sdk.DecCoin{sdk.NewDecCoin(fee[0].Denom, fee[0].Amount.QuoRaw(2))})
suite.checkFeeAnte(tx, fee, ctx)

// ensure no fees for oracle msgs
suite.Require().NoError(suite.txBuilder.SetMsgs(
// Test4: ensure no fees for oracle msgs
require.NoError(suite.txBuilder.SetMsgs(
oracletypes.NewMsgAggregateExchangeRatePrevote(oracletypes.AggregateVoteHash{}, addr1, sdk.ValAddress(addr1)),
oracletypes.NewMsgAggregateExchangeRateVote("", "", addr1, sdk.ValAddress(addr1)),
))
suite.txBuilder.SetFeeAmount(sdk.Coins{})
suite.txBuilder.SetGasLimit(0)
oracleTx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.ctx.ChainID())
_, err = antehandler(suite.ctx, oracleTx, false)
suite.Require().NoError(err, "Decorator should not require high price for oracle tx")
require.NoError(err)
require.True(oracleTx.GetFee().IsZero(), "got: %s", oracleTx.GetFee())
require.Equal(uint64(0), oracleTx.GetGas())
require.True(ante.IsOracleTx(oracleTx.GetMsgs()))
toteki marked this conversation as resolved.
Show resolved Hide resolved

suite.ctx = suite.ctx.WithIsCheckTx(false)

// antehandler should not error since we do not check minGasPrice in DeliverTx
_, err = antehandler(suite.ctx, tx, false)
suite.Require().NoError(err, "MempoolFeeDecorator returned error in DeliverTx")

suite.ctx = suite.ctx.WithIsCheckTx(true)

atomPrice = sdk.NewDecCoinFromDec("atom", sdk.NewDec(0).Quo(sdk.NewDec(100000)))
lowGasPrice := []sdk.DecCoin{atomPrice}
suite.ctx = suite.ctx.WithMinGasPrices(lowGasPrice)
suite.checkFeeAnte(oracleTx, sdk.Coins{}, suite.ctx.WithIsCheckTx(true))
suite.checkFeeAnte(oracleTx, sdk.Coins{}, suite.ctx.WithIsCheckTx(false))
}

_, err = antehandler(suite.ctx, tx, false)
suite.Require().NoError(err, "Decorator should not have errored on fee higher than local gasPrice")
func (suite *IntegrationTestSuite) checkFeeAnte(tx sdk.Tx, feeExpected sdk.Coins, ctx sdk.Context) {
require := suite.Require()
fee, _, err := ante.FeeAndPriority(ctx, tx)
require.NoError(err)
if len(feeExpected) == 0 {
require.True(fee.IsZero(), "fee should be zero, got: %s", fee)
} else {
require.True(fee.IsEqual(feeExpected), "Fee expected %s, got: %s", feeExpected, fee)
}
}
11 changes: 8 additions & 3 deletions ante/spam_prevention.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,14 @@ func (spd *SpamPreventionDecorator) CheckOracleSpam(ctx sdk.Context, msgs []sdk.
return nil
}

func (spd *SpamPreventionDecorator) validate(ctx sdk.Context, feeder, validator string,
cache map[string]int64, curHeight int64, txType string) error {

func (spd *SpamPreventionDecorator) validate(
ctx sdk.Context,
feeder,
validator string,
cache map[string]int64,
curHeight int64,
txType string,
) error {
feederAddr, err := sdk.AccAddressFromBech32(feeder)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion ante/spam_prevention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func (suite *IntegrationTestSuite) TestOracleSpam() {
suite.SetupTest()
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

priv1, _, addr1 := testdata.KeyTestPubAddr()
Expand Down
Loading