routing/router: resume payment state machine at startup

On startup the router will fetch the in-flight payments from the control
tower, and resume their execution.
This commit is contained in:
Johan T. Halseth 2019-05-23 20:05:29 +02:00
parent 677cb018c9
commit 3323800e02
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 47 additions and 0 deletions

@ -242,6 +242,19 @@ func (m *missionControl) NewPaymentSessionForRoute(preBuiltRoute *route.Route) *
}
}
// NewPaymentSessionEmpty creates a new paymentSession instance that is empty,
// and will be exhausted immediately. Used for failure reporting to
// missioncontrol for resumed payment we don't want to make more attempts for.
func (m *missionControl) NewPaymentSessionEmpty() *paymentSession {
return &paymentSession{
pruneViewSnapshot: m.GraphPruneView(),
errFailedPolicyChans: make(map[EdgeLocator]struct{}),
mc: m,
preBuiltRoute: &route.Route{},
preBuiltRouteTried: true,
}
}
// generateBandwidthHints is a helper function that's utilized the main
// findPath function in order to obtain hints from the lower layer w.r.t to the
// available bandwidth of edges on the network. Currently, we'll only obtain

@ -492,6 +492,40 @@ func (r *ChannelRouter) Start() error {
}
}
// If any payments are still in flight, we resume, to make sure their
// results are properly handled.
payments, err := r.cfg.Control.FetchInFlightPayments()
if err != nil {
return err
}
for _, payment := range payments {
log.Infof("Resuming payment with hash %v", payment.Info.PaymentHash)
r.wg.Add(1)
go func(payment *channeldb.InFlightPayment) {
defer r.wg.Done()
// We create a dummy, empty payment session such that
// we won't make another payment attempt when the
// result for the in-flight attempt is received.
paySession := r.missionControl.NewPaymentSessionEmpty()
lPayment := &LightningPayment{
PaymentHash: payment.Info.PaymentHash,
}
_, _, err = r.sendPayment(payment.Attempt, lPayment, paySession)
if err != nil {
log.Errorf("Resuming payment with hash %v "+
"failed: %v.", payment.Info.PaymentHash, err)
return
}
log.Infof("Resumed payment with hash %v completed.",
payment.Info.PaymentHash)
}(payment)
}
r.wg.Add(1)
go r.networkHandler()