loopout: apply server-provided route hints before paying invoices

pull/420/head
carla 3 years ago
parent a275dc4755
commit 351124c7c0
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -535,8 +535,51 @@ func (s *loopOutSwap) persistState(ctx context.Context) error {
return s.sendUpdate(ctx)
}
func (s *loopOutSwap) getRouteHints(ctx context.Context) error {
if !s.executeConfig.routingHints {
s.log.Infof("Routing hints disabled, not adding hints")
return nil
}
hints, err := s.executeConfig.getHints(
// TODO[carla]: decode invoice, amt requested is != amt routed.
ctx, s.LoopOutContract.AmountRequested,
int(s.executeConfig.loopOutMaxParts),
)
if err != nil {
return err
}
s.log.Infof("Applying: %v routing hints", len(hints))
entries := make([]*lndclient.MissionControlEntry, len(hints))
for i, hint := range hints {
entries[i] = &lndclient.MissionControlEntry{
NodeFrom: hint.fromNode,
NodeTo: hint.toNode,
FailTime: hint.timestamp,
FailAmt: hint.failAmt,
SuccessTime: hint.timestamp,
SuccessAmt: hint.successAmt,
}
}
if err := s.lnd.Router.ImportMissionControl(ctx, entries); err != nil {
return err
}
return nil
}
// payInvoices pays both swap invoices.
func (s *loopOutSwap) payInvoices(ctx context.Context) {
// Before we pay our invoices, try to get routing hints that will assist
// with pathfinding. It is not critical is this operation fails, so we
// just log any errors.
if err := s.getRouteHints(ctx); err != nil {
s.log.Warnf("Could not get routing hints: %v", err)
}
// Pay the swap invoice.
s.log.Infof("Sending swap payment %v", s.SwapInvoice)

Loading…
Cancel
Save