MCPcopy Create free account
hub / github.com/ElementsProject/lightning / fill_from_update

Function fill_from_update

common/gossmap.c:525–568  ·  view source on GitHub ↗

Does not set hc->nodeidx! * Returns false if it doesn't fit in our representation: this happens * on the real network, as people set absurd fees */

Source from the content-addressed store, hash-verified

523 * on the real network, as people set absurd fees
524 */
525static bool fill_from_update(struct gossmap *map,
526 struct short_channel_id_dir *scidd,
527 struct half_chan *hc,
528 u64 cupdate_off)
529{
530 /* Note that first two bytes are message type */
531 const u64 scid_off = cupdate_off + 2 + (64 + 32);
532 const u64 message_flags_off = scid_off + 8 + 4;
533 const u64 channel_flags_off = message_flags_off + 1;
534 const u64 cltv_expiry_delta_off = channel_flags_off + 1;
535 const u64 htlc_minimum_off = cltv_expiry_delta_off + 2;
536 const u64 fee_base_off = htlc_minimum_off + 8;
537 const u64 fee_prop_off = fee_base_off + 4;
538 const u64 htlc_maximum_off = fee_prop_off + 4;
539 u8 chanflags;
540 u32 base_fee, proportional_fee;
541 u16 delay;
542
543 /* We round this *down*, since too-low min is more conservative */
544 hc->htlc_min = u64_to_fp16(map_be64(map, htlc_minimum_off), false);
545 hc->htlc_max = u64_to_fp16(map_be64(map, htlc_maximum_off), true);
546
547 scidd->scid.u64 = map_be64(map, scid_off);
548 chanflags = map_u8(map, channel_flags_off);
549 scidd->dir = (chanflags & ROUTING_FLAGS_DIRECTION);
550 hc->enabled = !(chanflags & ROUTING_FLAGS_DISABLED);
551 base_fee = map_be32(map, fee_base_off);
552 proportional_fee = map_be32(map, fee_prop_off);
553 delay = map_be16(map, cltv_expiry_delta_off);
554
555 hc->base_fee = base_fee;
556 hc->proportional_fee = proportional_fee;
557 hc->delay = delay;
558
559 /* Check they fit: we turn off if not. */
560 if (hc->base_fee != base_fee
561 || hc->proportional_fee != proportional_fee
562 || hc->delay != delay) {
563 hc->htlc_max = 0;
564 hc->enabled = false;
565 return false;
566 }
567 return true;
568}
569
570/* BOLT #7:
571 * 1. type: 258 (`channel_update`)

Callers 2

update_channelFunction · 0.85
gossmap_apply_localmodsFunction · 0.85

Calls 5

u64_to_fp16Function · 0.85
map_be64Function · 0.85
map_u8Function · 0.85
map_be32Function · 0.85
map_be16Function · 0.85

Tested by

no test coverage detected