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

[WIP] Eureka forwarding #7588

Draft
wants to merge 16 commits into
base: feat/ibc-eureka
Choose a base branch
from
8 changes: 4 additions & 4 deletions modules/apps/transfer/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ func (k Keeper) GetAllDenomTraces(ctx sdk.Context) []internaltypes.DenomTrace {
return traces
}

// TokenFromCoin is a wrapper around tokenFromCoin for testing purposes.
func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) {
return k.tokenFromCoin(ctx, coin)
}
// // TokenFromCoin is a wrapper around tokenFromCoin for testing purposes.
// func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) {
// return k.tokenFromCoin(ctx, coin)
// }

// UnwindHops is a wrapper around unwindHops for testing purposes.
func (k Keeper) UnwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgTransfer, error) {
Expand Down
15 changes: 15 additions & 0 deletions modules/apps/transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
cmtbytes "github.com/cometbft/cometbft/libs/bytes"

"github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
typesv2 "github.com/cosmos/ibc-go/v9/modules/apps/transfer/v2/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
Expand Down Expand Up @@ -346,6 +347,20 @@ func (k Keeper) getAllForwardedPackets(ctx context.Context) []types.ForwardedPac
return packets
}

// TODO This should go in keeperV2, bu there's no storeService there.
// SetForwardedPacketSequenceAndDestinationChannel stores the sequence and the destinationChannel for a forwarded packet.
func (k Keeper) SetForwardedPacketSequenceAndDestinationChannel(ctx context.Context, portID, channelID string, sequence uint64, destChannel string) {
store := k.storeService.OpenKVStore(ctx)
bigEndianBz := sdk.Uint64ToBigEndian(sequence)
destChannelBz := []byte(destChannel)
if err := store.Set(typesv2.ForwardedPacketSequenceKey(portID, channelID), bigEndianBz); err != nil {
panic(err)
}
if err := store.Set(typesv2.ForwardedPacketDestinationChannelKey(portID, channelID), destChannelBz); err != nil {
panic(err)
}
}

// iterateForwardedPackets iterates over the forward packets in the store and performs a callback function.
func (k Keeper) iterateForwardedPackets(ctx context.Context, cb func(packet types.ForwardedPacket) bool) {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgT
msg.Forwarding.Hops = append(unwindHops[1:], msg.Forwarding.Hops...)
msg.Forwarding.Unwind = false

// Message is validate again, this would only fail if hops now exceeds maximum allowed.
// Message is validated again, this would only fail if hops now exceeds maximum allowed.
if err := msg.ValidateBasic(); err != nil {
return nil, err
}
Expand All @@ -98,7 +98,7 @@ func (k Keeper) getUnwindHops(ctx sdk.Context, coins sdk.Coins) ([]types.Hop, er
return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "coins cannot be empty")
}

token, err := k.tokenFromCoin(ctx, coins[0])
token, err := k.TokenFromCoin(ctx, coins[0])
if err != nil {
return nil, err
}
Expand All @@ -109,7 +109,7 @@ func (k Keeper) getUnwindHops(ctx sdk.Context, coins sdk.Coins) ([]types.Hop, er

unwindTrace := token.Denom.Trace
for _, coin := range coins[1:] {
token, err := k.tokenFromCoin(ctx, coin)
token, err := k.TokenFromCoin(ctx, coin)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (k Keeper) sendTransfer(
coin.Amount = k.BankKeeper.GetBalance(ctx, sender, coin.Denom).Amount
}

token, err := k.tokenFromCoin(ctx, coin)
token, err := k.TokenFromCoin(ctx, coin)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -385,6 +385,7 @@ func (k Keeper) refundPacketTokens(ctx context.Context, packet channeltypes.Pack

// EscrowCoin will send the given coin from the provided sender to the escrow address. It will also
// update the total escrowed amount by adding the escrowed coin's amount to the current total escrow.

func (k Keeper) EscrowCoin(ctx context.Context, sender, escrowAddress sdk.AccAddress, coin sdk.Coin) error {
if err := k.BankKeeper.SendCoins(ctx, sender, escrowAddress, sdk.NewCoins(coin)); err != nil {
// failure is expected for insufficient balances
Expand Down Expand Up @@ -419,7 +420,7 @@ func (k Keeper) UnescrowCoin(ctx context.Context, escrowAddress, receiver sdk.Ac
}

// tokenFromCoin constructs an IBC token given an SDK coin.
func (k Keeper) tokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) {
func (k Keeper) TokenFromCoin(ctx sdk.Context, coin sdk.Coin) (types.Token, error) {
// if the coin does not have an IBC denom, return as is
if !strings.HasPrefix(coin.Denom, "ibc/") {
return types.Token{
Expand Down
93 changes: 65 additions & 28 deletions modules/apps/transfer/types/packet.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions modules/apps/transfer/v2/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"


errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -14,6 +15,7 @@ import (
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"
"github.com/cosmos/ibc-go/v9/modules/core/api"

ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors"
)

Expand Down Expand Up @@ -66,6 +68,7 @@ func (im *IBCModule) OnRecvPacket(ctx context.Context, sourceChannel string, des
events.EmitOnRecvPacketEvent(ctx, data, ack, ackErr)
}()


data, ackErr = transfertypes.UnmarshalPacketData(payload.Value, payload.Version, payload.Encoding)
if ackErr != nil {
ack = channeltypes.NewErrorAcknowledgement(ackErr)
Expand Down Expand Up @@ -98,6 +101,7 @@ func (im *IBCModule) OnRecvPacket(ctx context.Context, sourceChannel string, des
return recvResult
}


func (im *IBCModule) OnTimeoutPacket(ctx context.Context, sourceChannel string, destinationChannel string, sequence uint64, payload types.Payload, relayer sdk.AccAddress) error {
data, err := transfertypes.UnmarshalPacketData(payload.Value, payload.Version, payload.Encoding)
if err != nil {
Expand Down
Loading
Loading