Substract a flow cycle from the channel allocation. */
| 770 | |
| 771 | /* Substract a flow cycle from the channel allocation. */ |
| 772 | static void substract_cycle(const struct gossmap *gossmap, |
| 773 | const struct node sink, |
| 774 | struct chan_flow *chan_flow, const u32 *prev_idx, |
| 775 | const int *prev_dir, |
| 776 | const struct gossmap_chan *const *prev_chan) |
| 777 | { |
| 778 | s64 delta = INFINITE; |
| 779 | u32 cur_idx; |
| 780 | |
| 781 | /* Compute greatest flow in this cycle. */ |
| 782 | for (cur_idx = sink.idx; cur_idx!=INVALID_INDEX;) { |
| 783 | const int dir = prev_dir[cur_idx]; |
| 784 | const struct gossmap_chan *const chan = prev_chan[cur_idx]; |
| 785 | const u32 chan_idx = gossmap_chan_idx(gossmap, chan); |
| 786 | |
| 787 | delta = MIN(delta, chan_flow[chan_idx].half[dir]); |
| 788 | |
| 789 | cur_idx = prev_idx[cur_idx]; |
| 790 | if (cur_idx == sink.idx) |
| 791 | /* we have come back full circle */ |
| 792 | break; |
| 793 | } |
| 794 | assert(cur_idx==sink.idx); |
| 795 | |
| 796 | /* Walk again and substract the flow value (delta). */ |
| 797 | assert(delta < INFINITE); |
| 798 | assert(delta > 0); |
| 799 | |
| 800 | for (cur_idx = sink.idx;cur_idx!=INVALID_INDEX;) { |
| 801 | const int dir = prev_dir[cur_idx]; |
| 802 | const struct gossmap_chan *const chan = prev_chan[cur_idx]; |
| 803 | const u32 chan_idx = gossmap_chan_idx(gossmap, chan); |
| 804 | |
| 805 | chan_flow[chan_idx].half[dir] -= delta; |
| 806 | |
| 807 | cur_idx = prev_idx[cur_idx]; |
| 808 | if (cur_idx == sink.idx) |
| 809 | /* we have come back full circle */ |
| 810 | break; |
| 811 | } |
| 812 | assert(cur_idx==sink.idx); |
| 813 | } |
| 814 | |
| 815 | /* Given a flow in the residual network, build a set of payment flows in the |
| 816 | * gossmap that corresponds to this flow. */ |
no test coverage detected