x/ibc: add logs (#6104)

This commit is contained in:
Federico Kunze 2020-04-30 08:37:02 -04:00 committed by GitHub
parent 2879c0702c
commit 7143d092c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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,