routerrpc+lncli: add flag to suppress in-flight updates

This is a preparation for enabling the REST interface on routerrpc.
It provides REST clients that don't support server-side streaming
via keep-alive connections to use the streaming endpoint in the
typical request/response pattern. The url just needs to contain
?no_inflight_updates=true and only the terminal response is sent
back before the connection is closed.
This commit is contained in:
Joost Jager authored and Olaoluwa Osuntokun committed 2020-04-21 17:02:09 -07:00
1 parent 1e51ec0a2d
commit d51bb65536
4 files changed
+191 -151

No files matched your search

+11 -3
View File
@@ -255,7 +255,7 @@ func (s *Server) SendPaymentV2(req *SendPaymentRequest,
return err
}
return s.trackPayment(payment.PaymentHash, stream)
return s.trackPayment(payment.PaymentHash, stream, req.NoInflightUpdates)
}
// EstimateRouteFee allows callers to obtain a lower bound w.r.t how much it
@@ -439,12 +439,12 @@ func (s *Server) TrackPaymentV2(request *TrackPaymentRequest,
log.Debugf("TrackPayment called for payment %v", paymentHash)
return s.trackPayment(paymentHash, stream)
return s.trackPayment(paymentHash, stream, request.NoInflightUpdates)
}
// trackPayment writes payment status updates to the provided stream.
func (s *Server) trackPayment(paymentHash lntypes.Hash,
stream Router_TrackPaymentV2Server) error {
stream Router_TrackPaymentV2Server, noInflightUpdates bool) error {
router := s.cfg.RouterBackend
@@ -470,6 +470,14 @@ func (s *Server) trackPayment(paymentHash lntypes.Hash,
return nil
}
result := item.(*channeldb.MPPayment)
// Skip in-flight updates unless requested.
if noInflightUpdates &&
result.Status == channeldb.StatusInFlight {
continue
}
rpcPayment, err := router.MarshallPayment(result)
if err != nil {
return err