Skip to content

Commit

Permalink
chore: remove packet-server. (#7481)
Browse files Browse the repository at this point in the history
* chore: remove packet-server.

* chore: remove commented out test funcs.
  • Loading branch information
DimitrisJim authored Oct 18, 2024
1 parent bad6098 commit 0a3b4be
Show file tree
Hide file tree
Showing 18 changed files with 16 additions and 1,765 deletions.
8 changes: 0 additions & 8 deletions modules/apps/callbacks/testing/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ import (
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v9/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v9/modules/core/keeper"
packetserverkeeper "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper"
solomachine "github.com/cosmos/ibc-go/v9/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v9/modules/light-clients/07-tendermint"
ibcmock "github.com/cosmos/ibc-go/v9/testing/mock"
Expand Down Expand Up @@ -194,7 +193,6 @@ type SimApp struct {
GroupKeeper groupkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
CircuitKeeper circuitkeeper.Keeper
PacketServer *packetserverkeeper.Keeper

// mock contract keeper used for testing
MockContractKeeper *ContractKeeper
Expand Down Expand Up @@ -376,7 +374,6 @@ func NewSimApp(
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.GetSubspace(ibcexported.ModuleName), app.UpgradeKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.PacketServer = packetserverkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[ibcexported.StoreKey]), app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper)

// NOTE: The mock ContractKeeper is only created for testing.
// Real applications should not use the mock ContractKeeper
Expand Down Expand Up @@ -1005,11 +1002,6 @@ func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

// GetPacketServer implements the TestingApp interface
func (app *SimApp) GetPacketServer() *packetserverkeeper.Keeper {
return app.PacketServer
}

// GetTxConfig implements the TestingApp interface.
func (app *SimApp) GetTxConfig() client.TxConfig {
return app.txConfig
Expand Down
28 changes: 0 additions & 28 deletions modules/core/04-channel/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import (
connectiontypes "github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
packetserver "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
)

var _ porttypes.ICS4Wrapper = (*Keeper)(nil)
Expand Down Expand Up @@ -826,29 +824,3 @@ func (k *Keeper) PruneAcknowledgements(ctx context.Context, portID, channelID st

return totalPruned, totalRemaining, nil
}

// GetV2Channel returns a version 2 channel for the given port and channel ID
// by converting the v1 channel into a version 2 channel
func (k *Keeper) GetV2Channel(ctx context.Context, portID, channelID string) (packetserver.Channel, bool) {
channel, ok := k.GetChannel(ctx, portID, channelID)
if !ok {
return packetserver.Channel{}, false
}
// Do not allow channel to be converted into a version 2 counterparty
// if the channel is not OPEN or if it is ORDERED
if channel.State != types.OPEN || channel.Ordering == types.ORDERED {
return packetserver.Channel{}, false
}
connection, ok := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
if !ok {
return packetserver.Channel{}, false
}
merklePathPrefix := commitmentv2types.NewMerklePath(connection.Counterparty.Prefix.KeyPrefix, []byte(""))

channelv2 := packetserver.Channel{
CounterpartyChannelId: channel.Counterparty.ChannelId,
ClientId: connection.ClientId,
MerklePathPrefix: merklePathPrefix,
}
return channelv2, true
}
77 changes: 0 additions & 77 deletions modules/core/04-channel/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
transfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
commitmentv2types "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types/v2"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
"github.com/cosmos/ibc-go/v9/modules/core/exported"
packetservertypes "github.com/cosmos/ibc-go/v9/modules/core/packet-server/types"
ibctesting "github.com/cosmos/ibc-go/v9/testing"
ibcmock "github.com/cosmos/ibc-go/v9/testing/mock"
)
Expand Down Expand Up @@ -549,81 +547,6 @@ func (suite *KeeperTestSuite) TestUnsetParams() {
})
}

func (suite *KeeperTestSuite) TestGetV2Channel() {
var path *ibctesting.Path

testCases := []struct {
name string
malleate func()
expPass bool
}{
{
"success",
func() {},
true,
},
{
"failure: channel not found",
func() {
path.EndpointA.ChannelID = ""
},
false,
},
{
"failure: channel not OPEN",
func() {
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.State = types.TRYOPEN })
},
false,
},
{
"failure: channel is ORDERED",
func() {
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.Ordering = types.ORDERED })
},
false,
},
{
"failure: connection not found",
func() {
path.EndpointA.UpdateChannel(func(channel *types.Channel) { channel.ConnectionHops = []string{ibctesting.InvalidID} })
},
false,
},
}

for _, tc := range testCases {
tc := tc

suite.Run(tc.name, func() {
suite.SetupTest() // reset

// create a previously existing path on chainA to change the identifiers
// between the path between chainA and chainB
path1 := ibctesting.NewPath(suite.chainA, suite.chainC)
path1.Setup()

path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.Setup()

tc.malleate()

channel, found := suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper.GetV2Channel(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

if tc.expPass {
suite.Require().True(found)

merklePath := commitmentv2types.NewMerklePath([]byte("ibc"), []byte(""))
expChannel := packetservertypes.NewChannel(path.EndpointA.ClientID, path.EndpointB.ChannelID, merklePath)
suite.Require().Equal(channel, expChannel)
} else {
suite.Require().False(found)
suite.Require().Equal(channel, packetservertypes.Channel{})
}
})
}
}

func (suite *KeeperTestSuite) TestPruneAcknowledgements() {
var (
path *ibctesting.Path
Expand Down
28 changes: 12 additions & 16 deletions modules/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ import (
portkeeper "github.com/cosmos/ibc-go/v9/modules/core/05-port/keeper"
porttypes "github.com/cosmos/ibc-go/v9/modules/core/05-port/types"
"github.com/cosmos/ibc-go/v9/modules/core/api"
packetserver "github.com/cosmos/ibc-go/v9/modules/core/packet-server/keeper"
"github.com/cosmos/ibc-go/v9/modules/core/types"
)

// Keeper defines each ICS keeper for IBC
type Keeper struct {
ClientKeeper *clientkeeper.Keeper
ConnectionKeeper *connectionkeeper.Keeper
ChannelKeeper *channelkeeper.Keeper
ChannelKeeperV2 *channelkeeperv2.Keeper
PacketServerKeeper *packetserver.Keeper
PortKeeper *portkeeper.Keeper
ClientKeeper *clientkeeper.Keeper
ConnectionKeeper *connectionkeeper.Keeper
ChannelKeeper *channelkeeper.Keeper
ChannelKeeperV2 *channelkeeperv2.Keeper
PortKeeper *portkeeper.Keeper

cdc codec.BinaryCodec

Expand All @@ -53,18 +51,16 @@ func NewKeeper(
connectionKeeper := connectionkeeper.NewKeeper(cdc, storeService, paramSpace, clientKeeper)
portKeeper := portkeeper.NewKeeper()
channelKeeper := channelkeeper.NewKeeper(cdc, storeService, clientKeeper, connectionKeeper)
packetKeeper := packetserver.NewKeeper(cdc, storeService, channelKeeper, clientKeeper)
channelKeeperV2 := channelkeeperv2.NewKeeper(cdc, storeService, clientKeeper, channelKeeper, connectionKeeper)

return &Keeper{
cdc: cdc,
ClientKeeper: clientKeeper,
ConnectionKeeper: connectionKeeper,
ChannelKeeper: channelKeeper,
ChannelKeeperV2: channelKeeperV2,
PacketServerKeeper: packetKeeper,
PortKeeper: portKeeper,
authority: authority,
cdc: cdc,
ClientKeeper: clientKeeper,
ConnectionKeeper: connectionKeeper,
ChannelKeeper: channelKeeper,
ChannelKeeperV2: channelKeeperV2,
PortKeeper: portKeeper,
authority: authority,
}
}

Expand Down
44 changes: 4 additions & 40 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"context"
"errors"
"fmt"

errorsmod "cosmossdk.io/errors"

Expand Down Expand Up @@ -391,7 +390,6 @@ func (k *Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Ms

// RecvPacket defines a rpc handler method for MsgRecvPacket.
func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacket) (*channeltypes.MsgRecvPacketResponse, error) {
var packetHandler PacketHandler
ctx := sdk.UnwrapSDKContext(goCtx)

relayer, err := sdk.AccAddressFromBech32(msg.Signer)
Expand All @@ -400,12 +398,6 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack
return nil, errorsmod.Wrap(err, "Invalid address for msg Signer")
}

packetHandler, err = k.getPacketHandlerAndModule(msg.Packet.ProtocolVersion)
if err != nil {
ctx.Logger().Error("receive packet failed", "port-id", msg.Packet.DestinationPort, "channel-id", msg.Packet.DestinationChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
return nil, errorsmod.Wrap(err, "could not retrieve module from port-id")
}

// Retrieve callbacks from router
cbs, ok := k.PortKeeper.Route(msg.Packet.DestinationPort)
if !ok {
Expand All @@ -418,7 +410,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack
// If the packet was already received, perform a no-op
// Use a cached context to prevent accidental state changes
cacheCtx, writeFn := ctx.CacheContext()
channelVersion, err := packetHandler.RecvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight)
channelVersion, err := k.ChannelKeeper.RecvPacket(cacheCtx, msg.Packet, msg.ProofCommitment, msg.ProofHeight)

switch err {
case nil:
Expand Down Expand Up @@ -449,7 +441,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack
// NOTE: IBC applications modules may call the WriteAcknowledgement asynchronously if the
// acknowledgement is nil.
if ack != nil {
if err := packetHandler.WriteAcknowledgement(ctx, msg.Packet, ack); err != nil {
if err := k.ChannelKeeper.WriteAcknowledgement(ctx, msg.Packet, ack); err != nil {
return nil, err
}
}
Expand All @@ -463,7 +455,6 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack

// Timeout defines a rpc handler method for MsgTimeout.
func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*channeltypes.MsgTimeoutResponse, error) {
var packetHandler PacketHandler
ctx := sdk.UnwrapSDKContext(goCtx)

relayer, err := sdk.AccAddressFromBech32(msg.Signer)
Expand All @@ -472,12 +463,6 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*
return nil, errorsmod.Wrap(err, "Invalid address for msg Signer")
}

packetHandler, err = k.getPacketHandlerAndModule(msg.Packet.ProtocolVersion)
if err != nil {
ctx.Logger().Error("timeout failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
return nil, errorsmod.Wrap(err, "could not retrieve module from port-id")
}

// Retrieve callbacks from router
cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort)
if !ok {
Expand All @@ -490,7 +475,7 @@ func (k *Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*
// If the timeout was already received, perform a no-op
// Use a cached context to prevent accidental state changes
cacheCtx, writeFn := ctx.CacheContext()
channelVersion, err := packetHandler.TimeoutPacket(cacheCtx, msg.Packet, msg.ProofUnreceived, msg.ProofHeight, msg.NextSequenceRecv)
channelVersion, err := k.ChannelKeeper.TimeoutPacket(cacheCtx, msg.Packet, msg.ProofUnreceived, msg.ProofHeight, msg.NextSequenceRecv)

switch err {
case nil:
Expand Down Expand Up @@ -572,7 +557,6 @@ func (k *Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTime

// Acknowledgement defines a rpc handler method for MsgAcknowledgement.
func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAcknowledgement) (*channeltypes.MsgAcknowledgementResponse, error) {
var packetHandler PacketHandler
ctx := sdk.UnwrapSDKContext(goCtx)

relayer, err := sdk.AccAddressFromBech32(msg.Signer)
Expand All @@ -581,12 +565,6 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck
return nil, errorsmod.Wrap(err, "Invalid address for msg Signer")
}

packetHandler, err = k.getPacketHandlerAndModule(msg.Packet.ProtocolVersion)
if err != nil {
ctx.Logger().Error("acknowledgement failed", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
return nil, errorsmod.Wrap(err, "could not retrieve module from port-id")
}

// Retrieve callbacks from router
cbs, ok := k.PortKeeper.Route(msg.Packet.SourcePort)
if !ok {
Expand All @@ -599,7 +577,7 @@ func (k *Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAck
// If the acknowledgement was already received, perform a no-op
// Use a cached context to prevent accidental state changes
cacheCtx, writeFn := ctx.CacheContext()
channelVersion, err := packetHandler.AcknowledgePacket(cacheCtx, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight)
channelVersion, err := k.ChannelKeeper.AcknowledgePacket(cacheCtx, msg.Packet, msg.Acknowledgement, msg.ProofAcked, msg.ProofHeight)

switch err {
case nil:
Expand Down Expand Up @@ -998,17 +976,3 @@ func (k *Keeper) UpdateChannelParams(goCtx context.Context, msg *channeltypes.Ms

return &channeltypes.MsgUpdateParamsResponse{}, nil
}

// getPacketHandlerAndModule returns the appropriate packet handler
// given the protocol version. An error is returned if the protocol
// version is not supported.
func (k *Keeper) getPacketHandlerAndModule(protocolVersion channeltypes.IBCVersion) (PacketHandler, error) {
switch protocolVersion {
case channeltypes.IBC_VERSION_UNSPECIFIED, channeltypes.IBC_VERSION_1:
return k.ChannelKeeper, nil
case channeltypes.IBC_VERSION_2:
return k.PacketServerKeeper, nil
default:
return nil, fmt.Errorf("unsupported protocol %s", protocolVersion)
}
}
Loading

0 comments on commit 0a3b4be

Please sign in to comment.