Browse Source

multi: fix most obvious linter errors

pull/94/head
Oliver Gugger 1 year ago
parent
commit
36838cf7f4
No known key found for this signature in database GPG Key ID: 8E4256593F177720
21 changed files with 41 additions and 50 deletions
  1. +1
    -1
      client.go
  2. +1
    -2
      cmd/loop/loopin.go
  3. +1
    -2
      cmd/loop/loopout.go
  4. +3
    -3
      cmd/loop/main.go
  5. +1
    -2
      cmd/loop/quote.go
  6. +3
    -3
      executor.go
  7. +2
    -2
      lndclient/invoices_client.go
  8. +2
    -1
      lndclient/log.go
  9. +2
    -1
      lndclient/router_client.go
  10. +2
    -3
      log.go
  11. +4
    -1
      loopdb/loopin.go
  12. +4
    -1
      loopdb/loopout.go
  13. +1
    -1
      loopin.go
  14. +3
    -3
      loopout_test.go
  15. +0
    -7
      server_mock_test.go
  16. +0
    -5
      store_mock_test.go
  17. +1
    -1
      sweep/sweeper.go
  18. +2
    -1
      test/log.go
  19. +4
    -1
      test/testutils.go
  20. +4
    -1
      test/timeout.go
  21. +0
    -8
      testcontext_test.go

+ 1
- 1
client.go View File

@ -384,7 +384,7 @@ func (s *Client) LoopOutQuote(ctx context.Context,
return &LoopOutQuote{
SwapFee: swapFee,
MinerFee: minerFee,
PrepayAmount: btcutil.Amount(quote.PrepayAmount),
PrepayAmount: quote.PrepayAmount,
SwapPaymentDest: quote.SwapPaymentDest,
CltvDelta: quote.CltvDelta,
}, nil

+ 1
- 2
cmd/loop/loopin.go View File

@ -41,8 +41,7 @@ func loopIn(ctx *cli.Context) error {
args = args.Tail()
default:
// Show command help if no arguments and flags were provided.
cli.ShowCommandHelp(ctx, "in")
return nil
return cli.ShowCommandHelp(ctx, "in")
}
amt, err := parseAmt(amtStr)

+ 1
- 2
cmd/loop/loopout.go View File

@ -59,8 +59,7 @@ func loopOut(ctx *cli.Context) error {
args = args.Tail()
default:
// Show command help if no arguments and flags were provided.
cli.ShowCommandHelp(ctx, "out")
return nil
return cli.ShowCommandHelp(ctx, "out")
}
amt, err := parseAmt(amtStr)

+ 3
- 3
cmd/loop/main.go View File

@ -97,7 +97,7 @@ type limits struct {
}
func getLimits(amt btcutil.Amount, quote *looprpc.QuoteResponse) *limits {
maxSwapRoutingFee := getMaxRoutingFee(btcutil.Amount(amt))
maxSwapRoutingFee := getMaxRoutingFee(amt)
maxPrepayRoutingFee := getMaxRoutingFee(btcutil.Amount(
quote.PrepayAmt,
))
@ -126,7 +126,7 @@ func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits,
if l.maxPrepayRoutingFee != nil {
totalSuccessMax += *l.maxPrepayRoutingFee
}
if swapType == loop.TypeIn && externalHtlc {
fmt.Printf("On-chain fee for external loop in is not " +
"included.\nSufficient fees will need to be paid " +
@ -135,7 +135,7 @@ func displayLimits(swapType loop.Type, amt btcutil.Amount, l *limits,
}
fmt.Printf("Max swap fees for %d Loop %v: %d\n",
btcutil.Amount(amt), swapType, totalSuccessMax,
amt, swapType, totalSuccessMax,
)
fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ")

+ 1
- 2
cmd/loop/quote.go View File

@ -28,8 +28,7 @@ func quote(ctx *cli.Context) error {
// Show command help if the incorrect number arguments and/or flags were
// provided.
if ctx.NArg() != 1 || ctx.NumFlags() > 1 {
cli.ShowCommandHelp(ctx, "quote")
return nil
return cli.ShowCommandHelp(ctx, "quote")
}
args := ctx.Args()

+ 3
- 3
executor.go View File

@ -69,7 +69,7 @@ func (s *executor) run(mainCtx context.Context,
select {
case h := <-blockEpochChan:
setHeight(int32(h))
setHeight(h)
case err := <-blockErrorChan:
return err
case <-mainCtx.Done():
@ -134,10 +134,10 @@ func (s *executor) run(mainCtx context.Context,
delete(blockEpochQueues, doneID)
case h := <-blockEpochChan:
setHeight(int32(h))
setHeight(h)
for _, queue := range blockEpochQueues {
select {
case queue.ChanIn() <- int32(h):
case queue.ChanIn() <- h:
case <-mainCtx.Done():
return mainCtx.Err()
}

+ 2
- 2
lndclient/invoices_client.go View File

@ -52,10 +52,10 @@ func (s *invoicesClient) WaitForFinished() {
func (s *invoicesClient) SettleInvoice(ctx context.Context,
preimage lntypes.Preimage) error {
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
timeoutCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
defer cancel()
rpcCtx = s.invoiceMac.WithMacaroonAuth(ctx)
rpcCtx := s.invoiceMac.WithMacaroonAuth(timeoutCtx)
_, err := s.client.SettleInvoice(rpcCtx, &invoicesrpc.SettleInvoiceMsg{
Preimage: preimage[:],
})

+ 2
- 1
lndclient/log.go View File

@ -1,8 +1,9 @@
package lndclient
import (
"github.com/btcsuite/btclog"
"os"
"github.com/btcsuite/btclog"
)
// log is a logger that is initialized with no output filters. This

+ 2
- 1
lndclient/router_client.go View File

@ -4,9 +4,10 @@ import (
"context"
"encoding/hex"
"fmt"
"time"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/routing/route"
"time"
"github.com/lightningnetwork/lnd/channeldb"
"google.golang.org/grpc/codes"

+ 2
- 3
log.go View File

@ -12,9 +12,8 @@ import (
// means the package will not perform any logging by default until the caller
// requests it.
var (
backendLog = btclog.NewBackend(logWriter{})
logger = backendLog.Logger("CLIENT")
servicesLogger = backendLog.Logger("SERVICES")
backendLog = btclog.NewBackend(logWriter{})
logger = backendLog.Logger("CLIENT")
)
// logWriter implements an io.Writer that outputs to both standard output and

+ 4
- 1
loopdb/loopin.go View File

@ -127,7 +127,10 @@ func deserializeLoopInContract(value []byte) (*LoopInContract, error) {
return nil, err
}
binary.Read(r, byteOrder, &contract.AmountRequested)
err = binary.Read(r, byteOrder, &contract.AmountRequested)
if err != nil {
return nil, err
}
n, err := r.Read(contract.SenderKey[:])
if err != nil {

+ 4
- 1
loopdb/loopout.go View File

@ -84,7 +84,10 @@ func deserializeLoopOutContract(value []byte, chainParams *chaincfg.Params) (
return nil, err
}
binary.Read(r, byteOrder, &contract.AmountRequested)
err = binary.Read(r, byteOrder, &contract.AmountRequested)
if err != nil {
return nil, err
}
contract.PrepayInvoice, err = wire.ReadVarString(r, 0)
if err != nil {

+ 1
- 1
loopin.go View File

@ -493,7 +493,7 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
case err := <-swapInvoiceErr:
return err
// An update to the swap invoice occured. Check the new state
// An update to the swap invoice occurred. Check the new state
// and update the swap state accordingly.
case update := <-swapInvoiceChan:
s.log.Infof("Received swap invoice update: %v",

+ 3
- 3
loopout_test.go View File

@ -176,7 +176,7 @@ func TestCustomSweepConfTarget(t *testing.T) {
// Notify the confirmation notification for the HTLC.
ctx.AssertRegisterConf()
blockEpochChan <- int32(ctx.Lnd.Height + 1)
blockEpochChan <- ctx.Lnd.Height + 1
htlcTx := wire.NewMsgTx(2)
htlcTx.AddTxOut(&wire.TxOut{
@ -238,7 +238,7 @@ func TestCustomSweepConfTarget(t *testing.T) {
// The sweep should have a fee that corresponds to the custom
// confirmation target.
sweepTx := assertSweepTx(testRequest.SweepConfTarget)
_ = assertSweepTx(testRequest.SweepConfTarget)
// We'll then notify the height at which we begin using the default
// confirmation target.
@ -249,7 +249,7 @@ func TestCustomSweepConfTarget(t *testing.T) {
// We should expect to see another sweep using the higher fee since the
// spend hasn't been confirmed yet.
sweepTx = assertSweepTx(DefaultSweepConfTarget)
sweepTx := assertSweepTx(DefaultSweepConfTarget)
// Notify the spend so that the swap reaches its final state.
ctx.NotifySpend(sweepTx, 0)

+ 0
- 7
server_mock_test.go View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"testing"
"time"
"github.com/btcsuite/btcd/chaincfg"
@ -20,20 +19,14 @@ var (
testLoopOutOnChainCltvDelta = int32(30)
testChargeOnChainCltvDelta = int32(100)
testCltvDelta = 50
testSwapFee = btcutil.Amount(210)
testInvoiceExpiry = 180 * time.Second
testFixedPrepayAmount = btcutil.Amount(100)
testMinSwapAmount = btcutil.Amount(10000)
testMaxSwapAmount = btcutil.Amount(1000000)
testTxConfTarget = 2
testRepublishDelay = 10 * time.Second
)
// serverMock is used in client unit tests to simulate swap server behaviour.
type serverMock struct {
t *testing.T
expectedSwapAmt btcutil.Amount
swapInvoiceAmt btcutil.Amount
prepayInvoiceAmt btcutil.Amount

+ 0
- 5
store_mock_test.go View File

@ -25,11 +25,6 @@ type storeMock struct {
t *testing.T
}
type finishData struct {
preimage lntypes.Hash
result loopdb.SwapState
}
// NewStoreMock instantiates a new mock store.
func newStoreMock(t *testing.T) *storeMock {
return &storeMock{

+ 1
- 1
sweep/sweeper.go View File

@ -112,7 +112,7 @@ func (s *Sweeper) GetSweepFee(ctx context.Context,
case *btcutil.AddressPubKeyHash:
weightEstimate.AddP2PKHOutput()
default:
return 0, fmt.Errorf("unknown adress type %T", destAddr)
return 0, fmt.Errorf("unknown address type %T", destAddr)
}
addInputEstimate(&weightEstimate)

+ 2
- 1
test/log.go View File

@ -1,8 +1,9 @@
package test
import (
"github.com/btcsuite/btclog"
"os"
"github.com/btcsuite/btclog"
)
// log is a logger that is initialized with no output filters. This

+ 4
- 1
test/testutils.go View File

@ -91,5 +91,8 @@ func GetInvoice(hash lntypes.Hash, amt btcutil.Amount, memo string) (
// DumpGoroutines dumps all currently running goroutines.
func DumpGoroutines() {
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
err := pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
if err != nil {
panic(err)
}
}

+ 4
- 1
test/timeout.go View File

@ -15,7 +15,10 @@ func Guard(t *testing.T) func() {
go func() {
select {
case <-time.After(5 * time.Second):
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
err := pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
if err != nil {
panic(err)
}
panic("test timeout")
case <-done:

+ 0
- 8
testcontext_test.go View File

@ -21,14 +21,6 @@ var (
1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4,
})
testPrepayPreimage = lntypes.Preimage([32]byte{
1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4,
1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 5,
})
testStartingHeight = uint32(600)
)
// testContext contains functionality to support client unit tests.

Loading…
Cancel
Save