Skip to content

Commit 2880b9a

Browse files
committed
mulit: fix linter
1 parent c5c4d6b commit 2880b9a

File tree

7 files changed

+67
-26
lines changed

7 files changed

+67
-26
lines changed

channeldb/duplicate_payments.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ type duplicateHTLCAttemptInfo struct {
6262

6363
// fetchDuplicatePaymentStatus fetches the payment status of the payment. If
6464
// the payment isn't found, it will return error `ErrPaymentNotInitiated`.
65-
func fetchDuplicatePaymentStatus(bucket kvdb.RBucket) (pymtpkg.PaymentStatus, error) {
65+
func fetchDuplicatePaymentStatus(bucket kvdb.RBucket) (pymtpkg.PaymentStatus,
66+
error) {
67+
6668
if bucket.Get(duplicatePaymentSettleInfoKey) != nil {
6769
return pymtpkg.StatusSucceeded, nil
6870
}

channeldb/payments.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ func (p *KVPaymentsDB) RegisterAttempt(paymentHash lntypes.Hash,
477477
// After invoking this method, InitPayment should always return an error to
478478
// prevent us from making duplicate payments to the same payment hash. The
479479
// provided preimage is atomically saved to the DB for record keeping.
480-
func (p *KVPaymentsDB) SettleAttempt(hash lntypes.Hash,
481-
attemptID uint64, settleInfo *pymtpkg.HTLCSettleInfo) (*pymtpkg.MPPayment, error) {
480+
func (p *KVPaymentsDB) SettleAttempt(hash lntypes.Hash, attemptID uint64,
481+
settleInfo *pymtpkg.HTLCSettleInfo) (*pymtpkg.MPPayment, error) {
482482

483483
var b bytes.Buffer
484484
if err := serializeHTLCSettleInfo(&b, settleInfo); err != nil {
@@ -490,8 +490,8 @@ func (p *KVPaymentsDB) SettleAttempt(hash lntypes.Hash,
490490
}
491491

492492
// FailAttempt marks the given payment attempt failed.
493-
func (p *KVPaymentsDB) FailAttempt(hash lntypes.Hash,
494-
attemptID uint64, failInfo *pymtpkg.HTLCFailInfo) (*pymtpkg.MPPayment, error) {
493+
func (p *KVPaymentsDB) FailAttempt(hash lntypes.Hash, attemptID uint64,
494+
failInfo *pymtpkg.HTLCFailInfo) (*pymtpkg.MPPayment, error) {
495495

496496
var b bytes.Buffer
497497
if err := serializeHTLCFailInfo(&b, failInfo); err != nil {
@@ -919,7 +919,9 @@ func (p *KVPaymentsDB) FetchPayments() ([]*pymtpkg.MPPayment, error) {
919919
return payments, nil
920920
}
921921

922-
func fetchCreationInfo(bucket kvdb.RBucket) (*pymtpkg.PaymentCreationInfo, error) {
922+
func fetchCreationInfo(bucket kvdb.RBucket) (*pymtpkg.PaymentCreationInfo,
923+
error) {
924+
923925
b := bucket.Get(paymentCreationInfoKey)
924926
if b == nil {
925927
return nil, fmt.Errorf("creation info not found")
@@ -1589,7 +1591,9 @@ func fetchSequenceNumbers(paymentBucket kvdb.RBucket) ([][]byte, error) {
15891591
}
15901592

15911593
// nolint: dupl
1592-
func serializePaymentCreationInfo(w io.Writer, c *pymtpkg.PaymentCreationInfo) error {
1594+
func serializePaymentCreationInfo(w io.Writer,
1595+
c *pymtpkg.PaymentCreationInfo) error {
1596+
15931597
var scratch [8]byte
15941598

15951599
if _, err := w.Write(c.PaymentIdentifier[:]); err != nil {

channeldb/payments_test.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ var (
104104
}
105105
)
106106

107-
func makeFakeInfo(t *testing.T) (*pymtpkg.PaymentCreationInfo, *pymtpkg.HTLCAttemptInfo) {
107+
func makeFakeInfo(t *testing.T) (*pymtpkg.PaymentCreationInfo,
108+
*pymtpkg.HTLCAttemptInfo) {
109+
108110
var preimg lntypes.Preimage
109111
copy(preimg[:], rev[:])
110112

@@ -846,8 +848,8 @@ func genPreimage() ([32]byte, error) {
846848
return preimage, nil
847849
}
848850

849-
func genInfo(t *testing.T) (*pymtpkg.PaymentCreationInfo, *pymtpkg.HTLCAttemptInfo,
850-
lntypes.Preimage, error) {
851+
func genInfo(t *testing.T) (*pymtpkg.PaymentCreationInfo,
852+
*pymtpkg.HTLCAttemptInfo, lntypes.Preimage, error) {
851853

852854
preimage, err := genPreimage()
853855
if err != nil {
@@ -904,7 +906,9 @@ func TestKVPaymentsDBSwitchFail(t *testing.T) {
904906
require.NoError(t, err, "unable to fail payment hash")
905907

906908
// Verify the status is indeed Failed.
907-
assertPaymentStatus(t, paymentDB, info.PaymentIdentifier, pymtpkg.StatusFailed)
909+
assertPaymentStatus(
910+
t, paymentDB, info.PaymentIdentifier, pymtpkg.StatusFailed,
911+
)
908912
assertPaymentInfo(
909913
t, paymentDB, info.PaymentIdentifier, info, &failReason, nil,
910914
)
@@ -1126,7 +1130,9 @@ func TestKVPaymentsDBFailsWithoutInFlight(t *testing.T) {
11261130
require.NoError(t, err, "unable to generate htlc message")
11271131

11281132
// Calling Fail should return an error.
1129-
_, err = paymentDB.Fail(info.PaymentIdentifier, pymtpkg.FailureReasonNoRoute)
1133+
_, err = paymentDB.Fail(
1134+
info.PaymentIdentifier, pymtpkg.FailureReasonNoRoute,
1135+
)
11301136
if !errors.Is(err, pymtpkg.ErrPaymentNotInitiated) {
11311137
t.Fatalf("expected ErrPaymentNotInitiated, got %v", err)
11321138
}
@@ -1548,7 +1554,8 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
15481554

15491555
assertPaymentIndex(t, paymentDB, info.PaymentIdentifier)
15501556
assertPaymentStatus(
1551-
t, paymentDB, info.PaymentIdentifier, pymtpkg.StatusInitiated,
1557+
t, paymentDB, info.PaymentIdentifier,
1558+
pymtpkg.StatusInitiated,
15521559
)
15531560
assertPaymentInfo(
15541561
t, paymentDB, info.PaymentIdentifier, info, nil, nil,
@@ -1621,7 +1628,8 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
16211628

16221629
// Payment should still be in-flight.
16231630
assertPaymentStatus(
1624-
t, paymentDB, info.PaymentIdentifier, pymtpkg.StatusInFlight,
1631+
t, paymentDB, info.PaymentIdentifier,
1632+
pymtpkg.StatusInFlight,
16251633
)
16261634

16271635
// Depending on the test case, settle or fail the first attempt.
@@ -1696,13 +1704,18 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
16961704
b.AttemptID = 3
16971705
_, err = paymentDB.RegisterAttempt(info.PaymentIdentifier, &b)
16981706
if test.settleFirst {
1699-
require.ErrorIs(t, err, pymtpkg.ErrPaymentPendingSettled)
1707+
require.ErrorIs(
1708+
t, err, pymtpkg.ErrPaymentPendingSettled,
1709+
)
17001710
} else {
1701-
require.ErrorIs(t, err, pymtpkg.ErrPaymentPendingFailed)
1711+
require.ErrorIs(
1712+
t, err, pymtpkg.ErrPaymentPendingFailed,
1713+
)
17021714
}
17031715

17041716
assertPaymentStatus(
1705-
t, paymentDB, info.PaymentIdentifier, pymtpkg.StatusInFlight,
1717+
t, paymentDB, info.PaymentIdentifier,
1718+
pymtpkg.StatusInFlight,
17061719
)
17071720

17081721
// Settle or fail the remaining attempt based on the testcase.
@@ -2010,7 +2023,8 @@ type htlcStatus struct {
20102023
// assertPaymentInfo retrieves the payment referred to by hash and verifies the
20112024
// expected values.
20122025
func assertPaymentInfo(t *testing.T, p *KVPaymentsDB, hash lntypes.Hash,
2013-
c *pymtpkg.PaymentCreationInfo, f *pymtpkg.FailureReason, a *htlcStatus) {
2026+
c *pymtpkg.PaymentCreationInfo, f *pymtpkg.FailureReason,
2027+
a *htlcStatus) {
20142028

20152029
t.Helper()
20162030

lnrpc/routerrpc/router_server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,12 @@ func (s *Server) trackPaymentStream(context context.Context,
14351435
// No more payment updates.
14361436
return nil
14371437
}
1438-
result := item.(*pymtpkg.MPPayment)
1438+
1439+
result, ok := item.(*pymtpkg.MPPayment)
1440+
if !ok {
1441+
return fmt.Errorf("unexpected type in "+
1442+
"payment update: %T", item)
1443+
}
14391444

14401445
log.Tracef("Payment %v updated to state %v",
14411446
result.Info.PaymentIdentifier, result.Status)

payments/mp_payment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ const (
512512
// reason.
513513
HTLCFailUnknown HTLCFailReason = 0
514514

515-
// HTLCFailUnreadable is recorded for htlcs that had a failure message that
516-
// couldn't be decrypted.
515+
// HTLCFailUnreadable is recorded for htlcs that had a failure message
516+
// that couldn't be decrypted.
517517
HTLCFailUnreadable HTLCFailReason = 1
518518

519519
// HTLCFailInternal is recorded for htlcs that failed because of an

routing/control_tower_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
121121
for result == nil || !result.Terminated() {
122122
select {
123123
case item := <-s.Updates():
124-
result = item.(*pymtpkg.MPPayment)
124+
_, ok := item.(*pymtpkg.MPPayment)
125+
require.True(t, ok, "unexpected type in "+
126+
"payment update: %T", item)
127+
125128
case <-time.After(testTimeout):
126129
t.Fatal("timeout waiting for payment result")
127130
}
@@ -246,8 +249,12 @@ func TestPaymentControlSubscribeAllSuccess(t *testing.T) {
246249
for i := 0; i < 6; i++ {
247250
select {
248251
case item := <-subscription.Updates():
249-
id := item.(*pymtpkg.MPPayment).Info.PaymentIdentifier
250-
results[id] = item.(*pymtpkg.MPPayment)
252+
payment, ok := item.(*pymtpkg.MPPayment)
253+
require.True(t, ok, "unexpected type in "+
254+
"payment update: %T", item)
255+
id := payment.Info.PaymentIdentifier
256+
results[id] = payment
257+
251258
case <-time.After(testTimeout):
252259
require.Fail(t, "timeout waiting for payment result")
253260
}
@@ -316,11 +323,15 @@ func TestPaymentControlSubscribeAllImmediate(t *testing.T) {
316323
select {
317324
case update := <-subscription.Updates():
318325
require.NotNil(t, update)
326+
payment, ok := update.(*pymtpkg.MPPayment)
327+
require.True(t, ok, "unexpected type in "+
328+
"payment update: %T", update)
319329
require.Equal(
320330
t, info.PaymentIdentifier,
321-
update.(*pymtpkg.MPPayment).Info.PaymentIdentifier,
331+
payment.Info.PaymentIdentifier,
322332
)
323333
require.Len(t, subscription.Updates(), 0)
334+
324335
case <-time.After(testTimeout):
325336
require.Fail(t, "timeout waiting for payment result")
326337
}
@@ -467,7 +478,10 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt,
467478
for result == nil || !result.Terminated() {
468479
select {
469480
case item := <-s.Updates():
470-
result = item.(*pymtpkg.MPPayment)
481+
_, ok := item.(*pymtpkg.MPPayment)
482+
require.True(t, ok, "unexpected type in "+
483+
"payment update: %T", item)
484+
471485
case <-time.After(testTimeout):
472486
t.Fatal("timeout waiting for payment result")
473487
}

routing/mock_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ func (m *mockControlTowerOld) SettleAttempt(phash lntypes.Hash,
441441

442442
// Mark the payment successful on first settled attempt.
443443
m.successful[phash] = struct{}{}
444+
444445
return &pymtpkg.HTLCAttempt{
445446
Settle: settleInfo,
446447
}, nil
@@ -479,6 +480,7 @@ func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
479480
}
480481

481482
p.attempts[i].Failure = failInfo
483+
482484
return &pymtpkg.HTLCAttempt{
483485
Failure: failInfo,
484486
}, nil

0 commit comments

Comments
 (0)