| 1479 | } |
| 1480 | |
| 1481 | struct 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 | |
| 1507 | get_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 | |
| 1516 | struct gossmap_chan *gossmap_nth_chan(const struct gossmap *map, |
| 1517 | const struct gossmap_node *node, |