From 7143d092c4071d999e62b1d3e56cdcee608a626f Mon Sep 17 00:00:00 2001 From: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Date: Thu, 30 Apr 2020 08:37:02 -0400 Subject: [PATCH] x/ibc: add logs (#6104) --- x/ibc/04-channel/keeper/handshake.go | 9 ++++++++- x/ibc/05-port/keeper/keeper.go | 8 ++++++++ x/ibc/20-transfer/handler.go | 2 ++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/x/ibc/04-channel/keeper/handshake.go b/x/ibc/04-channel/keeper/handshake.go index 0c5817bb48..1c311cca8d 100644 --- a/x/ibc/04-channel/keeper/handshake.go +++ b/x/ibc/04-channel/keeper/handshake.go @@ -76,6 +76,7 @@ func (k Keeper) ChanOpenInit( k.SetNextSequenceSend(ctx, portID, channelID, 1) k.SetNextSequenceRecv(ctx, portID, channelID, 1) + k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: NONE -> INIT", portID, channelID) return capKey, nil } @@ -156,6 +157,7 @@ func (k Keeper) ChanOpenTry( k.SetNextSequenceSend(ctx, portID, channelID, 1) k.SetNextSequenceRecv(ctx, portID, channelID, 1) + k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: NONE -> TRYOPEN", portID, channelID) return capKey, nil } @@ -223,6 +225,7 @@ func (k Keeper) ChanOpenAck( channel.Version = counterpartyVersion k.SetChannel(ctx, portID, channelID, channel) + k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: INIT -> OPEN", portID, channelID) return nil } @@ -287,6 +290,7 @@ func (k Keeper) ChanOpenConfirm( channel.State = exported.OPEN k.SetChannel(ctx, portID, channelID, channel) + k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: TRYOPEN -> OPEN", portID, channelID) return nil } @@ -328,9 +332,10 @@ func (k Keeper) ChanCloseInit( ) } + k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: %s -> CLOSED", portID, channelID, channel.State) + channel.State = exported.CLOSED k.SetChannel(ctx, portID, channelID, channel) - k.Logger(ctx).Info("channel close initialized: portID (%s), channelID (%s)", portID, channelID) return nil } @@ -390,6 +395,8 @@ func (k Keeper) ChanCloseConfirm( return err } + k.Logger(ctx).Info("channel (port-id: %s, channel-id: %s) state updated: %s -> CLOSED", portID, channelID, channel.State) + channel.State = exported.CLOSED k.SetChannel(ctx, portID, channelID, channel) diff --git a/x/ibc/05-port/keeper/keeper.go b/x/ibc/05-port/keeper/keeper.go index cb0749e35c..39bf7dc9be 100644 --- a/x/ibc/05-port/keeper/keeper.go +++ b/x/ibc/05-port/keeper/keeper.go @@ -3,6 +3,8 @@ package keeper import ( "fmt" + "github.com/tendermint/tendermint/libs/log" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/capability" "github.com/cosmos/cosmos-sdk/x/ibc/05-port/types" @@ -22,6 +24,11 @@ func NewKeeper(sck capability.ScopedKeeper) Keeper { } } +// Logger returns a module-specific logger. +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s/%s", ibctypes.ModuleName, types.SubModuleName)) +} + // isBounded checks a given port ID is already bounded. func (k Keeper) isBound(ctx sdk.Context, portID string) bool { _, ok := k.scopedKeeper.GetCapability(ctx, types.PortPath(portID)) @@ -46,6 +53,7 @@ func (k *Keeper) BindPort(ctx sdk.Context, portID string) *capability.Capability panic(err.Error()) } + k.Logger(ctx).Info("port %s binded", portID) return key } diff --git a/x/ibc/20-transfer/handler.go b/x/ibc/20-transfer/handler.go index ee9f8582fb..63a31d9307 100644 --- a/x/ibc/20-transfer/handler.go +++ b/x/ibc/20-transfer/handler.go @@ -25,6 +25,8 @@ func handleMsgTransfer(ctx sdk.Context, k Keeper, msg MsgTransfer) (*sdk.Result, return nil, err } + k.Logger(ctx).Info("IBC transfer: %s from %s to %s", msg.Amount, msg.Sender, msg.Receiver) + ctx.EventManager().EmitEvent( sdk.NewEvent( sdk.EventTypeMessage,