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

+2 -2
View File
@@ -1306,7 +1306,7 @@ func TestChannelLinkMultiHopUnknownPaymentHash(t *testing.T) {
) )
require.NoError(t, err, "unable to get send payment") 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(), pid, htlc.PaymentHash, newMockDeobfuscator(),
) )
require.NoError(t, err, "unable to get payment result") 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") 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(), pid, htlc.PaymentHash, newMockDeobfuscator(),
) )
require.NoError(t, err, "unable to get payment result") require.NoError(t, err, "unable to get payment result")
+4 -4
View File
@@ -427,16 +427,16 @@ func (s *Switch) ProcessContractResolution(msg contractcourt.ResolutionMsg) erro
} }
} }
// GetPaymentResult returns the the result of the payment attempt with the // GetAttemptResult returns the result of the payment attempt with the given
// given attemptID. The paymentHash should be set to the payment's overall // attemptID. The paymentHash should be set to the payment's overall hash, or
// hash, or in case of AMP payments the payment's unique identifier. // in case of AMP payments the payment's unique identifier.
// //
// The method returns a channel where the payment result will be sent when // 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 // 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. // 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 // The switch shutting down is signaled by closing the channel. If the
// attemptID is unknown, ErrPaymentIDNotFound will be returned. // 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) { deobfuscator ErrorDecrypter) (<-chan *PaymentResult, error) {
var ( var (
+10 -10
View File
@@ -2699,7 +2699,7 @@ func TestSwitchSendPayment(t *testing.T) {
// First check that the switch will correctly respond that this payment // First check that the switch will correctly respond that this payment
// ID is unknown. // ID is unknown.
_, err = s.GetPaymentResult( _, err = s.GetAttemptResult(
paymentID, rhash, newMockDeobfuscator(), paymentID, rhash, newMockDeobfuscator(),
) )
if err != ErrPaymentIDNotFound { if err != ErrPaymentIDNotFound {
@@ -2717,7 +2717,7 @@ func TestSwitchSendPayment(t *testing.T) {
return return
} }
resultChan, err := s.GetPaymentResult( resultChan, err := s.GetAttemptResult(
paymentID, rhash, newMockDeobfuscator(), paymentID, rhash, newMockDeobfuscator(),
) )
if err != nil { 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 // 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 // payment ID. This is important for not to lose results under concurrent
// lookup and receiving results. // lookup and receiving results.
func TestSwitchGetPaymentResult(t *testing.T) { func TestSwitchGetAttemptResult(t *testing.T) {
t.Parallel() t.Parallel()
const paymentID = 123 const paymentID = 123
@@ -3100,7 +3100,7 @@ func TestSwitchGetPaymentResult(t *testing.T) {
// added anything to the store yet, ErrPaymentIDNotFound should be // added anything to the store yet, ErrPaymentIDNotFound should be
// returned. // returned.
lookup <- nil lookup <- nil
_, err = s.GetPaymentResult( _, err = s.GetAttemptResult(
paymentID, lntypes.Hash{}, newMockDeobfuscator(), paymentID, lntypes.Hash{}, newMockDeobfuscator(),
) )
if err != ErrPaymentIDNotFound { 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 // Next let the lookup find the circuit in the circuit map. It should
// subscribe to payment results, and return the result when available. // subscribe to payment results, and return the result when available.
lookup <- &PaymentCircuit{} lookup <- &PaymentCircuit{}
resultChan, err := s.GetPaymentResult( resultChan, err := s.GetAttemptResult(
paymentID, lntypes.Hash{}, newMockDeobfuscator(), paymentID, lntypes.Hash{}, newMockDeobfuscator(),
) )
require.NoError(t, err, "unable to get payment result") 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 // in the circuit map, it should be immediately available from the
// store. // store.
lookup <- nil lookup <- nil
resultChan, err = s.GetPaymentResult( resultChan, err = s.GetAttemptResult(
paymentID, lntypes.Hash{}, newMockDeobfuscator(), paymentID, lntypes.Hash{}, newMockDeobfuscator(),
) )
require.NoError(t, err, "unable to get payment result") 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, paymentID, rhash, &deobfuscator,
) )
if err != nil { if err != nil {
@@ -3283,7 +3283,7 @@ func TestInvalidFailure(t *testing.T) {
}, },
} }
resultChan, err = s.GetPaymentResult( resultChan, err = s.GetAttemptResult(
paymentID, rhash, &deobfuscator, paymentID, rhash, &deobfuscator,
) )
if err != nil { if err != nil {
@@ -4415,7 +4415,7 @@ func TestSwitchDustForwarding(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
carolAttemptID++ carolAttemptID++
carolResultChan, err := n.carolServer.htlcSwitch.GetPaymentResult( carolResultChan, err := n.carolServer.htlcSwitch.GetAttemptResult(
uint64(carolAttemptID-1), carolHash, newMockDeobfuscator(), uint64(carolAttemptID-1), carolHash, newMockDeobfuscator(),
) )
require.NoError(t, err) require.NoError(t, err)
+2 -2
View File
@@ -787,7 +787,7 @@ func preparePayment(sendingPeer, receivingPeer lnpeer.Peer,
if err != nil { if err != nil {
return err return err
} }
resultChan, err := sender.htlcSwitch.GetPaymentResult( resultChan, err := sender.htlcSwitch.GetAttemptResult(
pid, hash, newMockDeobfuscator(), pid, hash, newMockDeobfuscator(),
) )
if err != nil { if err != nil {
@@ -1345,7 +1345,7 @@ func (n *twoHopNetwork) makeHoldPayment(sendingPeer, receivingPeer lnpeer.Peer,
} }
go func() { go func() {
resultChan, err := sender.htlcSwitch.GetPaymentResult( resultChan, err := sender.htlcSwitch.GetAttemptResult(
pid, rhash, newMockDeobfuscator(), pid, rhash, newMockDeobfuscator(),
) )
if err != nil { if err != nil {
+3 -3
View File
@@ -56,7 +56,7 @@ func (m *mockPaymentAttemptDispatcherOld) SendHTLC(
return nil return nil
} }
func (m *mockPaymentAttemptDispatcherOld) GetPaymentResult(paymentID uint64, func (m *mockPaymentAttemptDispatcherOld) GetAttemptResult(paymentID uint64,
_ lntypes.Hash, _ htlcswitch.ErrorDecrypter) ( _ lntypes.Hash, _ htlcswitch.ErrorDecrypter) (
<-chan *htlcswitch.PaymentResult, error) { <-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) { _ htlcswitch.ErrorDecrypter) (<-chan *htlcswitch.PaymentResult, error) {
select { select {
@@ -578,7 +578,7 @@ func (m *mockPaymentAttemptDispatcher) SendHTLC(firstHop lnwire.ShortChannelID,
return args.Error(0) return args.Error(0)
} }
func (m *mockPaymentAttemptDispatcher) GetPaymentResult(attemptID uint64, func (m *mockPaymentAttemptDispatcher) GetAttemptResult(attemptID uint64,
paymentHash lntypes.Hash, deobfuscator htlcswitch.ErrorDecrypter) ( paymentHash lntypes.Hash, deobfuscator htlcswitch.ErrorDecrypter) (
<-chan *htlcswitch.PaymentResult, error) { <-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 // Now ask the switch to return the result of the payment when
// available. // available.
resultChan, err := p.router.cfg.Payer.GetPaymentResult( resultChan, err := p.router.cfg.Payer.GetAttemptResult(
attempt.AttemptID, p.identifier, errorDecryptor, attempt.AttemptID, p.identifier, errorDecryptor,
) )
switch { switch {
+9 -9
View File
@@ -107,20 +107,20 @@ const (
sendToSwitchResultFailure = "SendToSwitch:failure" sendToSwitchResultFailure = "SendToSwitch:failure"
// getPaymentResultSuccess is a test step where we expect the // 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. // respond with a successful payment result.
getPaymentResultSuccess = "GetPaymentResult:success" getPaymentResultSuccess = "GetAttemptResult:success"
// getPaymentResultTempFailure is a test step where we expect the // 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. // 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 // 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 // we will respond with a terminal error, expecting the router
// to stop making payment attempts. // to stop making payment attempts.
getPaymentResultTerminalFailure = "GetPaymentResult:terminal-failure" getPaymentResultTerminalFailure = "GetAttemptResult:terminal-failure"
// resendPayment is a test step where we manually try to resend // resendPayment is a test step where we manually try to resend
// the same payment, making sure the router responds with an // 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") 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 // to be called, and we respond with the preimage to
// complete the payment. // complete the payment.
case getPaymentResultSuccess: case getPaymentResultSuccess:
@@ -664,7 +664,7 @@ func testPaymentLifecycle(t *testing.T, test paymentLifecycleTestCase,
fatal("unable to send result") 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 // to be called, and we respond with a forwarding
// error, indicating that the router should retry. // error, indicating that the router should retry.
case getPaymentResultTempFailure: case getPaymentResultTempFailure:
@@ -682,7 +682,7 @@ func testPaymentLifecycle(t *testing.T, test paymentLifecycleTestCase,
} }
// In this state we expect the router to call the // 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 // terminal error, indicating the router should stop
// making payment attempts. // making payment attempts.
case getPaymentResultTerminalFailure: case getPaymentResultTerminalFailure:
+2 -2
View File
@@ -169,7 +169,7 @@ type PaymentAttemptDispatcher interface {
attemptID uint64, attemptID uint64,
htlcAdd *lnwire.UpdateAddHTLC) error 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 // the given attemptID. The paymentHash should be set to the payment's
// overall hash, or in case of AMP payments the payment's unique // overall hash, or in case of AMP payments the payment's unique
// identifier. // identifier.
@@ -180,7 +180,7 @@ type PaymentAttemptDispatcher interface {
// longer be in flight. The switch shutting down is signaled by // longer be in flight. The switch shutting down is signaled by
// closing the channel. If the attemptID is unknown, // closing the channel. If the attemptID is unknown,
// ErrPaymentIDNotFound will be returned. // ErrPaymentIDNotFound will be returned.
GetPaymentResult(attemptID uint64, paymentHash lntypes.Hash, GetAttemptResult(attemptID uint64, paymentHash lntypes.Hash,
deobfuscator htlcswitch.ErrorDecrypter) ( deobfuscator htlcswitch.ErrorDecrypter) (
<-chan *htlcswitch.PaymentResult, error) <-chan *htlcswitch.PaymentResult, error)
+21 -21
View File
@@ -3441,9 +3441,9 @@ func TestSendMPPaymentSucceed(t *testing.T) {
payment.HTLCs = append(payment.HTLCs, activeAttempt) 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.resultChan = make(chan *htlcswitch.PaymentResult, 10)
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything, mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) { ).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to // 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) 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.resultChan = make(chan *htlcswitch.PaymentResult, 10)
// We use the failAttemptCount to track how many attempts we want to // We use the failAttemptCount to track how many attempts we want to
// fail. Each time the following mock method is called, the count gets // fail. Each time the following mock method is called, the count gets
// updated. // updated.
failAttemptCount := 0 failAttemptCount := 0
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything, mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) { ).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to // 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) 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.resultChan = make(chan *htlcswitch.PaymentResult, 10)
// We use the failAttemptCount to track how many attempts we want to // We use the failAttemptCount to track how many attempts we want to
// fail. Each time the following mock method is called, the count gets // fail. Each time the following mock method is called, the count gets
// updated. // updated.
failAttemptCount := 0 failAttemptCount := 0
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything, mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) { ).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to // 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) 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.resultChan = make(chan *htlcswitch.PaymentResult, 10)
// We use the getPaymentResultCnt to track how many times we called // We use the getPaymentResultCnt to track how many times we called
// GetPaymentResult. As shard launch is sequential, and we fail the // GetAttemptResult. As shard launch is sequential, and we fail the
// first shard that calls GetPaymentResult, we may end up with different // first shard that calls GetAttemptResult, we may end up with different
// counts since the lifecycle itself is asynchronous. To avoid flakes // counts since the lifecycle itself is asynchronous. To avoid flakes
// due to this undeterminsitic behavior, we'll compare the final // due to this undeterminsitic behavior, we'll compare the final
// getPaymentResultCnt with other counters to create a final test // getPaymentResultCnt with other counters to create a final test
// expectation. // expectation.
getPaymentResultCnt := 0 getPaymentResultCnt := 0
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, identifier, mock.Anything, mock.Anything, identifier, mock.Anything,
).Run(func(args mock.Arguments) { ).Run(func(args mock.Arguments) {
// Before the mock method is returned, we send the result to // 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, mock.Anything, mock.Anything, mock.Anything,
).Return(nil) ).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.resultChan = make(chan *htlcswitch.PaymentResult, 1)
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) { ).Run(func(_ mock.Arguments) {
// Send a successful payment result. // Send a successful payment result.
@@ -4329,7 +4329,7 @@ func TestSendToRouteSkipTempErrTempFailure(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Return(nil) ).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.resultChan = make(chan *htlcswitch.PaymentResult, 1)
// Create the error to be returned. // Create the error to be returned.
@@ -4338,8 +4338,8 @@ func TestSendToRouteSkipTempErrTempFailure(t *testing.T) {
1, 1,
) )
// Mock GetPaymentResult to return a failure. // Mock GetAttemptResult to return a failure.
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) { ).Run(func(_ mock.Arguments) {
// Send an attempt failure. // Send an attempt failure.
@@ -4418,7 +4418,7 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Return(nil) ).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.resultChan = make(chan *htlcswitch.PaymentResult, 1)
// Create the error to be returned. // Create the error to be returned.
@@ -4426,8 +4426,8 @@ func TestSendToRouteSkipTempErrPermanentFailure(t *testing.T) {
&lnwire.FailIncorrectDetails{}, 1, &lnwire.FailIncorrectDetails{}, 1,
) )
// Mock GetPaymentResult to return a failure. // Mock GetAttemptResult to return a failure.
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) { ).Run(func(_ mock.Arguments) {
// Send a permanent failure. // Send a permanent failure.
@@ -4507,7 +4507,7 @@ func TestSendToRouteTempFailure(t *testing.T) {
mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Return(nil) ).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.resultChan = make(chan *htlcswitch.PaymentResult, 1)
// Create the error to be returned. // Create the error to be returned.
@@ -4516,8 +4516,8 @@ func TestSendToRouteTempFailure(t *testing.T) {
1, 1,
) )
// Mock GetPaymentResult to return a failure. // Mock GetAttemptResult to return a failure.
payer.On("GetPaymentResult", payer.On("GetAttemptResult",
mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything,
).Run(func(_ mock.Arguments) { ).Run(func(_ mock.Arguments) {
// Send an attempt failure. // Send an attempt failure.