mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-10 07:42:39 +02:00
routing: add new NewPaymentSessionFromRoutes function instead of interface
In this commit, we modify the recent refactoring of the mission control sub-system to overload the existing payment session, rather than create a brand new one. This allows us to re-use more of the existing logic, and also feedback into mission control the failures incurred by any user selected routes.
This commit is contained in:
@@ -1532,37 +1532,6 @@ type LightningPayment struct {
|
||||
// TODO(roasbeef): add e2e message?
|
||||
}
|
||||
|
||||
// PaymentSession imitates paymentSession created from mission control
|
||||
// and enables SendPayment and SendToRoute to call sendPayment.
|
||||
type PaymentSession interface {
|
||||
RequestRoute(payment *LightningPayment, currentHeight uint32,
|
||||
finalCLTVDelta uint16) (*Route, error)
|
||||
|
||||
ReportVertexFailure(Vertex)
|
||||
ReportChannelFailure(chanID uint64)
|
||||
}
|
||||
|
||||
// sendToRoutePaymentSession implements PaymentSession.
|
||||
type sendToRoutePaymentSession struct {
|
||||
currentRouteIndex int
|
||||
routes []*Route
|
||||
}
|
||||
|
||||
func (s *sendToRoutePaymentSession) RequestRoute(payment *LightningPayment,
|
||||
currentHeight uint32, finalCLTVDelta uint16) (*Route, error) {
|
||||
|
||||
defer func() { s.currentRouteIndex++ }()
|
||||
|
||||
if s.currentRouteIndex < len(s.routes) {
|
||||
return s.routes[s.currentRouteIndex], nil
|
||||
}
|
||||
return nil, errors.New("unable to send payment along any of " +
|
||||
"the given routes")
|
||||
}
|
||||
|
||||
func (s *sendToRoutePaymentSession) ReportVertexFailure(v Vertex) {}
|
||||
func (s *sendToRoutePaymentSession) ReportChannelFailure(chanID uint64) {}
|
||||
|
||||
// SendPayment attempts to send a payment as described within the passed
|
||||
// LightningPayment. This function is blocking and will return either: when the
|
||||
// payment is successful, or all candidates routes have been attempted and
|
||||
@@ -1594,9 +1563,9 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
|
||||
func (r *ChannelRouter) SendToRoute(routes []*Route,
|
||||
payment *LightningPayment) ([32]byte, *Route, error) {
|
||||
|
||||
paySession := &sendToRoutePaymentSession{
|
||||
routes: routes,
|
||||
}
|
||||
paySession := r.missionControl.NewPaymentSessionFromRoutes(
|
||||
routes,
|
||||
)
|
||||
|
||||
return r.sendPayment(payment, paySession)
|
||||
}
|
||||
@@ -1609,7 +1578,7 @@ func (r *ChannelRouter) SendToRoute(routes []*Route,
|
||||
// within the network to reach the destination. Additionally, the payment
|
||||
// preimage will also be returned.
|
||||
func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
||||
paySession PaymentSession) ([32]byte, *Route, error) {
|
||||
paySession *paymentSession) ([32]byte, *Route, error) {
|
||||
|
||||
log.Tracef("Dispatching route for lightning payment: %v",
|
||||
newLogClosure(func() string {
|
||||
@@ -1960,7 +1929,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
||||
// pruneVertexFailure will attempt to prune a vertex from the current available
|
||||
// vertexes of the target payment session in response to an encountered routing
|
||||
// error.
|
||||
func pruneVertexFailure(paySession PaymentSession, route *Route,
|
||||
func pruneVertexFailure(paySession *paymentSession, route *Route,
|
||||
errSource *btcec.PublicKey, nextNode bool) {
|
||||
|
||||
// By default, we'll try to prune the node that actually sent us the
|
||||
@@ -1986,7 +1955,7 @@ func pruneVertexFailure(paySession PaymentSession, route *Route,
|
||||
// pruneEdgeFailure will attempts to prune an edge from the current available
|
||||
// edges of the target payment session in response to an encountered routing
|
||||
// error.
|
||||
func pruneEdgeFailure(paySession PaymentSession, route *Route,
|
||||
func pruneEdgeFailure(paySession *paymentSession, route *Route,
|
||||
errSource *btcec.PublicKey) {
|
||||
|
||||
// As this error indicates that the target channel was unable to carry
|
||||
|
Reference in New Issue
Block a user