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. */
| 1769 | /* A payment is finished if a) it is in a final state, of b) it's in a |
| 1770 | * child-spawning state and all of its children are in a final state. */ |
| 1771 | static bool payment_is_finished(const struct payment *p) |
| 1772 | { |
| 1773 | top: |
| 1774 | if (p->step == PAYMENT_STEP_FAILED || p->step == PAYMENT_STEP_SUCCESS || p->abort) |
| 1775 | return true; |
| 1776 | else if (p->step == PAYMENT_STEP_SPLIT || p->step == PAYMENT_STEP_RETRY) { |
| 1777 | size_t num_children = tal_count(p->children); |
| 1778 | |
| 1779 | /* Retry case will almost always have just one child, so avoid |
| 1780 | * the overhead of pushing and popping off the C stack and |
| 1781 | * tail-recurse manually. */ |
| 1782 | if (num_children == 1) { |
| 1783 | p = p->children[0]; |
| 1784 | goto top; |
| 1785 | } |
| 1786 | |
| 1787 | for (size_t i = 0; i < num_children; i++) |
| 1788 | /* In other words: if any child is unfinished, |
| 1789 | * we are unfinished. */ |
| 1790 | if (!payment_is_finished(p->children[i])) |
| 1791 | return false; |
| 1792 | return true; |
| 1793 | } else { |
| 1794 | return false; |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | static enum payment_step payment_aggregate_states(struct payment *p) |
| 1799 | { |
no outgoing calls
no test coverage detected