Skip to content

Commit

Permalink
move priority return to move ante
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Dec 6, 2023
1 parent efe8e75 commit 890d749
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 49 deletions.
15 changes: 1 addition & 14 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ante

import (
"cosmossdk.io/errors"
"cosmossdk.io/math"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

Expand Down Expand Up @@ -70,19 +69,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, 0, errors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

// priority calculated based on the fee value
feeValueInBaseUnit := math.OneInt()
for _, coin := range feeTx.GetFee() {
quotePrice, err := options.MoveKeeper.GetPoolSpotPrice(ctx, coin.Denom)
if err != nil {
return nil, 1, err
}

quoteValueInBaseUnit := quotePrice.MulInt(coin.Amount).TruncateInt()
feeValueInBaseUnit = feeValueInBaseUnit.Add(quoteValueInBaseUnit)
}

return feeTx.GetFee(), feeValueInBaseUnit.Int64(), nil
return feeTx.GetFee(), 1 /* FIFO */, nil
}

anteDecorators := []sdk.AnteDecorator{
Expand Down
59 changes: 24 additions & 35 deletions x/move/ante/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,28 @@ func (fc MempoolFeeChecker) CheckTxFeeWithMinGasPrices(ctx sdk.Context, tx sdk.T
feeCoins := feeTx.GetFee()
gas := feeTx.GetGas()

priority := int64(1)
if ctx.IsCheckTx() {
minGasPrices := ctx.MinGasPrices()
feeValueInBaseUnit := math.ZeroInt()
if fc.keeper != nil {
baseDenom := fc.keeper.BaseDenom(ctx)
baseMinGasPrice := fc.keeper.BaseMinGasPrice(ctx)

minGasPrices = combinedMinGasPrices(baseDenom, baseMinGasPrice, minGasPrices)

for _, coin := range feeTx.GetFee() {
quotePrice, err := fc.fetchPrice(ctx, baseDenom, coin.Denom)
if err != nil {
return nil, 1, err
}

quoteValueInBaseUnit := quotePrice.MulInt(coin.Amount).TruncateInt()
feeValueInBaseUnit = feeValueInBaseUnit.Add(quoteValueInBaseUnit)
}
if feeValueInBaseUnit.GT(math.OneInt()) {
priority = feeValueInBaseUnit.Int64()
}
}

if !minGasPrices.IsZero() {
Expand All @@ -59,30 +74,8 @@ func (fc MempoolFeeChecker) CheckTxFeeWithMinGasPrices(ctx sdk.Context, tx sdk.T
baseDenom := fc.keeper.BaseDenom(ctx)
requiredBaseAmount := requiredFees.AmountOfNoDenomValidation(baseDenom)

// If the requiredBaseAmount is zero, it means the operator
// do not want to receive base denom fee but want to get other
// denom fee.
if !requiredBaseAmount.IsZero() {
for _, coin := range feeCoins {
quotePrice, skip, err := fc.fetchOrSkipPrice(ctx, baseDenom, coin.Denom)
if err != nil {
return nil, 0, err
}
if skip {
continue
}

// sum the converted fee values
quoteValueInBaseUnit := quotePrice.MulInt(coin.Amount).TruncateInt()
sumInBaseUnit = sumInBaseUnit.Add(quoteValueInBaseUnit)

// check the sum is greater than the required.
if sumInBaseUnit.GTE(requiredBaseAmount) {
isSufficient = true
break
}
}
}
// converting to base token only works when the requiredBaseAmount is non-zero.
isSufficient = !requiredBaseAmount.IsZero() && feeValueInBaseUnit.GTE(requiredBaseAmount)
}

if !isSufficient {
Expand All @@ -98,27 +91,23 @@ func (fc MempoolFeeChecker) CheckTxFeeWithMinGasPrices(ctx sdk.Context, tx sdk.T
}
}

// TODO - if we want to use ethereum like priority system,
// then we need to compute all dex prices of all fee coins
return feeCoins, 1 /* FIFO */, nil
return feeCoins, priority, nil
}

func (fc MempoolFeeChecker) fetchOrSkipPrice(ctx sdk.Context, baseDenom, quoteDenom string) (price sdk.Dec, skip bool, err error) {
func (fc MempoolFeeChecker) fetchPrice(ctx sdk.Context, baseDenom, quoteDenom string) (price sdk.Dec, err error) {
if quoteDenom == baseDenom {
return sdk.OneDec(), false, nil
return sdk.OneDec(), nil
}

if found, err := fc.keeper.HasDexPair(ctx, quoteDenom); err != nil {
return sdk.ZeroDec(), false, err
return sdk.ZeroDec(), err
} else if !found {
return sdk.ZeroDec(), true, nil
return sdk.ZeroDec(), nil
}

if quotePrice, err := fc.keeper.GetPoolSpotPrice(ctx, quoteDenom); err != nil {
return sdk.ZeroDec(), false, err
} else if quotePrice.IsZero() {
return sdk.ZeroDec(), true, nil
return sdk.ZeroDec(), err
} else {
return quotePrice, false, nil
return quotePrice, nil
}
}

0 comments on commit 890d749

Please sign in to comment.