loopout: do not report prepays and fix plugin type if acquire fails

pull/462/head
Andras Banki-Horvath 2 years ago
parent f650071bca
commit 32d55dc814
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8

@ -587,7 +587,7 @@ func (s *loopOutSwap) payInvoices(ctx context.Context) {
// Use the recommended routing plugin. // Use the recommended routing plugin.
s.swapPaymentChan = s.payInvoice( s.swapPaymentChan = s.payInvoice(
ctx, s.SwapInvoice, s.MaxSwapRoutingFee, ctx, s.SwapInvoice, s.MaxSwapRoutingFee,
s.LoopOutContract.OutgoingChanSet, pluginType, s.LoopOutContract.OutgoingChanSet, pluginType, true,
) )
// Pay the prepay invoice. Won't use the routing plugin here as the // Pay the prepay invoice. Won't use the routing plugin here as the
@ -595,7 +595,7 @@ func (s *loopOutSwap) payInvoices(ctx context.Context) {
s.log.Infof("Sending prepayment %v", s.PrepayInvoice) s.log.Infof("Sending prepayment %v", s.PrepayInvoice)
s.prePaymentChan = s.payInvoice( s.prePaymentChan = s.payInvoice(
ctx, s.PrepayInvoice, s.MaxPrepayRoutingFee, ctx, s.PrepayInvoice, s.MaxPrepayRoutingFee,
nil, RoutingPluginNone, nil, RoutingPluginNone, false,
) )
} }
@ -623,7 +623,8 @@ func (p paymentResult) failure() error {
// payInvoice pays a single invoice. // payInvoice pays a single invoice.
func (s *loopOutSwap) payInvoice(ctx context.Context, invoice string, func (s *loopOutSwap) payInvoice(ctx context.Context, invoice string,
maxFee btcutil.Amount, outgoingChanIds loopdb.ChannelSet, maxFee btcutil.Amount, outgoingChanIds loopdb.ChannelSet,
pluginType RoutingPluginType) chan paymentResult { pluginType RoutingPluginType,
reportPluginResult bool) chan paymentResult {
resultChan := make(chan paymentResult) resultChan := make(chan paymentResult)
sendResult := func(result paymentResult) { sendResult := func(result paymentResult) {
@ -638,6 +639,7 @@ func (s *loopOutSwap) payInvoice(ctx context.Context, invoice string,
status, err := s.payInvoiceAsync( status, err := s.payInvoiceAsync(
ctx, invoice, maxFee, outgoingChanIds, pluginType, ctx, invoice, maxFee, outgoingChanIds, pluginType,
reportPluginResult,
) )
if err != nil { if err != nil {
result.err = err result.err = err
@ -665,8 +667,8 @@ func (s *loopOutSwap) payInvoice(ctx context.Context, invoice string,
// payInvoiceAsync is the asynchronously executed part of paying an invoice. // payInvoiceAsync is the asynchronously executed part of paying an invoice.
func (s *loopOutSwap) payInvoiceAsync(ctx context.Context, func (s *loopOutSwap) payInvoiceAsync(ctx context.Context,
invoice string, maxFee btcutil.Amount, invoice string, maxFee btcutil.Amount,
outgoingChanIds loopdb.ChannelSet, pluginType RoutingPluginType) ( outgoingChanIds loopdb.ChannelSet, pluginType RoutingPluginType,
*lndclient.PaymentStatus, error) { reportPluginResult bool) (*lndclient.PaymentStatus, error) {
// Extract hash from payment request. Unfortunately the request // Extract hash from payment request. Unfortunately the request
// components aren't available directly. // components aren't available directly.
@ -719,11 +721,21 @@ func (s *loopOutSwap) payInvoiceAsync(ctx context.Context,
paymentSuccess := err == nil && paymentSuccess := err == nil &&
paymentStatus.State == lnrpc.Payment_SUCCEEDED paymentStatus.State == lnrpc.Payment_SUCCEEDED
if err := s.swapKit.server.ReportRoutingResult( if reportPluginResult {
ctx, s.swapInfo().SwapHash, s.swapInvoicePaymentAddr, pluginType, // If the plugin couldn't be acquired then override the reported
paymentSuccess, int32(attempts), dt.Milliseconds(), // plugin type to RoutingPluginNone.
); err != nil { reportType := pluginType
s.log.Warnf("Failed to report routing result: %v", err) if routingPlugin == nil {
reportType = RoutingPluginNone
}
if err := s.swapKit.server.ReportRoutingResult(
ctx, s.swapInfo().SwapHash, s.swapInvoicePaymentAddr,
reportType, paymentSuccess, int32(attempts),
dt.Milliseconds(),
); err != nil {
s.log.Warnf("Failed to report routing result: %v", err)
}
} }
return paymentStatus, err return paymentStatus, err

Loading…
Cancel
Save