mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
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>
This commit is contained in:
parent
c71e16f784
commit
9d1e496b11
@ -356,17 +356,17 @@ static void send_temporary_announcement(struct peer *peer)
|
||||
!peer->funding_locked[REMOTE])
|
||||
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
|
||||
* through us */
|
||||
msg = create_channel_update(NULL, peer, false);
|
||||
enqueue_peer_msg(peer, take(msg));
|
||||
msg = create_channel_update(tmpctx, peer, false);
|
||||
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)
|
||||
|
@ -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);
|
||||
err = handle_channel_update(rstate, msg, true);
|
||||
if (err)
|
||||
return err;
|
||||
break;
|
||||
@ -1489,7 +1489,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);
|
||||
err = handle_channel_update(rstate, update, true);
|
||||
if (err)
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"rejected keepalive channel_update: %s",
|
||||
@ -2385,7 +2385,7 @@ static struct io_plan *handle_disable_channel(struct io_conn *conn,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
err = handle_channel_update(daemon->rstate, msg);
|
||||
err = handle_channel_update(daemon->rstate, msg, true);
|
||||
if (err)
|
||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||
"rejected disabling channel_update: %s",
|
||||
|
@ -196,12 +196,9 @@ gossip_send_gossip,,gossip,len*u8
|
||||
# we can use it already.
|
||||
gossip_local_add_channel,3017
|
||||
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,,cltv_expiry_delta,u16
|
||||
gossip_local_add_channel,,htlc_minimum_msat,u64
|
||||
gossip_local_add_channel,,fee_base_msat,u32
|
||||
gossip_local_add_channel,,fee_proportional_millionths,u32
|
||||
gossip_local_add_channel,,len,u16
|
||||
gossip_local_add_channel,,update,len*u8
|
||||
|
||||
# Gossipd->master get this tx output please.
|
||||
gossip_get_txout,3018
|
||||
|
|
@ -786,7 +786,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);
|
||||
err = handle_channel_update(rstate, cupdate, true);
|
||||
if (err) {
|
||||
status_trace("Pending channel_update for %s: %s",
|
||||
type_to_string(tmpctx, struct short_channel_id, scid),
|
||||
@ -879,14 +879,14 @@ static void update_pending(struct pending_cannouncement *pending,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
static 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)
|
||||
{
|
||||
struct half_chan *c = &chan->half[idx];
|
||||
|
||||
@ -961,7 +961,8 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
||||
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;
|
||||
struct half_chan *c;
|
||||
@ -1060,7 +1061,8 @@ 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. */
|
||||
gossip_store_add_channel_update(rstate->store, serialized);
|
||||
if (add_to_store)
|
||||
gossip_store_add_channel_update(rstate->store, serialized);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -1430,7 +1432,7 @@ void routing_failure(struct routing_state *rstate,
|
||||
(int) failcode);
|
||||
return;
|
||||
}
|
||||
err = handle_channel_update(rstate, channel_update);
|
||||
err = handle_channel_update(rstate, channel_update, true);
|
||||
if (err) {
|
||||
status_unusual("routing_failure: "
|
||||
"bad channel_update %s",
|
||||
@ -1504,32 +1506,20 @@ void route_prune(struct routing_state *rstate)
|
||||
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 bitcoin_blkid chain_hash;
|
||||
struct pubkey remote_node_id;
|
||||
u16 cltv_expiry_delta;
|
||||
u32 fee_base_msat, fee_proportional_millionths;
|
||||
u64 htlc_minimum_msat;
|
||||
int idx;
|
||||
u8 *update;
|
||||
struct chan *chan;
|
||||
u8 *err;
|
||||
|
||||
if (!fromwire_gossip_local_add_channel(
|
||||
msg, &scid, &chain_hash, &remote_node_id,
|
||||
&cltv_expiry_delta, &htlc_minimum_msat, &fee_base_msat,
|
||||
&fee_proportional_millionths)) {
|
||||
if (!fromwire_gossip_local_add_channel(msg, msg, &scid, &remote_node_id,
|
||||
&update)) {
|
||||
status_broken("Unable to parse local_add_channel message: %s", tal_hex(msg, msg));
|
||||
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. */
|
||||
if (get_channel(rstate, &scid)) {
|
||||
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 */
|
||||
chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id);
|
||||
|
||||
idx = pubkey_idx(&rstate->local_id, &remote_node_id),
|
||||
/* Activate the half_chan from us to them. */
|
||||
set_connection_values(chan, idx,
|
||||
fee_base_msat,
|
||||
fee_proportional_millionths,
|
||||
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);
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
@ -220,21 +220,12 @@ 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);
|
||||
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. */
|
||||
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() */
|
||||
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
|
||||
* `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 */
|
||||
|
@ -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 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(); }
|
||||
/* 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)
|
||||
|
@ -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 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(); }
|
||||
/* 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)
|
||||
|
@ -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 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(); }
|
||||
/* 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…
Reference in New Issue
Block a user