From 8d83778314eeffb2f6f684908321df8f74e0452e Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 15 Feb 2022 11:16:19 +0100 Subject: [PATCH 1/3] tools+golangci-lint: enable fixed version of whitespace linter --- .golangci.yml | 4 ---- tools/go.mod | 3 +++ tools/go.sum | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d8d79cbfe..3949f123e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -83,10 +83,6 @@ linters: # Causes stack overflow, see https://github.com/polyfloyd/go-errorlint/issues/19. - errorlint - # Has an issue (https://github.com/ultraware/whitespace/issues/6) but will - # want to enable this in the future. - - whitespace - # Deprecated linters. See https://golangci-lint.run/usage/linters/. - interfacer - golint diff --git a/tools/go.mod b/tools/go.mod index a8e8fa570..7389fb925 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -11,3 +11,6 @@ require ( github.com/rinchsan/gosimports v0.1.5 github.com/stephens2424/writerset v1.0.2 // indirect ) + +// Can be removed once this version is included in golangci-lint. +replace github.com/ultraware/whitespace => github.com/ultraware/whitespace v0.0.5 diff --git a/tools/go.sum b/tools/go.sum index 5e3975424..e26483566 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -859,8 +859,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ultraware/funlen v0.0.3 h1:5ylVWm8wsNwH5aWo9438pwvsK0QiqVuUrt9bn7S/iLA= github.com/ultraware/funlen v0.0.3/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA= -github.com/ultraware/whitespace v0.0.4 h1:If7Va4cM03mpgrNH9k49/VOicWpGoG70XPBFFODYDsg= -github.com/ultraware/whitespace v0.0.4/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA= +github.com/ultraware/whitespace v0.0.5 h1:hh+/cpIcopyMYbZNVov9iSxvJU3OYQg78Sfaqzi/CzI= +github.com/ultraware/whitespace v0.0.5/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/uudashr/gocognit v1.0.5 h1:rrSex7oHr3/pPLQ0xoWq108XMU8s678FJcQ+aSfOHa4= From 13f187046b2bd51e72372718b3f4334f8a74fae3 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 15 Feb 2022 16:25:54 +0100 Subject: [PATCH 2/3] multi: fix issues reported by whitespace linter --- channeldb/invoices.go | 1 - channeldb/migration24/migration.go | 4 ++-- channeldb/payments_test.go | 8 ++++---- contractcourt/briefcase_test.go | 1 + contractcourt/channel_arbitrator_test.go | 3 +++ contractcourt/htlc_success_resolver_test.go | 3 +++ contractcourt/htlc_timeout_resolver_test.go | 1 + htlcswitch/mailbox_test.go | 3 +++ lnrpc/walletrpc/psbt.go | 1 - lntest/itest/lnd_funding_test.go | 1 + routing/pathfind_test.go | 4 ++-- routing/payment_lifecycle.go | 1 - routing/router_test.go | 12 ++++++------ rpcserver.go | 1 - 14 files changed, 26 insertions(+), 18 deletions(-) diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 8dffd6ed9..eb63d34e0 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -1463,7 +1463,6 @@ func (d *DB) InvoicesSettledSince(sinceSettleIndex uint64) ([]Invoice, error) { seqNo, indexValue := invoiceCursor.Next() for ; seqNo != nil && bytes.Compare(seqNo, startIndex[:]) > 0; seqNo, indexValue = invoiceCursor.Next() { - // Depending on the length of the index value, this may // or may not be an AMP invoice, so we'll extract the // invoice value into two components: the invoice num, diff --git a/channeldb/migration24/migration.go b/channeldb/migration24/migration.go index 1110ea360..287955dbf 100644 --- a/channeldb/migration24/migration.go +++ b/channeldb/migration24/migration.go @@ -81,8 +81,8 @@ func MigrateFwdPkgCleanup(tx kvdb.RwTx) error { // Otherwise, wipe all the forwarding packages. if err := fwdPkgBkt.DeleteNestedBucket( - sourceBytes[:]); err != nil { - + sourceBytes[:], + ); err != nil { return err } } diff --git a/channeldb/payments_test.go b/channeldb/payments_test.go index 0ed3bf03f..33371bb34 100644 --- a/channeldb/payments_test.go +++ b/channeldb/payments_test.go @@ -615,9 +615,8 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) { test := test t.Run(test.name, func(t *testing.T) { - err := kvdb.Update(db, - func(tx walletdb.ReadWriteTx) error { - + err := kvdb.Update( + db, func(tx walletdb.ReadWriteTx) error { var seqNrBytes [8]byte byteOrder.PutUint64( seqNrBytes[:], test.sequenceNumber, @@ -627,7 +626,8 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) { tx, test.paymentHash, seqNrBytes[:], ) return err - }, func() {}) + }, func() {}, + ) require.Equal(t, test.expectedErr, err) }) } diff --git a/contractcourt/briefcase_test.go b/contractcourt/briefcase_test.go index 29d7edfbe..01424fc0f 100644 --- a/contractcourt/briefcase_test.go +++ b/contractcourt/briefcase_test.go @@ -179,6 +179,7 @@ func newTestBoltArbLog(chainhash chainhash.Hash, testArbCfg := ChannelArbitratorConfig{ PutResolverReport: func(_ kvdb.RwTx, _ *channeldb.ResolverReport) error { + return nil }, } diff --git a/contractcourt/channel_arbitrator_test.go b/contractcourt/channel_arbitrator_test.go index 5738fbc34..bd9461739 100644 --- a/contractcourt/channel_arbitrator_test.go +++ b/contractcourt/channel_arbitrator_test.go @@ -383,6 +383,7 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog, }, MarkChannelClosed: func(*channeldb.ChannelCloseSummary, ...channeldb.ChannelStatus) error { + return nil }, IsPendingClose: false, @@ -1635,6 +1636,7 @@ func TestChannelArbitratorCommitFailure(t *testing.T) { chanArb.cfg.MarkChannelClosed = func( *channeldb.ChannelCloseSummary, ...channeldb.ChannelStatus) error { + close(closed) return nil } @@ -2169,6 +2171,7 @@ func TestRemoteCloseInitiator(t *testing.T) { // about setting of channel status. mockMarkClosed := func(_ *channeldb.ChannelCloseSummary, statuses ...channeldb.ChannelStatus) error { + for _, status := range statuses { err := alice.State().ApplyChanStatus(status) if err != nil { diff --git a/contractcourt/htlc_success_resolver_test.go b/contractcourt/htlc_success_resolver_test.go index a3a9c3cb4..6ba03f3c2 100644 --- a/contractcourt/htlc_success_resolver_test.go +++ b/contractcourt/htlc_success_resolver_test.go @@ -62,6 +62,7 @@ func newHtlcResolverTestContext(t *testing.T, Sweeper: newMockSweeper(), IncubateOutputs: func(wire.OutPoint, *lnwallet.OutgoingHtlcResolution, *lnwallet.IncomingHtlcResolution, uint32) error { + return nil }, DeliverResolutionMsg: func(msgs ...ResolutionMsg) error { @@ -86,6 +87,7 @@ func newHtlcResolverTestContext(t *testing.T, // this so set nolint directive. checkpointFunc := func(c ContractResolver, // nolint r ...*channeldb.ResolverReport) error { + return testCtx.checkpoint(c, r...) } @@ -253,6 +255,7 @@ func TestHtlcSuccessSecondStageResolution(t *testing.T) { // to resolve our htlc. preCheckpoint: func(ctx *htlcResolverTestContext, _ bool) error { + ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{ SpendingTx: sweepTx, SpenderTxHash: &sweepHash, diff --git a/contractcourt/htlc_timeout_resolver_test.go b/contractcourt/htlc_timeout_resolver_test.go index 6968a9b59..a48e138c3 100644 --- a/contractcourt/htlc_timeout_resolver_test.go +++ b/contractcourt/htlc_timeout_resolver_test.go @@ -861,6 +861,7 @@ func TestHtlcTimeoutSecondStageRemoteSpend(t *testing.T) { // success transcation. preCheckpoint: func(ctx *htlcResolverTestContext, _ bool) error { + ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{ SpendingTx: remoteSuccessTx, SpenderTxHash: &successTxid, diff --git a/htlcswitch/mailbox_test.go b/htlcswitch/mailbox_test.go index 86c8faa6d..32a90e11b 100644 --- a/htlcswitch/mailbox_test.go +++ b/htlcswitch/mailbox_test.go @@ -208,6 +208,7 @@ func newMailboxContext(t *testing.T, startTime time.Time, ctx.mailbox = newMemoryMailBox(&mailBoxConfig{ fetchUpdate: func(sid lnwire.ShortChannelID) ( *lnwire.ChannelUpdate, error) { + return &lnwire.ChannelUpdate{ ShortChannelID: sid, }, nil @@ -671,12 +672,14 @@ func TestMailOrchestrator(t *testing.T) { mo := newMailOrchestrator(&mailOrchConfig{ fetchUpdate: func(sid lnwire.ShortChannelID) ( *lnwire.ChannelUpdate, error) { + return &lnwire.ChannelUpdate{ ShortChannelID: sid, }, nil }, forwardPackets: func(_ chan struct{}, pkts ...*htlcPacket) error { + return nil }, clock: clock.NewTestClock(time.Now()), diff --git a/lnrpc/walletrpc/psbt.go b/lnrpc/walletrpc/psbt.go index 40deedd08..0724f6ce1 100644 --- a/lnrpc/walletrpc/psbt.go +++ b/lnrpc/walletrpc/psbt.go @@ -70,7 +70,6 @@ func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) ( if err := w.ReleaseOutput( LndInternalLockID, op, ); err != nil { - log.Errorf("could not release the "+ "lock on %v: %v", op, err) } diff --git a/lntest/itest/lnd_funding_test.go b/lntest/itest/lnd_funding_test.go index 0c23ecd47..531d8d2a5 100644 --- a/lntest/itest/lnd_funding_test.go +++ b/lntest/itest/lnd_funding_test.go @@ -297,6 +297,7 @@ func testUnconfirmedChannelFunding(net *lntest.NetworkHarness, t *harnessTest) { // response to a channel balance RPC. checkChannelBalance := func(node *lntest.HarnessNode, local, remote, pendingLocal, pendingRemote btcutil.Amount) { + expectedResponse := &lnrpc.ChannelBalanceResponse{ LocalBalance: &lnrpc.Amount{ Sat: uint64(local), diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index 981639148..0e3b92fc2 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -614,8 +614,8 @@ func createTestGraphFromChannels(useCache bool, testChannels []*testChannel, for _, testChannel := range testChannels { for _, node := range []*testChannelEnd{ - testChannel.Node1, testChannel.Node2} { - + testChannel.Node1, testChannel.Node2, + } { _, exists := aliasMap[node.Alias] if !exists { var features *lnwire.FeatureVector diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index 2816ebd67..e30b5a785 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -779,7 +779,6 @@ func (p *shardHandler) handleSendError(attempt *channeldb.HTLCAttemptInfo, if err := p.router.cfg.Control.Fail( p.identifier, *reason, ); err != nil { - log.Errorf("unable to report failure to control "+ "tower: %v", err) diff --git a/routing/router_test.go b/routing/router_test.go index e5c4da601..c9778bcc2 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -670,7 +670,6 @@ func TestSendPaymentErrorFeeInsufficientPrivateEdge(t *testing.T) { copy(preImage[:], bytes.Repeat([]byte{9}, 32)) ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcherOld).setPaymentResult( func(firstHop lnwire.ShortChannelID) ([32]byte, error) { - if firstHop != roasbeefSongoku || errorReturned { return preImage, nil } @@ -685,7 +684,8 @@ func TestSendPaymentErrorFeeInsufficientPrivateEdge(t *testing.T) { Update: errChanUpdate, }, 1, ) - }) + }, + ) // Send off the payment request to the router, route through son // goku and then across the private channel to elst. @@ -802,7 +802,6 @@ func TestSendPaymentPrivateEdgeUpdateFeeExceedsLimit(t *testing.T) { copy(preImage[:], bytes.Repeat([]byte{9}, 32)) ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcherOld).setPaymentResult( func(firstHop lnwire.ShortChannelID) ([32]byte, error) { - if firstHop != roasbeefSongoku || errorReturned { return preImage, nil } @@ -817,7 +816,8 @@ func TestSendPaymentPrivateEdgeUpdateFeeExceedsLimit(t *testing.T) { Update: errChanUpdate, }, 1, ) - }) + }, + ) // Send off the payment request to the router, route through son // goku and then across the private channel to elst. @@ -3071,7 +3071,6 @@ func TestSendToRouteMultiShardSend(t *testing.T) { ctx.router.cfg.Payer.(*mockPaymentAttemptDispatcherOld).setPaymentResult( func(firstHop lnwire.ShortChannelID) ([32]byte, error) { - // Signal that the shard has been initiated and is // waiting for a result. waitForResultSignal <- struct{}{} @@ -3082,7 +3081,8 @@ func TestSendToRouteMultiShardSend(t *testing.T) { return [32]byte{}, fmt.Errorf("failure") } return res, nil - }) + }, + ) // Launch three shards by calling SendToRoute in three goroutines, // returning their final error on the channel. diff --git a/rpcserver.go b/rpcserver.go index e003a6092..453e7c193 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -1653,7 +1653,6 @@ func (r *rpcServer) ConnectPeer(ctx context.Context, if err := r.server.ConnectToPeer( peerAddr, in.Perm, timeout, ); err != nil { - rpcsLog.Errorf( "[connectpeer]: error connecting to peer: %v", err, ) From eb366a64e677c82dac7b5b1be218cced0dee7273 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 15 Feb 2022 16:30:14 +0100 Subject: [PATCH 3/3] docs: add release notes --- docs/release-notes/release-notes-0.15.0.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/release-notes-0.15.0.md b/docs/release-notes/release-notes-0.15.0.md index f2da8ee17..2e89439a7 100644 --- a/docs/release-notes/release-notes-0.15.0.md +++ b/docs/release-notes/release-notes-0.15.0.md @@ -100,9 +100,14 @@ * [The `golangci-lint` package was updated and new linters were enabled](https://github.com/lightningnetwork/lnd/pull/6244). - **Note to developers**: please make sure you delete the old version of - `golangci-lint` in your `$GOPATH/bin` directory. `make lint` does not - automatically replace it with the new version if the binary already exists! + +* The linting process now runs [inside a docker + container](https://github.com/lightningnetwork/lnd/pull/6248) to fix + versioning issues between projects. + +* The [`whitespace` linter](https://github.com/lightningnetwork/lnd/pull/6270) + was enabled to make sure multi-line `if` conditions and function/method + declarations are followed by an empty line to improve readability. # Contributors (Alphabetical Order)