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

Function gossmap_chan_get_capacity

common/gossmap.c:1475–1508  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1473}
1474
1475struct amount_msat gossmap_chan_get_capacity(const struct gossmap *map,
1476 const struct gossmap_chan *c)
1477{
1478 struct gossip_hdr ghdr;
1479 u64 off;
1480 u16 type;
1481 struct amount_sat sat;
1482 struct amount_msat msat;
1483
1484 if (gossmap_chan_is_localmod(map, c)) {
1485 /* Amount is *before* c->cann_off */
1486 off = c->cann_off - sizeof(u64);
1487 goto get_amount;
1488 }
1489
1490 /* Skip over this record to next; expect a gossip_store_channel_amount */
1491 off = c->cann_off - sizeof(ghdr);
1492 map_copy(map, off, &ghdr, sizeof(ghdr));
1493 off += sizeof(ghdr) + be16_to_cpu(ghdr.len);
1494
1495 /* We don't allow loading a channel unless it has capacity field! */
1496 type = map_be16(map, off + sizeof(ghdr));
1497 assert(type == WIRE_GOSSIP_STORE_CHANNEL_AMOUNT);
1498
1499 off += sizeof(ghdr) + sizeof(be16);
1500
1501get_amount:
1502 /* Shouldn't overflow */
1503 sat = amount_sat(map_be64(map, off));
1504 if (!amount_sat_to_msat(&msat, sat))
1505 errx(1, "invalid capacity %s", fmt_amount_sat(tmpctx, sat));
1506
1507 return msat;
1508}
1509
1510struct gossmap_chan *gossmap_nth_chan(const struct gossmap *map,
1511 const struct gossmap_node *node,

Callers 15

calc_capacityFunction · 0.85
dijkstra_to_hopsFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
capacity_biasFunction · 0.85
mainFunction · 0.85
capacity_biasFunction · 0.85
json_add_halfchanFunction · 0.85
get_capacitiesFunction · 0.85
node_statsFunction · 0.85
explain_failureFunction · 0.85

Calls 9

gossmap_chan_is_localmodFunction · 0.85
map_copyFunction · 0.85
be16_to_cpuFunction · 0.85
map_be16Function · 0.85
map_be64Function · 0.85
errxFunction · 0.85
amount_satClass · 0.70
amount_sat_to_msatFunction · 0.70
fmt_amount_satFunction · 0.70

Tested by 5

mainFunction · 0.68
mainFunction · 0.68
capacity_biasFunction · 0.68
mainFunction · 0.68
test_flow_to_routeFunction · 0.68