Skip to content

Commit b998ce1

Browse files
committed
routing+htlcswitch: add new interface method HasAttemptResult
1 parent bbf58ab commit b998ce1

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

htlcswitch/switch.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,21 @@ func (s *Switch) ProcessContractResolution(msg contractcourt.ResolutionMsg) erro
431431
}
432432
}
433433

434+
// HasAttemptResult reads the network result store to fetch the specified
435+
// attempt. Returns true if the attempt result exists.
436+
func (s *Switch) HasAttemptResult(attemptID uint64) (bool, error) {
437+
_, err := s.networkResults.getResult(attemptID)
438+
if err == nil {
439+
return true, nil
440+
}
441+
442+
if !errors.Is(err, ErrPaymentIDNotFound) {
443+
return false, err
444+
}
445+
446+
return false, nil
447+
}
448+
434449
// GetAttemptResult returns the result of the HTLC attempt with the given
435450
// attemptID. The paymentHash should be set to the payment's overall hash, or
436451
// in case of AMP payments the payment's unique identifier.

routing/mock_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ func (m *mockPaymentAttemptDispatcherOld) SendHTLC(
6060
return nil
6161
}
6262

63+
func (m *mockPaymentAttemptDispatcherOld) HasAttemptResult(
64+
attemptID uint64) (bool, error) {
65+
66+
return false, nil
67+
}
68+
6369
func (m *mockPaymentAttemptDispatcherOld) GetAttemptResult(paymentID uint64,
6470
_ lntypes.Hash, _ htlcswitch.ErrorDecrypter) (
6571
<-chan *htlcswitch.PaymentResult, error) {
@@ -209,6 +215,10 @@ func (m *mockPayerOld) SendHTLC(_ lnwire.ShortChannelID,
209215

210216
}
211217

218+
func (m *mockPayerOld) HasAttemptResult(attemptID uint64) (bool, error) {
219+
return false, nil
220+
}
221+
212222
func (m *mockPayerOld) GetAttemptResult(paymentID uint64, _ lntypes.Hash,
213223
_ htlcswitch.ErrorDecrypter) (<-chan *htlcswitch.PaymentResult, error) {
214224

@@ -585,6 +595,13 @@ func (m *mockPaymentAttemptDispatcher) SendHTLC(firstHop lnwire.ShortChannelID,
585595
return args.Error(0)
586596
}
587597

598+
func (m *mockPaymentAttemptDispatcher) HasAttemptResult(
599+
attemptID uint64) (bool, error) {
600+
601+
args := m.Called(attemptID)
602+
return args.Bool(0), args.Error(1)
603+
}
604+
588605
func (m *mockPaymentAttemptDispatcher) GetAttemptResult(attemptID uint64,
589606
paymentHash lntypes.Hash, deobfuscator htlcswitch.ErrorDecrypter) (
590607
<-chan *htlcswitch.PaymentResult, error) {

routing/router.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ type PaymentAttemptDispatcher interface {
135135
// NOTE: New payment attempts MUST NOT be made after the keepPids map
136136
// has been created and this method has returned.
137137
CleanStore(keepPids map[uint64]struct{}) error
138+
139+
// HasAttemptResult reads the network result store to fetch the
140+
// specified attempt. Returns true if the attempt result exists.
141+
//
142+
// NOTE: This method is used and should only be used by the router to
143+
// resume payments during startup. It can be viewed as a subset of
144+
// `GetAttemptResult` in terms of its functionality, and can be removed
145+
// once we move the construction of `UpdateAddHTLC` and
146+
// `ErrorDecrypter` into `htlcswitch`.
147+
HasAttemptResult(attemptID uint64) (bool, error)
138148
}
139149

140150
// PaymentSessionSource is an interface that defines a source for the router to

0 commit comments

Comments
 (0)