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

remove unnecessary defer func statements #3304

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions modules/core/02-client/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo

k.Logger(ctx).Info("client updated after governance proposal passed", "client-id", p.SubjectClientId)

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"ibc", "client", "update"},
1,
[]metrics.Label{
telemetry.NewLabel(types.LabelClientType, substituteClientState.ClientType()),
telemetry.NewLabel(types.LabelClientID, p.SubjectClientId),
telemetry.NewLabel(types.LabelUpdateType, "proposal"),
},
)
}()
defer telemetry.IncrCounterWithLabels(
[]string{"ibc", "client", "update"},
1,
[]metrics.Label{
telemetry.NewLabel(types.LabelClientType, substituteClientState.ClientType()),
telemetry.NewLabel(types.LabelClientID, p.SubjectClientId),
telemetry.NewLabel(types.LabelUpdateType, "proposal"),
},
)

// emitting events in the keeper for proposal updates to clients
emitUpdateClientProposalEvent(ctx, p.SubjectClientId, substituteClientState.ClientType())
Expand Down
16 changes: 4 additions & 12 deletions modules/core/03-connection/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ func (k Keeper) ConnOpenInit(

k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", "NONE", "new-state", "INIT")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-init")
}()
defer telemetry.IncrCounter(1, "ibc", "connection", "open-init")

emitConnectionOpenInitEvent(ctx, connectionID, clientID, counterparty)

Expand Down Expand Up @@ -150,9 +148,7 @@ func (k Keeper) ConnOpenTry(
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", "NONE", "new-state", "TRYOPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-try")
}()
defer telemetry.IncrCounter(1, "ibc", "connection", "open-try")

emitConnectionOpenTryEvent(ctx, connectionID, clientID, counterparty)

Expand Down Expand Up @@ -244,9 +240,7 @@ func (k Keeper) ConnOpenAck(

k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", "INIT", "new-state", "OPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-ack")
}()
defer telemetry.IncrCounter(1, "ibc", "connection", "open-ack")

// Update connection state to Open
connection.State = types.OPEN
Expand Down Expand Up @@ -300,9 +294,7 @@ func (k Keeper) ConnOpenConfirm(
k.SetConnection(ctx, connectionID, connection)
k.Logger(ctx).Info("connection state updated", "connection-id", connectionID, "previous-state", "TRYOPEN", "new-state", "OPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "connection", "open-confirm")
}()
defer telemetry.IncrCounter(1, "ibc", "connection", "open-confirm")

emitConnectionOpenConfirmEvent(ctx, connectionID, connection)

Expand Down
24 changes: 6 additions & 18 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ func (k Keeper) WriteOpenInitChannel(

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", "NONE", "new-state", "INIT")

defer func() {
telemetry.IncrCounter(1, "ibc", "channel", "open-init")
}()
defer telemetry.IncrCounter(1, "ibc", "channel", "open-init")

emitChannelOpenInitEvent(ctx, portID, channelID, channel)
}
Expand Down Expand Up @@ -208,9 +206,7 @@ func (k Keeper) WriteOpenTryChannel(

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", "NONE", "new-state", "TRYOPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "channel", "open-try")
}()
defer telemetry.IncrCounter(1, "ibc", "channel", "open-try")

emitChannelOpenTryEvent(ctx, portID, channelID, channel)
}
Expand Down Expand Up @@ -293,9 +289,7 @@ func (k Keeper) WriteOpenAckChannel(

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", channel.State.String(), "new-state", "OPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "channel", "open-ack")
}()
defer telemetry.IncrCounter(1, "ibc", "channel", "open-ack")

emitChannelOpenAckEvent(ctx, portID, channelID, channel)
}
Expand Down Expand Up @@ -373,9 +367,7 @@ func (k Keeper) WriteOpenConfirmChannel(
k.SetChannel(ctx, portID, channelID, channel)
k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", "TRYOPEN", "new-state", "OPEN")

defer func() {
telemetry.IncrCounter(1, "ibc", "channel", "open-confirm")
}()
defer telemetry.IncrCounter(1, "ibc", "channel", "open-confirm")

emitChannelOpenConfirmEvent(ctx, portID, channelID, channel)
}
Expand Down Expand Up @@ -429,9 +421,7 @@ func (k Keeper) ChanCloseInit(

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", channel.State.String(), "new-state", "CLOSED")

defer func() {
telemetry.IncrCounter(1, "ibc", "channel", "close-init")
}()
defer telemetry.IncrCounter(1, "ibc", "channel", "close-init")

channel.State = types.CLOSED
k.SetChannel(ctx, portID, channelID, channel)
Expand Down Expand Up @@ -494,9 +484,7 @@ func (k Keeper) ChanCloseConfirm(

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", channel.State.String(), "new-state", "CLOSED")

defer func() {
telemetry.IncrCounter(1, "ibc", "channel", "close-confirm")
}()
defer telemetry.IncrCounter(1, "ibc", "channel", "close-confirm")

channel.State = types.CLOSED
k.SetChannel(ctx, portID, channelID, channel)
Expand Down
92 changes: 42 additions & 50 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,18 +469,16 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke
}
}

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"tx", "msg", "ibc", channeltypes.EventTypeRecvPacket},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
},
)
}()
defer telemetry.IncrCounterWithLabels(
[]string{"tx", "msg", "ibc", channeltypes.EventTypeRecvPacket},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
},
)

ctx.Logger().Info("receive packet callback succeeded", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "result", channeltypes.SUCCESS.String())

Expand Down Expand Up @@ -541,19 +539,17 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c
return nil, err
}

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"ibc", "timeout", "packet"},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
telemetry.NewLabel(coretypes.LabelTimeoutType, "height"),
},
)
}()
defer telemetry.IncrCounterWithLabels(
[]string{"ibc", "timeout", "packet"},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
telemetry.NewLabel(coretypes.LabelTimeoutType, "height"),
},
)

ctx.Logger().Info("timeout packet callback succeeded", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "result", channeltypes.SUCCESS.String())

Expand Down Expand Up @@ -617,19 +613,17 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo
return nil, err
}

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"ibc", "timeout", "packet"},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
telemetry.NewLabel(coretypes.LabelTimeoutType, "channel-closed"),
},
)
}()
defer telemetry.IncrCounterWithLabels(
[]string{"ibc", "timeout", "packet"},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
telemetry.NewLabel(coretypes.LabelTimeoutType, "channel-closed"),
},
)

ctx.Logger().Info("timeout on close callback succeeded", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "result", channeltypes.SUCCESS.String())

Expand Down Expand Up @@ -685,18 +679,16 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn
return nil, errorsmod.Wrap(err, "acknowledge packet callback failed")
}

defer func() {
telemetry.IncrCounterWithLabels(
[]string{"tx", "msg", "ibc", channeltypes.EventTypeAcknowledgePacket},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
},
)
}()
defer telemetry.IncrCounterWithLabels(
[]string{"tx", "msg", "ibc", channeltypes.EventTypeAcknowledgePacket},
1,
[]metrics.Label{
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
},
)

ctx.Logger().Info("acknowledgement succeeded", "port-id", msg.Packet.SourcePort, "channel-id", msg.Packet.SourceChannel, "result", channeltypes.SUCCESS.String())

Expand Down