From f45c13d86d0e714693e44a1c30ce45247d4b872b Mon Sep 17 00:00:00 2001 From: GnaD Date: Thu, 16 Mar 2023 14:49:29 +0700 Subject: [PATCH] remove unnecessary defer func statements --- modules/core/02-client/keeper/proposal.go | 20 ++-- .../core/03-connection/keeper/handshake.go | 16 +--- modules/core/04-channel/keeper/handshake.go | 24 ++--- modules/core/keeper/msg_server.go | 92 +++++++++---------- 4 files changed, 61 insertions(+), 91 deletions(-) diff --git a/modules/core/02-client/keeper/proposal.go b/modules/core/02-client/keeper/proposal.go index 1dc7edd33e0..2cb0787be47 100644 --- a/modules/core/02-client/keeper/proposal.go +++ b/modules/core/02-client/keeper/proposal.go @@ -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()) diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index 523296194d3..912c38feb4d 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index cfca1efd00d..fe3fff7b171 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -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) } @@ -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) } @@ -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) } @@ -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) } @@ -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) @@ -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) diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 2bf694e1e2f..15eb5411580 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -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()) @@ -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()) @@ -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()) @@ -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())