Skip to content

Commit 710ae77

Browse files
committed
loopout: log in-flight htlc status
1 parent 4039ba9 commit 710ae77

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lndclient/router_client.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@ type RouterClient interface {
3434

3535
// PaymentStatus describe the state of a payment.
3636
type PaymentStatus struct {
37-
State lnrpc.Payment_PaymentStatus
38-
Preimage lntypes.Preimage
39-
Fee lnwire.MilliSatoshi
40-
Value lnwire.MilliSatoshi
37+
State lnrpc.Payment_PaymentStatus
38+
Preimage lntypes.Preimage
39+
Fee lnwire.MilliSatoshi
40+
Value lnwire.MilliSatoshi
41+
InFlightAmt lnwire.MilliSatoshi
42+
InFlightHtlcs int
43+
}
44+
45+
func (p PaymentStatus) String() string {
46+
text := fmt.Sprintf("state=%v", p.State)
47+
if p.State == lnrpc.Payment_IN_FLIGHT {
48+
text += fmt.Sprintf(", inflight_htlcs=%v, inflight_amt=%v",
49+
p.InFlightHtlcs, p.InFlightAmt)
50+
}
51+
52+
return text
4153
}
4254

4355
// SendPaymentRequest defines the payment parameters for a new payment.
@@ -227,6 +239,19 @@ func unmarshallPaymentStatus(rpcPayment *lnrpc.Payment) (
227239
status.Value = lnwire.MilliSatoshi(rpcPayment.ValueMsat)
228240
}
229241

242+
for _, htlc := range rpcPayment.Htlcs {
243+
if htlc.Status != lnrpc.HTLCAttempt_IN_FLIGHT {
244+
continue
245+
}
246+
247+
status.InFlightHtlcs++
248+
249+
lastHop := htlc.Route.Hops[len(htlc.Route.Hops)-1]
250+
status.InFlightAmt += lnwire.MilliSatoshi(
251+
lastHop.AmtToForwardMsat,
252+
)
253+
}
254+
230255
return &status, nil
231256
}
232257

loopout.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ func (s *loopOutSwap) payInvoiceAsync(ctx context.Context,
469469
select {
470470
// Payment advanced to the next state.
471471
case payState := <-payStatusChan:
472-
s.log.Infof("Payment %v: state=%v",
473-
hash, payState.State)
472+
s.log.Infof("Payment %v: %v", hash, payState)
474473

475474
switch payState.State {
476475
case lnrpc.Payment_SUCCEEDED:

0 commit comments

Comments
 (0)