channeldb+routing: apply method Terminated to decide a payment's terminal state

This commit applies the new method `Terminated`. A side effect from
using this method is, we can now save one query `fetchPayment` inside
`FetchInFlightPayments`.
This commit is contained in:
yyforyongyu
2022-11-17 10:28:22 +08:00
committed by Olaoluwa Osuntokun
parent fac6044501
commit c175386c4d
4 changed files with 26 additions and 19 deletions

View File

@@ -119,9 +119,9 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
subscriber1, subscriber2, subscriber3,
}
for _, s := range subscribers {
for i, s := range subscribers {
var result *channeldb.MPPayment
for result == nil || result.Status == channeldb.StatusInFlight {
for result == nil || !result.Terminated() {
select {
case item := <-s.Updates():
result = item.(*channeldb.MPPayment)
@@ -130,9 +130,10 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
}
}
if result.Status != channeldb.StatusSucceeded {
t.Fatal("unexpected payment state")
}
require.Equalf(t, channeldb.StatusSucceeded, result.Status,
"subscriber %v failed, want %s, got %s", i,
channeldb.StatusSucceeded, result.Status)
settle, _ := result.TerminalInfo()
if settle.Preimage != preimg {
t.Fatal("unexpected preimage")
@@ -474,9 +475,9 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt,
subscriber1, subscriber2,
}
for _, s := range subscribers {
for i, s := range subscribers {
var result *channeldb.MPPayment
for result == nil || result.Status == channeldb.StatusInFlight {
for result == nil || !result.Terminated() {
select {
case item := <-s.Updates():
result = item.(*channeldb.MPPayment)
@@ -510,6 +511,10 @@ func testPaymentControlSubscribeFail(t *testing.T, registerAttempt,
len(result.HTLCs))
}
require.Equalf(t, channeldb.StatusFailed, result.Status,
"subscriber %v failed, want %s, got %s", i,
channeldb.StatusFailed, result.Status)
if *result.FailureReason != channeldb.FailureReasonTimeout {
t.Fatal("unexpected failure reason")
}