| 2916 | } |
| 2917 | |
| 2918 | void htlcs_notify_new_block(struct lightningd *ld) |
| 2919 | { |
| 2920 | bool removed; |
| 2921 | u32 height = get_block_height(ld->topology); |
| 2922 | |
| 2923 | /* BOLT #2: |
| 2924 | * |
| 2925 | * - if an HTLC which it offered is in either node's current |
| 2926 | * commitment transaction, AND is past this timeout deadline: |
| 2927 | * - SHOULD send an `error` to the receiving peer (if connected). |
| 2928 | * - MUST fail the channel. |
| 2929 | */ |
| 2930 | /* FIXME: use db to look this up in one go (earliest deadline per-peer) */ |
| 2931 | do { |
| 2932 | struct htlc_out *hout; |
| 2933 | struct htlc_out_map_iter outi; |
| 2934 | |
| 2935 | removed = false; |
| 2936 | |
| 2937 | for (hout = htlc_out_map_first(ld->htlcs_out, &outi); |
| 2938 | hout; |
| 2939 | hout = htlc_out_map_next(ld->htlcs_out, &outi)) { |
| 2940 | /* Not timed out yet? */ |
| 2941 | if (height < htlc_out_deadline(hout)) |
| 2942 | continue; |
| 2943 | |
| 2944 | /* Channel dying already? */ |
| 2945 | if (!channel_state_can_add_htlc(hout->key.channel->state)) { |
| 2946 | consider_failing_incoming(ld, height, hout); |
| 2947 | continue; |
| 2948 | } |
| 2949 | |
| 2950 | /* Peer already failed, or we hit it? */ |
| 2951 | if (hout->key.channel->error) |
| 2952 | continue; |
| 2953 | |
| 2954 | channel_fail_permanent(hout->key.channel, |
| 2955 | REASON_PROTOCOL, |
| 2956 | "Offered HTLC %"PRIu64 |
| 2957 | " %s cltv %u hit deadline", |
| 2958 | hout->key.id, |
| 2959 | htlc_state_name(hout->hstate), |
| 2960 | hout->cltv_expiry); |
| 2961 | removed = true; |
| 2962 | } |
| 2963 | /* Iteration while removing is safe, but can skip entries! */ |
| 2964 | } while (removed); |
| 2965 | |
| 2966 | |
| 2967 | /* BOLT #2: |
| 2968 | * |
| 2969 | * - for each HTLC it is attempting to fulfill: |
| 2970 | * - MUST estimate a fulfillment deadline. |
| 2971 | *... |
| 2972 | * - if an HTLC it has fulfilled is in either node's current commitment |
| 2973 | * transaction, AND is past this fulfillment deadline: |
| 2974 | * - SHOULD send an `error` to the offering peer (if connected). |
| 2975 | * - MUST fail the channel. |
no test coverage detected