Skip to content

Commit 9d9d658

Browse files
ViktorTigerstromellemouton
authored andcommitted
accounts: refactor in-flight check
This commit refactors the in-flight check in the accounts service to its own function. The in-flight check is also inverted to only check the states that are not considered as in-flight. This makes the check forward-compatible with lnd `v0.18.0-beta` which introduces a new `lnrpc.Payment_INITIATED` state.
1 parent 61f32f6 commit 9d9d658

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

accounts/service.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,7 @@ func (s *InterceptorService) paymentUpdate(hash lntypes.Hash,
764764
// Are we still in-flight? Then we don't have to do anything just yet.
765765
// The unknown state should never happen in practice but if it ever did
766766
// we couldn't handle it anyway, so let's also ignore it.
767-
if status.State == lnrpc.Payment_IN_FLIGHT ||
768-
status.State == lnrpc.Payment_UNKNOWN {
769-
767+
if inflightState(status.State) {
770768
return false, nil
771769
}
772770

@@ -888,6 +886,13 @@ func successState(status lnrpc.Payment_PaymentStatus) bool {
888886
return status == lnrpc.Payment_SUCCEEDED
889887
}
890888

889+
// inflightState returns true if a payment should be seen as in-flight by the
890+
// accounts system.
891+
func inflightState(status lnrpc.Payment_PaymentStatus) bool {
892+
return status != lnrpc.Payment_SUCCEEDED &&
893+
status != lnrpc.Payment_FAILED
894+
}
895+
891896
// requestValuesStore is an in-memory implementation of the
892897
// RequestValuesStore interface.
893898
type requestValuesStore struct {

0 commit comments

Comments
 (0)