mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
gossipd: Use channels map to lookup pending cannouncements
Iterating over lists is so 1980s Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
b09666c51c
commit
f6c9c4fc3a
@ -797,6 +797,7 @@ static void handle_local_add_channel(struct peer *peer, u8 *msg)
|
||||
chan->public = false;
|
||||
uintmap_add(&rstate->channels, short_channel_id_to_uint(&scid), chan);
|
||||
|
||||
chan->pending = NULL;
|
||||
direction = get_channel_direction(&rstate->local_id, &remote_node_id);
|
||||
c = half_add_connection(rstate, &rstate->local_id, &remote_node_id, &scid, direction);
|
||||
channel_add_connection(rstate, chan, c);
|
||||
|
@ -33,8 +33,6 @@
|
||||
/* We've unpacked and checked its signatures, now we wait for master to tell
|
||||
* us the txout to check */
|
||||
struct pending_cannouncement {
|
||||
struct list_node list;
|
||||
|
||||
/* Unpacked fields here */
|
||||
struct short_channel_id short_channel_id;
|
||||
struct pubkey node_id_1;
|
||||
@ -569,21 +567,6 @@ static bool check_channel_announcement(
|
||||
check_signed_hash(&hash, bitcoin2_sig, bitcoin2_key);
|
||||
}
|
||||
|
||||
/* While master always processes in order, bitcoind is async, so they could
|
||||
* theoretically return out of order. */
|
||||
static struct pending_cannouncement *
|
||||
find_pending_cannouncement(struct routing_state *rstate,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
struct pending_cannouncement *i;
|
||||
|
||||
list_for_each(&rstate->pending_cannouncement, i, list) {
|
||||
if (short_channel_id_eq(scid, &i->short_channel_id))
|
||||
return i;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct routing_channel *routing_channel_new(const tal_t *ctx,
|
||||
struct short_channel_id *scid)
|
||||
{
|
||||
@ -740,7 +723,9 @@ const struct short_channel_id *handle_channel_announcement(
|
||||
&pending->short_channel_id));
|
||||
|
||||
/* 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);
|
||||
if (chan == NULL)
|
||||
chan = routing_channel_new(rstate, &pending->short_channel_id);
|
||||
chan->pending = tal_steal(chan, pending);
|
||||
|
||||
/* The channel will be public if we complete the verification */
|
||||
chan->public = true;
|
||||
@ -751,7 +736,6 @@ const struct short_channel_id *handle_channel_announcement(
|
||||
add_pending_node_announcement(rstate, &pending->node_id_1);
|
||||
add_pending_node_announcement(rstate, &pending->node_id_2);
|
||||
|
||||
list_add_tail(&rstate->pending_cannouncement, &pending->list);
|
||||
return &pending->short_channel_id;
|
||||
}
|
||||
|
||||
@ -770,9 +754,9 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
|
||||
chan = uintmap_get(&rstate->channels, uscid);
|
||||
assert(chan);
|
||||
|
||||
pending = find_pending_cannouncement(rstate, scid);
|
||||
pending = chan->pending;
|
||||
assert(pending);
|
||||
list_del_from(&rstate->pending_cannouncement, &pending->list);
|
||||
chan->pending = NULL;
|
||||
|
||||
tag = tal_arr(pending, u8, 0);
|
||||
towire_short_channel_id(&tag, scid);
|
||||
@ -858,9 +842,10 @@ static bool update_to_pending(struct routing_state *rstate,
|
||||
u32 timestamp, const u8 *update,
|
||||
const u8 direction)
|
||||
{
|
||||
struct pending_cannouncement *pending;
|
||||
u64 uscid = short_channel_id_to_uint(scid);
|
||||
struct routing_channel *chan = uintmap_get(&rstate->channels, uscid);
|
||||
struct pending_cannouncement *pending = chan?chan->pending:NULL;
|
||||
|
||||
pending = find_pending_cannouncement(rstate, scid);
|
||||
if (!pending)
|
||||
return false;
|
||||
|
||||
|
@ -85,6 +85,7 @@ bool node_map_node_eq(const struct node *n, const secp256k1_pubkey *key);
|
||||
HTABLE_DEFINE_TYPE(struct node, node_map_keyof_node, node_map_hash_key, node_map_node_eq, node_map);
|
||||
|
||||
struct pending_node_map;
|
||||
struct pending_cannouncement;
|
||||
|
||||
enum txout_state {
|
||||
TXOUT_FETCHING,
|
||||
@ -104,6 +105,8 @@ struct routing_channel {
|
||||
|
||||
/* Is this a public channel, or was it only added locally? */
|
||||
bool public;
|
||||
|
||||
struct pending_cannouncement *pending;
|
||||
};
|
||||
|
||||
struct routing_state {
|
||||
|
Loading…
Reference in New Issue
Block a user