| 2958 | } |
| 2959 | |
| 2960 | void htlcs_notify_new_block(struct lightningd *ld) |
| 2961 | { |
| 2962 | bool removed; |
| 2963 | u32 height = get_block_height(ld->topology); |
| 2964 | |
| 2965 | /* BOLT #2: |
| 2966 | * |
| 2967 | * - if an HTLC which it offered is in either node's current |
| 2968 | * commitment transaction, AND is past this timeout deadline: |
| 2969 | * - SHOULD send an `error` to the receiving peer (if connected). |
| 2970 | * - MUST fail the channel. |
| 2971 | */ |
| 2972 | /* FIXME: use db to look this up in one go (earliest deadline per-peer) */ |
| 2973 | do { |
| 2974 | struct htlc_out *hout; |
| 2975 | struct htlc_out_map_iter outi; |
| 2976 | |
| 2977 | removed = false; |
| 2978 | |
| 2979 | for (hout = htlc_out_map_first(ld->htlcs_out, &outi); |
| 2980 | hout; |
| 2981 | hout = htlc_out_map_next(ld->htlcs_out, &outi)) { |
| 2982 | /* Not timed out yet? */ |
| 2983 | if (height < htlc_out_deadline(hout)) |
| 2984 | continue; |
| 2985 | |
| 2986 | /* Channel dying already? */ |
| 2987 | if (!channel_state_can_add_htlc(hout->key.channel->state)) { |
| 2988 | consider_failing_incoming(ld, height, hout); |
| 2989 | continue; |
| 2990 | } |
| 2991 | |
| 2992 | /* Peer already failed, or we hit it? */ |
| 2993 | if (hout->key.channel->error) |
| 2994 | continue; |
| 2995 | |
| 2996 | channel_fail_permanent(hout->key.channel, |
| 2997 | REASON_PROTOCOL, |
| 2998 | "Offered HTLC %"PRIu64 |
| 2999 | " %s cltv %u hit deadline", |
| 3000 | hout->key.id, |
| 3001 | htlc_state_name(hout->hstate), |
| 3002 | hout->cltv_expiry); |
| 3003 | removed = true; |
| 3004 | } |
| 3005 | /* Iteration while removing is safe, but can skip entries! */ |
| 3006 | } while (removed); |
| 3007 | |
| 3008 | |
| 3009 | /* BOLT #2: |
| 3010 | * |
| 3011 | * - for each HTLC it is attempting to fulfill: |
| 3012 | * - MUST estimate a fulfillment deadline. |
| 3013 | *... |
| 3014 | * - if an HTLC it has fulfilled is in either node's current commitment |
| 3015 | * transaction, AND is past this fulfillment deadline: |
| 3016 | * - SHOULD send an `error` to the offering peer (if connected). |
| 3017 | * - MUST fail the channel. |
no test coverage detected