From 710ae777509ebd374b2fe198bbc906180071be5e Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Tue, 14 Apr 2020 14:35:56 +0200 Subject: [PATCH] loopout: log in-flight htlc status --- lndclient/router_client.go | 33 +++++++++++++++++++++++++++++---- loopout.go | 3 +-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lndclient/router_client.go b/lndclient/router_client.go index ae827b7..fb8a4d6 100644 --- a/lndclient/router_client.go +++ b/lndclient/router_client.go @@ -34,10 +34,22 @@ type RouterClient interface { // PaymentStatus describe the state of a payment. type PaymentStatus struct { - State lnrpc.Payment_PaymentStatus - Preimage lntypes.Preimage - Fee lnwire.MilliSatoshi - Value lnwire.MilliSatoshi + State lnrpc.Payment_PaymentStatus + Preimage lntypes.Preimage + Fee lnwire.MilliSatoshi + Value lnwire.MilliSatoshi + InFlightAmt lnwire.MilliSatoshi + InFlightHtlcs int +} + +func (p PaymentStatus) String() string { + text := fmt.Sprintf("state=%v", p.State) + if p.State == lnrpc.Payment_IN_FLIGHT { + text += fmt.Sprintf(", inflight_htlcs=%v, inflight_amt=%v", + p.InFlightHtlcs, p.InFlightAmt) + } + + return text } // SendPaymentRequest defines the payment parameters for a new payment. @@ -227,6 +239,19 @@ func unmarshallPaymentStatus(rpcPayment *lnrpc.Payment) ( status.Value = lnwire.MilliSatoshi(rpcPayment.ValueMsat) } + for _, htlc := range rpcPayment.Htlcs { + if htlc.Status != lnrpc.HTLCAttempt_IN_FLIGHT { + continue + } + + status.InFlightHtlcs++ + + lastHop := htlc.Route.Hops[len(htlc.Route.Hops)-1] + status.InFlightAmt += lnwire.MilliSatoshi( + lastHop.AmtToForwardMsat, + ) + } + return &status, nil } diff --git a/loopout.go b/loopout.go index a4dad22..82c3ecc 100644 --- a/loopout.go +++ b/loopout.go @@ -469,8 +469,7 @@ func (s *loopOutSwap) payInvoiceAsync(ctx context.Context, select { // Payment advanced to the next state. case payState := <-payStatusChan: - s.log.Infof("Payment %v: state=%v", - hash, payState.State) + s.log.Infof("Payment %v: %v", hash, payState) switch payState.State { case lnrpc.Payment_SUCCEEDED: