From 8a34933c1a380138fc225031c4e4a9d9ebd739ab Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 31 Jul 2018 11:57:30 +0200 Subject: [PATCH] gossip: Annotate locally added channels with their capacity We were adding channels without their capacity, and eventually annotated them when we exchanged `channel_update`s. This worked as long as we weren't considering the channel capacity, but would result in local-only channels to be unusable once we start checking. --- channeld/channel.c | 3 ++- gossipd/gossip_wire.csv | 1 + gossipd/routing.c | 11 ++++++++--- gossipd/test/run-bench-find_route.c | 2 +- gossipd/test/run-find_route-specific.c | 2 +- gossipd/test/run-find_route.c | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/channeld/channel.c b/channeld/channel.c index 0ddf34198..f8741767b 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -275,7 +275,8 @@ static void make_channel_local_active(struct peer *peer) /* Tell gossipd about local channel. */ msg = towire_gossip_local_add_channel(NULL, &peer->short_channel_ids[LOCAL], - &peer->node_ids[REMOTE]); + &peer->node_ids[REMOTE], + peer->channel->funding_msat / 1000); wire_sync_write(GOSSIP_FD, take(msg)); /* Tell gossipd and the other side what parameters we expect should diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index 193596500..5e2abc5a4 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -121,6 +121,7 @@ gossip_send_gossip,,gossip,len*u8 gossip_local_add_channel,3017 gossip_local_add_channel,,short_channel_id,struct short_channel_id gossip_local_add_channel,,remote_node_id,struct pubkey +gossip_local_add_channel,,satoshis,u64 gossip_local_channel_update,3026 gossip_local_channel_update,,short_channel_id,struct short_channel_id diff --git a/gossipd/routing.c b/gossipd/routing.c index 541d74713..935795892 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -1672,9 +1672,13 @@ void handle_local_add_channel(struct routing_state *rstate, const u8 *msg) { struct short_channel_id scid; struct pubkey remote_node_id; + struct chan *chan; + u64 satoshis; - if (!fromwire_gossip_local_add_channel(msg, &scid, &remote_node_id)) { - status_broken("Unable to parse local_add_channel message: %s", tal_hex(msg, msg)); + if (!fromwire_gossip_local_add_channel(msg, &scid, &remote_node_id, + &satoshis)) { + status_broken("Unable to parse local_add_channel message: %s", + tal_hex(msg, msg)); return; } @@ -1688,5 +1692,6 @@ void handle_local_add_channel(struct routing_state *rstate, const u8 *msg) type_to_string(tmpctx, struct short_channel_id, &scid)); /* Create new (unannounced) channel */ - new_chan(rstate, &scid, &rstate->local_id, &remote_node_id); + chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id); + chan->satoshis = satoshis; } diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index d9ec64d26..9c7d70a98 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -66,7 +66,7 @@ bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNE bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); } /* Generated stub for fromwire_gossip_local_add_channel */ -bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED) +bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u64 *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_announcement */ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED) diff --git a/gossipd/test/run-find_route-specific.c b/gossipd/test/run-find_route-specific.c index 7bf0f67ea..3995c32e5 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -30,7 +30,7 @@ bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNE bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); } /* Generated stub for fromwire_gossip_local_add_channel */ -bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED) +bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u64 *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_announcement */ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED) diff --git a/gossipd/test/run-find_route.c b/gossipd/test/run-find_route.c index 352de4dd8..8bd1d8070 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -28,7 +28,7 @@ bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNE bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); } /* Generated stub for fromwire_gossip_local_add_channel */ -bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED) +bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u64 *satoshis UNNEEDED) { fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); } /* Generated stub for fromwire_gossip_store_channel_announcement */ bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED)