mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-29 07:00:55 +02:00
multi: fix linter
This commit is contained in:
@@ -488,5 +488,6 @@ func serializeTime(w io.Writer, t time.Time) error {
|
|||||||
|
|
||||||
byteOrder.PutUint64(scratch[:], uint64(unixNano))
|
byteOrder.PutUint64(scratch[:], uint64(unixNano))
|
||||||
_, err := w.Write(scratch[:])
|
_, err := w.Write(scratch[:])
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -1448,7 +1448,11 @@ func (s *Server) trackPaymentStream(context context.Context,
|
|||||||
// No more payment updates.
|
// No more payment updates.
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
result := item.(*paymentsdb.MPPayment)
|
result, ok := item.(*paymentsdb.MPPayment)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected payment type: %T",
|
||||||
|
item)
|
||||||
|
}
|
||||||
|
|
||||||
log.Tracef("Payment %v updated to state %v",
|
log.Tracef("Payment %v updated to state %v",
|
||||||
result.Info.PaymentIdentifier, result.Status)
|
result.Info.PaymentIdentifier, result.Status)
|
||||||
|
@@ -2,6 +2,7 @@ package paymentsdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -19,21 +20,20 @@ type UnknownElementType = channeldb.UnknownElementType
|
|||||||
func ReadElement(r io.Reader, element interface{}) error {
|
func ReadElement(r io.Reader, element interface{}) error {
|
||||||
err := channeldb.ReadElement(r, element)
|
err := channeldb.ReadElement(r, element)
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
// Known to channeldb codec.
|
// Known to channeldb codec.
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
// Fail if error is not UnknownElementType.
|
// Fail if error is not UnknownElementType.
|
||||||
default:
|
default:
|
||||||
if _, ok := err.(UnknownElementType); !ok {
|
var unknownElementType UnknownElementType
|
||||||
|
if !errors.As(err, &unknownElementType) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process any wtdb-specific extensions to the codec.
|
// Process any wtdb-specific extensions to the codec.
|
||||||
switch e := element.(type) {
|
switch e := element.(type) {
|
||||||
|
|
||||||
case *paymentIndexType:
|
case *paymentIndexType:
|
||||||
if err := binary.Read(r, byteOrder, e); err != nil {
|
if err := binary.Read(r, byteOrder, e); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -53,21 +53,20 @@ func ReadElement(r io.Reader, element interface{}) error {
|
|||||||
func WriteElement(w io.Writer, element interface{}) error {
|
func WriteElement(w io.Writer, element interface{}) error {
|
||||||
err := channeldb.WriteElement(w, element)
|
err := channeldb.WriteElement(w, element)
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
// Known to channeldb codec.
|
// Known to channeldb codec.
|
||||||
case err == nil:
|
case err == nil:
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
// Fail if error is not UnknownElementType.
|
// Fail if error is not UnknownElementType.
|
||||||
default:
|
default:
|
||||||
if _, ok := err.(UnknownElementType); !ok {
|
var unknownElementType UnknownElementType
|
||||||
|
if !errors.As(err, &unknownElementType) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process any wtdb-specific extensions to the codec.
|
// Process any wtdb-specific extensions to the codec.
|
||||||
switch e := element.(type) {
|
switch e := element.(type) {
|
||||||
|
|
||||||
case paymentIndexType:
|
case paymentIndexType:
|
||||||
if err := binary.Write(w, byteOrder, e); err != nil {
|
if err := binary.Write(w, byteOrder, e); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -137,5 +136,6 @@ func serializeTime(w io.Writer, t time.Time) error {
|
|||||||
|
|
||||||
byteOrder.PutUint64(scratch[:], uint64(unixNano))
|
byteOrder.PutUint64(scratch[:], uint64(unixNano))
|
||||||
_, err := w.Write(scratch[:])
|
_, err := w.Write(scratch[:])
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -954,7 +954,6 @@ func TestKVPaymentsDBMultiShard(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
test := test
|
|
||||||
subTest := fmt.Sprintf("first=%v, second=%v",
|
subTest := fmt.Sprintf("first=%v, second=%v",
|
||||||
test.settleFirst, test.settleLast)
|
test.settleFirst, test.settleLast)
|
||||||
|
|
||||||
@@ -1643,9 +1642,8 @@ func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
test := test
|
|
||||||
|
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
//nolint:ll
|
||||||
err := kvdb.Update(
|
err := kvdb.Update(
|
||||||
paymentDB.db, func(tx walletdb.ReadWriteTx) error {
|
paymentDB.db, func(tx walletdb.ReadWriteTx) error {
|
||||||
var seqNrBytes [8]byte
|
var seqNrBytes [8]byte
|
||||||
|
@@ -8,8 +8,6 @@ import (
|
|||||||
// log is a logger that is initialized with no output filters. This
|
// log is a logger that is initialized with no output filters. This
|
||||||
// means the package will not perform any logging by default until the caller
|
// means the package will not perform any logging by default until the caller
|
||||||
// requests it.
|
// requests it.
|
||||||
//
|
|
||||||
//nolint:unused
|
|
||||||
var log btclog.Logger
|
var log btclog.Logger
|
||||||
|
|
||||||
// Subsystem defines the logging identifier for this subsystem.
|
// Subsystem defines the logging identifier for this subsystem.
|
||||||
|
@@ -255,8 +255,8 @@ const (
|
|||||||
// reason.
|
// reason.
|
||||||
HTLCFailUnknown HTLCFailReason = 0
|
HTLCFailUnknown HTLCFailReason = 0
|
||||||
|
|
||||||
// HTLCFailUnreadable is recorded for htlcs that had a failure message that
|
// HTLCFailUnreadable is recorded for htlcs that had a failure message
|
||||||
// couldn't be decrypted.
|
// that couldn't be decrypted.
|
||||||
HTLCFailUnreadable HTLCFailReason = 1
|
HTLCFailUnreadable HTLCFailReason = 1
|
||||||
|
|
||||||
// HTLCFailInternal is recorded for htlcs that failed because of an
|
// HTLCFailInternal is recorded for htlcs that failed because of an
|
||||||
|
@@ -60,19 +60,6 @@ var (
|
|||||||
LegacyPayload: true,
|
LegacyPayload: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
testHop3 = &route.Hop{
|
|
||||||
PubKeyBytes: route.NewVertex(pub),
|
|
||||||
ChannelID: 12345,
|
|
||||||
OutgoingTimeLock: 111,
|
|
||||||
AmtToForward: 555,
|
|
||||||
CustomRecords: record.CustomSet{
|
|
||||||
65536: []byte{},
|
|
||||||
80001: []byte{},
|
|
||||||
},
|
|
||||||
AMP: record.NewAMP([32]byte{0x69}, [32]byte{0x42}, 1),
|
|
||||||
Metadata: []byte{1, 2, 3},
|
|
||||||
}
|
|
||||||
|
|
||||||
testRoute = route.Route{
|
testRoute = route.Route{
|
||||||
TotalTimeLock: 123,
|
TotalTimeLock: 123,
|
||||||
TotalAmount: 1234567,
|
TotalAmount: 1234567,
|
||||||
|
@@ -130,15 +130,23 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
|
|||||||
for result == nil || !result.Terminated() {
|
for result == nil || !result.Terminated() {
|
||||||
select {
|
select {
|
||||||
case item := <-s.Updates():
|
case item := <-s.Updates():
|
||||||
result = item.(*paymentsdb.MPPayment)
|
payment, ok := item.(*paymentsdb.MPPayment)
|
||||||
|
require.True(
|
||||||
|
t, ok, "unexpected payment type: %T",
|
||||||
|
item)
|
||||||
|
|
||||||
|
result = payment
|
||||||
|
|
||||||
case <-time.After(testTimeout):
|
case <-time.After(testTimeout):
|
||||||
t.Fatal("timeout waiting for payment result")
|
t.Fatal("timeout waiting for payment result")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equalf(t, paymentsdb.StatusSucceeded, result.GetStatus(),
|
require.Equalf(t, paymentsdb.StatusSucceeded,
|
||||||
"subscriber %v failed, want %s, got %s", i,
|
result.GetStatus(), "subscriber %v failed, want %s, "+
|
||||||
paymentsdb.StatusSucceeded, result.GetStatus())
|
"got %s", i, paymentsdb.StatusSucceeded,
|
||||||
|
result.GetStatus(),
|
||||||
|
)
|
||||||
|
|
||||||
attempt, _ := result.TerminalInfo()
|
attempt, _ := result.TerminalInfo()
|
||||||
if attempt.Settle.Preimage != preimg {
|
if attempt.Settle.Preimage != preimg {
|
||||||
@@ -261,8 +269,14 @@ func TestKVPaymentsDBSubscribeAllSuccess(t *testing.T) {
|
|||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
select {
|
select {
|
||||||
case item := <-subscription.Updates():
|
case item := <-subscription.Updates():
|
||||||
id := item.(*paymentsdb.MPPayment).Info.PaymentIdentifier
|
payment, ok := item.(*paymentsdb.MPPayment)
|
||||||
results[id] = item.(*paymentsdb.MPPayment)
|
require.True(
|
||||||
|
t, ok, "unexpected payment type: %T",
|
||||||
|
item)
|
||||||
|
|
||||||
|
id := payment.Info.PaymentIdentifier
|
||||||
|
results[id] = payment
|
||||||
|
|
||||||
case <-time.After(testTimeout):
|
case <-time.After(testTimeout):
|
||||||
require.Fail(t, "timeout waiting for payment result")
|
require.Fail(t, "timeout waiting for payment result")
|
||||||
}
|
}
|
||||||
@@ -337,11 +351,17 @@ func TestKVPaymentsDBSubscribeAllImmediate(t *testing.T) {
|
|||||||
select {
|
select {
|
||||||
case update := <-subscription.Updates():
|
case update := <-subscription.Updates():
|
||||||
require.NotNil(t, update)
|
require.NotNil(t, update)
|
||||||
|
payment, ok := update.(*paymentsdb.MPPayment)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("unexpected payment type: %T", update)
|
||||||
|
}
|
||||||
|
|
||||||
require.Equal(
|
require.Equal(
|
||||||
t, info.PaymentIdentifier,
|
t, info.PaymentIdentifier,
|
||||||
update.(*paymentsdb.MPPayment).Info.PaymentIdentifier,
|
payment.Info.PaymentIdentifier,
|
||||||
)
|
)
|
||||||
require.Len(t, subscription.Updates(), 0)
|
require.Len(t, subscription.Updates(), 0)
|
||||||
|
|
||||||
case <-time.After(testTimeout):
|
case <-time.After(testTimeout):
|
||||||
require.Fail(t, "timeout waiting for payment result")
|
require.Fail(t, "timeout waiting for payment result")
|
||||||
}
|
}
|
||||||
@@ -502,7 +522,12 @@ func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
|
|||||||
for result == nil || !result.Terminated() {
|
for result == nil || !result.Terminated() {
|
||||||
select {
|
select {
|
||||||
case item := <-s.Updates():
|
case item := <-s.Updates():
|
||||||
result = item.(*paymentsdb.MPPayment)
|
payment, ok := item.(*paymentsdb.MPPayment)
|
||||||
|
require.True(
|
||||||
|
t, ok, "unexpected payment type: %T",
|
||||||
|
item)
|
||||||
|
|
||||||
|
result = payment
|
||||||
case <-time.After(testTimeout):
|
case <-time.After(testTimeout):
|
||||||
t.Fatal("timeout waiting for payment result")
|
t.Fatal("timeout waiting for payment result")
|
||||||
}
|
}
|
||||||
|
@@ -441,6 +441,7 @@ func (m *mockControlTowerOld) SettleAttempt(phash lntypes.Hash,
|
|||||||
|
|
||||||
// Mark the payment successful on first settled attempt.
|
// Mark the payment successful on first settled attempt.
|
||||||
m.successful[phash] = struct{}{}
|
m.successful[phash] = struct{}{}
|
||||||
|
|
||||||
return &paymentsdb.HTLCAttempt{
|
return &paymentsdb.HTLCAttempt{
|
||||||
Settle: settleInfo,
|
Settle: settleInfo,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -479,6 +480,7 @@ func (m *mockControlTowerOld) FailAttempt(phash lntypes.Hash, pid uint64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.attempts[i].Failure = failInfo
|
p.attempts[i].Failure = failInfo
|
||||||
|
|
||||||
return &paymentsdb.HTLCAttempt{
|
return &paymentsdb.HTLCAttempt{
|
||||||
Failure: failInfo,
|
Failure: failInfo,
|
||||||
}, nil
|
}, nil
|
||||||
|
Reference in New Issue
Block a user