mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
instantout: treat closed payment streams as errors
Closed payment channels yielded zero values or nil errors in failure paths. Return explicit errors so the observer cannot report a failed swap as success.
This commit is contained in:
parent
fc884a4ef0
commit
6b3f4d9856
1 changed files with 15 additions and 3 deletions
|
|
@ -244,7 +244,13 @@ func (f *FSM) PollPaymentAcceptedAction(ctx context.Context,
|
|||
timer := time.NewTimer(time.Second)
|
||||
for {
|
||||
select {
|
||||
case payRes := <-payChan:
|
||||
case payRes, ok := <-payChan:
|
||||
if !ok {
|
||||
return f.handleErrorAndUnlockReservations(
|
||||
ctx, errors.New("payment status channel closed"),
|
||||
)
|
||||
}
|
||||
|
||||
f.Debugf("payment result: %v", payRes)
|
||||
if payRes.State == lnrpc.Payment_FAILED {
|
||||
return f.handleErrorAndUnlockReservations(
|
||||
|
|
@ -252,12 +258,18 @@ func (f *FSM) PollPaymentAcceptedAction(ctx context.Context,
|
|||
payRes.FailureReason),
|
||||
)
|
||||
}
|
||||
case err := <-paymentErrChan:
|
||||
case err, ok := <-paymentErrChan:
|
||||
if !ok {
|
||||
err = errors.New("payment error channel closed")
|
||||
} else if err == nil {
|
||||
err = errors.New("payment error channel returned nil")
|
||||
}
|
||||
|
||||
f.Errorf("error sending payment: %v", err)
|
||||
return f.handleErrorAndUnlockReservations(ctx, err)
|
||||
|
||||
case <-ctx.Done():
|
||||
return f.handleErrorAndUnlockReservations(ctx, nil)
|
||||
return f.handleErrorAndUnlockReservations(ctx, ctx.Err())
|
||||
|
||||
case <-timer.C:
|
||||
res, err := f.cfg.InstantOutClient.PollPaymentAccepted(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue