mirror of
https://github.com/lightninglabs/loop
synced 2024-11-04 06:00:21 +00:00
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.
This commit is contained in:
parent
446f163530
commit
4baf88c414
@ -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/*
|
||||
|
@ -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
|
||||
|
@ -141,7 +141,6 @@ func TestLoopOutFailWrongAmount(t *testing.T) {
|
||||
m.prepayInvoiceAmt += 10
|
||||
}, ErrPrepayAmountTooHigh)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// TestLoopOutResume tests that swaps in various states are properly resumed
|
||||
|
@ -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")
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
11
loopin.go
11
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
|
||||
|
15
loopout.go
15
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
|
||||
|
@ -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.
|
||||
|
@ -246,7 +246,6 @@ func (s *storeMock) assertLoopInState(
|
||||
}
|
||||
|
||||
func (s *storeMock) assertStorePreimageReveal() {
|
||||
|
||||
s.t.Helper()
|
||||
|
||||
select {
|
||||
|
2
swap.go
2
swap.go
@ -14,7 +14,7 @@ import (
|
||||
type swapKit struct {
|
||||
hash lntypes.Hash
|
||||
|
||||
height int32
|
||||
height int32 //nolint:structcheck
|
||||
|
||||
log *swap.PrefixLog
|
||||
|
||||
|
14
swap/htlc.go
14
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.
|
||||
//
|
||||
// <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_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 .
|
||||
func newHTLCScriptV2(cltvExpiry int32, senderHtlcKey,
|
||||
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):
|
||||
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")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user