htlcswitch+routing: rename GetPaymentResult to GetAttemptResult

This commit renames the method `GetPaymentResult` to be
`GetAttemptResult` to avoid potential confusion and to address the
one-to-many relationship between a payment and its attempts.
This commit is contained in:
yyforyongyu committed 2022-12-07 18:38:01 +08:00
1 parent d1611c999a
commit e3bc4f4cc9
9 files changed
+54 -54

No files matched your search

+3 -3
View File
@@ -56,7 +56,7 @@ func (m *mockPaymentAttemptDispatcherOld) SendHTLC(
return nil
}
func (m *mockPaymentAttemptDispatcherOld) GetPaymentResult(paymentID uint64,
func (m *mockPaymentAttemptDispatcherOld) GetAttemptResult(paymentID uint64,
_ lntypes.Hash, _ htlcswitch.ErrorDecrypter) (
<-chan *htlcswitch.PaymentResult, error) {
@@ -205,7 +205,7 @@ func (m *mockPayerOld) SendHTLC(_ lnwire.ShortChannelID,
}
func (m *mockPayerOld) GetPaymentResult(paymentID uint64, _ lntypes.Hash,
func (m *mockPayerOld) GetAttemptResult(paymentID uint64, _ lntypes.Hash,
_ htlcswitch.ErrorDecrypter) (<-chan *htlcswitch.PaymentResult, error) {
select {
@@ -578,7 +578,7 @@ func (m *mockPaymentAttemptDispatcher) SendHTLC(firstHop lnwire.ShortChannelID,
return args.Error(0)
}
func (m *mockPaymentAttemptDispatcher) GetPaymentResult(attemptID uint64,
func (m *mockPaymentAttemptDispatcher) GetAttemptResult(attemptID uint64,
paymentHash lntypes.Hash, deobfuscator htlcswitch.ErrorDecrypter) (
<-chan *htlcswitch.PaymentResult, error) {
+1 -1
View File
@@ -562,7 +562,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
// Now ask the switch to return the result of the payment when
// available.
resultChan, err := p.router.cfg.Payer.GetPaymentResult(
resultChan, err := p.router.cfg.Payer.GetAttemptResult(
attempt.AttemptID, p.identifier, errorDecryptor,
)
switch {
+9 -9
View File
@@ -107,20 +107,20 @@ const (
sendToSwitchResultFailure = "SendToSwitch:failure"
// getPaymentResultSuccess is a test step where we expect the
// router to call the GetPaymentResult method, and we will
// router to call the GetAttemptResult method, and we will
// respond with a successful payment result.
getPaymentResultSuccess = "GetPaymentResult:success"
getPaymentResultSuccess = "GetAttemptResult:success"
// getPaymentResultTempFailure is a test step where we expect the
// router to call the GetPaymentResult method, and we will
// router to call the GetAttemptResult method, and we will
// respond with a forwarding error, expecting the router to retry.
getPaymentResultTempFailure = "GetPaymentResult:temp-failure"
getPaymentResultTempFailure = "GetAttemptResult:temp-failure"
// getPaymentResultTerminalFailure is a test step where we
// expect the router to call the GetPaymentResult method, and
// expect the router to call the GetAttemptResult method, and
// we will respond with a terminal error, expecting the router
// to stop making payment attempts.
getPaymentResultTerminalFailure = "GetPaymentResult:terminal-failure"
getPaymentResultTerminalFailure = "GetAttemptResult:terminal-failure"
// resendPayment is a test step where we manually try to resend
// the same payment, making sure the router responds with an
@@ -652,7 +652,7 @@ func testPaymentLifecycle(t *testing.T, test paymentLifecycleTestCase,
fatal("unable to send result")
}
// In this step we expect the GetPaymentResult method
// In this step we expect the GetAttemptResult method
// to be called, and we respond with the preimage to
// complete the payment.
case getPaymentResultSuccess:
@@ -664,7 +664,7 @@ func testPaymentLifecycle(t *testing.T, test paymentLifecycleTestCase,
fatal("unable to send result")
}
// In this state we expect the GetPaymentResult method
// In this state we expect the GetAttemptResult method
// to be called, and we respond with a forwarding
// error, indicating that the router should retry.
case getPaymentResultTempFailure:
@@ -682,7 +682,7 @@ func testPaymentLifecycle(t *testing.T, test paymentLifecycleTestCase,
}
// In this state we expect the router to call the
// GetPaymentResult method, and we will respond with a
// GetAttemptResult method, and we will respond with a
// terminal error, indicating the router should stop
// making payment attempts.
case getPaymentResultTerminalFailure:
+2 -2
View File
@@ -169,7 +169,7 @@ type PaymentAttemptDispatcher interface {
attemptID uint64,
htlcAdd *lnwire.UpdateAddHTLC) error
// GetPaymentResult returns the result of the payment attempt with
// GetAttemptResult returns the result of the payment attempt with
// the given attemptID. The paymentHash should be set to the payment's
// overall hash, or in case of AMP payments the payment's unique
// identifier.
@@ -180,7 +180,7 @@ type PaymentAttemptDispatcher interface {
// longer be in flight. The switch shutting down is signaled by
// closing the channel. If the attemptID is unknown,
// ErrPaymentIDNotFound will be returned.
GetPaymentResult(attemptID uint64, paymentHash lntypes.Hash,
GetAttemptResult(attemptID uint64, paymentHash lntypes.Hash,
deobfuscator htlcswitch.ErrorDecrypter) (
<-chan *htlcswitch.PaymentResult, error)
+21 -21
View File
@@ -3441,9 +3441,9 @@ func TestSendMPPaymentSucceed(t *testing.T) {
payment.HTLCs = append(payment.HTLCs, activeAttempt)
})
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 10)
payer.On("GetPaymentResult",
payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to
@@ -3608,14 +3608,14 @@ func TestSendMPPaymentSucceedOnExtraShards(t *testing.T) {
payment.HTLCs = append(payment.HTLCs, activeAttempt)
})
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 10)
// We use the failAttemptCount to track how many attempts we want to
// fail. Each time the following mock method is called, the count gets
// updated.
failAttemptCount := 0
payer.On("GetPaymentResult",
payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to
@@ -3820,14 +3820,14 @@ func TestSendMPPaymentFailed(t *testing.T) {
payment.HTLCs = append(payment.HTLCs, activeAttempt)
})
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 10)
// We use the failAttemptCount to track how many attempts we want to
// fail. Each time the following mock method is called, the count gets
// updated.
failAttemptCount := 0
payer.On("GetPaymentResult",
payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to
@@ -4024,18 +4024,18 @@ func TestSendMPPaymentFailedWithShardsInFlight(t *testing.T) {
payment.HTLCs = append(payment.HTLCs, activeAttempt)
})
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 10)
// We use the getPaymentResultCnt to track how many times we called
// GetPaymentResult. As shard launch is sequential, and we fail the
// first shard that calls GetPaymentResult, we may end up with different
// GetAttemptResult. As shard launch is sequential, and we fail the
// first shard that calls GetAttemptResult, we may end up with different
// counts since the lifecycle itself is asynchronous. To avoid flakes
// due to this undeterminsitic behavior, we'll compare the final
// getPaymentResultCnt with other counters to create a final test
// expectation.
getPaymentResultCnt := 0
payer.On("GetPaymentResult",
payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to
@@ -4254,9 +4254,9 @@ func TestSendToRouteSkipTempErrSuccess(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything,
).Return(nil)
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 1)
payer.On("GetPaymentResult",
payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) {
// Send a successful payment result.
@@ -4329,7 +4329,7 @@ func TestSendToRouteSkipTempErrTempFailure(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything,
).Return(nil)
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 1)
// Create the error to be returned.
@@ -4338,8 +4338,8 @@ func TestSendToRouteSkipTempErrTempFailure(t *testing.T) {
1,
)
// Mock GetPaymentResult to return a failure.
payer.On("GetPaymentResult",
// Mock GetAttemptResult to return a failure.
payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) {
// Send an attempt failure.
@@ -4418,7 +4418,7 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything,
).Return(nil)
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 1)
// Create the error to be returned.
@@ -4426,8 +4426,8 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
&lnwire.FailIncorrectDetails{}, 1,
)
// Mock GetPaymentResult to return a failure.
payer.On("GetPaymentResult",
// Mock GetAttemptResult to return a failure.
payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) {
// Send a permanent failure.
@@ -4507,7 +4507,7 @@ func TestSendToRouteTempFailure(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything,
).Return(nil)
// Create a buffered chan and it will be returned by GetPaymentResult.
// Create a buffered chan and it will be returned by GetAttemptResult.
payer.resultChan = make(chan *htlcswitch.PaymentResult, 1)
// Create the error to be returned.
@@ -4516,8 +4516,8 @@ func TestSendToRouteTempFailure(t *testing.T) {
1,
)
// Mock GetPaymentResult to return a failure.
payer.On("GetPaymentResult",
// Mock GetAttemptResult to return a failure.
payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) {
// Send an attempt failure.