A payment is finished if a) it is in a final state, of b) it's in a * child-spawning state and all of its children are in a final state. */
| 2020 | /* A payment is finished if a) it is in a final state, of b) it's in a |
| 2021 | * child-spawning state and all of its children are in a final state. */ |
| 2022 | static bool payment_is_finished(const struct payment *p) |
| 2023 | { |
| 2024 | top: |
| 2025 | if (p->step == PAYMENT_STEP_FAILED || p->step == PAYMENT_STEP_SUCCESS || p->abort) |
| 2026 | return true; |
| 2027 | else if (p->step == PAYMENT_STEP_SPLIT || p->step == PAYMENT_STEP_RETRY) { |
| 2028 | size_t num_children = tal_count(p->children); |
| 2029 | |
| 2030 | /* Retry case will almost always have just one child, so avoid |
| 2031 | * the overhead of pushing and popping off the C stack and |
| 2032 | * tail-recurse manually. */ |
| 2033 | if (num_children == 1) { |
| 2034 | p = p->children[0]; |
| 2035 | goto top; |
| 2036 | } |
| 2037 | |
| 2038 | for (size_t i = 0; i < num_children; i++) |
| 2039 | /* In other words: if any child is unfinished, |
| 2040 | * we are unfinished. */ |
| 2041 | if (!payment_is_finished(p->children[i])) |
| 2042 | return false; |
| 2043 | return true; |
| 2044 | } else { |
| 2045 | return false; |
| 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | static enum payment_step payment_aggregate_states(struct payment *p) |
| 2050 | { |
no outgoing calls
no test coverage detected