Skip to content

Commit e99e666

Browse files
committed
multi: update linter, fix new issues
1 parent 9eef428 commit e99e666

File tree

21 files changed

+453
-441
lines changed

21 files changed

+453
-441
lines changed

.golangci.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,26 @@ linters:
195195
# The linter is too aggressive and doesn't add much value since reviewers
196196
# will also catch magic numbers that make sense to extract.
197197
- gomnd
198+
- mnd
198199

199-
# Some of the tests cannot be parallelized. On the other hand, we don't
200-
# gain much performance with this check so we disable it for now until
201-
# unit tests become our CI bottleneck.
200+
# Some of the tests cannot be parallelized. On the other hand, we don't
201+
# gain much performance with this check so we disable it for now until
202+
# unit tests become our CI bottleneck.
202203
- paralleltest
203204

205+
# New linters that we haven't had time to address yet.
206+
- testifylint
207+
- perfsprint
208+
- inamedparam
209+
- copyloopvar
210+
- tagalign
211+
- protogetter
212+
- revive
213+
- depguard
214+
- gosmopolitan
215+
- intrange
216+
217+
204218
issues:
205219
# Only show newly introduced problems.
206220
new-from-rev: 8c66353e4c02329abdacb5a8df29998035ec2e24

channeldb/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
23822382
methodsMu.Unlock()
23832383

23842384
err := fn()
2385-
require.NoErrorf(t, err, fmt.Sprintf(name))
2385+
require.NoErrorf(t, err, name)
23862386
}
23872387
})
23882388
}

contractcourt/channel_arbitrator.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,9 +1982,11 @@ func (c *ChannelArbitrator) isPreimageAvailable(hash lntypes.Hash) (bool,
19821982
// have the incoming contest resolver decide that we don't want to
19831983
// settle this invoice.
19841984
invoice, err := c.cfg.Registry.LookupInvoice(context.Background(), hash)
1985-
switch err {
1986-
case nil:
1987-
case invoices.ErrInvoiceNotFound, invoices.ErrNoInvoicesCreated:
1985+
switch {
1986+
case err == nil:
1987+
case errors.Is(err, invoices.ErrInvoiceNotFound) ||
1988+
errors.Is(err, invoices.ErrNoInvoicesCreated):
1989+
19881990
return false, nil
19891991
default:
19901992
return false, err

contractcourt/mock_htlcnotifier_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ type mockHTLCNotifier struct {
1010
}
1111

1212
func (m *mockHTLCNotifier) NotifyFinalHtlcEvent(key models.CircuitKey,
13-
info channeldb.FinalHtlcInfo) { //nolint:whitespace
13+
info channeldb.FinalHtlcInfo) {
14+
1415
}

graph/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func (b *Builder) handleNetworkUpdate(vb *ValidationBarrier,
681681
update.err <- err
682682

683683
case IsError(err, ErrParentValidationFailed):
684-
update.err <- newErrf(ErrIgnored, err.Error())
684+
update.err <- newErrf(ErrIgnored, err.Error()) //nolint
685685

686686
default:
687687
log.Warnf("unexpected error during validation "+

htlcswitch/link.go

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,10 +1154,11 @@ func (l *channelLink) htlcManager() {
11541154
// be updated when the close transaction is
11551155
// ready to avoid that we go down before
11561156
// storing the transaction in the db.
1157-
l.fail(
1157+
l.failf(
1158+
//nolint:lll
11581159
LinkFailureError{
11591160
code: ErrSyncError,
1160-
FailureAction: LinkFailureForceClose, //nolint:lll
1161+
FailureAction: LinkFailureForceClose,
11611162
},
11621163
"unable to synchronize channel "+
11631164
"states: %v", err,
@@ -1195,7 +1196,7 @@ func (l *channelLink) htlcManager() {
11951196
default:
11961197
}
11971198

1198-
l.fail(
1199+
l.failf(
11991200
LinkFailureError{
12001201
code: ErrRecoveryError,
12011202
FailureAction: LinkFailureForceNone,
@@ -1259,14 +1260,14 @@ func (l *channelLink) htlcManager() {
12591260
// If the duplicate keystone error was encountered, we'll fail
12601261
// without sending an Error message to the peer.
12611262
case ErrDuplicateKeystone:
1262-
l.fail(LinkFailureError{code: ErrCircuitError},
1263+
l.failf(LinkFailureError{code: ErrCircuitError},
12631264
"temporary circuit error: %v", err)
12641265
return
12651266

12661267
// A non-nil error was encountered, send an Error message to
12671268
// the peer.
12681269
default:
1269-
l.fail(LinkFailureError{code: ErrInternalError},
1270+
l.failf(LinkFailureError{code: ErrInternalError},
12701271
"unable to resolve fwd pkgs: %v", err)
12711272
return
12721273
}
@@ -1405,7 +1406,7 @@ func (l *channelLink) htlcManager() {
14051406
}
14061407

14071408
case <-l.cfg.PendingCommitTicker.Ticks():
1408-
l.fail(
1409+
l.failf(
14091410
LinkFailureError{
14101411
code: ErrRemoteUnresponsive,
14111412
FailureAction: LinkFailureDisconnect,
@@ -1438,19 +1439,19 @@ func (l *channelLink) htlcManager() {
14381439
// If the duplicate keystone error was encountered,
14391440
// fail back gracefully.
14401441
case ErrDuplicateKeystone:
1441-
l.fail(LinkFailureError{code: ErrCircuitError},
1442-
fmt.Sprintf("process hodl queue: "+
1443-
"temporary circuit error: %v",
1444-
err,
1445-
),
1442+
l.failf(LinkFailureError{
1443+
code: ErrCircuitError,
1444+
}, "process hodl queue: "+
1445+
"temporary circuit error: %v",
1446+
err,
14461447
)
14471448

14481449
// Send an Error message to the peer.
14491450
default:
1450-
l.fail(LinkFailureError{code: ErrInternalError},
1451-
fmt.Sprintf("process hodl queue: "+
1452-
"unable to update commitment:"+
1453-
" %v", err),
1451+
l.failf(LinkFailureError{
1452+
code: ErrInternalError,
1453+
}, "process hodl queue: unable to update "+
1454+
"commitment: %v", err,
14541455
)
14551456
}
14561457

@@ -1960,7 +1961,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
19601961
// handle message ordering due to concurrency choices.
19611962
// An issue has been filed to address this here:
19621963
// https://github.com/lightningnetwork/lnd/issues/8393
1963-
l.fail(
1964+
l.failf(
19641965
LinkFailureError{
19651966
code: ErrInvalidUpdate,
19661967
FailureAction: LinkFailureDisconnect,
@@ -1979,7 +1980,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
19791980
// where we are a relaying node (as the blinding point will
19801981
// be in the payload when we're the introduction node).
19811982
if msg.BlindingPoint.IsSome() && l.cfg.DisallowRouteBlinding {
1982-
l.fail(LinkFailureError{code: ErrInvalidUpdate},
1983+
l.failf(LinkFailureError{code: ErrInvalidUpdate},
19831984
"blinding point included when route blinding "+
19841985
"is disabled")
19851986

@@ -1991,7 +1992,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
19911992
// without sending a revoke. This would mean that the switch
19921993
// check would only occur later.
19931994
if l.isOverexposedWithHtlc(msg, true) {
1994-
l.fail(LinkFailureError{code: ErrInternalError},
1995+
l.failf(LinkFailureError{code: ErrInternalError},
19951996
"peer sent us an HTLC that exceeded our max "+
19961997
"fee exposure")
19971998

@@ -2003,7 +2004,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
20032004
// "settle" list in the event that we know the preimage.
20042005
index, err := l.channel.ReceiveHTLC(msg)
20052006
if err != nil {
2006-
l.fail(LinkFailureError{code: ErrInvalidUpdate},
2007+
l.failf(LinkFailureError{code: ErrInvalidUpdate},
20072008
"unable to handle upstream add HTLC: %v", err)
20082009
return
20092010
}
@@ -2029,15 +2030,15 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
20292030
}
20302031

20312032
if !lockedin {
2032-
l.fail(
2033+
l.failf(
20332034
LinkFailureError{code: ErrInvalidUpdate},
20342035
"unable to handle upstream settle",
20352036
)
20362037
return
20372038
}
20382039

20392040
if err := l.channel.ReceiveHTLCSettle(pre, idx); err != nil {
2040-
l.fail(
2041+
l.failf(
20412042
LinkFailureError{
20422043
code: ErrInvalidUpdate,
20432044
FailureAction: LinkFailureForceClose,
@@ -2126,7 +2127,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
21262127
// message to the usual HTLC fail message.
21272128
err := l.channel.ReceiveFailHTLC(msg.ID, b.Bytes())
21282129
if err != nil {
2129-
l.fail(LinkFailureError{code: ErrInvalidUpdate},
2130+
l.failf(LinkFailureError{code: ErrInvalidUpdate},
21302131
"unable to handle upstream fail HTLC: %v", err)
21312132
return
21322133
}
@@ -2164,7 +2165,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
21642165
idx := msg.ID
21652166
err := l.channel.ReceiveFailHTLC(idx, msg.Reason[:])
21662167
if err != nil {
2167-
l.fail(LinkFailureError{code: ErrInvalidUpdate},
2168+
l.failf(LinkFailureError{code: ErrInvalidUpdate},
21682169
"unable to handle upstream fail HTLC: %v", err)
21692170
return
21702171
}
@@ -2183,7 +2184,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
21832184
l.uncommittedPreimages...,
21842185
)
21852186
if err != nil {
2186-
l.fail(
2187+
l.failf(
21872188
LinkFailureError{code: ErrInternalError},
21882189
"unable to add preimages=%v to cache: %v",
21892190
l.uncommittedPreimages, err,
@@ -2219,7 +2220,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
22192220
case *lnwallet.InvalidHtlcSigError:
22202221
sendData = []byte(err.Error())
22212222
}
2222-
l.fail(
2223+
l.failf(
22232224
LinkFailureError{
22242225
code: ErrInvalidCommitment,
22252226
FailureAction: LinkFailureForceClose,
@@ -2248,7 +2249,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
22482249
// NOTE: We do not trigger a force close because this
22492250
// could resolve itself in case our db was just busy
22502251
// not accepting new transactions.
2251-
l.fail(
2252+
l.failf(
22522253
LinkFailureError{
22532254
code: ErrInternalError,
22542255
Warning: true,
@@ -2336,7 +2337,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
23362337
ReceiveRevocation(msg)
23372338
if err != nil {
23382339
// TODO(halseth): force close?
2339-
l.fail(
2340+
l.failf(
23402341
LinkFailureError{
23412342
code: ErrInvalidRevocation,
23422343
FailureAction: LinkFailureDisconnect,
@@ -2376,9 +2377,9 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
23762377
&chanID, state.RemoteCommitment.CommitHeight-1,
23772378
)
23782379
if err != nil {
2379-
l.fail(LinkFailureError{code: ErrInternalError},
2380-
"unable to queue breach backup: %v",
2381-
err)
2380+
l.failf(LinkFailureError{
2381+
code: ErrInternalError,
2382+
}, "unable to queue breach backup: %v", err)
23822383
return
23832384
}
23842385
}
@@ -2425,7 +2426,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
24252426
// indicates something is wrong with our channel state.
24262427
l.log.Errorf("Unable to determine if fee threshold " +
24272428
"exceeded")
2428-
l.fail(LinkFailureError{code: ErrInternalError},
2429+
l.failf(LinkFailureError{code: ErrInternalError},
24292430
"error calculating fee exposure: %v", err)
24302431

24312432
return
@@ -2434,15 +2435,15 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
24342435
if isDust {
24352436
// The proposed fee-rate makes us exceed the fee
24362437
// threshold.
2437-
l.fail(LinkFailureError{code: ErrInternalError},
2438+
l.failf(LinkFailureError{code: ErrInternalError},
24382439
"fee threshold exceeded: %v", err)
24392440
return
24402441
}
24412442

24422443
// We received fee update from peer. If we are the initiator we
24432444
// will fail the channel, if not we will apply the update.
24442445
if err := l.channel.ReceiveUpdateFee(fee); err != nil {
2445-
l.fail(LinkFailureError{code: ErrInvalidUpdate},
2446+
l.failf(LinkFailureError{code: ErrInvalidUpdate},
24462447
"error receiving fee update: %v", err)
24472448
return
24482449
}
@@ -2461,7 +2462,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
24612462
// Error received from remote, MUST fail channel, but should
24622463
// only print the contents of the error message if all
24632464
// characters are printable ASCII.
2464-
l.fail(
2465+
l.failf(
24652466
LinkFailureError{
24662467
code: ErrRemoteError,
24672468

@@ -2550,14 +2551,14 @@ func (l *channelLink) updateCommitTxOrFail() bool {
25502551
// A duplicate keystone error should be resolved and is not fatal, so
25512552
// we won't send an Error message to the peer.
25522553
case ErrDuplicateKeystone:
2553-
l.fail(LinkFailureError{code: ErrCircuitError},
2554+
l.failf(LinkFailureError{code: ErrCircuitError},
25542555
"temporary circuit error: %v", err)
25552556
return false
25562557

25572558
// Any other error is treated results in an Error message being sent to
25582559
// the peer.
25592560
default:
2560-
l.fail(LinkFailureError{code: ErrInternalError},
2561+
l.failf(LinkFailureError{code: ErrInternalError},
25612562
"unable to update commitment: %v", err)
25622563
return false
25632564
}
@@ -3440,7 +3441,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
34403441
fwdPkg.ID(), decodeReqs,
34413442
)
34423443
if sphinxErr != nil {
3443-
l.fail(LinkFailureError{code: ErrInternalError},
3444+
l.failf(LinkFailureError{code: ErrInternalError},
34443445
"unable to decode hop iterators: %v", sphinxErr)
34453446
return
34463447
}
@@ -3599,9 +3600,9 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
35993600
pd, obfuscator, fwdInfo, heightNow, pld,
36003601
)
36013602
if err != nil {
3602-
l.fail(LinkFailureError{code: ErrInternalError},
3603-
err.Error(),
3604-
)
3603+
l.failf(LinkFailureError{
3604+
code: ErrInternalError,
3605+
}, err.Error()) //nolint
36053606

36063607
return
36073608
}
@@ -3745,7 +3746,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
37453746
if fwdPkg.State == channeldb.FwdStateLockedIn {
37463747
err := l.channel.SetFwdFilter(fwdPkg.Height, fwdPkg.FwdFilter)
37473748
if err != nil {
3748-
l.fail(LinkFailureError{code: ErrInternalError},
3749+
l.failf(LinkFailureError{code: ErrInternalError},
37493750
"unable to set fwd filter: %v", err)
37503751
return
37513752
}
@@ -4077,13 +4078,14 @@ func (l *channelLink) sendMalformedHTLCError(htlcIndex uint64,
40774078
})
40784079
}
40794080

4080-
// fail is a function which is used to encapsulate the action necessary for
4081+
// failf is a function which is used to encapsulate the action necessary for
40814082
// properly failing the link. It takes a LinkFailureError, which will be passed
40824083
// to the OnChannelFailure closure, in order for it to determine if we should
40834084
// force close the channel, and if we should send an error message to the
40844085
// remote peer.
4085-
func (l *channelLink) fail(linkErr LinkFailureError,
4086-
format string, a ...interface{}) {
4086+
func (l *channelLink) failf(linkErr LinkFailureError, format string,
4087+
a ...interface{}) {
4088+
40874089
reason := fmt.Errorf(format, a...)
40884090

40894091
// Return if we have already notified about a failure.

htlcswitch/link_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4879,7 +4879,8 @@ func (h *persistentLinkHarness) restartLink(
48794879
FetchLastChannelUpdate: mockGetChanUpdateMessage,
48804880
PreimageCache: pCache,
48814881
OnChannelFailure: func(lnwire.ChannelID,
4882-
lnwire.ShortChannelID, LinkFailureError) { // nolint:whitespace
4882+
lnwire.ShortChannelID, LinkFailureError) {
4883+
48834884
},
48844885
UpdateContractSignals: func(*contractcourt.ContractSignals) error {
48854886
return nil
@@ -5834,7 +5835,7 @@ func TestChannelLinkFail(t *testing.T) {
58345835
c.cfg.Peer.(*mockPeer).disconnected = true
58355836
},
58365837
func(*testing.T, *Switch, *channelLink,
5837-
*lnwallet.LightningChannel) { //nolint:whitespace,lll
5838+
*lnwallet.LightningChannel) {
58385839

58395840
// Should fail at startup.
58405841
},
@@ -5854,7 +5855,7 @@ func TestChannelLinkFail(t *testing.T) {
58545855
c.channel.State().Packager = pkg
58555856
},
58565857
func(*testing.T, *Switch, *channelLink,
5857-
*lnwallet.LightningChannel) { //nolint:whitespace,lll
5858+
*lnwallet.LightningChannel) {
58585859

58595860
// Should fail at startup.
58605861
},

0 commit comments

Comments
 (0)