diff --git a/.golangci.yml b/.golangci.yml index 1ada065..1af0453 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -106,7 +106,8 @@ linters: - nilnil - stylecheck - thelper - + - revive + # Additions compared to LND - exhaustruct @@ -120,6 +121,7 @@ issues: - path: _test\.go linters: - forbidigo + - unparam # Allow fmt.Printf() in loopd - path: cmd/loopd/* diff --git a/client.go b/client.go index 0bf6e46..3f4899a 100644 --- a/client.go +++ b/client.go @@ -355,7 +355,7 @@ func (s *Client) resumeSwaps(ctx context.Context, if pend.State().State.Type() != loopdb.StateTypePending { continue } - swap, err := resumeLoopOutSwap(ctx, swapCfg, pend) + swap, err := resumeLoopOutSwap(swapCfg, pend) if err != nil { log.Errorf("resuming loop out swap: %v", err) continue diff --git a/client_test.go b/client_test.go index b49e0ba..3ca2995 100644 --- a/client_test.go +++ b/client_test.go @@ -141,7 +141,6 @@ func TestLoopOutFailWrongAmount(t *testing.T) { m.prepayInvoiceAmt += 10 }, ErrPrepayAmountTooHigh) }) - } // TestLoopOutResume tests that swaps in various states are properly resumed diff --git a/cmd/loop/loopin.go b/cmd/loop/loopin.go index 4c7d92e..ea1bf1a 100644 --- a/cmd/loop/loopin.go +++ b/cmd/loop/loopin.go @@ -94,7 +94,6 @@ func loopIn(ctx *cli.Context) error { amtStr = ctx.String("amt") case ctx.NArg() > 0: amtStr = args[0] - args = args.Tail() default: // Show command help if no arguments and flags were provided. return cli.ShowCommandHelp(ctx, "in") diff --git a/executor.go b/executor.go index d0ce0af..4488011 100644 --- a/executor.go +++ b/executor.go @@ -38,7 +38,7 @@ type executorConfig struct { // executor is responsible for executing swaps. // -// TODO(roasbeef): rename to SubSwapper +// TODO(roasbeef): rename to SubSwapper. type executor struct { wg sync.WaitGroup newSwaps chan genericSwap @@ -134,9 +134,9 @@ func (s *executor) run(mainCtx context.Context, swapDoneChan := make(chan int) nextSwapID := 0 + for { select { - case newSwap := <-s.newSwaps: queue := queue.NewConcurrentQueue(10) queue.Start() diff --git a/interface.go b/interface.go index 4b19329..790a907 100644 --- a/interface.go +++ b/interface.go @@ -363,7 +363,7 @@ type SwapInfo struct { OutgoingChanSet loopdb.ChannelSet } -// LastUpdate returns the last update time of the swap +// LastUpdate returns the last update time of the swap. func (s *In) LastUpdate() time.Time { return s.LastUpdateTime } diff --git a/loopdb/loop.go b/loopdb/loop.go index 98f195a..e98745f 100644 --- a/loopdb/loop.go +++ b/loopdb/loop.go @@ -58,7 +58,7 @@ type SwapContract struct { ProtocolVersion ProtocolVersion } -// Loop contains fields shared between LoopIn and LoopOut +// Loop contains fields shared between LoopIn and LoopOut. type Loop struct { Hash lntypes.Hash Events []*LoopEvent diff --git a/loopdb/meta.go b/loopdb/meta.go index 88fdf9a..1c27323 100644 --- a/loopdb/meta.go +++ b/loopdb/meta.go @@ -92,7 +92,6 @@ func syncVersions(db *bbolt.DB, chainParams *chaincfg.Params) error { "db_version=%v", latestDBVersion, currentVersion) switch { - // If the database reports a higher version that we are aware of, the // user is probably trying to revert to a prior version of lnd. We fail // here to prevent reversions and unintended corruption. diff --git a/loopin.go b/loopin.go index 62d2a42..efb2242 100644 --- a/loopin.go +++ b/loopin.go @@ -221,7 +221,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig, // Validate the response parameters the prevent us continuing with a // swap that is based on parameters outside our allowed range. - err = validateLoopInContract(cfg.lnd, currentHeight, request, swapResp) + err = validateLoopInContract(currentHeight, swapResp) if err != nil { return nil, err } @@ -387,11 +387,7 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig, // validateLoopInContract validates the contract parameters against our // request. -func validateLoopInContract(lnd *lndclient.LndServices, - height int32, - request *LoopInRequest, - response *newLoopInResponse) error { - +func validateLoopInContract(height int32, response *newLoopInResponse) error { // Verify that we are not forced to publish an htlc that locks up our // funds for too long in case the server doesn't follow through. if response.expiry-height > MaxLoopInAcceptDelta { @@ -640,7 +636,6 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) ( var conf *chainntnfs.TxConfirmation for conf == nil { select { - // P2WSH htlc confirmed. case conf = <-confChanP2WSH: s.htlc = s.htlcP2WSH @@ -756,7 +751,6 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) { } return true, nil - } // getTxFee calculates our fee for a transaction that we have broadcast. We use @@ -875,7 +869,6 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context, update.State) switch update.State { - // Swap invoice was paid, so update server cost balance. case channeldb.ContractSettled: s.cost.Server -= update.AmtPaid diff --git a/loopout.go b/loopout.go index 6b03bfd..9d58b7d 100644 --- a/loopout.go +++ b/loopout.go @@ -92,7 +92,7 @@ type executeConfig struct { sweeper *sweep.Sweeper statusChan chan<- SwapInfo blockEpochChan <-chan interface{} - timerFactory func(d time.Duration) <-chan time.Time + timerFactory func(time.Duration) <-chan time.Time loopOutMaxParts uint32 totalPaymentTimout time.Duration maxPaymentRetries int @@ -144,7 +144,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig, } err = validateLoopOutContract( - cfg.lnd, currentHeight, request, swapHash, swapResp, + cfg.lnd, request, swapHash, swapResp, ) if err != nil { return nil, err @@ -246,8 +246,8 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig, // resumeLoopOutSwap returns a swap object representing a pending swap that has // been restored from the database. -func resumeLoopOutSwap(reqContext context.Context, cfg *swapConfig, - pend *loopdb.LoopOut) (*loopOutSwap, error) { +func resumeLoopOutSwap(cfg *swapConfig, pend *loopdb.LoopOut, +) (*loopOutSwap, error) { hash := lntypes.Hash(sha256.Sum256(pend.Contract.Preimage[:])) @@ -386,7 +386,6 @@ func (s *loopOutSwap) execute(mainCtx context.Context, // executeAndFinalize executes a swap and awaits the definitive outcome of the // offchain payments. When this method returns, the swap outcome is final. func (s *loopOutSwap) executeAndFinalize(globalCtx context.Context) error { - // Announce swap by sending out an initial update. err := s.sendUpdate(globalCtx) if err != nil { @@ -996,7 +995,6 @@ func (s *loopOutSwap) waitForConfirmedHtlc(globalCtx context.Context) ( } s.log.Infof("Swap script confirmed on chain") - } else { s.log.Infof("Retrieving htlc onchain") select { @@ -1650,9 +1648,8 @@ func (s *loopOutSwap) sweep(ctx context.Context, htlcOutpoint wire.OutPoint, // validateLoopOutContract validates the contract parameters against our // request. -func validateLoopOutContract(lnd *lndclient.LndServices, - height int32, request *OutRequest, swapHash lntypes.Hash, - response *newLoopOutResponse) error { +func validateLoopOutContract(lnd *lndclient.LndServices, request *OutRequest, + swapHash lntypes.Hash, response *newLoopOutResponse) error { // Check invoice amounts. chainParams := lnd.ChainParams diff --git a/loopout_test.go b/loopout_test.go index 67566e8..6853e07 100644 --- a/loopout_test.go +++ b/loopout_test.go @@ -219,7 +219,7 @@ func testLateHtlcPublish(t *testing.T) { ctx.AssertRegisterConf(false, defaultConfirmations) // // Wait too long before publishing htlc. - blockEpochChan <- int32(swap.CltvExpiry - 10) + blockEpochChan <- swap.CltvExpiry - 10 signalSwapPaymentResult( errors.New(lndclient.PaymentResultUnknownPaymentHash), @@ -430,7 +430,7 @@ func testCustomSweepConfTarget(t *testing.T) { // confirmation target. defaultConfTargetHeight := ctx.Lnd.Height + testLoopOutMinOnChainCltvDelta - DefaultSweepConfTargetDelta - blockEpochChan <- int32(defaultConfTargetHeight) + blockEpochChan <- defaultConfTargetHeight expiryChan <- time.Now() // Expect another signing request. diff --git a/store_mock_test.go b/store_mock_test.go index 4ec9daa..4e8a0ad 100644 --- a/store_mock_test.go +++ b/store_mock_test.go @@ -246,7 +246,6 @@ func (s *storeMock) assertLoopInState( } func (s *storeMock) assertStorePreimageReveal() { - s.t.Helper() select { diff --git a/swap.go b/swap.go index 764af79..3253277 100644 --- a/swap.go +++ b/swap.go @@ -14,7 +14,7 @@ import ( type swapKit struct { hash lntypes.Hash - height int32 + height int32 //nolint:structcheck log *swap.PrefixLog diff --git a/swap/htlc.go b/swap/htlc.go index 8a1101a..3c0f411 100644 --- a/swap/htlc.go +++ b/swap/htlc.go @@ -22,7 +22,7 @@ import ( type HtlcOutputType uint8 const ( - // HtlcP2WSH is a pay-to-witness-script-hash output (segwit only) + // HtlcP2WSH is a pay-to-witness-script-hash output (segwit only). HtlcP2WSH HtlcOutputType = iota // HtlcP2TR is a pay-to-taproot output with three separate spend paths. @@ -329,11 +329,15 @@ type HtlcScriptV2 struct { // newHTLCScriptV2 construct an HtlcScipt with the HTLC V2 witness script. // // OP_CHECKSIG OP_NOTIF -// OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIGVERIFY -// OP_CHECKLOCKTIMEVERIFY +// +// OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIGVERIFY +// OP_CHECKLOCKTIMEVERIFY +// // OP_ELSE -// OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 OP_EQUALVERIFY 1 -// OP_CHECKSEQUENCEVERIFY +// +// OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 OP_EQUALVERIFY 1 +// OP_CHECKSEQUENCEVERIFY +// // OP_ENDIF . func newHTLCScriptV2(cltvExpiry int32, senderHtlcKey, receiverHtlcKey [33]byte, swapHash lntypes.Hash) (*HtlcScriptV2, error) { diff --git a/test/context.go b/test/context.go index e8c517c..be46a9a 100644 --- a/test/context.go +++ b/test/context.go @@ -62,7 +62,6 @@ func (ctx *Context) NotifySpend(tx *wire.MsgTx, inputIndex uint32) { }: case <-time.After(Timeout): ctx.T.Fatalf("htlc spend not consumed") - } } @@ -76,7 +75,6 @@ func (ctx *Context) NotifyConf(tx *wire.MsgTx) { }: case <-time.After(Timeout): ctx.T.Fatalf("htlc spend not consumed") - } } diff --git a/test/lnd_services_mock.go b/test/lnd_services_mock.go index 3bf0c41..221d1d8 100644 --- a/test/lnd_services_mock.go +++ b/test/lnd_services_mock.go @@ -115,7 +115,7 @@ type RouterPaymentChannelMessage struct { TrackPaymentMessage } -// SingleInvoiceSubscription contains the single invoice subscribers +// SingleInvoiceSubscription contains the single invoice subscribers. type SingleInvoiceSubscription struct { Hash lntypes.Hash Update chan lndclient.InvoiceUpdate diff --git a/testcontext_test.go b/testcontext_test.go index a221a28..8abe9db 100644 --- a/testcontext_test.go +++ b/testcontext_test.go @@ -148,16 +148,6 @@ func (ctx *testContext) finish() { ctx.assertIsDone() } - -// notifyHeight notifies swap client of the arrival of a new block and -// waits for the notification to be processed by selecting on a dedicated -// test channel. -func (ctx *testContext) notifyHeight(height int32) { - ctx.T.Helper() - - require.NoError(ctx.T, ctx.Lnd.NotifyHeight(height)) -} - func (ctx *testContext) assertIsDone() { require.NoError(ctx.T, ctx.Lnd.IsDone()) require.NoError(ctx.T, ctx.store.isDone()) @@ -185,11 +175,9 @@ func (ctx *testContext) assertStoreFinished(expectedResult loopdb.SwapState) { ctx.T.Helper() ctx.store.assertStoreFinished(expectedResult) - } func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) { - ctx.T.Helper() for { diff --git a/tools/Dockerfile b/tools/Dockerfile index 018ec73..de68082 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18.0-buster +FROM golang:1.18 RUN apt-get update && apt-get install -y git ENV GOCACHE=/tmp/build/.cache @@ -11,6 +11,7 @@ RUN cd /tmp \ && mkdir -p /tmp/build/.modcache \ && cd /tmp/tools \ && go install -trimpath -tags=tools github.com/golangci/golangci-lint/cmd/golangci-lint \ - && chmod -R 777 /tmp/build/ + && chmod -R 777 /tmp/build/ \ + && git config --global --add safe.directory /build WORKDIR /build \ No newline at end of file