diff --git a/gossipd/gossip.c b/gossipd/gossip.c index d59540d14..395b4b7c3 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -765,7 +765,6 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg) u32 fee_base_msat, fee_proportional_millionths; u64 htlc_minimum_msat; int idx; - struct node_connection *c; struct routing_channel *chan; if (!fromwire_gossip_local_add_channel( @@ -792,16 +791,15 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg) chan = new_routing_channel(rstate, &scid, &rstate->local_id, &remote_node_id); - idx = pubkey_idx(&rstate->local_id, &remote_node_id); - c = chan->connections[idx]; - - /* FIXME: Deduplicate with code in routing.c */ - c->active = true; - c->last_timestamp = 0; - c->delay = cltv_expiry_delta; - c->htlc_minimum_msat = htlc_minimum_msat; - c->base_fee = fee_base_msat; - c->proportional_fee = fee_proportional_millionths; + idx = pubkey_idx(&rstate->local_id, &remote_node_id), + /* Activate the node_connection 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), diff --git a/gossipd/routing.c b/gossipd/routing.c index be791d297..97821ac9f 100644 --- a/gossipd/routing.c +++ b/gossipd/routing.c @@ -825,6 +825,43 @@ static void update_pending(struct pending_cannouncement *pending, } } +void set_connection_values(struct routing_channel *chan, + int idx, + u32 base_fee, + u32 proportional_fee, + u32 delay, + bool active, + u64 timestamp, + u32 htlc_minimum_msat) +{ + struct node_connection *c = chan->connections[idx]; + + c->delay = delay; + c->htlc_minimum_msat = htlc_minimum_msat; + c->base_fee = base_fee; + c->proportional_fee = proportional_fee; + c->active = active; + c->last_timestamp = timestamp; + assert((c->flags & 0x1) == idx); + + /* If it was temporarily unroutable, re-enable */ + c->unroutable_until = 0; + + SUPERVERBOSE("Channel %s(%d) was updated.", + type_to_string(trc, struct short_channel_id, &chan->scid), + idx); + + if (c->proportional_fee >= MAX_PROPORTIONAL_FEE) { + status_trace("Channel %s(%d) massive proportional fee %u:" + " disabling.", + type_to_string(trc, struct short_channel_id, + &chan->scid), + idx, + c->proportional_fee); + c->active = false; + } +} + void handle_channel_update(struct routing_state *rstate, const u8 *update) { u8 *serialized; @@ -916,27 +953,13 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update) flags & 0x01, flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE"); - c->last_timestamp = timestamp; - c->delay = expiry; - c->htlc_minimum_msat = htlc_minimum_msat; - c->base_fee = fee_base_msat; - c->proportional_fee = fee_proportional_millionths; - c->active = (flags & ROUTING_FLAGS_DISABLED) == 0; - c->unroutable_until = 0; - SUPERVERBOSE("Channel %s(%d) was updated.", - type_to_string(trc, struct short_channel_id, - &short_channel_id), - direction); - - if (c->proportional_fee >= MAX_PROPORTIONAL_FEE) { - status_trace("Channel %s(%d) massive proportional fee %u:" - " disabling.", - type_to_string(trc, struct short_channel_id, - &short_channel_id), - direction, - fee_proportional_millionths); - c->active = false; - } + set_connection_values(chan, direction, + fee_base_msat, + fee_proportional_millionths, + expiry, + (flags & ROUTING_FLAGS_DISABLED) == 0, + timestamp, + htlc_minimum_msat); u8 *tag = tal_arr(tmpctx, u8, 0); towire_short_channel_id(&tag, &short_channel_id); diff --git a/gossipd/routing.h b/gossipd/routing.h index 5c44225ad..bcba75364 100644 --- a/gossipd/routing.h +++ b/gossipd/routing.h @@ -219,6 +219,16 @@ bool handle_pending_cannouncement(struct routing_state *rstate, void handle_channel_update(struct routing_state *rstate, const u8 *update); void handle_node_announcement(struct routing_state *rstate, const u8 *node); +/* Set values on the struct node_connection */ +void set_connection_values(struct routing_channel *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);