Notify all channels of new blocks. */
| 926 | |
| 927 | /* Notify all channels of new blocks. */ |
| 928 | void channel_notify_new_block(struct lightningd *ld, |
| 929 | u32 block_height) |
| 930 | { |
| 931 | struct peer *peer; |
| 932 | struct channel *channel; |
| 933 | struct channel **to_forget = tal_arr(NULL, struct channel *, 0); |
| 934 | size_t i; |
| 935 | |
| 936 | list_for_each (&ld->peers, peer, list) { |
| 937 | list_for_each (&peer->channels, channel, list) { |
| 938 | if (channel_unsaved(channel)) |
| 939 | continue; |
| 940 | if (is_fundee_should_forget(ld, channel, block_height)) { |
| 941 | tal_arr_expand(&to_forget, channel); |
| 942 | } else |
| 943 | /* Let channels know about new blocks, |
| 944 | * required for lease updates */ |
| 945 | try_update_blockheight(ld, channel, |
| 946 | block_height); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | /* Need to forget in a separate loop, else the above |
| 951 | * nested loops may crash due to the last channel of |
| 952 | * a peer also deleting the peer, making the inner |
| 953 | * loop crash. |
| 954 | * list_for_each_safe does not work because it is not |
| 955 | * just the freeing of the channel that occurs, but the |
| 956 | * potential destruction of the peer that invalidates |
| 957 | * memory the inner loop is accessing. */ |
| 958 | for (i = 0; i < tal_count(to_forget); ++i) { |
| 959 | channel = to_forget[i]; |
| 960 | /* Report it first. */ |
| 961 | log_unusual(channel->log, |
| 962 | "Forgetting channel: " |
| 963 | "It has been %"PRIu32" blocks without the " |
| 964 | "funding transaction %s getting deeply " |
| 965 | "confirmed. " |
| 966 | "We are fundee and can forget channel without " |
| 967 | "loss of funds.", |
| 968 | block_height - channel->first_blocknum, |
| 969 | type_to_string(tmpctx, struct bitcoin_txid, |
| 970 | &channel->funding.txid)); |
| 971 | /* FIXME: Send an error packet for this case! */ |
| 972 | /* And forget it. */ |
| 973 | delete_channel(channel); |
| 974 | } |
| 975 | |
| 976 | tal_free(to_forget); |
| 977 | } |
| 978 | |
| 979 | /* Since this could vanish while we're checking with bitcoind, we need to save |
| 980 | * the details and re-lookup. |
no test coverage detected