Skip to content

Commit 08026da

Browse files
committed
multi: update linter, fix issues
1 parent bac1416 commit 08026da

25 files changed

+525
-346
lines changed

.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ linters:
7676
- golint
7777
- maligned
7878
- scopelint
79+
- varcheck
80+
- structcheck
81+
- deadcode
7982

8083
# New linters that need a code adjustment first.
8184
- wrapcheck
@@ -107,6 +110,10 @@ linters:
107110
- stylecheck
108111
- thelper
109112
- revive
113+
- tagalign
114+
- depguard
115+
- nosnakecase
116+
- interfacebloat
110117

111118
# Additions compared to LND
112119
- exhaustruct
@@ -122,6 +129,10 @@ issues:
122129
linters:
123130
- forbidigo
124131
- unparam
132+
- gosec
133+
- path: _mock\.go
134+
linters:
135+
- gosec
125136

126137
# Allow fmt.Printf() in loopd
127138
- path: cmd/loopd/*

client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
204204
swaps := make([]*SwapInfo, 0, len(loopInSwaps)+len(loopOutSwaps))
205205

206206
for _, swp := range loopOutSwaps {
207+
swp := swp
208+
207209
swapInfo := &SwapInfo{
208210
SwapType: swap.TypeOut,
209211
SwapContract: swp.Contract.SwapContract,
@@ -235,6 +237,8 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
235237
}
236238

237239
for _, swp := range loopInSwaps {
240+
swp := swp
241+
238242
swapInfo := &SwapInfo{
239243
SwapType: swap.TypeIn,
240244
SwapContract: swp.Contract.SwapContract,

fsm/fsm_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ func TestStateMachine_ActionError(t *testing.T) {
8888

8989
// Add a Transition to State2 if the Action on Stat2 fails.
9090
// The new StateMap looks like this:
91-
// State1 -> Event1 -> State2
92-
// State2 -> OnError -> ErrorState
91+
// State1 -> Event1 -> State2
92+
//
93+
// State2 -> OnError -> ErrorState
9394
states["State2"] = State{
9495
Action: ctx.errorAction,
9596
Transitions: Transitions{

liquidity/autoloop_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ func TestAutoloopBothTypes(t *testing.T) {
984984
Events: []*loopdb.LoopEvent{
985985
{
986986
SwapStateData: loopdb.SwapStateData{
987-
State: loopdb.SwapState(loopdb.StateSuccess),
987+
State: loopdb.StateSuccess,
988988
},
989989
},
990990
},
@@ -1168,7 +1168,7 @@ func TestAutoLoopRecurringBudget(t *testing.T) {
11681168
Events: []*loopdb.LoopEvent{
11691169
{
11701170
SwapStateData: loopdb.SwapStateData{
1171-
State: loopdb.SwapState(loopdb.StateSuccess),
1171+
State: loopdb.StateSuccess,
11721172
},
11731173
},
11741174
},

liquidity/fees.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (f *FeePortion) loopOutLimits(swapAmt btcutil.Amount,
349349
// multiplier from the miner fees. We do this because we want to
350350
// consider the average case for our budget calculations and not the
351351
// severe edge-case miner fees.
352-
miner = miner / maxMinerMultiplier
352+
miner /= maxMinerMultiplier
353353

354354
// Calculate the worst case fees that we could pay for this swap,
355355
// ensuring that we are within our fee limit even if the swap fails.

liquidity/liquidity.go

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
536536

537537
// Get a summary of our existing swaps so that we can check our autoloop
538538
// budget.
539-
summary, err := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
540-
if err != nil {
541-
return err
542-
}
539+
summary := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
543540

544541
err = m.checkSummaryBudget(summary)
545542
if err != nil {
@@ -581,7 +578,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
581578
// allowed clamp it to max.
582579
amount := localTotal - m.params.EasyAutoloopTarget
583580
if amount > restrictions.Maximum {
584-
amount = btcutil.Amount(restrictions.Maximum)
581+
amount = restrictions.Maximum
585582
}
586583

587584
// If the amount we want to loop out is less than the minimum we can't
@@ -601,7 +598,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
601598
builder := newLoopOutBuilder(m.cfg)
602599

603600
channel := m.pickEasyAutoloopChannel(
604-
channels, restrictions, loopOut, loopIn, amount,
601+
channels, restrictions, loopOut, loopIn,
605602
)
606603
if channel == nil {
607604
return fmt.Errorf("no eligible channel for easy autoloop")
@@ -624,12 +621,12 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
624621
switch feeLimit := easyParams.FeeLimit.(type) {
625622
case *FeePortion:
626623
if feeLimit.PartsPerMillion == 0 {
627-
feeLimit = &FeePortion{
624+
easyParams.FeeLimit = &FeePortion{
628625
PartsPerMillion: defaultFeePPM,
629626
}
630627
}
631628
default:
632-
feeLimit = &FeePortion{
629+
easyParams.FeeLimit = &FeePortion{
633630
PartsPerMillion: defaultFeePPM,
634631
}
635632
}
@@ -646,16 +643,16 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
646643
return err
647644
}
648645

649-
swap := loop.OutRequest{}
646+
var swp loop.OutRequest
650647
if t, ok := suggestion.(*loopOutSwapSuggestion); ok {
651-
swap = t.OutRequest
648+
swp = t.OutRequest
652649
} else {
653650
return fmt.Errorf("unexpected swap suggestion type: %T", t)
654651
}
655652

656653
// Dispatch a sticky loop out.
657654
go m.dispatchStickyLoopOut(
658-
ctx, swap, defaultAmountBackoffRetry, defaultAmountBackoff,
655+
ctx, swp, defaultAmountBackoffRetry, defaultAmountBackoff,
659656
)
660657

661658
return nil
@@ -762,10 +759,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context) (
762759

763760
// Get a summary of our existing swaps so that we can check our autoloop
764761
// budget.
765-
summary, err := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
766-
if err != nil {
767-
return nil, err
768-
}
762+
summary := m.checkExistingAutoLoops(ctx, loopOut, loopIn)
769763

770764
err = m.checkSummaryBudget(summary)
771765
if err != nil {
@@ -1074,9 +1068,9 @@ func (e *existingAutoLoopSummary) totalFees() btcutil.Amount {
10741068
// automatically dispatched swaps that have completed, and the worst-case fee
10751069
// total for our set of ongoing, automatically dispatched swaps as well as a
10761070
// current in-flight count.
1077-
func (m *Manager) checkExistingAutoLoops(ctx context.Context,
1078-
loopOuts []*loopdb.LoopOut, loopIns []*loopdb.LoopIn) (
1079-
*existingAutoLoopSummary, error) {
1071+
func (m *Manager) checkExistingAutoLoops(_ context.Context,
1072+
loopOuts []*loopdb.LoopOut,
1073+
loopIns []*loopdb.LoopIn) *existingAutoLoopSummary {
10801074

10811075
var summary existingAutoLoopSummary
10821076

@@ -1133,7 +1127,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
11331127
}
11341128
}
11351129

1136-
return &summary, nil
1130+
return &summary
11371131
}
11381132

11391133
// currentSwapTraffic examines our existing swaps and returns a summary of the
@@ -1416,7 +1410,7 @@ func (m *Manager) waitForSwapPayment(ctx context.Context, swapHash lntypes.Hash,
14161410
// swap conflicts.
14171411
func (m *Manager) pickEasyAutoloopChannel(channels []lndclient.ChannelInfo,
14181412
restrictions *Restrictions, loopOut []*loopdb.LoopOut,
1419-
loopIn []*loopdb.LoopIn, amount btcutil.Amount) *lndclient.ChannelInfo {
1413+
loopIn []*loopdb.LoopIn) *lndclient.ChannelInfo {
14201414

14211415
traffic := m.currentSwapTraffic(loopOut, loopIn)
14221416

@@ -1472,7 +1466,6 @@ func (m *Manager) numActiveStickyLoops() int {
14721466
defer m.activeStickyLock.Unlock()
14731467

14741468
return m.activeStickyLoops
1475-
14761469
}
14771470

14781471
func (m *Manager) checkSummaryBudget(summary *existingAutoLoopSummary) error {
@@ -1482,7 +1475,6 @@ func (m *Manager) checkSummaryBudget(summary *existingAutoLoopSummary) error {
14821475
"(upper limit)",
14831476
m.params.AutoFeeBudget, summary.spentFees,
14841477
summary.pendingFees)
1485-
14861478
}
14871479

14881480
return nil
@@ -1556,7 +1548,3 @@ func satPerKwToSatPerVByte(satPerKw chainfee.SatPerKWeight) int64 {
15561548
func ppmToSat(amount btcutil.Amount, ppm uint64) btcutil.Amount {
15571549
return btcutil.Amount(uint64(amount) * ppm / FeeBase)
15581550
}
1559-
1560-
func mSatToSatoshis(amount lnwire.MilliSatoshi) btcutil.Amount {
1561-
return btcutil.Amount(amount / 1000)
1562-
}

liquidity/parameters.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package liquidity
33
import (
44
"errors"
55
"fmt"
6-
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
76
"strings"
87
"time"
98

109
"github.com/btcsuite/btcd/btcutil"
1110
"github.com/lightninglabs/lndclient"
1211
"github.com/lightninglabs/loop/swap"
12+
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
1313
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1414
"github.com/lightningnetwork/lnd/lnwire"
1515
"github.com/lightningnetwork/lnd/routing/route"
@@ -527,7 +527,6 @@ func ParametersToRpc(cfg Parameters) (*clientrpc.LiquidityParameters,
527527

528528
default:
529529
addrType = clientrpc.AddressType_ADDRESS_TYPE_UNKNOWN
530-
531530
}
532531

533532
rpcCfg := &clientrpc.LiquidityParameters{

liquidity/threshold_rule.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ func (r *ThresholdRule) swapAmount(channel *balances,
127127
// This function can be used for loop out or loop in, but the concept is the
128128
// same - we want liquidity in one (target) direction, while preserving some
129129
// minimum in the other (reserve) direction.
130-
// * target: this is the side of the channel(s) where we want to acquire some
131-
// liquidity. We aim for this liquidity to reach the threshold amount set.
132-
// * reserve: this is the side of the channel(s) that we will move liquidity
133-
// away from. This may not drop below a certain reserve threshold.
130+
// - target: this is the side of the channel(s) where we want to acquire some
131+
// liquidity. We aim for this liquidity to reach the threshold amount set.
132+
// - reserve: this is the side of the channel(s) that we will move liquidity
133+
// away from. This may not drop below a certain reserve threshold.
134134
func calculateSwapAmount(targetAmount, reserveAmount,
135135
capacity btcutil.Amount, targetThresholdPercentage,
136136
reserveThresholdPercentage uint64) btcutil.Amount {

loopd/daemon.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"sync"
1212
"sync/atomic"
13+
"time"
1314

1415
"github.com/coreos/bbolt"
1516
proxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
@@ -302,7 +303,10 @@ func (d *Daemon) startWebServers() error {
302303
if d.restListener != nil {
303304
log.Infof("Starting REST proxy listener")
304305

305-
d.restServer = &http.Server{Handler: restHandler}
306+
d.restServer = &http.Server{
307+
Handler: restHandler,
308+
ReadHeaderTimeout: 5 * time.Second,
309+
}
306310

307311
d.wg.Add(1)
308312
go func() {

loopd/migration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func migrateBoltdb(ctx context.Context, cfg *Config) error {
6161
return err
6262
}
6363

64-
// If the migration was successfull we'll rename the bolt db to
64+
// If the migration was successful we'll rename the bolt db to
6565
// loop.db.bk.
6666
err = os.Rename(
6767
filepath.Join(cfg.DataDir, "loop.db"),

0 commit comments

Comments
 (0)