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

fix(delayedack): do not create eibc order on timeout/errack if fee is not positive #801

Merged
merged 5 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@
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())

Check warning on line 67 in x/delayedack/eibc.go

View check run for this annotation

Codecov / codecov/patch

x/delayedack/eibc.go#L67

Added line #L67 was not covered by tests
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 @@
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
Loading