Skip to content

Commit 4baf88c

Browse files
committed
multi: fix linter issues
This commit fixes outstanding linter issues, that we're not found by running `make lint` locally. The linter issues were found by running `docker run -v $(pwd):/build loop-tools golangci-lint run --whole-files` I added the `revive` to the excludes as it would be to much of a refactor and IMO seems unneccesary. E.g. `interface.go:222:6: exported: type name will be used as loop.LoopInTerms by other packages, and that stutters; consider calling this InTerms (revive)`. I think `loop.LoopInTerms` is fine.
1 parent 446f163 commit 4baf88c

18 files changed

+32
-53
lines changed

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ linters:
106106
- nilnil
107107
- stylecheck
108108
- thelper
109-
109+
- revive
110+
110111
# Additions compared to LND
111112
- exhaustruct
112113

@@ -120,6 +121,7 @@ issues:
120121
- path: _test\.go
121122
linters:
122123
- forbidigo
124+
- unparam
123125

124126
# Allow fmt.Printf() in loopd
125127
- path: cmd/loopd/*

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (s *Client) resumeSwaps(ctx context.Context,
355355
if pend.State().State.Type() != loopdb.StateTypePending {
356356
continue
357357
}
358-
swap, err := resumeLoopOutSwap(ctx, swapCfg, pend)
358+
swap, err := resumeLoopOutSwap(swapCfg, pend)
359359
if err != nil {
360360
log.Errorf("resuming loop out swap: %v", err)
361361
continue

client_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func TestLoopOutFailWrongAmount(t *testing.T) {
141141
m.prepayInvoiceAmt += 10
142142
}, ErrPrepayAmountTooHigh)
143143
})
144-
145144
}
146145

147146
// TestLoopOutResume tests that swaps in various states are properly resumed

cmd/loop/loopin.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func loopIn(ctx *cli.Context) error {
9494
amtStr = ctx.String("amt")
9595
case ctx.NArg() > 0:
9696
amtStr = args[0]
97-
args = args.Tail()
9897
default:
9998
// Show command help if no arguments and flags were provided.
10099
return cli.ShowCommandHelp(ctx, "in")

executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type executorConfig struct {
3838

3939
// executor is responsible for executing swaps.
4040
//
41-
// TODO(roasbeef): rename to SubSwapper
41+
// TODO(roasbeef): rename to SubSwapper.
4242
type executor struct {
4343
wg sync.WaitGroup
4444
newSwaps chan genericSwap
@@ -134,9 +134,9 @@ func (s *executor) run(mainCtx context.Context,
134134

135135
swapDoneChan := make(chan int)
136136
nextSwapID := 0
137+
137138
for {
138139
select {
139-
140140
case newSwap := <-s.newSwaps:
141141
queue := queue.NewConcurrentQueue(10)
142142
queue.Start()

interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ type SwapInfo struct {
363363
OutgoingChanSet loopdb.ChannelSet
364364
}
365365

366-
// LastUpdate returns the last update time of the swap
366+
// LastUpdate returns the last update time of the swap.
367367
func (s *In) LastUpdate() time.Time {
368368
return s.LastUpdateTime
369369
}

loopdb/loop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type SwapContract struct {
5858
ProtocolVersion ProtocolVersion
5959
}
6060

61-
// Loop contains fields shared between LoopIn and LoopOut
61+
// Loop contains fields shared between LoopIn and LoopOut.
6262
type Loop struct {
6363
Hash lntypes.Hash
6464
Events []*LoopEvent

loopdb/meta.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func syncVersions(db *bbolt.DB, chainParams *chaincfg.Params) error {
9292
"db_version=%v", latestDBVersion, currentVersion)
9393

9494
switch {
95-
9695
// If the database reports a higher version that we are aware of, the
9796
// user is probably trying to revert to a prior version of lnd. We fail
9897
// here to prevent reversions and unintended corruption.

loopin.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
221221

222222
// Validate the response parameters the prevent us continuing with a
223223
// swap that is based on parameters outside our allowed range.
224-
err = validateLoopInContract(cfg.lnd, currentHeight, request, swapResp)
224+
err = validateLoopInContract(currentHeight, swapResp)
225225
if err != nil {
226226
return nil, err
227227
}
@@ -387,11 +387,7 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig,
387387

388388
// validateLoopInContract validates the contract parameters against our
389389
// request.
390-
func validateLoopInContract(lnd *lndclient.LndServices,
391-
height int32,
392-
request *LoopInRequest,
393-
response *newLoopInResponse) error {
394-
390+
func validateLoopInContract(height int32, response *newLoopInResponse) error {
395391
// Verify that we are not forced to publish an htlc that locks up our
396392
// funds for too long in case the server doesn't follow through.
397393
if response.expiry-height > MaxLoopInAcceptDelta {
@@ -640,7 +636,6 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
640636
var conf *chainntnfs.TxConfirmation
641637
for conf == nil {
642638
select {
643-
644639
// P2WSH htlc confirmed.
645640
case conf = <-confChanP2WSH:
646641
s.htlc = s.htlcP2WSH
@@ -756,7 +751,6 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
756751
}
757752

758753
return true, nil
759-
760754
}
761755

762756
// getTxFee calculates our fee for a transaction that we have broadcast. We use
@@ -875,7 +869,6 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
875869
update.State)
876870

877871
switch update.State {
878-
879872
// Swap invoice was paid, so update server cost balance.
880873
case channeldb.ContractSettled:
881874
s.cost.Server -= update.AmtPaid

loopout.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type executeConfig struct {
9292
sweeper *sweep.Sweeper
9393
statusChan chan<- SwapInfo
9494
blockEpochChan <-chan interface{}
95-
timerFactory func(d time.Duration) <-chan time.Time
95+
timerFactory func(time.Duration) <-chan time.Time
9696
loopOutMaxParts uint32
9797
totalPaymentTimout time.Duration
9898
maxPaymentRetries int
@@ -144,7 +144,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
144144
}
145145

146146
err = validateLoopOutContract(
147-
cfg.lnd, currentHeight, request, swapHash, swapResp,
147+
cfg.lnd, request, swapHash, swapResp,
148148
)
149149
if err != nil {
150150
return nil, err
@@ -246,8 +246,8 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
246246

247247
// resumeLoopOutSwap returns a swap object representing a pending swap that has
248248
// been restored from the database.
249-
func resumeLoopOutSwap(reqContext context.Context, cfg *swapConfig,
250-
pend *loopdb.LoopOut) (*loopOutSwap, error) {
249+
func resumeLoopOutSwap(cfg *swapConfig, pend *loopdb.LoopOut,
250+
) (*loopOutSwap, error) {
251251

252252
hash := lntypes.Hash(sha256.Sum256(pend.Contract.Preimage[:]))
253253

@@ -386,7 +386,6 @@ func (s *loopOutSwap) execute(mainCtx context.Context,
386386
// executeAndFinalize executes a swap and awaits the definitive outcome of the
387387
// offchain payments. When this method returns, the swap outcome is final.
388388
func (s *loopOutSwap) executeAndFinalize(globalCtx context.Context) error {
389-
390389
// Announce swap by sending out an initial update.
391390
err := s.sendUpdate(globalCtx)
392391
if err != nil {
@@ -996,7 +995,6 @@ func (s *loopOutSwap) waitForConfirmedHtlc(globalCtx context.Context) (
996995
}
997996

998997
s.log.Infof("Swap script confirmed on chain")
999-
1000998
} else {
1001999
s.log.Infof("Retrieving htlc onchain")
10021000
select {
@@ -1650,9 +1648,8 @@ func (s *loopOutSwap) sweep(ctx context.Context, htlcOutpoint wire.OutPoint,
16501648

16511649
// validateLoopOutContract validates the contract parameters against our
16521650
// request.
1653-
func validateLoopOutContract(lnd *lndclient.LndServices,
1654-
height int32, request *OutRequest, swapHash lntypes.Hash,
1655-
response *newLoopOutResponse) error {
1651+
func validateLoopOutContract(lnd *lndclient.LndServices, request *OutRequest,
1652+
swapHash lntypes.Hash, response *newLoopOutResponse) error {
16561653

16571654
// Check invoice amounts.
16581655
chainParams := lnd.ChainParams

loopout_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func testLateHtlcPublish(t *testing.T) {
219219
ctx.AssertRegisterConf(false, defaultConfirmations)
220220

221221
// // Wait too long before publishing htlc.
222-
blockEpochChan <- int32(swap.CltvExpiry - 10)
222+
blockEpochChan <- swap.CltvExpiry - 10
223223

224224
signalSwapPaymentResult(
225225
errors.New(lndclient.PaymentResultUnknownPaymentHash),
@@ -430,7 +430,7 @@ func testCustomSweepConfTarget(t *testing.T) {
430430
// confirmation target.
431431
defaultConfTargetHeight := ctx.Lnd.Height +
432432
testLoopOutMinOnChainCltvDelta - DefaultSweepConfTargetDelta
433-
blockEpochChan <- int32(defaultConfTargetHeight)
433+
blockEpochChan <- defaultConfTargetHeight
434434
expiryChan <- time.Now()
435435

436436
// Expect another signing request.

store_mock_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ func (s *storeMock) assertLoopInState(
246246
}
247247

248248
func (s *storeMock) assertStorePreimageReveal() {
249-
250249
s.t.Helper()
251250

252251
select {

swap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type swapKit struct {
1515
hash lntypes.Hash
1616

17-
height int32
17+
height int32 //nolint:structcheck
1818

1919
log *swap.PrefixLog
2020

swap/htlc.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
type HtlcOutputType uint8
2323

2424
const (
25-
// HtlcP2WSH is a pay-to-witness-script-hash output (segwit only)
25+
// HtlcP2WSH is a pay-to-witness-script-hash output (segwit only).
2626
HtlcP2WSH HtlcOutputType = iota
2727

2828
// HtlcP2TR is a pay-to-taproot output with three separate spend paths.
@@ -329,11 +329,15 @@ type HtlcScriptV2 struct {
329329
// newHTLCScriptV2 construct an HtlcScipt with the HTLC V2 witness script.
330330
//
331331
// <receiverHtlcKey> OP_CHECKSIG OP_NOTIF
332-
// OP_DUP OP_HASH160 <HASH160(senderHtlcKey)> OP_EQUALVERIFY OP_CHECKSIGVERIFY
333-
// <cltv timeout> OP_CHECKLOCKTIMEVERIFY
332+
//
333+
// OP_DUP OP_HASH160 <HASH160(senderHtlcKey)> OP_EQUALVERIFY OP_CHECKSIGVERIFY
334+
// <cltv timeout> OP_CHECKLOCKTIMEVERIFY
335+
//
334336
// OP_ELSE
335-
// OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <ripemd(swapHash)> OP_EQUALVERIFY 1
336-
// OP_CHECKSEQUENCEVERIFY
337+
//
338+
// OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <ripemd(swapHash)> OP_EQUALVERIFY 1
339+
// OP_CHECKSEQUENCEVERIFY
340+
//
337341
// OP_ENDIF .
338342
func newHTLCScriptV2(cltvExpiry int32, senderHtlcKey,
339343
receiverHtlcKey [33]byte, swapHash lntypes.Hash) (*HtlcScriptV2, error) {

test/context.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func (ctx *Context) NotifySpend(tx *wire.MsgTx, inputIndex uint32) {
6262
}:
6363
case <-time.After(Timeout):
6464
ctx.T.Fatalf("htlc spend not consumed")
65-
6665
}
6766
}
6867

@@ -76,7 +75,6 @@ func (ctx *Context) NotifyConf(tx *wire.MsgTx) {
7675
}:
7776
case <-time.After(Timeout):
7877
ctx.T.Fatalf("htlc spend not consumed")
79-
8078
}
8179
}
8280

test/lnd_services_mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type RouterPaymentChannelMessage struct {
115115
TrackPaymentMessage
116116
}
117117

118-
// SingleInvoiceSubscription contains the single invoice subscribers
118+
// SingleInvoiceSubscription contains the single invoice subscribers.
119119
type SingleInvoiceSubscription struct {
120120
Hash lntypes.Hash
121121
Update chan lndclient.InvoiceUpdate

testcontext_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,6 @@ func (ctx *testContext) finish() {
148148

149149
ctx.assertIsDone()
150150
}
151-
152-
// notifyHeight notifies swap client of the arrival of a new block and
153-
// waits for the notification to be processed by selecting on a dedicated
154-
// test channel.
155-
func (ctx *testContext) notifyHeight(height int32) {
156-
ctx.T.Helper()
157-
158-
require.NoError(ctx.T, ctx.Lnd.NotifyHeight(height))
159-
}
160-
161151
func (ctx *testContext) assertIsDone() {
162152
require.NoError(ctx.T, ctx.Lnd.IsDone())
163153
require.NoError(ctx.T, ctx.store.isDone())
@@ -185,11 +175,9 @@ func (ctx *testContext) assertStoreFinished(expectedResult loopdb.SwapState) {
185175
ctx.T.Helper()
186176

187177
ctx.store.assertStoreFinished(expectedResult)
188-
189178
}
190179

191180
func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) {
192-
193181
ctx.T.Helper()
194182

195183
for {

tools/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.18.0-buster
1+
FROM golang:1.18
22

33
RUN apt-get update && apt-get install -y git
44
ENV GOCACHE=/tmp/build/.cache
@@ -11,6 +11,7 @@ RUN cd /tmp \
1111
&& mkdir -p /tmp/build/.modcache \
1212
&& cd /tmp/tools \
1313
&& go install -trimpath -tags=tools github.com/golangci/golangci-lint/cmd/golangci-lint \
14-
&& chmod -R 777 /tmp/build/
14+
&& chmod -R 777 /tmp/build/ \
15+
&& git config --global --add safe.directory /build
1516

1617
WORKDIR /build

0 commit comments

Comments
 (0)