@@ -406,7 +406,7 @@ func (p *KVPaymentsDB) InitPayment(paymentHash lntypes.Hash,
406
406
// are initializing a payment that was attempted earlier, but
407
407
// left in a state where we could retry.
408
408
err = bucket .DeleteNestedBucket (paymentHtlcsBucket )
409
- if err != nil && err != kvdb .ErrBucketNotFound {
409
+ if err != nil && ! errors . Is ( err , kvdb .ErrBucketNotFound ) {
410
410
return err
411
411
}
412
412
@@ -431,6 +431,7 @@ func (p *KVPaymentsDB) DeleteFailedAttempts(hash lntypes.Hash) error {
431
431
return err
432
432
}
433
433
}
434
+
434
435
return nil
435
436
}
436
437
@@ -454,6 +455,7 @@ func createPaymentIndexEntry(tx kvdb.RwTx, sequenceNumber []byte,
454
455
}
455
456
456
457
indexes := tx .ReadWriteBucket (paymentsIndexBucket )
458
+
457
459
return indexes .Put (sequenceNumber , b .Bytes ())
458
460
}
459
461
@@ -621,6 +623,7 @@ func (p *KVPaymentsDB) RegisterAttempt(paymentHash lntypes.Hash,
621
623
622
624
// Retrieve attempt info for the notification.
623
625
payment , err = fetchPayment (bucket )
626
+
624
627
return err
625
628
})
626
629
if err != nil {
@@ -696,17 +699,25 @@ func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
696
699
return fmt .Errorf ("htlcs bucket not found" )
697
700
}
698
701
699
- if htlcsBucket .Get (htlcBucketKey (htlcAttemptInfoKey , aid )) == nil {
702
+ attemptInfo := htlcsBucket .Get (
703
+ htlcBucketKey (htlcAttemptInfoKey , aid ),
704
+ )
705
+ if attemptInfo == nil {
700
706
return fmt .Errorf ("HTLC with ID %v not registered" ,
701
707
attemptID )
702
708
}
703
709
704
- // Make sure the shard is not already failed or settled.
705
- if htlcsBucket .Get (htlcBucketKey (htlcFailInfoKey , aid )) != nil {
710
+ failInfo := htlcsBucket .Get (
711
+ htlcBucketKey (htlcFailInfoKey , aid ),
712
+ )
713
+ if failInfo != nil {
706
714
return ErrAttemptAlreadyFailed
707
715
}
708
716
709
- if htlcsBucket .Get (htlcBucketKey (htlcSettleInfoKey , aid )) != nil {
717
+ settleInfo := htlcsBucket .Get (
718
+ htlcBucketKey (htlcSettleInfoKey , aid ),
719
+ )
720
+ if settleInfo != nil {
710
721
return ErrAttemptAlreadySettled
711
722
}
712
723
@@ -718,6 +729,7 @@ func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
718
729
719
730
// Retrieve attempt info for the notification.
720
731
payment , err = fetchPayment (bucket )
732
+
721
733
return err
722
734
})
723
735
if err != nil {
@@ -746,7 +758,7 @@ func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
746
758
747
759
prefetchPayment (tx , paymentHash )
748
760
bucket , err := fetchPaymentBucketUpdate (tx , paymentHash )
749
- if err == ErrPaymentNotInitiated {
761
+ if errors . Is ( err , ErrPaymentNotInitiated ) {
750
762
updateErr = ErrPaymentNotInitiated
751
763
return nil
752
764
} else if err != nil {
@@ -861,7 +873,6 @@ func fetchPaymentBucket(tx kvdb.RTx, paymentHash lntypes.Hash) (
861
873
}
862
874
863
875
return bucket , nil
864
-
865
876
}
866
877
867
878
// fetchPaymentBucketUpdate is identical to fetchPaymentBucket, but it returns a
@@ -902,6 +913,7 @@ func (p *KVPaymentsDB) nextPaymentSequence() ([]byte, error) {
902
913
903
914
currPaymentSeq = paymentsBucket .Sequence ()
904
915
newUpperBound = currPaymentSeq + paymentSeqBlockSize
916
+
905
917
return paymentsBucket .SetSequence (newUpperBound )
906
918
}, func () {}); err != nil {
907
919
return nil , err
@@ -987,6 +999,7 @@ func (p *KVPaymentsDB) FetchInFlightPayments() ([]*MPPayment, error) {
987
999
}
988
1000
989
1001
inFlights = append (inFlights , p )
1002
+
990
1003
return nil
991
1004
})
992
1005
}, func () {
0 commit comments