Skip to content

Commit

Permalink
fix(delayedack): do not create eibc order on timeout/errack if fee is…
Browse files Browse the repository at this point in the history
… not positive (#801)
  • Loading branch information
danwt authored and omritoptix committed Apr 4, 2024
1 parent 100bf7d commit e5ffc85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 9 additions & 2 deletions ibctesting/eibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (suite *EIBCTestSuite) TestTimeoutEIBCDemandOrderFulfillment() {
type TC struct {
name string
malleate func(channeltypes.Packet)
fee func(params eibctypes.Params) sdk.Dec
}

nOrdersCreated := 0
Expand All @@ -361,6 +362,9 @@ func (suite *EIBCTestSuite) TestTimeoutEIBCDemandOrderFulfillment() {
err := hubEndpoint.TimeoutPacket(packet)
suite.Require().NoError(err)
},
fee: func(params eibctypes.Params) sdk.Dec {
return params.TimeoutFee
},
},
{
name: "err acknowledgement",
Expand All @@ -378,6 +382,9 @@ func (suite *EIBCTestSuite) TestTimeoutEIBCDemandOrderFulfillment() {
err = hubEndpoint.AcknowledgePacket(packet, ack.Acknowledgement())
suite.Require().NoError(err)
},
fee: func(params eibctypes.Params) sdk.Dec {
return params.ErrackFee
},
},
} {
suite.Run(tc.name, func() {
Expand Down Expand Up @@ -428,10 +435,10 @@ func (suite *EIBCTestSuite) TestTimeoutEIBCDemandOrderFulfillment() {
// Get the last demand order created t
lastDemandOrder := getLastDemandOrderByChannelAndSequence(demandOrders)
// Validate the demand order price and denom
timeoutFee := eibcKeeper.GetParams(suite.hubChain.GetContext()).TimeoutFee
fee := tc.fee(eibcKeeper.GetParams(suite.hubChain.GetContext()))
amountDec, err := sdk.NewDecFromStr(coinToSendToB.Amount.String())
suite.Require().NoError(err)
expectedPrice := amountDec.Mul(sdk.NewDec(1).Sub(timeoutFee)).TruncateInt()
expectedPrice := amountDec.Mul(sdk.NewDec(1).Sub(fee)).TruncateInt()
suite.Require().Equal(expectedPrice, lastDemandOrder.Price[0].Amount)
suite.Require().Equal(coinToSendToB.Denom, lastDemandOrder.Price[0].Denom)
// Fulfill the demand order
Expand Down
13 changes: 7 additions & 6 deletions x/delayedack/eibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ func (im IBCMiddleware) eIBCDemandOrderHandler(ctx sdk.Context, rollappPacket co
if t == commontypes.RollappPacket_ON_ACK {
feeMultiplier = im.keeper.ErrAckFee(ctx)
}
if feeMultiplier.IsZero() {
logger.Debug("fee is zero, skipping demand order creation", "fee type", t)

fee := amountDec.Mul(feeMultiplier).TruncateInt()
if !fee.IsPositive() {
logger.Debug("fee is not positive, skipping demand order creation", "fee type", t, "fee", fee.String(), "multiplier", feeMultiplier.String())
return nil
}
fee := amountDec.Mul(feeMultiplier).TruncateInt().String()
packetMetaData = &types.PacketMetadata{
EIBC: &types.EIBCMetadata{
Fee: fee,
Fee: fee.String(),
},
}
}
Expand Down Expand Up @@ -108,13 +109,13 @@ func (im IBCMiddleware) createDemandOrderFromIBCPacket(fungibleTokenPacketData t
if im.keeper.BlockedAddr(fungibleTokenPacketData.Receiver) {
return nil, fmt.Errorf("not allowed to receive funds: receiver: %s", fungibleTokenPacketData.Receiver)
}
// Get the fee from the memo
fee := eibcMetaData.Fee
// Calculate the demand order price and validate it
amountInt, ok := sdk.NewIntFromString(fungibleTokenPacketData.Amount)
if !ok || !amountInt.IsPositive() {
return nil, fmt.Errorf("convert amount to positive integer: %s", fungibleTokenPacketData.Amount)
}
// Get the fee from the memo
fee := eibcMetaData.Fee
feeInt, ok := sdk.NewIntFromString(fee)
if !ok || !feeInt.IsPositive() {
return nil, fmt.Errorf("convert fee to positive integer: %s", fee)
Expand Down

0 comments on commit e5ffc85

Please sign in to comment.