| 2852 | } |
| 2853 | |
| 2854 | static void setup_peer(struct peer *peer) |
| 2855 | { |
| 2856 | struct channel *channel; |
| 2857 | struct channel_inflight *inflight; |
| 2858 | struct lightningd *ld = peer->ld; |
| 2859 | bool connect = false, important = false; |
| 2860 | |
| 2861 | list_for_each(&peer->channels, channel, list) { |
| 2862 | switch (channel->state) { |
| 2863 | case DUALOPEND_OPEN_INIT: |
| 2864 | case DUALOPEND_OPEN_COMMIT_READY: |
| 2865 | case DUALOPEND_OPEN_COMMITTED: |
| 2866 | /* Nothing to watch */ |
| 2867 | continue; |
| 2868 | |
| 2869 | /* Normal cases where we watch funding */ |
| 2870 | case CHANNELD_AWAITING_LOCKIN: |
| 2871 | case CHANNELD_NORMAL: |
| 2872 | case CHANNELD_SHUTTING_DOWN: |
| 2873 | case CLOSINGD_SIGEXCHANGE: |
| 2874 | /* We still want to watch spend, to tell onchaind: */ |
| 2875 | case CLOSINGD_COMPLETE: |
| 2876 | case AWAITING_UNILATERAL: |
| 2877 | case FUNDING_SPEND_SEEN: |
| 2878 | case ONCHAIN: |
| 2879 | case CLOSED: |
| 2880 | channel_watch_funding(ld, channel); |
| 2881 | break; |
| 2882 | |
| 2883 | /* We need to watch all inflights which may open channel */ |
| 2884 | case DUALOPEND_AWAITING_LOCKIN: |
| 2885 | list_for_each(&channel->inflights, inflight, list) |
| 2886 | watch_opening_inflight(ld, inflight); |
| 2887 | break; |
| 2888 | |
| 2889 | /* We need to watch all inflights which may splice */ |
| 2890 | case CHANNELD_AWAITING_SPLICE: |
| 2891 | list_for_each(&channel->inflights, inflight, list) |
| 2892 | watch_splice_inflight(ld, inflight); |
| 2893 | break; |
| 2894 | } |
| 2895 | |
| 2896 | /* Don't reconnect for private channels if --dev-no-reconnect-private */ |
| 2897 | if (!channel->peer->ld->reconnect_private |
| 2898 | && !(channel->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)) |
| 2899 | continue; |
| 2900 | |
| 2901 | if (channel_state_wants_peercomms(channel->state) |
| 2902 | && !ignore_idle_channel(ld, channel)) |
| 2903 | connect = true; |
| 2904 | if (channel_important_filter(channel, NULL)) |
| 2905 | important = true; |
| 2906 | } |
| 2907 | |
| 2908 | /* Make sure connectd knows to try reconnecting (unless |
| 2909 | * --dev-no-reconnect). */ |
| 2910 | if (connect && ld->reconnect) |
| 2911 | connectd_connect_to_peer(ld, peer, |
no test coverage detected