diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index cd3890d17..bf3916651 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1306,7 +1306,7 @@ func TestChannelLinkMultiHopUnknownPaymentHash(t *testing.T) { ) require.NoError(t, err, "unable to get send payment") - resultChan, err := n.aliceServer.htlcSwitch.GetPaymentResult( + resultChan, err := n.aliceServer.htlcSwitch.GetAttemptResult( pid, htlc.PaymentHash, newMockDeobfuscator(), ) require.NoError(t, err, "unable to get payment result") @@ -3979,7 +3979,7 @@ func TestChannelLinkAcceptDuplicatePayment(t *testing.T) { ) require.NoError(t, err, "unable to send payment to carol") - resultChan, err := n.aliceServer.htlcSwitch.GetPaymentResult( + resultChan, err := n.aliceServer.htlcSwitch.GetAttemptResult( pid, htlc.PaymentHash, newMockDeobfuscator(), ) require.NoError(t, err, "unable to get payment result") diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 34997ac82..ee1712c77 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -427,16 +427,16 @@ func (s *Switch) ProcessContractResolution(msg contractcourt.ResolutionMsg) erro } } -// GetPaymentResult returns the 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. +// 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. // // The method returns a channel where the payment result will be sent when // available, or an error is encountered during forwarding. When a result is // received on the channel, the HTLC is guaranteed to no longer be in flight. // The switch shutting down is signaled by closing the channel. If the // attemptID is unknown, ErrPaymentIDNotFound will be returned. -func (s *Switch) GetPaymentResult(attemptID uint64, paymentHash lntypes.Hash, +func (s *Switch) GetAttemptResult(attemptID uint64, paymentHash lntypes.Hash, deobfuscator ErrorDecrypter) (<-chan *PaymentResult, error) { var ( diff --git a/htlcswitch/switch_test.go b/htlcswitch/switch_test.go index 4d666b760..a8c7aa4ab 100644 --- a/htlcswitch/switch_test.go +++ b/htlcswitch/switch_test.go @@ -2699,7 +2699,7 @@ func TestSwitchSendPayment(t *testing.T) { // First check that the switch will correctly respond that this payment // ID is unknown. - _, err = s.GetPaymentResult( + _, err = s.GetAttemptResult( paymentID, rhash, newMockDeobfuscator(), ) if err != ErrPaymentIDNotFound { @@ -2717,7 +2717,7 @@ func TestSwitchSendPayment(t *testing.T) { return } - resultChan, err := s.GetPaymentResult( + resultChan, err := s.GetAttemptResult( paymentID, rhash, newMockDeobfuscator(), ) if err != nil { @@ -3072,11 +3072,11 @@ func TestUpdateFailMalformedHTLCErrorConversion(t *testing.T) { }) } -// TestSwitchGetPaymentResult tests that the switch interacts as expected with +// TestSwitchGetAttemptResult tests that the switch interacts as expected with // the circuit map and network result store when looking up the result of a // payment ID. This is important for not to lose results under concurrent // lookup and receiving results. -func TestSwitchGetPaymentResult(t *testing.T) { +func TestSwitchGetAttemptResult(t *testing.T) { t.Parallel() const paymentID = 123 @@ -3100,7 +3100,7 @@ func TestSwitchGetPaymentResult(t *testing.T) { // added anything to the store yet, ErrPaymentIDNotFound should be // returned. lookup <- nil - _, err = s.GetPaymentResult( + _, err = s.GetAttemptResult( paymentID, lntypes.Hash{}, newMockDeobfuscator(), ) if err != ErrPaymentIDNotFound { @@ -3110,7 +3110,7 @@ func TestSwitchGetPaymentResult(t *testing.T) { // Next let the lookup find the circuit in the circuit map. It should // subscribe to payment results, and return the result when available. lookup <- &PaymentCircuit{} - resultChan, err := s.GetPaymentResult( + resultChan, err := s.GetAttemptResult( paymentID, lntypes.Hash{}, newMockDeobfuscator(), ) require.NoError(t, err, "unable to get payment result") @@ -3151,7 +3151,7 @@ func TestSwitchGetPaymentResult(t *testing.T) { // in the circuit map, it should be immediately available from the // store. lookup <- nil - resultChan, err = s.GetPaymentResult( + resultChan, err = s.GetAttemptResult( paymentID, lntypes.Hash{}, newMockDeobfuscator(), ) require.NoError(t, err, "unable to get payment result") @@ -3257,7 +3257,7 @@ func TestInvalidFailure(t *testing.T) { }, } - resultChan, err := s.GetPaymentResult( + resultChan, err := s.GetAttemptResult( paymentID, rhash, &deobfuscator, ) if err != nil { @@ -3283,7 +3283,7 @@ func TestInvalidFailure(t *testing.T) { }, } - resultChan, err = s.GetPaymentResult( + resultChan, err = s.GetAttemptResult( paymentID, rhash, &deobfuscator, ) if err != nil { @@ -4415,7 +4415,7 @@ func TestSwitchDustForwarding(t *testing.T) { require.NoError(t, err) carolAttemptID++ - carolResultChan, err := n.carolServer.htlcSwitch.GetPaymentResult( + carolResultChan, err := n.carolServer.htlcSwitch.GetAttemptResult( uint64(carolAttemptID-1), carolHash, newMockDeobfuscator(), ) require.NoError(t, err) diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index e4568fc0e..b9ba325ab 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -787,7 +787,7 @@ func preparePayment(sendingPeer, receivingPeer lnpeer.Peer, if err != nil { return err } - resultChan, err := sender.htlcSwitch.GetPaymentResult( + resultChan, err := sender.htlcSwitch.GetAttemptResult( pid, hash, newMockDeobfuscator(), ) if err != nil { @@ -1345,7 +1345,7 @@ func (n *twoHopNetwork) makeHoldPayment(sendingPeer, receivingPeer lnpeer.Peer, } go func() { - resultChan, err := sender.htlcSwitch.GetPaymentResult( + resultChan, err := sender.htlcSwitch.GetAttemptResult( pid, rhash, newMockDeobfuscator(), ) if err != nil { diff --git a/routing/mock_test.go b/routing/mock_test.go index c321db3db..6d6dbf9b8 100644 --- a/routing/mock_test.go +++ b/routing/mock_test.go @@ -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) { diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index cd3ab81f3..6a7198ba2 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -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 { diff --git a/routing/payment_lifecycle_test.go b/routing/payment_lifecycle_test.go index b69df3e79..a220df8d0 100644 --- a/routing/payment_lifecycle_test.go +++ b/routing/payment_lifecycle_test.go @@ -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: diff --git a/routing/router.go b/routing/router.go index 7d7ceb7b1..affad930b 100644 --- a/routing/router.go +++ b/routing/router.go @@ -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) diff --git a/routing/router_test.go b/routing/router_test.go index a63149c6c..8387c284d 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -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.