mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
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:
parent
d1611c999a
commit
e3bc4f4cc9
@ -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")
|
||||
|
@ -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 (
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user