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

Function fill_from_update

common/gossmap.c:528–571  ·  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

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