From 177a1fc88ebd8e087efff03400af3f40cbf06c32 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 May 2018 14:39:59 +0930 Subject: [PATCH] gossipd: handle local channel creation separately from update. Note: this will break the gossip_store if they have current channels, but it will fail to parse and be discarded. Have local_add_channel do just that: the update is logically separate and can be sent separately. This removes the ugly 'bool add_to_store' flag. Signed-off-by: Rusty Russell --- channeld/channel.c | 14 ++++++------- gossipd/gossip.c | 6 +++--- gossipd/gossip_wire.csv | 4 +--- gossipd/routing.c | 27 +++++++------------------- gossipd/routing.h | 3 +-- gossipd/test/run-bench-find_route.c | 2 +- gossipd/test/run-find_route-specific.c | 2 +- gossipd/test/run-find_route.c | 2 +- 8 files changed, 21 insertions(+), 39 deletions(-) diff --git a/channeld/channel.c b/channeld/channel.c index 9edf87d0e..7c8a4a475 100644 --- a/channeld/channel.c +++ b/channeld/channel.c @@ -374,17 +374,15 @@ static void send_temporary_announcement(struct peer *peer) { u8 *msg; - /* Tell the other side what parameters we expect should they route - * through us */ - msg = create_channel_update(tmpctx, peer, 0); - enqueue_peer_msg(peer, msg); - + /* Tell gossipd about local channel. */ msg = towire_gossip_local_add_channel(NULL, &peer->short_channel_ids[LOCAL], - &peer->node_ids[REMOTE], - msg); - wire_sync_write(GOSSIP_FD, take(msg)); + &peer->node_ids[REMOTE]); + wire_sync_write(GOSSIP_FD, take(msg)); + /* Tell gossipd and the other side what parameters we expect should + * they route through us */ + send_channel_update(peer, true, 0); } static void send_announcement_signatures(struct peer *peer) diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 30bd3abe5..1703947d8 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -657,7 +657,7 @@ static u8 *handle_gossip_msg(struct daemon *daemon, const u8 *msg) break; case WIRE_CHANNEL_UPDATE: - err = handle_channel_update(rstate, msg, true); + err = handle_channel_update(rstate, msg); if (err) return err; break; @@ -1482,7 +1482,7 @@ static void gossip_send_keepalive_update(struct routing_state *rstate, status_trace("Sending keepalive channel_update for %s", type_to_string(tmpctx, struct short_channel_id, &scid)); - err = handle_channel_update(rstate, update, true); + err = handle_channel_update(rstate, update); if (err) status_failed(STATUS_FAIL_INTERNAL_ERROR, "rejected keepalive channel_update: %s", @@ -2420,7 +2420,7 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn, strerror(errno)); } - err = handle_channel_update(daemon->rstate, msg, true); + err = handle_channel_update(daemon->rstate, msg); if (err) status_failed(STATUS_FAIL_INTERNAL_ERROR, "rejected disabling channel_update: %s", diff --git a/gossipd/gossip_wire.csv b/gossipd/gossip_wire.csv index ab1c701eb..44d63a095 100644 --- a/gossipd/gossip_wire.csv +++ b/gossipd/gossip_wire.csv @@ -193,12 +193,10 @@ gossip_send_gossip,,gossip,len*u8 # Both sides have seen the funding tx being locked, but we have not # yet reached the announcement depth. So we add the channel locally so -# we can use it already. +# we (and peer) can update it already. 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,,len,u16 -gossip_local_add_channel,,update,len*u8 # Gossipd->master get this tx output please. gossip_get_txout,3018 diff --git a/gossipd/routing.c b/gossipd/routing.c index 6fdda9ce0..11336a6a9 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -784,7 +784,7 @@ static void process_pending_channel_update(struct routing_state *rstate, return; /* FIXME: We don't remember who sent us updates, so can't error them */ - err = handle_channel_update(rstate, cupdate, true); + err = handle_channel_update(rstate, cupdate); if (err) { status_trace("Pending channel_update for %s: %s", type_to_string(tmpctx, struct short_channel_id, scid), @@ -958,8 +958,7 @@ bool routing_add_channel_update(struct routing_state *rstate, return true; } -u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, - bool add_to_store) +u8 *handle_channel_update(struct routing_state *rstate, const u8 *update) { u8 *serialized; struct half_chan *c; @@ -1058,8 +1057,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, /* Store the channel_update for both public and non-public channels * (non-public ones may just be the incoming direction). We'd have * dropped invalid ones earlier. */ - if (add_to_store) - gossip_store_add_channel_update(rstate->store, serialized); + gossip_store_add_channel_update(rstate->store, serialized); return NULL; } @@ -1431,7 +1429,7 @@ void routing_failure(struct routing_state *rstate, (int) failcode); return; } - err = handle_channel_update(rstate, channel_update, true); + err = handle_channel_update(rstate, channel_update); if (err) { status_unusual("routing_failure: " "bad channel_update %s", @@ -1509,12 +1507,8 @@ void handle_local_add_channel(struct routing_state *rstate, const u8 *msg) { struct short_channel_id scid; struct pubkey remote_node_id; - u8 *update; - struct chan *chan; - u8 *err; - if (!fromwire_gossip_local_add_channel(msg, msg, &scid, &remote_node_id, - &update)) { + 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)); return; } @@ -1525,13 +1519,6 @@ void handle_local_add_channel(struct routing_state *rstate, const u8 *msg) return; } - /* Create new channel */ - chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id); - - /* We've already put this in the store: don't again! */ - err = handle_channel_update(rstate, update, false); - if (err) { - status_broken("local_add_channel: %s", err); - tal_free(chan); - } + /* Create new (unannounced) channel */ + new_chan(rstate, &scid, &rstate->local_id, &remote_node_id); } diff --git a/gossipd/routing.h b/gossipd/routing.h index 83ea09aa6..13eff7f65 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -228,8 +228,7 @@ bool handle_pending_cannouncement(struct routing_state *rstate, const u8 *txscript); /* Returns NULL if all OK, otherwise an error for the peer which sent. */ -u8 *handle_channel_update(struct routing_state *rstate, const u8 *update, - bool add_to_store); +u8 *handle_channel_update(struct routing_state *rstate, const u8 *update); /* Returns NULL if all OK, otherwise an error for the peer which sent. */ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node); diff --git a/gossipd/test/run-bench-find_route.c b/gossipd/test/run-bench-find_route.c index 3492175d1..e5ecf32ca 100644 --- a/gossipd/test/run-bench-find_route.c +++ b/gossipd/test/run-bench-find_route.c @@ -63,7 +63,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 tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u8 **update 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) { 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 714213f10..aef9e2afd 100644 --- a/gossipd/test/run-find_route-specific.c +++ b/gossipd/test/run-find_route-specific.c @@ -27,7 +27,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 tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u8 **update 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) { 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 9176d8e61..f8d74568d 100644 --- a/gossipd/test/run-find_route.c +++ b/gossipd/test/run-find_route.c @@ -25,7 +25,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 tal_t *ctx UNNEEDED, const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u8 **update 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) { 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)