multi: change RegisterAttempt error checking order
Move our more generic terminal check forward so that we only need to handle a single class of expected errors. This change is mirrored in our mock, and our reproducing tests are updated to assert that this move catches both classes of errors we get.
This commit is contained in:
4 files changed
+14
-17
No files matched your search
@@ -290,18 +290,19 @@ func (p *PaymentControl) RegisterAttempt(paymentHash lntypes.Hash,
|
||||
return err
|
||||
}
|
||||
|
||||
// Ensure the payment is in-flight.
|
||||
if err := ensureInFlight(p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// We cannot register a new attempt if the payment already has
|
||||
// reached a terminal condition:
|
||||
// reached a terminal condition. We check this before
|
||||
// ensureInFlight because it is a more general check.
|
||||
settle, fail := p.TerminalInfo()
|
||||
if settle != nil || fail != nil {
|
||||
return ErrPaymentTerminal
|
||||
}
|
||||
|
||||
// Ensure the payment is in-flight.
|
||||
if err := ensureInFlight(p); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Make sure any existing shards match the new one with regards
|
||||
// to MPP options.
|
||||
mpp := attempt.Route.FinalHop().MPP
|
||||
|
||||
@@ -1013,19 +1013,15 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
// up in the Succeeded state. If both failed the payment should
|
||||
// also be Failed at this poinnt.
|
||||
finalStatus := StatusFailed
|
||||
expRegErr := ErrPaymentAlreadyFailed
|
||||
if test.settleFirst || test.settleLast {
|
||||
finalStatus = StatusSucceeded
|
||||
expRegErr = ErrPaymentAlreadySucceeded
|
||||
}
|
||||
|
||||
assertPaymentStatus(t, pControl, info.PaymentHash, finalStatus)
|
||||
|
||||
// Finally assert we cannot register more attempts.
|
||||
_, err = pControl.RegisterAttempt(info.PaymentHash, &b)
|
||||
if err != expRegErr {
|
||||
t.Fatalf("expected error %v, got: %v", expRegErr, err)
|
||||
}
|
||||
require.Equal(t, ErrPaymentTerminal, err)
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
Reference in new issue
Block a user