Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
177a1fc88e
  1. 12
      channeld/channel.c
  2. 6
      gossipd/gossip.c
  3. 4
      gossipd/gossip_wire.csv
  4. 25
      gossipd/routing.c
  5. 3
      gossipd/routing.h
  6. 2
      gossipd/test/run-bench-find_route.c
  7. 2
      gossipd/test/run-find_route-specific.c
  8. 2
      gossipd/test/run-find_route.c

12
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);
&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)

6
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",

4
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

Can't render this file because it has a wrong number of fields in line 6.

25
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,7 +1057,6 @@ 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);
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);
}

3
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);

2
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)

2
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)

2
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)

Loading…
Cancel
Save