Skip to content

Commit 61f32f6

Browse files
committed
accounts: start logging errored request info
1 parent fde86d3 commit 61f32f6

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

accounts/checkers.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func NewAccountChecker(service Service,
186186
r.AmtMsat, r.PaymentRequest,
187187
r.PaymentHash, r.FeeLimit,
188188
)
189-
}, sendResponseHandler, mid.PassThroughErrorHandler,
189+
}, sendResponseHandler, erroredPaymentHandler(service),
190190
),
191191
"/lnrpc.Lightning/SendPaymentSync": mid.NewFullChecker(
192192
&lnrpc.SendRequest{},
@@ -197,7 +197,7 @@ func NewAccountChecker(service Service,
197197
r.AmtMsat, r.PaymentRequest,
198198
r.PaymentHash, r.FeeLimit,
199199
)
200-
}, sendResponseHandler, mid.PassThroughErrorHandler,
200+
}, sendResponseHandler, erroredPaymentHandler(service),
201201
),
202202
// routerrpc.Router/SendPayment is deprecated.
203203
"/routerrpc.Router/SendPaymentV2": mid.NewFullChecker(
@@ -237,7 +237,7 @@ func NewAccountChecker(service Service,
237237
return checkSendResponse(
238238
ctx, service, r.Status, hash, fullAmt,
239239
)
240-
}, mid.PassThroughErrorHandler,
240+
}, erroredPaymentHandler(service),
241241
),
242242
"/lnrpc.Lightning/SendToRoute": mid.NewFullChecker(
243243
&lnrpc.SendToRouteRequest{},
@@ -248,7 +248,7 @@ func NewAccountChecker(service Service,
248248
return checkSendToRoute(
249249
ctx, service, r.PaymentHash, r.Route,
250250
)
251-
}, sendResponseHandler, mid.PassThroughErrorHandler,
251+
}, sendResponseHandler, erroredPaymentHandler(service),
252252
),
253253
"/lnrpc.Lightning/SendToRouteSync": mid.NewFullChecker(
254254
&lnrpc.SendToRouteRequest{},
@@ -259,7 +259,7 @@ func NewAccountChecker(service Service,
259259
return checkSendToRoute(
260260
ctx, service, r.PaymentHash, r.Route,
261261
)
262-
}, sendResponseHandler, mid.PassThroughErrorHandler,
262+
}, sendResponseHandler, erroredPaymentHandler(service),
263263
),
264264
// routerrpc.Router/SendToRoute is deprecated.
265265
"/routerrpc.Router/SendToRouteV2": mid.NewFullChecker(
@@ -273,7 +273,7 @@ func NewAccountChecker(service Service,
273273
)
274274
},
275275
sendToRouteHTLCResponseHandler(service),
276-
mid.PassThroughErrorHandler,
276+
erroredPaymentHandler(service),
277277
),
278278
"/lnrpc.Lightning/DecodePayReq": DecodePayReqPassThrough,
279279
"/lnrpc.Lightning/ListPayments": mid.NewResponseRewriter(
@@ -730,6 +730,36 @@ func checkSendToRoute(ctx context.Context, service Service, paymentHash []byte,
730730
})
731731
}
732732

733+
// erroredPaymentHandler does some trace logging about the errored payment and
734+
// clears up any state we may have had for the payment.
735+
func erroredPaymentHandler(service Service) mid.ErrorHandler {
736+
return func(ctx context.Context, respErr error) (error, error) {
737+
log, acct, reqID, err := requestScopedValuesFromCtx(ctx)
738+
if err != nil {
739+
return nil, err
740+
}
741+
742+
reqVals, ok := service.GetValues(reqID)
743+
if !ok {
744+
return nil, fmt.Errorf("no request values found for "+
745+
"request: %d", reqID)
746+
}
747+
748+
log.Tracef("Handling payment request error for payment with "+
749+
"hash: %s and amount: %d", reqVals.PaymentHash,
750+
reqVals.PaymentAmount)
751+
752+
err = service.PaymentErrored(acct.ID, reqVals.PaymentHash)
753+
if err != nil {
754+
return nil, err
755+
}
756+
757+
service.DeleteValues(reqID)
758+
759+
return nil, nil
760+
}
761+
}
762+
733763
// sendToRouteHTLCResponseHandler creates a response handler for the
734764
// SendToRouteV2 endpoint which is a streaming endpoint that may return multiple
735765
// HTLCAttempt updates.

0 commit comments

Comments
 (0)