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: ics rewards take 4 😢 #496

Merged
merged 2 commits into from
Jul 12, 2023
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
23 changes: 17 additions & 6 deletions x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,25 @@ func (k *Keeper) HandleMsgTransfer(ctx sdk.Context, msg sdk.Msg) error {
receivedCoin := sMsg.Token

zone, found := k.GetZoneForWithdrawalAccount(ctx, sMsg.Sender)
if !found {
return fmt.Errorf("zone not found for withdrawal account %s", sMsg.Sender)
}

channel, cfound := k.IBCKeeper.ChannelKeeper.GetChannel(ctx, sMsg.SourcePort, sMsg.SourceChannel)
if !cfound {
var channel *channeltypes.IdentifiedChannel
k.IBCKeeper.ChannelKeeper.IterateChannels(ctx, func(ic channeltypes.IdentifiedChannel) bool {
if ic.Counterparty.ChannelId == sMsg.SourceChannel && ic.Counterparty.PortId == sMsg.SourcePort && len(ic.ConnectionHops) == 1 && ic.ConnectionHops[0] == zone.ConnectionId {
channel = &ic
return true
}
return false
})

if channel == nil {
k.Logger(ctx).Error("channel not found for the packet", "port", sMsg.SourcePort, "channel", sMsg.SourceChannel)
return errors.New("channel not found for the packet")
}

denomTrace := utils.DeriveIbcDenomTrace(channel.Counterparty.PortId, channel.Counterparty.ChannelId, receivedCoin.Denom)
denomTrace := utils.DeriveIbcDenomTrace(channel.PortId, channel.ChannelId, receivedCoin.Denom)
receivedCoin.Denom = denomTrace.IBCDenom()

if found && denomTrace.BaseDenom != zone.BaseDenom {
Expand Down Expand Up @@ -374,7 +385,7 @@ func (k *Keeper) HandleCompleteSend(ctx sdk.Context, msg sdk.Msg, memo string) e
case zone.IsDelegateAddress(sMsg.ToAddress) && zone.DepositAddress.Address == sMsg.FromAddress:
return k.handleSendToDelegate(ctx, zone, sMsg, memo)
default:
err = errors.New("unexpected completed send")
err = fmt.Errorf("unexpected completed send (2) from %s to %s (amount: %s)", sMsg.FromAddress, sMsg.ToAddress, sMsg.Amount)
k.Logger(ctx).Error(err.Error())
return err
}
Expand Down Expand Up @@ -758,9 +769,9 @@ func (k *Keeper) HandleFailedBankSend(ctx sdk.Context, msg sdk.Msg, memo string)
// MsgSend from deposit account to delegate account for deposit.
k.Logger(ctx).Error("MsgSend from deposit account to delegate account failed")
default:
err = errors.New("unexpected completed send")
err = fmt.Errorf("unexpected completed send (1) from %s to %s (amount: %s)", sMsg.FromAddress, sMsg.ToAddress, sMsg.Amount)
k.Logger(ctx).Error(err.Error())
return err
return nil
}

return nil
Expand Down
66 changes: 33 additions & 33 deletions x/interchainstaking/keeper/ibc_packet_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
var TestChannel = channeltypes.Channel{
State: channeltypes.OPEN,
Ordering: channeltypes.UNORDERED,
Counterparty: channeltypes.NewCounterparty("transfer", "channel-4"),
ConnectionHops: []string{"connection-2"},
Counterparty: channeltypes.NewCounterparty("transfer", "channel-0"),
ConnectionHops: []string{"connection-0"},
}

func (suite *KeeperTestSuite) TestHandleMsgTransferGood() {
Expand Down Expand Up @@ -1463,24 +1463,23 @@ func (suite *KeeperTestSuite) Test_v045Callback() {
{
name: "msg response with some data",
setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, []byte) {
sender := addressutils.GenerateAccAddressForTest()
senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender)
suite.Require().NoError(err)
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
if !found {
suite.Fail("unable to retrieve zone for test")
}
sender := zone.WithdrawalAddress.Address

quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel)

channel, cfound := quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.GetChannel(ctx, "transfer", "channel-0")
suite.Require().True(cfound)

ibcDenom := utils.DeriveIbcDenom(channel.Counterparty.PortId, channel.Counterparty.ChannelId, "denom")
err = quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(100))))
ibcDenom := utils.DeriveIbcDenom("transfer", "channel-0", zone.BaseDenom)
err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(100))))
suite.Require().NoError(err)

transferMsg := ibctransfertypes.MsgTransfer{
SourcePort: "transfer",
SourceChannel: "channel-0",
Token: sdk.NewCoin("denom", sdk.NewInt(100)),
Sender: senderAddr,
Token: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)),
Sender: sender,
Receiver: quicksilver.AccountKeeper.GetModuleAddress(icstypes.ModuleName).String(),
}
response := ibctransfertypes.MsgTransferResponse{
Expand All @@ -1491,16 +1490,17 @@ func (suite *KeeperTestSuite) Test_v045Callback() {
return []sdk.Msg{&transferMsg}, respBytes
},
assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool {
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
if !found {
suite.Fail("unable to retrieve zone for test")
}

txMacc := quicksilver.AccountKeeper.GetModuleAddress(icstypes.ModuleName)
feeMacc := quicksilver.AccountKeeper.GetModuleAddress(authtypes.FeeCollectorName)
txMaccBalance2 := quicksilver.BankKeeper.GetAllBalances(ctx, txMacc)
feeMaccBalance2 := quicksilver.BankKeeper.GetAllBalances(ctx, feeMacc)

// assert that ics module balance is now 100denom less than before HandleMsgTransfer()
channel, cfound := quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.GetChannel(ctx, "transfer", "channel-0")
suite.Require().True(cfound)

ibcDenom := utils.DeriveIbcDenom(channel.Counterparty.PortId, channel.Counterparty.ChannelId, "denom")
ibcDenom := utils.DeriveIbcDenom("transfer", "channel-0", zone.BaseDenom)
if txMaccBalance2.AmountOf(ibcDenom).Equal(sdk.ZeroInt()) && feeMaccBalance2.AmountOf(ibcDenom).Equal(sdk.NewInt(100)) {
return true
}
Expand Down Expand Up @@ -1576,7 +1576,7 @@ func (suite *KeeperTestSuite) Test_v045Callback() {
packet := channeltypes.Packet{
Data: packetBytes,
}

ctx = suite.chainA.GetContext()
suite.Require().NoError(quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, icatypes.ModuleCdc.MustMarshalJSON(&acknowledgement)))

suite.Require().True(test.assertStatements(ctx, quicksilver))
Expand All @@ -1593,24 +1593,23 @@ func (suite *KeeperTestSuite) Test_v046Callback() {
{
name: "msg response with some data",
setStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) ([]sdk.Msg, *codectypes.Any) {
// since SendPacket did not prefix the denomination, we must prefix denomination here
sender := addressutils.GenerateAccAddressForTest()
senderAddr, err := sdk.Bech32ifyAddressBytes("cosmos", sender)
suite.Require().NoError(err)
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
if !found {
suite.Fail("unable to retrieve zone for test")
}
sender := zone.WithdrawalAddress.Address

quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel)
channel, cfound := quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.GetChannel(ctx, "transfer", "channel-0")
suite.Require().True(cfound)

ibcDenom := utils.DeriveIbcDenom(channel.Counterparty.PortId, channel.Counterparty.ChannelId, "denom")
err = quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(100))))
ibcDenom := utils.DeriveIbcDenom("transfer", "channel-0", zone.BaseDenom)
err := quicksilver.BankKeeper.MintCoins(ctx, icstypes.ModuleName, sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(100))))
suite.Require().NoError(err)

transferMsg := ibctransfertypes.MsgTransfer{
SourcePort: "transfer",
SourceChannel: "channel-0",
Token: sdk.NewCoin("denom", sdk.NewInt(100)),
Sender: senderAddr,
Token: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(100)),
Sender: sender,
Receiver: quicksilver.AccountKeeper.GetModuleAddress(icstypes.ModuleName).String(),
}
response := ibctransfertypes.MsgTransferResponse{
Expand All @@ -1622,16 +1621,17 @@ func (suite *KeeperTestSuite) Test_v046Callback() {
return []sdk.Msg{&transferMsg}, anyResponse
},
assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool {
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
if !found {
suite.Fail("unable to retrieve zone for test")
}

txMacc := quicksilver.AccountKeeper.GetModuleAddress(icstypes.ModuleName)
feeMacc := quicksilver.AccountKeeper.GetModuleAddress(authtypes.FeeCollectorName)
txMaccBalance2 := quicksilver.BankKeeper.GetAllBalances(ctx, txMacc)
feeMaccBalance2 := quicksilver.BankKeeper.GetAllBalances(ctx, feeMacc)

// assert that ics module balance is now 100denom less than before HandleMsgTransfer()
channel, cfound := quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.GetChannel(ctx, "transfer", "channel-0")
suite.Require().True(cfound)

ibcDenom := utils.DeriveIbcDenom(channel.Counterparty.PortId, channel.Counterparty.ChannelId, "denom")
ibcDenom := utils.DeriveIbcDenom("transfer", "channel-0", zone.BaseDenom)
if txMaccBalance2.AmountOf(ibcDenom).Equal(sdk.ZeroInt()) && feeMaccBalance2.AmountOf(ibcDenom).Equal(sdk.NewInt(100)) {
return true
}
Expand Down