Skip to content

Commit 087bc5d

Browse files
authored
improve 04-channel logging (#692)
## Description closes: #674 --- Before we can merge this PR, please make sure that all the following items have been checked off. If any of the checklist items are not applicable, please leave them but write a little note why. - [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [x] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md). - [x] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing) - [x] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`) - [x] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code). - [x] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md` - [x] Re-reviewed `Files changed` in the Github PR explorer - [x] Review `Codecov Report` in the comment section below once CI passes
1 parent 3ff0927 commit 087bc5d

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5353

5454
### Improvements
5555

56+
* (channel) [\#692](https://github.com/cosmos/ibc-go/pull/692) Minimize channel logging by only emitting the packet sequence, source port/channel, destination port/channel upon packet receives, acknowledgements and timeouts.
5657
* [\#383](https://github.com/cosmos/ibc-go/pull/383) Adds helper functions for merging and splitting middleware versions from the underlying app version.
5758
* (modules/core/05-port) [\#288](https://github.com/cosmos/ibc-go/issues/288) Making the 05-port keeper function IsBound public. The IsBound function checks if the provided portID is already binded to a module.
5859
* (channel) [\#644](https://github.com/cosmos/ibc-go/pull/644) Adds `GetChannelConnection` to the ChannelKeeper. This function returns the connectionID and connection state associated with a channel.

modules/core/04-channel/keeper/packet.go

+25-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package keeper
22

33
import (
44
"bytes"
5-
"fmt"
65
"time"
76

87
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -135,6 +134,7 @@ func (k Keeper) SendPacket(
135134
"dst_port", packet.GetDestPort(),
136135
"dst_channel", packet.GetDestChannel(),
137136
)
137+
138138
return nil
139139
}
140140

@@ -281,7 +281,14 @@ func (k Keeper) RecvPacket(
281281
}
282282

283283
// log that a packet has been received & executed
284-
k.Logger(ctx).Info("packet received", "packet", fmt.Sprintf("%v", packet))
284+
k.Logger(ctx).Info(
285+
"packet received",
286+
"sequence", packet.GetSequence(),
287+
"src_port", packet.GetSourcePort(),
288+
"src_channel", packet.GetSourceChannel(),
289+
"dst_port", packet.GetDestPort(),
290+
"dst_channel", packet.GetDestChannel(),
291+
)
285292

286293
// emit an event that the relayer can query for
287294
EmitRecvPacketEvent(ctx, packet, channel)
@@ -345,7 +352,14 @@ func (k Keeper) WriteAcknowledgement(
345352
)
346353

347354
// log that a packet acknowledgement has been written
348-
k.Logger(ctx).Info("acknowledged written", "packet", fmt.Sprintf("%v", packet))
355+
k.Logger(ctx).Info(
356+
"acknowledgement written",
357+
"sequence", packet.GetSequence,
358+
"src_port", packet.GetSourcePort(),
359+
"src_channel", packet.GetSourceChannel(),
360+
"dst_port", packet.GetDestPort(),
361+
"dst_channel", packet.GetDestChannel(),
362+
)
349363

350364
EmitWriteAcknowledgementEvent(ctx, packet, channel, acknowledgement)
351365

@@ -472,7 +486,14 @@ func (k Keeper) AcknowledgePacket(
472486
k.deletePacketCommitment(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
473487

474488
// log that a packet has been acknowledged
475-
k.Logger(ctx).Info("packet acknowledged", "packet", fmt.Sprintf("%v", packet))
489+
k.Logger(ctx).Info(
490+
"packet acknowledged",
491+
"sequence", packet.GetSequence,
492+
"src_port", packet.GetSourcePort(),
493+
"src_channel", packet.GetSourceChannel(),
494+
"dst_port", packet.GetDestPort(),
495+
"dst_channel", packet.GetDestChannel(),
496+
)
476497

477498
// emit an event marking that we have processed the acknowledgement
478499
EmitAcknowledgePacketEvent(ctx, packet, channel)

modules/core/04-channel/keeper/timeout.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package keeper
22

33
import (
44
"bytes"
5-
"fmt"
65

76
sdk "github.com/cosmos/cosmos-sdk/types"
87
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -157,7 +156,14 @@ func (k Keeper) TimeoutExecuted(
157156
k.SetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel(), channel)
158157
}
159158

160-
k.Logger(ctx).Info("packet timed-out", "packet", fmt.Sprintf("%v", packet))
159+
k.Logger(ctx).Info(
160+
"packet timed-out",
161+
"sequence", packet.GetSequence(),
162+
"src_port", packet.GetSourcePort(),
163+
"src_channel", packet.GetSourceChannel(),
164+
"dst_port", packet.GetDestPort(),
165+
"dst_channel", packet.GetDestChannel(),
166+
)
161167

162168
// emit an event marking that we have processed the timeout
163169
EmitTimeoutPacketEvent(ctx, packet, channel)

0 commit comments

Comments
 (0)