mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
routing: remove redundant fields from struct node_connection.
The containing `struct routing_channel` contains src and dst, so remove them. However, the channel_update msgidx does belong int `struct node_connection` along with the channel_update. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
172af04247
commit
61bcb054e0
2 changed files with 16 additions and 34 deletions
|
@ -74,16 +74,6 @@ HTABLE_DEFINE_TYPE(struct pending_node_announce, pending_node_announce_keyof,
|
||||||
node_map_hash_key, pending_node_announce_eq,
|
node_map_hash_key, pending_node_announce_eq,
|
||||||
pending_node_map);
|
pending_node_map);
|
||||||
|
|
||||||
/**
|
|
||||||
* routing_channel keeps track of the indices in the broadcast queue
|
|
||||||
* for the corresponding messages. This way we always know exactly
|
|
||||||
* which broadcast to replace, and don't have to search for it */
|
|
||||||
enum gossip_msg_indexes {
|
|
||||||
MSG_INDEX_CUPDATE_0,
|
|
||||||
MSG_INDEX_CUPDATE_1,
|
|
||||||
MSG_INDEX_CANNOUNCE
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct node_map *empty_node_map(const tal_t *ctx)
|
static struct node_map *empty_node_map(const tal_t *ctx)
|
||||||
{
|
{
|
||||||
struct node_map *map = tal(ctx, struct node_map);
|
struct node_map *map = tal(ctx, struct node_map);
|
||||||
|
@ -198,20 +188,12 @@ static void destroy_routing_channel(struct routing_channel *chan,
|
||||||
|
|
||||||
static void init_node_connection(struct routing_state *rstate,
|
static void init_node_connection(struct routing_state *rstate,
|
||||||
struct routing_channel *chan,
|
struct routing_channel *chan,
|
||||||
struct node *from,
|
|
||||||
struct node *to,
|
|
||||||
int idx)
|
int idx)
|
||||||
{
|
{
|
||||||
struct node_connection *c = &chan->connections[idx];
|
struct node_connection *c = &chan->connections[idx];
|
||||||
|
|
||||||
/* We are going to put this in the right way? */
|
|
||||||
assert(idx == pubkey_idx(&from->id, &to->id));
|
|
||||||
assert(from == chan->nodes[idx]);
|
|
||||||
assert(to == chan->nodes[!idx]);
|
|
||||||
|
|
||||||
c->src = from;
|
|
||||||
c->dst = to;
|
|
||||||
c->channel_update = NULL;
|
c->channel_update = NULL;
|
||||||
|
c->channel_update_msgidx = 0;
|
||||||
c->unroutable_until = 0;
|
c->unroutable_until = 0;
|
||||||
c->active = false;
|
c->active = false;
|
||||||
c->flags = idx;
|
c->flags = idx;
|
||||||
|
@ -243,8 +225,8 @@ struct routing_channel *new_routing_channel(struct routing_state *rstate,
|
||||||
chan->nodes[!n1idx] = n2;
|
chan->nodes[!n1idx] = n2;
|
||||||
chan->txout_script = NULL;
|
chan->txout_script = NULL;
|
||||||
chan->channel_announcement = NULL;
|
chan->channel_announcement = NULL;
|
||||||
|
chan->channel_announce_msgidx = 0;
|
||||||
chan->public = false;
|
chan->public = false;
|
||||||
memset(&chan->msg_indexes, 0, sizeof(chan->msg_indexes));
|
|
||||||
|
|
||||||
n = tal_count(n2->channels);
|
n = tal_count(n2->channels);
|
||||||
tal_resize(&n2->channels, n+1);
|
tal_resize(&n2->channels, n+1);
|
||||||
|
@ -254,8 +236,8 @@ struct routing_channel *new_routing_channel(struct routing_state *rstate,
|
||||||
n1->channels[n] = chan;
|
n1->channels[n] = chan;
|
||||||
|
|
||||||
/* Populate with (inactive) connections */
|
/* Populate with (inactive) connections */
|
||||||
init_node_connection(rstate, chan, n1, n2, n1idx);
|
init_node_connection(rstate, chan, n1idx);
|
||||||
init_node_connection(rstate, chan, n2, n1, !n1idx);
|
init_node_connection(rstate, chan, !n1idx);
|
||||||
|
|
||||||
uintmap_add(&rstate->channels, scid->u64, chan);
|
uintmap_add(&rstate->channels, scid->u64, chan);
|
||||||
|
|
||||||
|
@ -733,7 +715,7 @@ bool handle_pending_cannouncement(struct routing_state *rstate,
|
||||||
chan->channel_announcement = tal_steal(chan, pending->announce);
|
chan->channel_announcement = tal_steal(chan, pending->announce);
|
||||||
|
|
||||||
if (replace_broadcast(rstate->broadcasts,
|
if (replace_broadcast(rstate->broadcasts,
|
||||||
&chan->msg_indexes[MSG_INDEX_CANNOUNCE],
|
&chan->channel_announce_msgidx,
|
||||||
WIRE_CHANNEL_ANNOUNCEMENT,
|
WIRE_CHANNEL_ANNOUNCEMENT,
|
||||||
tag, pending->announce))
|
tag, pending->announce))
|
||||||
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
status_failed(STATUS_FAIL_INTERNAL_ERROR,
|
||||||
|
@ -884,7 +866,8 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!check_channel_update(&c->src->id, &signature, serialized)) {
|
if (!check_channel_update(&chan->nodes[direction]->id,
|
||||||
|
&signature, serialized)) {
|
||||||
status_trace("Signature verification failed.");
|
status_trace("Signature verification failed.");
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
return;
|
return;
|
||||||
|
@ -908,7 +891,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update)
|
||||||
towire_short_channel_id(&tag, &short_channel_id);
|
towire_short_channel_id(&tag, &short_channel_id);
|
||||||
towire_u16(&tag, direction);
|
towire_u16(&tag, direction);
|
||||||
replace_broadcast(rstate->broadcasts,
|
replace_broadcast(rstate->broadcasts,
|
||||||
&chan->msg_indexes[MSG_INDEX_CUPDATE_0 | direction],
|
&chan->connections[direction].channel_update_msgidx,
|
||||||
WIRE_CHANNEL_UPDATE,
|
WIRE_CHANNEL_UPDATE,
|
||||||
tag,
|
tag,
|
||||||
serialized);
|
serialized);
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
#define ROUTING_FLAGS_DISABLED 2
|
#define ROUTING_FLAGS_DISABLED 2
|
||||||
|
|
||||||
struct node_connection {
|
struct node_connection {
|
||||||
/* FIXME: Remove */
|
|
||||||
struct node *src, *dst;
|
|
||||||
/* millisatoshi. */
|
/* millisatoshi. */
|
||||||
u32 base_fee;
|
u32 base_fee;
|
||||||
/* millionths */
|
/* millionths */
|
||||||
|
@ -37,6 +35,7 @@ struct node_connection {
|
||||||
|
|
||||||
/* Cached `channel_update` we might forward to new peers*/
|
/* Cached `channel_update` we might forward to new peers*/
|
||||||
u8 *channel_update;
|
u8 *channel_update;
|
||||||
|
u64 channel_update_msgidx;
|
||||||
|
|
||||||
/* If greater than current time, this connection should not
|
/* If greater than current time, this connection should not
|
||||||
* be used for routing. */
|
* be used for routing. */
|
||||||
|
@ -101,8 +100,7 @@ struct routing_channel {
|
||||||
/* Cached `channel_announcement` we might forward to new peers*/
|
/* Cached `channel_announcement` we might forward to new peers*/
|
||||||
const u8 *channel_announcement;
|
const u8 *channel_announcement;
|
||||||
|
|
||||||
/* FIXME: Move msg_index[MSG_INDEX_CUPDATE*] into connections[] */
|
u64 channel_announce_msgidx;
|
||||||
u64 msg_indexes[3];
|
|
||||||
|
|
||||||
/* Is this a public channel, or was it only added locally? */
|
/* Is this a public channel, or was it only added locally? */
|
||||||
bool public;
|
bool public;
|
||||||
|
@ -114,32 +112,33 @@ static inline int pubkey_idx(const struct pubkey *id1, const struct pubkey *id2)
|
||||||
return pubkey_cmp(id1, id2) > 0;
|
return pubkey_cmp(id1, id2) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fast versions: if you know n is one end of the channel */
|
||||||
static inline struct node *other_node(const struct node *n,
|
static inline struct node *other_node(const struct node *n,
|
||||||
struct routing_channel *chan)
|
struct routing_channel *chan)
|
||||||
{
|
{
|
||||||
int idx = (chan->nodes[1] == n);
|
int idx = (chan->nodes[1] == n);
|
||||||
|
|
||||||
|
assert(chan->nodes[0] == n || chan->nodes[1] == n);
|
||||||
return chan->nodes[!idx];
|
return chan->nodes[!idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: We could avoid these by having two channels arrays */
|
/* If you know n is one end of the channel, get connection src == n */
|
||||||
static inline struct node_connection *connection_from(const struct node *n,
|
static inline struct node_connection *connection_from(const struct node *n,
|
||||||
struct routing_channel *chan)
|
struct routing_channel *chan)
|
||||||
{
|
{
|
||||||
int idx = (chan->nodes[1] == n);
|
int idx = (chan->nodes[1] == n);
|
||||||
|
|
||||||
assert(chan->connections[idx].src == n);
|
assert(chan->nodes[0] == n || chan->nodes[1] == n);
|
||||||
assert(chan->connections[!idx].dst == n);
|
|
||||||
return &chan->connections[idx];
|
return &chan->connections[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If you know n is one end of the channel, get index dst == n */
|
||||||
static inline int connection_to(const struct node *n,
|
static inline int connection_to(const struct node *n,
|
||||||
struct routing_channel *chan)
|
struct routing_channel *chan)
|
||||||
{
|
{
|
||||||
int idx = (chan->nodes[1] == n);
|
int idx = (chan->nodes[1] == n);
|
||||||
|
|
||||||
assert(chan->connections[idx].src == n);
|
assert(chan->nodes[0] == n || chan->nodes[1] == n);
|
||||||
assert(chan->connections[!idx].dst == n);
|
|
||||||
return !idx;
|
return !idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue