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.
pull/527/head
sputn1ck 1 year ago
parent 446f163530
commit 4baf88c414
No known key found for this signature in database
GPG Key ID: 671103D881A5F0E4

@ -106,7 +106,8 @@ linters:
- nilnil - nilnil
- stylecheck - stylecheck
- thelper - thelper
- revive
# Additions compared to LND # Additions compared to LND
- exhaustruct - exhaustruct
@ -120,6 +121,7 @@ issues:
- path: _test\.go - path: _test\.go
linters: linters:
- forbidigo - forbidigo
- unparam
# Allow fmt.Printf() in loopd # Allow fmt.Printf() in loopd
- path: cmd/loopd/* - path: cmd/loopd/*

@ -355,7 +355,7 @@ func (s *Client) resumeSwaps(ctx context.Context,
if pend.State().State.Type() != loopdb.StateTypePending { if pend.State().State.Type() != loopdb.StateTypePending {
continue continue
} }
swap, err := resumeLoopOutSwap(ctx, swapCfg, pend) swap, err := resumeLoopOutSwap(swapCfg, pend)
if err != nil { if err != nil {
log.Errorf("resuming loop out swap: %v", err) log.Errorf("resuming loop out swap: %v", err)
continue continue

@ -141,7 +141,6 @@ func TestLoopOutFailWrongAmount(t *testing.T) {
m.prepayInvoiceAmt += 10 m.prepayInvoiceAmt += 10
}, ErrPrepayAmountTooHigh) }, ErrPrepayAmountTooHigh)
}) })
} }
// TestLoopOutResume tests that swaps in various states are properly resumed // TestLoopOutResume tests that swaps in various states are properly resumed

@ -94,7 +94,6 @@ func loopIn(ctx *cli.Context) error {
amtStr = ctx.String("amt") amtStr = ctx.String("amt")
case ctx.NArg() > 0: case ctx.NArg() > 0:
amtStr = args[0] amtStr = args[0]
args = args.Tail()
default: default:
// Show command help if no arguments and flags were provided. // Show command help if no arguments and flags were provided.
return cli.ShowCommandHelp(ctx, "in") return cli.ShowCommandHelp(ctx, "in")

@ -38,7 +38,7 @@ type executorConfig struct {
// executor is responsible for executing swaps. // executor is responsible for executing swaps.
// //
// TODO(roasbeef): rename to SubSwapper // TODO(roasbeef): rename to SubSwapper.
type executor struct { type executor struct {
wg sync.WaitGroup wg sync.WaitGroup
newSwaps chan genericSwap newSwaps chan genericSwap
@ -134,9 +134,9 @@ func (s *executor) run(mainCtx context.Context,
swapDoneChan := make(chan int) swapDoneChan := make(chan int)
nextSwapID := 0 nextSwapID := 0
for { for {
select { select {
case newSwap := <-s.newSwaps: case newSwap := <-s.newSwaps:
queue := queue.NewConcurrentQueue(10) queue := queue.NewConcurrentQueue(10)
queue.Start() queue.Start()

@ -363,7 +363,7 @@ type SwapInfo struct {
OutgoingChanSet loopdb.ChannelSet 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 { func (s *In) LastUpdate() time.Time {
return s.LastUpdateTime return s.LastUpdateTime
} }

@ -58,7 +58,7 @@ type SwapContract struct {
ProtocolVersion ProtocolVersion ProtocolVersion ProtocolVersion
} }
// Loop contains fields shared between LoopIn and LoopOut // Loop contains fields shared between LoopIn and LoopOut.
type Loop struct { type Loop struct {
Hash lntypes.Hash Hash lntypes.Hash
Events []*LoopEvent Events []*LoopEvent

@ -92,7 +92,6 @@ func syncVersions(db *bbolt.DB, chainParams *chaincfg.Params) error {
"db_version=%v", latestDBVersion, currentVersion) "db_version=%v", latestDBVersion, currentVersion)
switch { switch {
// If the database reports a higher version that we are aware of, the // 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 // user is probably trying to revert to a prior version of lnd. We fail
// here to prevent reversions and unintended corruption. // here to prevent reversions and unintended corruption.

@ -221,7 +221,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
// Validate the response parameters the prevent us continuing with a // Validate the response parameters the prevent us continuing with a
// swap that is based on parameters outside our allowed range. // swap that is based on parameters outside our allowed range.
err = validateLoopInContract(cfg.lnd, currentHeight, request, swapResp) err = validateLoopInContract(currentHeight, swapResp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -387,11 +387,7 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig,
// validateLoopInContract validates the contract parameters against our // validateLoopInContract validates the contract parameters against our
// request. // request.
func validateLoopInContract(lnd *lndclient.LndServices, func validateLoopInContract(height int32, response *newLoopInResponse) error {
height int32,
request *LoopInRequest,
response *newLoopInResponse) error {
// Verify that we are not forced to publish an htlc that locks up our // 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. // funds for too long in case the server doesn't follow through.
if response.expiry-height > MaxLoopInAcceptDelta { if response.expiry-height > MaxLoopInAcceptDelta {
@ -640,7 +636,6 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
var conf *chainntnfs.TxConfirmation var conf *chainntnfs.TxConfirmation
for conf == nil { for conf == nil {
select { select {
// P2WSH htlc confirmed. // P2WSH htlc confirmed.
case conf = <-confChanP2WSH: case conf = <-confChanP2WSH:
s.htlc = s.htlcP2WSH s.htlc = s.htlcP2WSH
@ -756,7 +751,6 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
} }
return true, nil return true, nil
} }
// getTxFee calculates our fee for a transaction that we have broadcast. We use // 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) update.State)
switch update.State { switch update.State {
// Swap invoice was paid, so update server cost balance. // Swap invoice was paid, so update server cost balance.
case channeldb.ContractSettled: case channeldb.ContractSettled:
s.cost.Server -= update.AmtPaid s.cost.Server -= update.AmtPaid

@ -92,7 +92,7 @@ type executeConfig struct {
sweeper *sweep.Sweeper sweeper *sweep.Sweeper
statusChan chan<- SwapInfo statusChan chan<- SwapInfo
blockEpochChan <-chan interface{} blockEpochChan <-chan interface{}
timerFactory func(d time.Duration) <-chan time.Time timerFactory func(time.Duration) <-chan time.Time
loopOutMaxParts uint32 loopOutMaxParts uint32
totalPaymentTimout time.Duration totalPaymentTimout time.Duration
maxPaymentRetries int maxPaymentRetries int
@ -144,7 +144,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
} }
err = validateLoopOutContract( err = validateLoopOutContract(
cfg.lnd, currentHeight, request, swapHash, swapResp, cfg.lnd, request, swapHash, swapResp,
) )
if err != nil { if err != nil {
return nil, err 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 // resumeLoopOutSwap returns a swap object representing a pending swap that has
// been restored from the database. // been restored from the database.
func resumeLoopOutSwap(reqContext context.Context, cfg *swapConfig, func resumeLoopOutSwap(cfg *swapConfig, pend *loopdb.LoopOut,
pend *loopdb.LoopOut) (*loopOutSwap, error) { ) (*loopOutSwap, error) {
hash := lntypes.Hash(sha256.Sum256(pend.Contract.Preimage[:])) 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 // executeAndFinalize executes a swap and awaits the definitive outcome of the
// offchain payments. When this method returns, the swap outcome is final. // offchain payments. When this method returns, the swap outcome is final.
func (s *loopOutSwap) executeAndFinalize(globalCtx context.Context) error { func (s *loopOutSwap) executeAndFinalize(globalCtx context.Context) error {
// Announce swap by sending out an initial update. // Announce swap by sending out an initial update.
err := s.sendUpdate(globalCtx) err := s.sendUpdate(globalCtx)
if err != nil { if err != nil {
@ -996,7 +995,6 @@ func (s *loopOutSwap) waitForConfirmedHtlc(globalCtx context.Context) (
} }
s.log.Infof("Swap script confirmed on chain") s.log.Infof("Swap script confirmed on chain")
} else { } else {
s.log.Infof("Retrieving htlc onchain") s.log.Infof("Retrieving htlc onchain")
select { select {
@ -1650,9 +1648,8 @@ func (s *loopOutSwap) sweep(ctx context.Context, htlcOutpoint wire.OutPoint,
// validateLoopOutContract validates the contract parameters against our // validateLoopOutContract validates the contract parameters against our
// request. // request.
func validateLoopOutContract(lnd *lndclient.LndServices, func validateLoopOutContract(lnd *lndclient.LndServices, request *OutRequest,
height int32, request *OutRequest, swapHash lntypes.Hash, swapHash lntypes.Hash, response *newLoopOutResponse) error {
response *newLoopOutResponse) error {
// Check invoice amounts. // Check invoice amounts.
chainParams := lnd.ChainParams chainParams := lnd.ChainParams

@ -219,7 +219,7 @@ func testLateHtlcPublish(t *testing.T) {
ctx.AssertRegisterConf(false, defaultConfirmations) ctx.AssertRegisterConf(false, defaultConfirmations)
// // Wait too long before publishing htlc. // // Wait too long before publishing htlc.
blockEpochChan <- int32(swap.CltvExpiry - 10) blockEpochChan <- swap.CltvExpiry - 10
signalSwapPaymentResult( signalSwapPaymentResult(
errors.New(lndclient.PaymentResultUnknownPaymentHash), errors.New(lndclient.PaymentResultUnknownPaymentHash),
@ -430,7 +430,7 @@ func testCustomSweepConfTarget(t *testing.T) {
// confirmation target. // confirmation target.
defaultConfTargetHeight := ctx.Lnd.Height + defaultConfTargetHeight := ctx.Lnd.Height +
testLoopOutMinOnChainCltvDelta - DefaultSweepConfTargetDelta testLoopOutMinOnChainCltvDelta - DefaultSweepConfTargetDelta
blockEpochChan <- int32(defaultConfTargetHeight) blockEpochChan <- defaultConfTargetHeight
expiryChan <- time.Now() expiryChan <- time.Now()
// Expect another signing request. // Expect another signing request.

@ -246,7 +246,6 @@ func (s *storeMock) assertLoopInState(
} }
func (s *storeMock) assertStorePreimageReveal() { func (s *storeMock) assertStorePreimageReveal() {
s.t.Helper() s.t.Helper()
select { select {

@ -14,7 +14,7 @@ import (
type swapKit struct { type swapKit struct {
hash lntypes.Hash hash lntypes.Hash
height int32 height int32 //nolint:structcheck
log *swap.PrefixLog log *swap.PrefixLog

@ -22,7 +22,7 @@ import (
type HtlcOutputType uint8 type HtlcOutputType uint8
const ( 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 HtlcP2WSH HtlcOutputType = iota
// HtlcP2TR is a pay-to-taproot output with three separate spend paths. // 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. // newHTLCScriptV2 construct an HtlcScipt with the HTLC V2 witness script.
// //
// <receiverHtlcKey> OP_CHECKSIG OP_NOTIF // <receiverHtlcKey> OP_CHECKSIG OP_NOTIF
// OP_DUP OP_HASH160 <HASH160(senderHtlcKey)> OP_EQUALVERIFY OP_CHECKSIGVERIFY //
// <cltv timeout> OP_CHECKLOCKTIMEVERIFY // OP_DUP OP_HASH160 <HASH160(senderHtlcKey)> OP_EQUALVERIFY OP_CHECKSIGVERIFY
// <cltv timeout> OP_CHECKLOCKTIMEVERIFY
//
// OP_ELSE // OP_ELSE
// OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <ripemd(swapHash)> OP_EQUALVERIFY 1 //
// OP_CHECKSEQUENCEVERIFY // OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <ripemd(swapHash)> OP_EQUALVERIFY 1
// OP_CHECKSEQUENCEVERIFY
//
// OP_ENDIF . // OP_ENDIF .
func newHTLCScriptV2(cltvExpiry int32, senderHtlcKey, func newHTLCScriptV2(cltvExpiry int32, senderHtlcKey,
receiverHtlcKey [33]byte, swapHash lntypes.Hash) (*HtlcScriptV2, error) { receiverHtlcKey [33]byte, swapHash lntypes.Hash) (*HtlcScriptV2, error) {

@ -62,7 +62,6 @@ func (ctx *Context) NotifySpend(tx *wire.MsgTx, inputIndex uint32) {
}: }:
case <-time.After(Timeout): case <-time.After(Timeout):
ctx.T.Fatalf("htlc spend not consumed") ctx.T.Fatalf("htlc spend not consumed")
} }
} }
@ -76,7 +75,6 @@ func (ctx *Context) NotifyConf(tx *wire.MsgTx) {
}: }:
case <-time.After(Timeout): case <-time.After(Timeout):
ctx.T.Fatalf("htlc spend not consumed") ctx.T.Fatalf("htlc spend not consumed")
} }
} }

@ -115,7 +115,7 @@ type RouterPaymentChannelMessage struct {
TrackPaymentMessage TrackPaymentMessage
} }
// SingleInvoiceSubscription contains the single invoice subscribers // SingleInvoiceSubscription contains the single invoice subscribers.
type SingleInvoiceSubscription struct { type SingleInvoiceSubscription struct {
Hash lntypes.Hash Hash lntypes.Hash
Update chan lndclient.InvoiceUpdate Update chan lndclient.InvoiceUpdate

@ -148,16 +148,6 @@ func (ctx *testContext) finish() {
ctx.assertIsDone() 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() { func (ctx *testContext) assertIsDone() {
require.NoError(ctx.T, ctx.Lnd.IsDone()) require.NoError(ctx.T, ctx.Lnd.IsDone())
require.NoError(ctx.T, ctx.store.isDone()) require.NoError(ctx.T, ctx.store.isDone())
@ -185,11 +175,9 @@ func (ctx *testContext) assertStoreFinished(expectedResult loopdb.SwapState) {
ctx.T.Helper() ctx.T.Helper()
ctx.store.assertStoreFinished(expectedResult) ctx.store.assertStoreFinished(expectedResult)
} }
func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) { func (ctx *testContext) assertStatus(expectedState loopdb.SwapState) {
ctx.T.Helper() ctx.T.Helper()
for { for {

@ -1,4 +1,4 @@
FROM golang:1.18.0-buster FROM golang:1.18
RUN apt-get update && apt-get install -y git RUN apt-get update && apt-get install -y git
ENV GOCACHE=/tmp/build/.cache ENV GOCACHE=/tmp/build/.cache
@ -11,6 +11,7 @@ RUN cd /tmp \
&& mkdir -p /tmp/build/.modcache \ && mkdir -p /tmp/build/.modcache \
&& cd /tmp/tools \ && cd /tmp/tools \
&& go install -trimpath -tags=tools github.com/golangci/golangci-lint/cmd/golangci-lint \ && 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 WORKDIR /build
Loading…
Cancel
Save