Skip to content

Commit

Permalink
channeldb+routing: continue payment lifecycle on register error
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Nov 4, 2024
1 parent 3d12518 commit 686acb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion channeldb/payment_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ var (
// amount exceed the total amount.
ErrSentExceedsTotal = errors.New("total sent exceeds total amount")

// ErrRegisterAttempt is returned when a new htlc attempt cannot be
// registered.
ErrRegisterAttempt = errors.New("cannot register htlc attempt")

// errNoAttemptInfo is returned when no attempt info is stored yet.
errNoAttemptInfo = errors.New("unable to find attempt info for " +
"inflight payment")
Expand Down Expand Up @@ -342,7 +346,8 @@ func (p *PaymentControl) RegisterAttempt(paymentHash lntypes.Hash,

// Check if registering a new attempt is allowed.
if err := payment.Registrable(); err != nil {
return err
return fmt.Errorf("%w: %v", ErrRegisterAttempt,
err.Error())
}

// If the final hop has encrypted data, then we know this is a
Expand Down
10 changes: 10 additions & 0 deletions routing/payment_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ lifecycle:
// We found a route to try, create a new HTLC attempt to try.
attempt, err := p.registerAttempt(rt, ps.RemainingAmt)
if err != nil {
// If the error is due to we cannot register another
// HTLC, we will skip this iteration and continue to
// the next one in case there are inflight HTLCs.
//
// TODO(yy): remove this check once we have a finer
// control over errors returned from the switch.
if errors.Is(err, channeldb.ErrRegisterAttempt) {
continue lifecycle
}

return exitWithErr(err)
}

Expand Down

0 comments on commit 686acb9

Please sign in to comment.