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

chore: remove unused ics29 keeper funcs #1044

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 0 additions & 4 deletions modules/apps/29-fee/keeper/escrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,6 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
suite.chainA.GetSimApp().IBCFeeKeeper.DistributePacketFees(suite.chainA.GetContext(), forwardRelayer, reverseRelayer, []types.PacketFee{packetFee, packetFee})

if tc.expPass {
// there should no longer be a fee in escrow for this packet
found := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeeInEscrow(suite.chainA.GetContext(), packetID)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed as DeleteFeesInEscrow() is called at the ibc_module.go level here and here for timeout.

suite.Require().False(found)

// check if the reverse relayer is paid
hasBalance := suite.chainA.GetSimApp().BankKeeper.HasBalance(suite.chainA.GetContext(), reverseRelayer, fee.AckFee[0].Add(fee.AckFee[0]))
suite.Require().True(hasBalance)
Expand Down
64 changes: 0 additions & 64 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,26 +230,6 @@ func (k Keeper) DeleteForwardRelayerAddress(ctx sdk.Context, packetId channeltyp
store.Delete(key)
}

// Stores a Fee for a given packet in state
func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.IdentifiedPacketFee) {
store := ctx.KVStore(k.storeKey)
bz := k.MustMarshalFee(&fee)
store.Set(types.KeyFeeInEscrow(fee.PacketId), bz)
}

// Gets a Fee for a given packet
func (k Keeper) GetFeeInEscrow(ctx sdk.Context, packetId channeltypes.PacketId) (types.IdentifiedPacketFee, bool) {
store := ctx.KVStore(k.storeKey)
key := types.KeyFeeInEscrow(packetId)
bz := store.Get(key)
if bz == nil {
return types.IdentifiedPacketFee{}, false
}
fee := k.MustUnmarshalFee(bz)

return fee, true
}

// GetFeesInEscrow returns all escrowed packet fees for a given packetID
func (k Keeper) GetFeesInEscrow(ctx sdk.Context, packetID channeltypes.PacketId) (types.PacketFees, bool) {
store := ctx.KVStore(k.storeKey)
Expand Down Expand Up @@ -299,36 +279,6 @@ func (k Keeper) IteratePacketFeesInEscrow(ctx sdk.Context, portID, channelID str
}
}

// IterateChannelFeesInEscrow iterates over all the fees on the given channel currently escrowed and calls the provided callback
// if the callback returns true, then iteration is stopped.
func (k Keeper) IterateChannelFeesInEscrow(ctx sdk.Context, portID, channelID string, cb func(identifiedFee types.IdentifiedPacketFee) (stop bool)) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.KeyFeeInEscrowChannelPrefix(portID, channelID))

defer iterator.Close()
for ; iterator.Valid(); iterator.Next() {
identifiedFee := k.MustUnmarshalFee(iterator.Value())
if cb(identifiedFee) {
break
}
}
}

// Deletes the fee associated with the given packetId
func (k Keeper) DeleteFeeInEscrow(ctx sdk.Context, packetId channeltypes.PacketId) {
store := ctx.KVStore(k.storeKey)
key := types.KeyFeeInEscrow(packetId)
store.Delete(key)
}

// HasFeeInEscrow returns true if there is a Fee still to be escrowed for a given packet
func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId channeltypes.PacketId) bool {
store := ctx.KVStore(k.storeKey)
key := types.KeyFeeInEscrow(packetId)

return store.Has(key)
}

// GetAllIdentifiedPacketFees returns a list of all IdentifiedPacketFees that are stored in state
func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []types.IdentifiedPacketFees {
store := ctx.KVStore(k.storeKey)
Expand All @@ -355,20 +305,6 @@ func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []types.IdentifiedPa
return identifiedFees
}

// MustMarshalFee attempts to encode a Fee object and returns the
// raw encoded bytes. It panics on error.
func (k Keeper) MustMarshalFee(fee *types.IdentifiedPacketFee) []byte {
return k.cdc.MustMarshal(fee)
}

// MustUnmarshalFee attempts to decode and return a Fee object from
// raw encoded bytes. It panics on error.
func (k Keeper) MustUnmarshalFee(bz []byte) types.IdentifiedPacketFee {
var fee types.IdentifiedPacketFee
k.cdc.MustUnmarshal(bz, &fee)
return fee
}

// MustMarshalFees attempts to encode a Fee object and returns the
// raw encoded bytes. It panics on error.
func (k Keeper) MustMarshalFees(fees types.PacketFees) []byte {
Expand Down
34 changes: 16 additions & 18 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -66,30 +67,27 @@ func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}

func (suite *KeeperTestSuite) TestFeeInEscrow() {
func (suite *KeeperTestSuite) TestFeesInEscrow() {
suite.coordinator.Setup(suite.path)

fee := types.Fee{RecvFee: defaultReceiveFee, AckFee: defaultAckFee, TimeoutFee: defaultTimeoutFee}
// escrow five fees for packet sequence 1
packetID := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 1)
fee := types.NewFee(defaultReceiveFee, defaultAckFee, defaultTimeoutFee)

// set some fees
for i := 1; i < 6; i++ {
packetId := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, uint64(i))
fee := types.NewIdentifiedPacketFee(packetId, fee, suite.chainA.SenderAccount.GetAddress().String(), []string{})
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeInEscrow(suite.chainA.GetContext(), fee)
packetFee := types.NewPacketFee(fee, suite.chainA.SenderAccount.GetAddress().String(), nil)
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), packetID, packetFee)
}

// delete 1 fee
packetId := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, suite.path.EndpointA.ChannelConfig.PortID, 3)
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeeInEscrow(suite.chainA.GetContext(), packetId)

// iterate over remaining fees
arr := []int64{}
expectedArr := []int64{1, 2, 4, 5}
suite.chainA.GetSimApp().IBCFeeKeeper.IterateChannelFeesInEscrow(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID, func(identifiedFee types.IdentifiedPacketFee) (stop bool) {
arr = append(arr, int64(identifiedFee.PacketId.Sequence))
return false
})
suite.Require().Equal(expectedArr, arr, "did not retrieve expected fees during iteration")
// retrieve the fees in escrow and assert the length of PacketFees
feesInEscrow, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeesInEscrow(suite.chainA.GetContext(), packetID)
suite.Require().True(found)
suite.Require().Len(feesInEscrow.PacketFees, 5, fmt.Sprintf("expected length 5, but got %d", len(feesInEscrow.PacketFees)))

// delete fees for packet sequence 1
suite.chainA.GetSimApp().IBCFeeKeeper.DeleteFeesInEscrow(suite.chainA.GetContext(), packetID)
hasFeesInEscrow := suite.chainA.GetSimApp().IBCFeeKeeper.HasFeesInEscrow(suite.chainA.GetContext(), packetID)
suite.Require().False(hasFeesInEscrow)
}

func (suite *KeeperTestSuite) TestDisableAllChannels() {
Expand Down
4 changes: 4 additions & 0 deletions modules/apps/29-fee/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ package types
// 29-fee events
const (
EventTypeIncentivizedPacket = "incentivized_ibc_packet"

AttributeKeyRecvFee = "recv_fee"
AttributeKeyAckFee = "ack_fee"
AttributeKeyTimeoutFee = "timeout_fee"
)
17 changes: 0 additions & 17 deletions modules/apps/29-fee/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,11 @@ const (
// CounterpartyRelayerAddressKeyPrefix is the key prefix for relayer address mapping
CounterpartyRelayerAddressKeyPrefix = "relayerAddress"

// FeeInEscrowPrefix is the key prefix for fee in escrow mapping
FeeInEscrowPrefix = "feeInEscrow"

// FeesInEscrowPrefix is the key prefix for fee in escrow mapping
FeesInEscrowPrefix = "feesInEscrow"

// ForwardRelayerPrefix is the key prefix for forward relayer addresses stored in state for async acknowledgements
ForwardRelayerPrefix = "forwardRelayer"

AttributeKeyRecvFee = "recv_fee"
AttributeKeyAckFee = "ack_fee"
AttributeKeyTimeoutFee = "timeout_fee"
)

// KeyFeeEnabled returns the key that stores a flag to determine if fee logic should
Expand Down Expand Up @@ -81,11 +74,6 @@ func KeyForwardRelayerAddress(packetId channeltypes.PacketId) []byte {
return []byte(fmt.Sprintf("%s/%s/%s/%d/", ForwardRelayerPrefix, packetId.PortId, packetId.ChannelId, packetId.Sequence))
}

// KeyFeeInEscrow returns the key for escrowed fees
func KeyFeeInEscrow(packetID channeltypes.PacketId) []byte {
return []byte(fmt.Sprintf("%s/%d", KeyFeeInEscrowChannelPrefix(packetID.PortId, packetID.ChannelId), packetID.Sequence))
}

// KeyFeesInEscrow returns the key for escrowed fees
func KeyFeesInEscrow(packetID channeltypes.PacketId) []byte {
return []byte(fmt.Sprintf("%s/%d", KeyFeesInEscrowChannelPrefix(packetID.PortId, packetID.ChannelId), packetID.Sequence))
Expand All @@ -109,11 +97,6 @@ func ParseKeyFeesInEscrow(key string) (channeltypes.PacketId, error) {
return packetID, nil
}

// KeyFeeInEscrowChannelPrefix returns the key prefix for escrowed fees on the given channel
func KeyFeeInEscrowChannelPrefix(portID, channelID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s/packet", FeeInEscrowPrefix, portID, channelID))
}

// KeyFeesInEscrowChannelPrefix returns the key prefix for escrowed fees on the given channel
func KeyFeesInEscrowChannelPrefix(portID, channelID string) []byte {
return []byte(fmt.Sprintf("%s/%s/%s", FeesInEscrowPrefix, portID, channelID))
Expand Down
5 changes: 5 additions & 0 deletions modules/apps/29-fee/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func TestKeyCounterpartyRelayer(t *testing.T) {
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s", types.CounterpartyRelayerAddressKeyPrefix, relayerAddress, channelID))
}

func TestKeyFeesInEscrow(t *testing.T) {
key := types.KeyFeesInEscrow(validPacketID)
require.Equal(t, string(key), fmt.Sprintf("%s/%s/%s/%d", types.FeesInEscrowPrefix, ibctesting.MockFeePort, ibctesting.FirstChannelID, 1))
}

func TestParseKeyFeeEnabled(t *testing.T) {
testCases := []struct {
name string
Expand Down