mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
gossip: Adding locally added channels to channels map
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
26b5588656
commit
a88076b1b0
@ -771,6 +771,7 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg)
|
|||||||
u32 fee_base_msat, fee_proportional_millionths;
|
u32 fee_base_msat, fee_proportional_millionths;
|
||||||
u64 htlc_minimum_msat;
|
u64 htlc_minimum_msat;
|
||||||
struct node_connection *c;
|
struct node_connection *c;
|
||||||
|
struct routing_channel *chan;
|
||||||
|
|
||||||
if (!fromwire_gossip_local_add_channel(
|
if (!fromwire_gossip_local_add_channel(
|
||||||
msg, NULL, &scid, &chain_hash, &remote_node_id, &flags,
|
msg, NULL, &scid, &chain_hash, &remote_node_id, &flags,
|
||||||
@ -792,8 +793,13 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chan = routing_channel_new(rstate, &scid);
|
||||||
|
chan->public = false;
|
||||||
|
uintmap_add(&rstate->channels, short_channel_id_to_uint(&scid), chan);
|
||||||
|
|
||||||
direction = get_channel_direction(&rstate->local_id, &remote_node_id);
|
direction = get_channel_direction(&rstate->local_id, &remote_node_id);
|
||||||
c = half_add_connection(rstate, &rstate->local_id, &remote_node_id, &scid, direction);
|
c = half_add_connection(rstate, &rstate->local_id, &remote_node_id, &scid, direction);
|
||||||
|
channel_add_connection(rstate, chan, c);
|
||||||
|
|
||||||
c->active = true;
|
c->active = true;
|
||||||
c->last_timestamp = 0;
|
c->last_timestamp = 0;
|
||||||
|
@ -565,8 +565,8 @@ find_pending_cannouncement(struct routing_state *rstate,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct routing_channel *
|
struct routing_channel *routing_channel_new(const tal_t *ctx,
|
||||||
routing_channel_new(const tal_t *ctx, struct short_channel_id *scid)
|
struct short_channel_id *scid)
|
||||||
{
|
{
|
||||||
struct routing_channel *chan = tal(ctx, struct routing_channel);
|
struct routing_channel *chan = tal(ctx, struct routing_channel);
|
||||||
chan->scid = *scid;
|
chan->scid = *scid;
|
||||||
@ -574,10 +574,34 @@ routing_channel_new(const tal_t *ctx, struct short_channel_id *scid)
|
|||||||
chan->nodes[0] = chan->nodes[1] = NULL;
|
chan->nodes[0] = chan->nodes[1] = NULL;
|
||||||
chan->txout_script = NULL;
|
chan->txout_script = NULL;
|
||||||
chan->state = TXOUT_FETCHING;
|
chan->state = TXOUT_FETCHING;
|
||||||
|
chan->public = false;
|
||||||
memset(&chan->msg_indexes, 0, sizeof(chan->msg_indexes));
|
memset(&chan->msg_indexes, 0, sizeof(chan->msg_indexes));
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void remove_connection_from_channel(struct node_connection *nc,
|
||||||
|
struct routing_state *rstate)
|
||||||
|
{
|
||||||
|
struct routing_channel *chan = uintmap_get(
|
||||||
|
&rstate->channels, short_channel_id_to_uint(&nc->short_channel_id));
|
||||||
|
struct node_connection *c = chan->connections[nc->flags & 0x1];
|
||||||
|
if (c == NULL)
|
||||||
|
return;
|
||||||
|
/* If we found a channel it should be the same */
|
||||||
|
assert(nc == c);
|
||||||
|
chan->connections[nc->flags & 0x1] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void channel_add_connection(struct routing_state *rstate,
|
||||||
|
struct routing_channel *chan,
|
||||||
|
struct node_connection *nc)
|
||||||
|
{
|
||||||
|
int direction = get_channel_direction(&nc->src->id, &nc->dst->id);
|
||||||
|
assert(chan != NULL);
|
||||||
|
chan->connections[direction] = nc;
|
||||||
|
tal_add_destructor2(nc, remove_connection_from_channel, rstate);
|
||||||
|
}
|
||||||
|
|
||||||
const struct short_channel_id *handle_channel_announcement(
|
const struct short_channel_id *handle_channel_announcement(
|
||||||
struct routing_state *rstate,
|
struct routing_state *rstate,
|
||||||
const u8 *announce TAKES)
|
const u8 *announce TAKES)
|
||||||
@ -617,7 +641,7 @@ const struct short_channel_id *handle_channel_announcement(
|
|||||||
/* Check if we know the channel already (no matter in what
|
/* Check if we know the channel already (no matter in what
|
||||||
* state, we stop here if yes). */
|
* state, we stop here if yes). */
|
||||||
chan = uintmap_get(&rstate->channels, scid);
|
chan = uintmap_get(&rstate->channels, scid);
|
||||||
if (chan != NULL) {
|
if (chan != NULL && chan->public) {
|
||||||
return tal_free(pending);
|
return tal_free(pending);
|
||||||
}
|
}
|
||||||
/* FIXME: Handle duplicates as per BOLT #7 */
|
/* FIXME: Handle duplicates as per BOLT #7 */
|
||||||
@ -673,6 +697,9 @@ const struct short_channel_id *handle_channel_announcement(
|
|||||||
|
|
||||||
/* So you're new in town, ey? Let's find you a room in the Inn. */
|
/* So you're new in town, ey? Let's find you a room in the Inn. */
|
||||||
chan = routing_channel_new(chan, &pending->short_channel_id);
|
chan = routing_channel_new(chan, &pending->short_channel_id);
|
||||||
|
|
||||||
|
/* The channel will be public if we complete the verification */
|
||||||
|
chan->public = true;
|
||||||
uintmap_add(&rstate->channels, scid, chan);
|
uintmap_add(&rstate->channels, scid, chan);
|
||||||
|
|
||||||
list_add_tail(&rstate->pending_cannouncement, &pending->list);
|
list_add_tail(&rstate->pending_cannouncement, &pending->list);
|
||||||
@ -742,10 +769,13 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
|
|||||||
c1 = get_connection(rstate, &pending->node_id_1, &pending->node_id_2);
|
c1 = get_connection(rstate, &pending->node_id_1, &pending->node_id_2);
|
||||||
forward = !c0 || !c1 || !c0->channel_announcement || !c1->channel_announcement;
|
forward = !c0 || !c1 || !c0->channel_announcement || !c1->channel_announcement;
|
||||||
|
|
||||||
add_channel_direction(rstate, &pending->node_id_1, &pending->node_id_2,
|
c0 = add_channel_direction(rstate, &pending->node_id_1, &pending->node_id_2,
|
||||||
&pending->short_channel_id, pending->announce);
|
&pending->short_channel_id, pending->announce);
|
||||||
add_channel_direction(rstate, &pending->node_id_2, &pending->node_id_1,
|
c1 = add_channel_direction(rstate, &pending->node_id_2, &pending->node_id_1,
|
||||||
&pending->short_channel_id, pending->announce);
|
&pending->short_channel_id, pending->announce);
|
||||||
|
|
||||||
|
channel_add_connection(rstate, chan, c0);
|
||||||
|
channel_add_connection(rstate, chan, c1);
|
||||||
|
|
||||||
if (forward) {
|
if (forward) {
|
||||||
if (replace_broadcast(rstate->broadcasts,
|
if (replace_broadcast(rstate->broadcasts,
|
||||||
|
@ -96,6 +96,9 @@ struct routing_channel {
|
|||||||
struct node *nodes[2];
|
struct node *nodes[2];
|
||||||
|
|
||||||
u64 msg_indexes[3];
|
u64 msg_indexes[3];
|
||||||
|
|
||||||
|
/* Is this a public channel, or was it only added locally? */
|
||||||
|
bool public;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct routing_state {
|
struct routing_state {
|
||||||
@ -180,6 +183,15 @@ void routing_failure(struct routing_state *rstate,
|
|||||||
enum onion_type failcode,
|
enum onion_type failcode,
|
||||||
const u8 *channel_update);
|
const u8 *channel_update);
|
||||||
|
|
||||||
|
/* routing_channel constructor */
|
||||||
|
struct routing_channel *routing_channel_new(const tal_t *ctx,
|
||||||
|
struct short_channel_id *scid);
|
||||||
|
|
||||||
|
/* Add the connection to the channel */
|
||||||
|
void channel_add_connection(struct routing_state *rstate,
|
||||||
|
struct routing_channel *chan,
|
||||||
|
struct node_connection *nc);
|
||||||
|
|
||||||
/* Utility function that, given a source and a destination, gives us
|
/* Utility function that, given a source and a destination, gives us
|
||||||
* the direction bit the matching channel should get */
|
* the direction bit the matching channel should get */
|
||||||
#define get_channel_direction(from, to) (pubkey_cmp(from, to) > 0)
|
#define get_channel_direction(from, to) (pubkey_cmp(from, to) > 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user