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

Function gossmap_chan_get_capacity

common/gossmap.c:1481–1514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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