Skip to content

Commit 85faf55

Browse files
authored
imp: remove unnecessary defer func statements (#3304)
1 parent 6be595a commit 85faf55

File tree

4 files changed

+61
-91
lines changed

4 files changed

+61
-91
lines changed

modules/core/02-client/keeper/proposal.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ func (k Keeper) ClientUpdateProposal(ctx sdk.Context, p *types.ClientUpdatePropo
5050

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

53-
defer func() {
54-
telemetry.IncrCounterWithLabels(
55-
[]string{"ibc", "client", "update"},
56-
1,
57-
[]metrics.Label{
58-
telemetry.NewLabel(types.LabelClientType, substituteClientState.ClientType()),
59-
telemetry.NewLabel(types.LabelClientID, p.SubjectClientId),
60-
telemetry.NewLabel(types.LabelUpdateType, "proposal"),
61-
},
62-
)
63-
}()
53+
defer telemetry.IncrCounterWithLabels(
54+
[]string{"ibc", "client", "update"},
55+
1,
56+
[]metrics.Label{
57+
telemetry.NewLabel(types.LabelClientType, substituteClientState.ClientType()),
58+
telemetry.NewLabel(types.LabelClientID, p.SubjectClientId),
59+
telemetry.NewLabel(types.LabelUpdateType, "proposal"),
60+
},
61+
)
6462

6563
// emitting events in the keeper for proposal updates to clients
6664
emitUpdateClientProposalEvent(ctx, p.SubjectClientId, substituteClientState.ClientType())

modules/core/03-connection/keeper/handshake.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ func (k Keeper) ConnOpenInit(
5353

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

56-
defer func() {
57-
telemetry.IncrCounter(1, "ibc", "connection", "open-init")
58-
}()
56+
defer telemetry.IncrCounter(1, "ibc", "connection", "open-init")
5957

6058
emitConnectionOpenInitEvent(ctx, connectionID, clientID, counterparty)
6159

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

153-
defer func() {
154-
telemetry.IncrCounter(1, "ibc", "connection", "open-try")
155-
}()
151+
defer telemetry.IncrCounter(1, "ibc", "connection", "open-try")
156152

157153
emitConnectionOpenTryEvent(ctx, connectionID, clientID, counterparty)
158154

@@ -244,9 +240,7 @@ func (k Keeper) ConnOpenAck(
244240

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

247-
defer func() {
248-
telemetry.IncrCounter(1, "ibc", "connection", "open-ack")
249-
}()
243+
defer telemetry.IncrCounter(1, "ibc", "connection", "open-ack")
250244

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

303-
defer func() {
304-
telemetry.IncrCounter(1, "ibc", "connection", "open-confirm")
305-
}()
297+
defer telemetry.IncrCounter(1, "ibc", "connection", "open-confirm")
306298

307299
emitConnectionOpenConfirmEvent(ctx, connectionID, connection)
308300

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

+6-18
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ func (k Keeper) WriteOpenInitChannel(
9595

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

98-
defer func() {
99-
telemetry.IncrCounter(1, "ibc", "channel", "open-init")
100-
}()
98+
defer telemetry.IncrCounter(1, "ibc", "channel", "open-init")
10199

102100
emitChannelOpenInitEvent(ctx, portID, channelID, channel)
103101
}
@@ -208,9 +206,7 @@ func (k Keeper) WriteOpenTryChannel(
208206

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

211-
defer func() {
212-
telemetry.IncrCounter(1, "ibc", "channel", "open-try")
213-
}()
209+
defer telemetry.IncrCounter(1, "ibc", "channel", "open-try")
214210

215211
emitChannelOpenTryEvent(ctx, portID, channelID, channel)
216212
}
@@ -293,9 +289,7 @@ func (k Keeper) WriteOpenAckChannel(
293289

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

296-
defer func() {
297-
telemetry.IncrCounter(1, "ibc", "channel", "open-ack")
298-
}()
292+
defer telemetry.IncrCounter(1, "ibc", "channel", "open-ack")
299293

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

376-
defer func() {
377-
telemetry.IncrCounter(1, "ibc", "channel", "open-confirm")
378-
}()
370+
defer telemetry.IncrCounter(1, "ibc", "channel", "open-confirm")
379371

380372
emitChannelOpenConfirmEvent(ctx, portID, channelID, channel)
381373
}
@@ -429,9 +421,7 @@ func (k Keeper) ChanCloseInit(
429421

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

432-
defer func() {
433-
telemetry.IncrCounter(1, "ibc", "channel", "close-init")
434-
}()
424+
defer telemetry.IncrCounter(1, "ibc", "channel", "close-init")
435425

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

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

497-
defer func() {
498-
telemetry.IncrCounter(1, "ibc", "channel", "close-confirm")
499-
}()
487+
defer telemetry.IncrCounter(1, "ibc", "channel", "close-confirm")
500488

501489
channel.State = types.CLOSED
502490
k.SetChannel(ctx, portID, channelID, channel)

modules/core/keeper/msg_server.go

+42-50
Original file line numberDiff line numberDiff line change
@@ -469,18 +469,16 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke
469469
}
470470
}
471471

472-
defer func() {
473-
telemetry.IncrCounterWithLabels(
474-
[]string{"tx", "msg", "ibc", channeltypes.EventTypeRecvPacket},
475-
1,
476-
[]metrics.Label{
477-
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
478-
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
479-
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
480-
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
481-
},
482-
)
483-
}()
472+
defer telemetry.IncrCounterWithLabels(
473+
[]string{"tx", "msg", "ibc", channeltypes.EventTypeRecvPacket},
474+
1,
475+
[]metrics.Label{
476+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
477+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
478+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
479+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
480+
},
481+
)
484482

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

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

544-
defer func() {
545-
telemetry.IncrCounterWithLabels(
546-
[]string{"ibc", "timeout", "packet"},
547-
1,
548-
[]metrics.Label{
549-
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
550-
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
551-
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
552-
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
553-
telemetry.NewLabel(coretypes.LabelTimeoutType, "height"),
554-
},
555-
)
556-
}()
542+
defer telemetry.IncrCounterWithLabels(
543+
[]string{"ibc", "timeout", "packet"},
544+
1,
545+
[]metrics.Label{
546+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
547+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
548+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
549+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
550+
telemetry.NewLabel(coretypes.LabelTimeoutType, "height"),
551+
},
552+
)
557553

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

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

620-
defer func() {
621-
telemetry.IncrCounterWithLabels(
622-
[]string{"ibc", "timeout", "packet"},
623-
1,
624-
[]metrics.Label{
625-
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
626-
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
627-
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
628-
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
629-
telemetry.NewLabel(coretypes.LabelTimeoutType, "channel-closed"),
630-
},
631-
)
632-
}()
616+
defer telemetry.IncrCounterWithLabels(
617+
[]string{"ibc", "timeout", "packet"},
618+
1,
619+
[]metrics.Label{
620+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
621+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
622+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
623+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
624+
telemetry.NewLabel(coretypes.LabelTimeoutType, "channel-closed"),
625+
},
626+
)
633627

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

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

688-
defer func() {
689-
telemetry.IncrCounterWithLabels(
690-
[]string{"tx", "msg", "ibc", channeltypes.EventTypeAcknowledgePacket},
691-
1,
692-
[]metrics.Label{
693-
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
694-
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
695-
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
696-
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
697-
},
698-
)
699-
}()
682+
defer telemetry.IncrCounterWithLabels(
683+
[]string{"tx", "msg", "ibc", channeltypes.EventTypeAcknowledgePacket},
684+
1,
685+
[]metrics.Label{
686+
telemetry.NewLabel(coretypes.LabelSourcePort, msg.Packet.SourcePort),
687+
telemetry.NewLabel(coretypes.LabelSourceChannel, msg.Packet.SourceChannel),
688+
telemetry.NewLabel(coretypes.LabelDestinationPort, msg.Packet.DestinationPort),
689+
telemetry.NewLabel(coretypes.LabelDestinationChannel, msg.Packet.DestinationChannel),
690+
},
691+
)
700692

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

0 commit comments

Comments
 (0)