2019-05-16 16:27:28 +03:00
|
|
|
package routing
|
|
|
|
|
|
|
|
import (
|
2019-05-23 21:05:30 +03:00
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
|
2019-04-30 14:24:37 +03:00
|
|
|
"github.com/go-errors/errors"
|
2019-05-23 21:05:30 +03:00
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
2019-05-16 16:27:28 +03:00
|
|
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
2019-05-23 21:05:30 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lntypes"
|
2019-05-16 16:27:28 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2019-05-23 21:05:30 +03:00
|
|
|
"github.com/lightningnetwork/lnd/routing/route"
|
2019-05-16 16:27:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type mockPaymentAttemptDispatcher struct {
|
|
|
|
onPayment func(firstHop lnwire.ShortChannelID) ([32]byte, error)
|
2019-05-16 16:27:29 +03:00
|
|
|
results map[uint64]*htlcswitch.PaymentResult
|
2020-04-01 01:13:27 +03:00
|
|
|
|
|
|
|
sync.Mutex
|
2019-05-16 16:27:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ PaymentAttemptDispatcher = (*mockPaymentAttemptDispatcher)(nil)
|
|
|
|
|
|
|
|
func (m *mockPaymentAttemptDispatcher) SendHTLC(firstHop lnwire.ShortChannelID,
|
2019-05-16 16:27:29 +03:00
|
|
|
pid uint64,
|
2019-05-16 16:27:29 +03:00
|
|
|
_ *lnwire.UpdateAddHTLC) error {
|
2019-05-16 16:27:29 +03:00
|
|
|
|
|
|
|
if m.onPayment == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var result *htlcswitch.PaymentResult
|
|
|
|
preimage, err := m.onPayment(firstHop)
|
|
|
|
if err != nil {
|
2020-01-14 16:07:42 +03:00
|
|
|
rtErr, ok := err.(htlcswitch.ClearTextError)
|
2019-05-16 16:27:29 +03:00
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
result = &htlcswitch.PaymentResult{
|
2020-01-14 16:07:42 +03:00
|
|
|
Error: rtErr,
|
2019-05-16 16:27:29 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = &htlcswitch.PaymentResult{Preimage: preimage}
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:27 +03:00
|
|
|
m.Lock()
|
|
|
|
if m.results == nil {
|
|
|
|
m.results = make(map[uint64]*htlcswitch.PaymentResult)
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:27:29 +03:00
|
|
|
m.results[pid] = result
|
2020-04-01 01:13:27 +03:00
|
|
|
m.Unlock()
|
2019-05-16 16:27:29 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-16 16:27:29 +03:00
|
|
|
func (m *mockPaymentAttemptDispatcher) GetPaymentResult(paymentID uint64,
|
2019-06-07 17:42:25 +03:00
|
|
|
_ lntypes.Hash, _ htlcswitch.ErrorDecrypter) (
|
|
|
|
<-chan *htlcswitch.PaymentResult, error) {
|
2019-05-16 16:27:28 +03:00
|
|
|
|
2019-05-16 16:27:29 +03:00
|
|
|
c := make(chan *htlcswitch.PaymentResult, 1)
|
2020-04-01 01:13:27 +03:00
|
|
|
|
|
|
|
m.Lock()
|
2019-05-16 16:27:29 +03:00
|
|
|
res, ok := m.results[paymentID]
|
2020-04-01 01:13:27 +03:00
|
|
|
m.Unlock()
|
|
|
|
|
2019-05-16 16:27:29 +03:00
|
|
|
if !ok {
|
|
|
|
return nil, htlcswitch.ErrPaymentIDNotFound
|
2019-05-16 16:27:28 +03:00
|
|
|
}
|
2019-05-16 16:27:29 +03:00
|
|
|
c <- res
|
|
|
|
|
|
|
|
return c, nil
|
2019-05-16 16:27:28 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockPaymentAttemptDispatcher) setPaymentResult(
|
|
|
|
f func(firstHop lnwire.ShortChannelID) ([32]byte, error)) {
|
|
|
|
|
|
|
|
m.onPayment = f
|
|
|
|
}
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
type mockPaymentSessionSource struct {
|
|
|
|
routes []*route.Route
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ PaymentSessionSource = (*mockPaymentSessionSource)(nil)
|
|
|
|
|
2020-04-01 01:13:22 +03:00
|
|
|
func (m *mockPaymentSessionSource) NewPaymentSession(
|
|
|
|
_ *LightningPayment) (PaymentSession, error) {
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
return &mockPaymentSession{m.routes}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockPaymentSessionSource) NewPaymentSessionForRoute(
|
|
|
|
preBuiltRoute *route.Route) PaymentSession {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockPaymentSessionSource) NewPaymentSessionEmpty() PaymentSession {
|
|
|
|
return &mockPaymentSession{}
|
|
|
|
}
|
|
|
|
|
2019-06-18 19:30:56 +03:00
|
|
|
type mockMissionControl struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ MissionController = (*mockMissionControl)(nil)
|
|
|
|
|
2019-08-05 13:13:58 +03:00
|
|
|
func (m *mockMissionControl) ReportPaymentFail(paymentID uint64, rt *route.Route,
|
|
|
|
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
|
|
|
*channeldb.FailureReason, error) {
|
2019-06-26 10:49:16 +03:00
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
// Report a permanent failure if this is an error caused
|
|
|
|
// by incorrect details.
|
|
|
|
if failure.Code() == lnwire.CodeIncorrectOrUnknownPaymentDetails {
|
|
|
|
reason := channeldb.FailureReasonPaymentDetails
|
|
|
|
return &reason, nil
|
|
|
|
}
|
|
|
|
|
2019-08-05 13:13:58 +03:00
|
|
|
return nil, nil
|
2019-06-26 10:49:16 +03:00
|
|
|
}
|
|
|
|
|
2019-07-29 15:20:06 +03:00
|
|
|
func (m *mockMissionControl) ReportPaymentSuccess(paymentID uint64,
|
|
|
|
rt *route.Route) error {
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-29 16:10:58 +03:00
|
|
|
func (m *mockMissionControl) GetProbability(fromNode, toNode route.Vertex,
|
2019-06-18 19:30:56 +03:00
|
|
|
amt lnwire.MilliSatoshi) float64 {
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-05-23 21:05:30 +03:00
|
|
|
type mockPaymentSession struct {
|
|
|
|
routes []*route.Route
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ PaymentSession = (*mockPaymentSession)(nil)
|
|
|
|
|
2020-04-01 01:13:22 +03:00
|
|
|
func (m *mockPaymentSession) RequestRoute(_, _ lnwire.MilliSatoshi,
|
|
|
|
_, height uint32) (*route.Route, error) {
|
|
|
|
|
2019-05-23 21:05:30 +03:00
|
|
|
if len(m.routes) == 0 {
|
2020-04-01 01:13:27 +03:00
|
|
|
return nil, errNoPathFound
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
r := m.routes[0]
|
|
|
|
m.routes = m.routes[1:]
|
|
|
|
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockPayer struct {
|
|
|
|
sendResult chan error
|
|
|
|
paymentResultErr chan error
|
|
|
|
paymentResult chan *htlcswitch.PaymentResult
|
|
|
|
quit chan struct{}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ PaymentAttemptDispatcher = (*mockPayer)(nil)
|
|
|
|
|
|
|
|
func (m *mockPayer) SendHTLC(_ lnwire.ShortChannelID,
|
|
|
|
paymentID uint64,
|
|
|
|
_ *lnwire.UpdateAddHTLC) error {
|
|
|
|
|
|
|
|
select {
|
|
|
|
case res := <-m.sendResult:
|
|
|
|
return res
|
|
|
|
case <-m.quit:
|
|
|
|
return fmt.Errorf("test quitting")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-07 17:42:25 +03:00
|
|
|
func (m *mockPayer) GetPaymentResult(paymentID uint64, _ lntypes.Hash,
|
|
|
|
_ htlcswitch.ErrorDecrypter) (<-chan *htlcswitch.PaymentResult, error) {
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
select {
|
|
|
|
case res := <-m.paymentResult:
|
|
|
|
resChan := make(chan *htlcswitch.PaymentResult, 1)
|
|
|
|
resChan <- res
|
|
|
|
return resChan, nil
|
|
|
|
case err := <-m.paymentResultErr:
|
|
|
|
return nil, err
|
|
|
|
case <-m.quit:
|
|
|
|
return nil, fmt.Errorf("test quitting")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type initArgs struct {
|
|
|
|
c *channeldb.PaymentCreationInfo
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
type registerAttemptArgs struct {
|
2020-02-07 12:31:27 +03:00
|
|
|
a *channeldb.HTLCAttemptInfo
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
type settleAttemptArgs struct {
|
2019-05-23 21:05:30 +03:00
|
|
|
preimg lntypes.Preimage
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
type failAttemptArgs struct {
|
|
|
|
reason *channeldb.HTLCFailInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
type failPaymentArgs struct {
|
2019-05-23 21:05:30 +03:00
|
|
|
reason channeldb.FailureReason
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
type testPayment struct {
|
|
|
|
info channeldb.PaymentCreationInfo
|
|
|
|
attempts []channeldb.HTLCAttempt
|
|
|
|
}
|
|
|
|
|
2019-05-23 21:05:30 +03:00
|
|
|
type mockControlTower struct {
|
2020-04-01 01:13:23 +03:00
|
|
|
payments map[lntypes.Hash]*testPayment
|
2019-05-23 21:05:30 +03:00
|
|
|
successful map[lntypes.Hash]struct{}
|
2020-04-01 01:13:23 +03:00
|
|
|
failed map[lntypes.Hash]channeldb.FailureReason
|
2019-05-23 21:05:30 +03:00
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
init chan initArgs
|
|
|
|
registerAttempt chan registerAttemptArgs
|
|
|
|
settleAttempt chan settleAttemptArgs
|
|
|
|
failAttempt chan failAttemptArgs
|
|
|
|
failPayment chan failPaymentArgs
|
|
|
|
fetchInFlight chan struct{}
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
2019-05-29 09:57:04 +03:00
|
|
|
var _ ControlTower = (*mockControlTower)(nil)
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
func makeMockControlTower() *mockControlTower {
|
|
|
|
return &mockControlTower{
|
2020-04-01 01:13:23 +03:00
|
|
|
payments: make(map[lntypes.Hash]*testPayment),
|
2019-05-23 21:05:30 +03:00
|
|
|
successful: make(map[lntypes.Hash]struct{}),
|
2020-04-01 01:13:23 +03:00
|
|
|
failed: make(map[lntypes.Hash]channeldb.FailureReason),
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockControlTower) InitPayment(phash lntypes.Hash,
|
|
|
|
c *channeldb.PaymentCreationInfo) error {
|
|
|
|
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
|
|
|
if m.init != nil {
|
|
|
|
m.init <- initArgs{c}
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
// Don't allow re-init a successful payment.
|
2019-05-23 21:05:30 +03:00
|
|
|
if _, ok := m.successful[phash]; ok {
|
2020-04-01 01:13:23 +03:00
|
|
|
return channeldb.ErrAlreadyPaid
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
_, failed := m.failed[phash]
|
|
|
|
_, ok := m.payments[phash]
|
|
|
|
|
|
|
|
// If the payment is known, only allow re-init if failed.
|
|
|
|
if ok && !failed {
|
|
|
|
return channeldb.ErrPaymentInFlight
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
delete(m.failed, phash)
|
|
|
|
m.payments[phash] = &testPayment{
|
|
|
|
info: *c,
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
|
2020-02-07 12:31:27 +03:00
|
|
|
a *channeldb.HTLCAttemptInfo) error {
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
if m.registerAttempt != nil {
|
|
|
|
m.registerAttempt <- registerAttemptArgs{a}
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
// Cannot register attempts for successful or failed payments.
|
|
|
|
if _, ok := m.successful[phash]; ok {
|
|
|
|
return channeldb.ErrPaymentAlreadySucceeded
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := m.failed[phash]; ok {
|
|
|
|
return channeldb.ErrPaymentAlreadyFailed
|
|
|
|
}
|
|
|
|
|
|
|
|
p, ok := m.payments[phash]
|
2019-05-23 21:05:30 +03:00
|
|
|
if !ok {
|
2020-04-01 01:13:23 +03:00
|
|
|
return channeldb.ErrPaymentNotInitiated
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
p.attempts = append(p.attempts, channeldb.HTLCAttempt{
|
|
|
|
HTLCAttemptInfo: *a,
|
|
|
|
})
|
|
|
|
m.payments[phash] = p
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:08:01 +03:00
|
|
|
func (m *mockControlTower) SettleAttempt(phash lntypes.Hash,
|
2020-05-06 16:44:36 +03:00
|
|
|
pid uint64, settleInfo *channeldb.HTLCSettleInfo) (
|
|
|
|
*channeldb.HTLCAttempt, error) {
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
if m.settleAttempt != nil {
|
|
|
|
m.settleAttempt <- settleAttemptArgs{settleInfo.Preimage}
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:25 +03:00
|
|
|
// Only allow setting attempts if the payment is known.
|
2020-04-01 01:13:23 +03:00
|
|
|
p, ok := m.payments[phash]
|
|
|
|
if !ok {
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, channeldb.ErrPaymentNotInitiated
|
2020-04-01 01:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the attempt with this pid, and set the settle info.
|
|
|
|
for i, a := range p.attempts {
|
|
|
|
if a.AttemptID != pid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:25 +03:00
|
|
|
if a.Settle != nil {
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, channeldb.ErrAttemptAlreadySettled
|
2020-04-01 01:13:25 +03:00
|
|
|
}
|
|
|
|
if a.Failure != nil {
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, channeldb.ErrAttemptAlreadyFailed
|
2020-04-01 01:13:25 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
p.attempts[i].Settle = settleInfo
|
|
|
|
|
|
|
|
// Mark the payment successful on first settled attempt.
|
|
|
|
m.successful[phash] = struct{}{}
|
2020-05-06 16:44:36 +03:00
|
|
|
return &channeldb.HTLCAttempt{
|
|
|
|
Settle: settleInfo,
|
|
|
|
}, nil
|
2020-04-01 01:13:23 +03:00
|
|
|
}
|
|
|
|
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, fmt.Errorf("pid not found")
|
2020-04-01 01:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockControlTower) FailAttempt(phash lntypes.Hash, pid uint64,
|
2020-05-06 16:44:36 +03:00
|
|
|
failInfo *channeldb.HTLCFailInfo) (*channeldb.HTLCAttempt, error) {
|
2020-04-01 01:13:23 +03:00
|
|
|
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
if m.failAttempt != nil {
|
|
|
|
m.failAttempt <- failAttemptArgs{failInfo}
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:25 +03:00
|
|
|
// Only allow failing attempts if the payment is known.
|
2020-04-01 01:13:23 +03:00
|
|
|
p, ok := m.payments[phash]
|
|
|
|
if !ok {
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, channeldb.ErrPaymentNotInitiated
|
2020-04-01 01:13:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the attempt with this pid, and set the failure info.
|
|
|
|
for i, a := range p.attempts {
|
|
|
|
if a.AttemptID != pid {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:25 +03:00
|
|
|
if a.Settle != nil {
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, channeldb.ErrAttemptAlreadySettled
|
2020-04-01 01:13:25 +03:00
|
|
|
}
|
|
|
|
if a.Failure != nil {
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, channeldb.ErrAttemptAlreadyFailed
|
2020-04-01 01:13:25 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
p.attempts[i].Failure = failInfo
|
2020-05-06 16:44:36 +03:00
|
|
|
return &channeldb.HTLCAttempt{
|
|
|
|
Failure: failInfo,
|
|
|
|
}, nil
|
2020-04-01 01:13:23 +03:00
|
|
|
}
|
|
|
|
|
2020-05-06 16:44:36 +03:00
|
|
|
return nil, fmt.Errorf("pid not found")
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2019-05-23 21:05:30 +03:00
|
|
|
func (m *mockControlTower) Fail(phash lntypes.Hash,
|
|
|
|
reason channeldb.FailureReason) error {
|
2019-05-23 21:05:30 +03:00
|
|
|
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
2020-04-01 01:13:26 +03:00
|
|
|
if m.failPayment != nil {
|
|
|
|
m.failPayment <- failPaymentArgs{reason}
|
2019-05-23 21:05:30 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:25 +03:00
|
|
|
// Payment must be known.
|
2020-04-01 01:13:23 +03:00
|
|
|
if _, ok := m.payments[phash]; !ok {
|
|
|
|
return channeldb.ErrPaymentNotInitiated
|
|
|
|
}
|
|
|
|
|
|
|
|
m.failed[phash] = reason
|
|
|
|
|
2019-05-23 21:05:30 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
func (m *mockControlTower) FetchPayment(phash lntypes.Hash) (
|
|
|
|
*channeldb.MPPayment, error) {
|
|
|
|
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
|
|
|
p, ok := m.payments[phash]
|
|
|
|
if !ok {
|
|
|
|
return nil, channeldb.ErrPaymentNotInitiated
|
|
|
|
}
|
|
|
|
|
|
|
|
mp := &channeldb.MPPayment{
|
|
|
|
Info: &p.info,
|
|
|
|
}
|
|
|
|
|
|
|
|
reason, ok := m.failed[phash]
|
|
|
|
if ok {
|
|
|
|
mp.FailureReason = &reason
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a copy of the current attempts.
|
|
|
|
mp.HTLCs = append(mp.HTLCs, p.attempts...)
|
|
|
|
|
|
|
|
return mp, nil
|
|
|
|
}
|
|
|
|
|
2019-05-23 21:05:30 +03:00
|
|
|
func (m *mockControlTower) FetchInFlightPayments() (
|
|
|
|
[]*channeldb.InFlightPayment, error) {
|
|
|
|
|
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
|
|
|
if m.fetchInFlight != nil {
|
|
|
|
m.fetchInFlight <- struct{}{}
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:13:23 +03:00
|
|
|
// In flight are all payments not successful or failed.
|
2019-05-23 21:05:30 +03:00
|
|
|
var fl []*channeldb.InFlightPayment
|
2020-04-01 01:13:23 +03:00
|
|
|
for hash, p := range m.payments {
|
|
|
|
if _, ok := m.successful[hash]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, ok := m.failed[hash]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
ifl := channeldb.InFlightPayment{
|
2020-09-24 10:48:27 +03:00
|
|
|
Info: &p.info,
|
2020-04-01 01:13:23 +03:00
|
|
|
}
|
|
|
|
|
2019-05-23 21:05:30 +03:00
|
|
|
fl = append(fl, &ifl)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fl, nil
|
|
|
|
}
|
2019-04-30 14:24:37 +03:00
|
|
|
|
|
|
|
func (m *mockControlTower) SubscribePayment(paymentHash lntypes.Hash) (
|
2020-04-03 18:05:05 +03:00
|
|
|
*ControlTowerSubscriber, error) {
|
2019-04-30 14:24:37 +03:00
|
|
|
|
2020-04-03 18:05:05 +03:00
|
|
|
return nil, errors.New("not implemented")
|
2019-04-30 14:24:37 +03:00
|
|
|
}
|