| 1473 | } |
| 1474 | |
| 1475 | struct 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 | |
| 1501 | get_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 | |
| 1510 | struct gossmap_chan *gossmap_nth_chan(const struct gossmap *map, |
| 1511 | const struct gossmap_node *node, |