routing/test: add test for stuck payment with in-flight htlcs

Add an additional stuck-payment case, where our payment gets
a terminal error while it has other htlcs in-flight, and a
shard fails with ErrTerminalPayment. This payment also falls in
our class of expected errors, but is not currently handled. The
mock is updated accordingly, using the same ordering as in our
real RegisterAttempt implementation.
This commit is contained in:
carla 2021-04-23 08:39:45 +02:00
parent 80451afe48
commit 12136a97a9
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
2 changed files with 54 additions and 0 deletions

View File

@ -333,6 +333,10 @@ 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,

View File

@ -650,6 +650,56 @@ func TestRouterPaymentStateMachine(t *testing.T) {
},
paymentErr: channeldb.ErrPaymentAlreadyFailed,
},
{
// A MP payment scenario when our path finding returns
// after we've just received a terminal failure, and
// we have another shard still in flight.
name: "MP shard in flight after terminal",
steps: []string{
routerInitPayment,
// shard 0
routeRelease,
routerRegisterAttempt,
sendToSwitchSuccess,
// shard 1
routeRelease,
routerRegisterAttempt,
sendToSwitchSuccess,
// shard 2
routeRelease,
routerRegisterAttempt,
sendToSwitchSuccess,
// We find a path for another shard.
routeRelease,
// shard 0 fails with a terminal error.
getPaymentResultTerminalFailure,
routerFailAttempt,
routerFailPayment,
// We try to register our final shard after
// processing a terminal failure.
routerRegisterAttempt,
// Our in-flight shards fail.
getPaymentResultTempFailure,
getPaymentResultTempFailure,
routerFailAttempt,
routerFailAttempt,
// Payment fails.
paymentError,
},
routes: []*route.Route{
shard, shard, shard, shard,
},
paymentErr: channeldb.ErrPaymentTerminal,
},
}
for _, test := range tests {