Browse Source

gossipd: use a real update in local_add_channel.

We generate one now, so let's use it.  That lets us simplify the
code, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
9d1e496b11
  1. 18
      channeld/channel.c
  2. 6
      gossipd/gossip.c
  3. 7
      gossipd/gossip_wire.csv
  4. 51
      gossipd/routing.c
  5. 15
      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

18
channeld/channel.c

@ -356,17 +356,17 @@ static void send_temporary_announcement(struct peer *peer)
!peer->funding_locked[REMOTE]) !peer->funding_locked[REMOTE])
return; return;
msg = towire_gossip_local_add_channel(
NULL, &peer->short_channel_ids[LOCAL], &peer->chain_hash,
&peer->node_ids[REMOTE], peer->cltv_delta,
peer->conf[REMOTE].htlc_minimum_msat, peer->fee_base,
peer->fee_per_satoshi);
wire_sync_write(GOSSIP_FD, take(msg));
/* Tell the other side what parameters we expect should they route /* Tell the other side what parameters we expect should they route
* through us */ * through us */
msg = create_channel_update(NULL, peer, false); msg = create_channel_update(tmpctx, peer, false);
enqueue_peer_msg(peer, take(msg)); enqueue_peer_msg(peer, msg);
msg = towire_gossip_local_add_channel(NULL,
&peer->short_channel_ids[LOCAL],
&peer->node_ids[REMOTE],
msg);
wire_sync_write(GOSSIP_FD, take(msg));
} }
static void send_announcement_signatures(struct peer *peer) 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; break;
case WIRE_CHANNEL_UPDATE: case WIRE_CHANNEL_UPDATE:
err = handle_channel_update(rstate, msg); err = handle_channel_update(rstate, msg, true);
if (err) if (err)
return err; return err;
break; break;
@ -1489,7 +1489,7 @@ static void gossip_send_keepalive_update(struct routing_state *rstate,
status_trace("Sending keepalive channel_update for %s", status_trace("Sending keepalive channel_update for %s",
type_to_string(tmpctx, struct short_channel_id, &scid)); type_to_string(tmpctx, struct short_channel_id, &scid));
err = handle_channel_update(rstate, update); err = handle_channel_update(rstate, update, true);
if (err) if (err)
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"rejected keepalive channel_update: %s", "rejected keepalive channel_update: %s",
@ -2385,7 +2385,7 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn,
strerror(errno)); strerror(errno));
} }
err = handle_channel_update(daemon->rstate, msg); err = handle_channel_update(daemon->rstate, msg, true);
if (err) if (err)
status_failed(STATUS_FAIL_INTERNAL_ERROR, status_failed(STATUS_FAIL_INTERNAL_ERROR,
"rejected disabling channel_update: %s", "rejected disabling channel_update: %s",

7
gossipd/gossip_wire.csv

@ -196,12 +196,9 @@ gossip_send_gossip,,gossip,len*u8
# we can use it already. # we can use it already.
gossip_local_add_channel,3017 gossip_local_add_channel,3017
gossip_local_add_channel,,short_channel_id,struct short_channel_id gossip_local_add_channel,,short_channel_id,struct short_channel_id
gossip_local_add_channel,,chain_hash,struct bitcoin_blkid
gossip_local_add_channel,,remote_node_id,struct pubkey gossip_local_add_channel,,remote_node_id,struct pubkey
gossip_local_add_channel,,cltv_expiry_delta,u16 gossip_local_add_channel,,len,u16
gossip_local_add_channel,,htlc_minimum_msat,u64 gossip_local_add_channel,,update,len*u8
gossip_local_add_channel,,fee_base_msat,u32
gossip_local_add_channel,,fee_proportional_millionths,u32
# Gossipd->master get this tx output please. # Gossipd->master get this tx output please.
gossip_get_txout,3018 gossip_get_txout,3018

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

51
gossipd/routing.c

@ -786,7 +786,7 @@ static void process_pending_channel_update(struct routing_state *rstate,
return; return;
/* FIXME: We don't remember who sent us updates, so can't error them */ /* FIXME: We don't remember who sent us updates, so can't error them */
err = handle_channel_update(rstate, cupdate); err = handle_channel_update(rstate, cupdate, true);
if (err) { if (err) {
status_trace("Pending channel_update for %s: %s", status_trace("Pending channel_update for %s: %s",
type_to_string(tmpctx, struct short_channel_id, scid), type_to_string(tmpctx, struct short_channel_id, scid),
@ -879,7 +879,7 @@ static void update_pending(struct pending_cannouncement *pending,
} }
} }
void set_connection_values(struct chan *chan, static void set_connection_values(struct chan *chan,
int idx, int idx,
u32 base_fee, u32 base_fee,
u32 proportional_fee, u32 proportional_fee,
@ -961,7 +961,8 @@ bool routing_add_channel_update(struct routing_state *rstate,
return true; return true;
} }
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update) u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
bool add_to_store)
{ {
u8 *serialized; u8 *serialized;
struct half_chan *c; struct half_chan *c;
@ -1060,6 +1061,7 @@ u8 *handle_channel_update(struct routing_state *rstate, const u8 *update)
/* Store the channel_update for both public and non-public channels /* Store the channel_update for both public and non-public channels
* (non-public ones may just be the incoming direction). We'd have * (non-public ones may just be the incoming direction). We'd have
* dropped invalid ones earlier. */ * 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; return NULL;
@ -1430,7 +1432,7 @@ void routing_failure(struct routing_state *rstate,
(int) failcode); (int) failcode);
return; return;
} }
err = handle_channel_update(rstate, channel_update); err = handle_channel_update(rstate, channel_update, true);
if (err) { if (err) {
status_unusual("routing_failure: " status_unusual("routing_failure: "
"bad channel_update %s", "bad channel_update %s",
@ -1504,32 +1506,20 @@ void route_prune(struct routing_state *rstate)
tal_free(pruned); tal_free(pruned);
} }
void handle_local_add_channel(struct routing_state *rstate, u8 *msg) void handle_local_add_channel(struct routing_state *rstate, const u8 *msg)
{ {
struct short_channel_id scid; struct short_channel_id scid;
struct bitcoin_blkid chain_hash;
struct pubkey remote_node_id; struct pubkey remote_node_id;
u16 cltv_expiry_delta; u8 *update;
u32 fee_base_msat, fee_proportional_millionths;
u64 htlc_minimum_msat;
int idx;
struct chan *chan; struct chan *chan;
u8 *err;
if (!fromwire_gossip_local_add_channel( if (!fromwire_gossip_local_add_channel(msg, msg, &scid, &remote_node_id,
msg, &scid, &chain_hash, &remote_node_id, &update)) {
&cltv_expiry_delta, &htlc_minimum_msat, &fee_base_msat,
&fee_proportional_millionths)) {
status_broken("Unable to parse local_add_channel message: %s", tal_hex(msg, msg)); status_broken("Unable to parse local_add_channel message: %s", tal_hex(msg, msg));
return; return;
} }
if (!structeq(&chain_hash, &rstate->chain_hash)) {
status_broken("Received local_add_channel for unknown chain %s",
type_to_string(msg, struct bitcoin_blkid,
&chain_hash));
return;
}
/* Can happen on channeld restart. */ /* Can happen on channeld restart. */
if (get_channel(rstate, &scid)) { if (get_channel(rstate, &scid)) {
status_trace("Attempted to local_add_channel a known channel"); status_trace("Attempted to local_add_channel a known channel");
@ -1539,17 +1529,10 @@ void handle_local_add_channel(struct routing_state *rstate, u8 *msg)
/* Create new channel */ /* Create new channel */
chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id); chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id);
idx = pubkey_idx(&rstate->local_id, &remote_node_id), /* We've already put this in the store: don't again! */
/* Activate the half_chan from us to them. */ err = handle_channel_update(rstate, update, false);
set_connection_values(chan, idx, if (err) {
fee_base_msat, status_broken("local_add_channel: %s", err);
fee_proportional_millionths, tal_free(chan);
cltv_expiry_delta, }
true,
0,
htlc_minimum_msat);
/* Designed to match msg in handle_channel_update, for easy testing */
status_trace("Received local update for channel %s(%d) now ACTIVE",
type_to_string(msg, struct short_channel_id, &scid),
idx);
} }

15
gossipd/routing.h

@ -220,21 +220,12 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
const u8 *txscript); const u8 *txscript);
/* Returns NULL if all OK, otherwise an error for the peer which sent. */ /* Returns NULL if all OK, otherwise an error for the peer which sent. */
u8 *handle_channel_update(struct routing_state *rstate, const u8 *update); u8 *handle_channel_update(struct routing_state *rstate, const u8 *update,
bool add_to_store);
/* Returns NULL if all OK, otherwise an error for the peer which sent. */ /* Returns NULL if all OK, otherwise an error for the peer which sent. */
u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node); u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node);
/* Set values on the struct node_connection */
void set_connection_values(struct chan *chan,
int idx,
u32 base_fee,
u32 proportional_fee,
u32 delay,
bool active,
u64 timestamp,
u32 htlc_minimum_msat);
/* Get a node: use this instead of node_map_get() */ /* Get a node: use this instead of node_map_get() */
struct node *get_node(struct routing_state *rstate, const struct pubkey *id); struct node *get_node(struct routing_state *rstate, const struct pubkey *id);
@ -301,6 +292,6 @@ bool routing_add_node_announcement(struct routing_state *rstate,
* is the case for private channels or channels that have not yet reached * is the case for private channels or channels that have not yet reached
* `announce_depth`. * `announce_depth`.
*/ */
void handle_local_add_channel(struct routing_state *rstate, u8 *msg); void handle_local_add_channel(struct routing_state *rstate, const u8 *msg);
#endif /* LIGHTNING_GOSSIPD_ROUTING_H */ #endif /* LIGHTNING_GOSSIPD_ROUTING_H */

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) 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(); } { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); }
/* Generated stub for fromwire_gossip_local_add_channel */ /* 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 bitcoin_blkid *chain_hash UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) 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)
{ fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_channel_announcement */ /* 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) 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) 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(); } { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); }
/* Generated stub for fromwire_gossip_local_add_channel */ /* 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 bitcoin_blkid *chain_hash UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) 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)
{ fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_channel_announcement */ /* 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) 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) 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(); } { fprintf(stderr, "fromwire_channel_update called!\n"); abort(); }
/* Generated stub for fromwire_gossip_local_add_channel */ /* 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 bitcoin_blkid *chain_hash UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED) 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)
{ fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); } { fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); }
/* Generated stub for fromwire_gossip_store_channel_announcement */ /* 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) bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED)

Loading…
Cancel
Save