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:
carla committed 2021-04-23 08:39:45 +02:00
1 parent 12136a97a9
commit 58d95be4dd
4 files changed
+14 -17

No files matched your search

+4 -4
View File
@@ -325,6 +325,10 @@ func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
_, settled := m.successful[phash]
_, failed := m.failed[phash]
if settled || failed {
return channeldb.ErrPaymentTerminal
}
if settled && !inFlight {
return channeldb.ErrPaymentAlreadySucceeded
}
@@ -333,10 +337,6 @@ func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
return channeldb.ErrPaymentAlreadyFailed
}
if settled || failed {
return channeldb.ErrPaymentTerminal
}
// Add attempt to payment.
p.attempts = append(p.attempts, channeldb.HTLCAttempt{
HTLCAttemptInfo: *a,
+2 -2
View File
@@ -619,7 +619,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
// A MP payment scenario when our path finding returns
// after we've just received a terminal failure, and
// demonstrates a bug where the payment will return with
// and "unexpected" ErrPaymentAlreadyFailed rather than
// and "unexpected" ErrPaymentTerminal rather than
// failing with a permanent error. This results in the
// payment getting stuck.
name: "MP path found after failure",
@@ -648,7 +648,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
routes: []*route.Route{
shard, shard,
},
paymentErr: channeldb.ErrPaymentAlreadyFailed,
paymentErr: channeldb.ErrPaymentTerminal,
},
{
// A MP payment scenario when our path finding returns