routing: move payment session constructor
This commit is contained in:
parent
eec3799da9
commit
6e8442b333
@ -140,18 +140,20 @@ func (c *integratedRoutingContext) testPayment(maxShards uint32) ([]htlcAttempt,
|
|||||||
MaxShards: maxShards,
|
MaxShards: maxShards,
|
||||||
}
|
}
|
||||||
|
|
||||||
session := &paymentSession{
|
session, err := newPaymentSession(
|
||||||
getBandwidthHints: getBandwidthHints,
|
&payment, getBandwidthHints,
|
||||||
payment: &payment,
|
func() (routingGraph, func(), error) {
|
||||||
pathFinder: findPath,
|
|
||||||
getRoutingGraph: func() (routingGraph, func(), error) {
|
|
||||||
return c.graph, func() {}, nil
|
return c.graph, func() {}, nil
|
||||||
},
|
},
|
||||||
pathFindingConfig: c.pathFindingCfg,
|
mc, c.pathFindingCfg,
|
||||||
missionControl: mc,
|
)
|
||||||
minShardAmt: lnwire.NewMSatFromSatoshis(5000),
|
if err != nil {
|
||||||
|
c.t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override default minimum shard amount.
|
||||||
|
session.minShardAmt = lnwire.NewMSatFromSatoshis(5000)
|
||||||
|
|
||||||
// Now the payment control loop starts. It will keep trying routes until
|
// Now the payment control loop starts. It will keep trying routes until
|
||||||
// the payment succeeds.
|
// the payment succeeds.
|
||||||
var (
|
var (
|
||||||
|
@ -126,6 +126,30 @@ type paymentSession struct {
|
|||||||
minShardAmt lnwire.MilliSatoshi
|
minShardAmt lnwire.MilliSatoshi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newPaymentSession instantiates a new payment session.
|
||||||
|
func newPaymentSession(p *LightningPayment,
|
||||||
|
getBandwidthHints func() (map[uint64]lnwire.MilliSatoshi, error),
|
||||||
|
getRoutingGraph func() (routingGraph, func(), error),
|
||||||
|
missionControl MissionController, pathFindingConfig PathFindingConfig) (
|
||||||
|
*paymentSession, error) {
|
||||||
|
|
||||||
|
edges, err := RouteHintsToEdges(p.RouteHints, p.Target)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &paymentSession{
|
||||||
|
additionalEdges: edges,
|
||||||
|
getBandwidthHints: getBandwidthHints,
|
||||||
|
payment: p,
|
||||||
|
pathFinder: findPath,
|
||||||
|
getRoutingGraph: getRoutingGraph,
|
||||||
|
pathFindingConfig: pathFindingConfig,
|
||||||
|
missionControl: missionControl,
|
||||||
|
minShardAmt: DefaultShardMinAmt,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// RequestRoute returns a route which is likely to be capable for successfully
|
// RequestRoute returns a route which is likely to be capable for successfully
|
||||||
// routing the specified HTLC payment to the target node. Initially the first
|
// routing the specified HTLC payment to the target node. Initially the first
|
||||||
// set of paths returned from this method may encounter routing failure along
|
// set of paths returned from this method may encounter routing failure along
|
||||||
|
@ -62,11 +62,6 @@ func (m *SessionSource) getRoutingGraph() (routingGraph, func(), error) {
|
|||||||
func (m *SessionSource) NewPaymentSession(p *LightningPayment) (
|
func (m *SessionSource) NewPaymentSession(p *LightningPayment) (
|
||||||
PaymentSession, error) {
|
PaymentSession, error) {
|
||||||
|
|
||||||
edges, err := RouteHintsToEdges(p.RouteHints, p.Target)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceNode, err := m.Graph.SourceNode()
|
sourceNode, err := m.Graph.SourceNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -78,16 +73,15 @@ func (m *SessionSource) NewPaymentSession(p *LightningPayment) (
|
|||||||
return generateBandwidthHints(sourceNode, m.QueryBandwidth)
|
return generateBandwidthHints(sourceNode, m.QueryBandwidth)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &paymentSession{
|
session, err := newPaymentSession(
|
||||||
additionalEdges: edges,
|
p, getBandwidthHints, m.getRoutingGraph,
|
||||||
getBandwidthHints: getBandwidthHints,
|
m.MissionControl, m.PathFindingConfig,
|
||||||
payment: p,
|
)
|
||||||
pathFinder: findPath,
|
if err != nil {
|
||||||
getRoutingGraph: m.getRoutingGraph,
|
return nil, err
|
||||||
pathFindingConfig: m.PathFindingConfig,
|
}
|
||||||
missionControl: m.MissionControl,
|
|
||||||
minShardAmt: DefaultShardMinAmt,
|
return session, nil
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPaymentSessionEmpty creates a new paymentSession instance that is empty,
|
// NewPaymentSessionEmpty creates a new paymentSession instance that is empty,
|
||||||
|
@ -13,9 +13,36 @@ func TestRequestRoute(t *testing.T) {
|
|||||||
height = 10
|
height = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
findPath := func(
|
cltvLimit := uint32(30)
|
||||||
g *graphParams,
|
finalCltvDelta := uint16(8)
|
||||||
r *RestrictParams, cfg *PathFindingConfig,
|
|
||||||
|
payment := &LightningPayment{
|
||||||
|
CltvLimit: cltvLimit,
|
||||||
|
FinalCLTVDelta: finalCltvDelta,
|
||||||
|
Amount: 1000,
|
||||||
|
FeeLimit: 1000,
|
||||||
|
}
|
||||||
|
|
||||||
|
session, err := newPaymentSession(
|
||||||
|
payment,
|
||||||
|
func() (map[uint64]lnwire.MilliSatoshi,
|
||||||
|
error) {
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
},
|
||||||
|
func() (routingGraph, func(), error) {
|
||||||
|
return &sessionGraph{}, func() {}, nil
|
||||||
|
},
|
||||||
|
&MissionControl{cfg: &MissionControlConfig{}},
|
||||||
|
PathFindingConfig{},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override pathfinder with a mock.
|
||||||
|
session.pathFinder = func(
|
||||||
|
g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
||||||
source, target route.Vertex, amt lnwire.MilliSatoshi,
|
source, target route.Vertex, amt lnwire.MilliSatoshi,
|
||||||
finalHtlcExpiry int32) ([]*channeldb.ChannelEdgePolicy, error) {
|
finalHtlcExpiry int32) ([]*channeldb.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
@ -38,32 +65,6 @@ func TestRequestRoute(t *testing.T) {
|
|||||||
return path, nil
|
return path, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cltvLimit := uint32(30)
|
|
||||||
finalCltvDelta := uint16(8)
|
|
||||||
|
|
||||||
payment := &LightningPayment{
|
|
||||||
CltvLimit: cltvLimit,
|
|
||||||
FinalCLTVDelta: finalCltvDelta,
|
|
||||||
Amount: 1000,
|
|
||||||
FeeLimit: 1000,
|
|
||||||
}
|
|
||||||
|
|
||||||
session := &paymentSession{
|
|
||||||
getBandwidthHints: func() (map[uint64]lnwire.MilliSatoshi,
|
|
||||||
error) {
|
|
||||||
|
|
||||||
return nil, nil
|
|
||||||
},
|
|
||||||
payment: payment,
|
|
||||||
pathFinder: findPath,
|
|
||||||
missionControl: &MissionControl{
|
|
||||||
cfg: &MissionControlConfig{},
|
|
||||||
},
|
|
||||||
getRoutingGraph: func() (routingGraph, func(), error) {
|
|
||||||
return &sessionGraph{}, func() {}, nil
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
route, err := session.RequestRoute(
|
route, err := session.RequestRoute(
|
||||||
payment.Amount, payment.FeeLimit, 0, height,
|
payment.Amount, payment.FeeLimit, 0, height,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user