routing/router: persist payment state machine

This commit makes the router use the ControlTower to drive the payment
life cycle state machine, to keep track of active payments across
restarts.  This lets the router resume payments on startup, such that
their final results can be handled and stored when ready.
This commit is contained in:
Johan T. Halseth
2019-05-23 20:05:29 +02:00
parent dd73c51a34
commit de1bf8a518
6 changed files with 198 additions and 56 deletions

View File

@@ -50,6 +50,7 @@ func (c *testCtx) RestartRouter() error {
Chain: c.chain,
ChainView: c.chainView,
Payer: &mockPaymentAttemptDispatcher{},
Control: makeMockControlTower(),
ChannelPruneExpiry: time.Hour * 24,
GraphPruneInterval: time.Hour * 2,
})
@@ -88,6 +89,7 @@ func createTestCtxFromGraphInstance(startingHeight uint32, graphInstance *testGr
Chain: chain,
ChainView: chainView,
Payer: &mockPaymentAttemptDispatcher{},
Control: makeMockControlTower(),
ChannelPruneExpiry: time.Hour * 24,
GraphPruneInterval: time.Hour * 2,
QueryBandwidth: func(e *channeldb.ChannelEdgeInfo) lnwire.MilliSatoshi {
@@ -1528,6 +1530,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
Chain: ctx.chain,
ChainView: ctx.chainView,
Payer: &mockPaymentAttemptDispatcher{},
Control: makeMockControlTower(),
ChannelPruneExpiry: time.Hour * 24,
GraphPruneInterval: time.Hour * 2,
})
@@ -2490,3 +2493,30 @@ func assertChannelsPruned(t *testing.T, graph *channeldb.ChannelGraph,
}
}
}
type mockControlTower struct{}
var _ channeldb.ControlTower = (*mockControlTower)(nil)
func makeMockControlTower() *mockControlTower {
return &mockControlTower{}
}
func (m *mockControlTower) InitPayment(lntypes.Hash,
*channeldb.PaymentCreationInfo) error {
return nil
}
func (m *mockControlTower) RegisterAttempt(lntypes.Hash,
*channeldb.PaymentAttemptInfo) error {
return nil
}
func (m *mockControlTower) Success(paymentHash lntypes.Hash,
preimg lntypes.Preimage) error {
return nil
}
func (m *mockControlTower) Fail(paymentHash lntypes.Hash) error {
return nil
}