mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
gossipd: keep a flag to indicate that we have features in channel_announcement.
This saves us keeping it in memory (so far, no channels have features), but lets us optimize that case so we don't need to hit the disk for most of the channels in listchannels. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
855debcfe1
commit
7cac5be5cb
@ -93,6 +93,8 @@ HTABLE_DEFINE_TYPE(struct pending_node_announce, pending_node_announce_keyof,
|
||||
struct unupdated_channel {
|
||||
/* The channel_announcement message */
|
||||
const u8 *channel_announce;
|
||||
/* The feature bitmap within it */
|
||||
const u8 *features;
|
||||
/* The short_channel_id */
|
||||
struct short_channel_id scid;
|
||||
/* The ids of the nodes */
|
||||
@ -571,7 +573,8 @@ struct chan *new_chan(struct routing_state *rstate,
|
||||
const struct short_channel_id *scid,
|
||||
const struct node_id *id1,
|
||||
const struct node_id *id2,
|
||||
struct amount_sat satoshis)
|
||||
struct amount_sat satoshis,
|
||||
const u8 *features)
|
||||
{
|
||||
struct chan *chan = tal(rstate, struct chan);
|
||||
int n1idx = node_id_idx(id1, id2);
|
||||
@ -606,6 +609,8 @@ struct chan *new_chan(struct routing_state *rstate,
|
||||
init_half_chan(rstate, chan, n1idx);
|
||||
init_half_chan(rstate, chan, !n1idx);
|
||||
|
||||
/* Stash hint here about whether we have features */
|
||||
chan->half[0].any_features = tal_bytelen(features) != 0;
|
||||
uintmap_add(&rstate->chanmap, scid->u64, chan);
|
||||
|
||||
/* Initialize shadow structure if it's local */
|
||||
@ -1651,6 +1656,7 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
|
||||
|
||||
uc = tal(rstate, struct unupdated_channel);
|
||||
uc->channel_announce = tal_dup_talarr(uc, u8, msg);
|
||||
uc->features = tal_steal(uc, features);
|
||||
uc->added = gossip_time_now(rstate);
|
||||
uc->index = index;
|
||||
uc->sat = sat;
|
||||
@ -2098,7 +2104,7 @@ bool routing_add_channel_update(struct routing_state *rstate,
|
||||
if (uc) {
|
||||
assert(!chan);
|
||||
chan = new_chan(rstate, &short_channel_id,
|
||||
&uc->id[0], &uc->id[1], sat);
|
||||
&uc->id[0], &uc->id[1], sat, uc->features);
|
||||
}
|
||||
|
||||
/* Discard older updates */
|
||||
@ -2926,7 +2932,8 @@ bool handle_local_add_channel(struct routing_state *rstate,
|
||||
type_to_string(tmpctx, struct short_channel_id, &scid));
|
||||
|
||||
/* Create new (unannounced) channel */
|
||||
chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id, sat);
|
||||
chan = new_chan(rstate, &scid, &rstate->local_id, &remote_node_id, sat,
|
||||
features);
|
||||
if (!index)
|
||||
index = gossip_store_add(rstate->gs, msg, 0, false, NULL);
|
||||
chan->bcast.index = index;
|
||||
|
@ -41,6 +41,10 @@ struct half_chan {
|
||||
/* Token bucket */
|
||||
u8 tokens;
|
||||
|
||||
/* Feature cache for parent chan: squeezed in here where it would
|
||||
* otherwise simply be padding. */
|
||||
u8 any_features;
|
||||
|
||||
/* Minimum and maximum number of msatoshi in an HTLC */
|
||||
struct amount_msat htlc_minimum, htlc_maximum;
|
||||
};
|
||||
@ -361,7 +365,8 @@ struct chan *new_chan(struct routing_state *rstate,
|
||||
const struct short_channel_id *scid,
|
||||
const struct node_id *id1,
|
||||
const struct node_id *id2,
|
||||
struct amount_sat sat);
|
||||
struct amount_sat sat,
|
||||
const u8 *features);
|
||||
|
||||
/* Handlers for incoming messages */
|
||||
|
||||
|
@ -149,7 +149,7 @@ static void add_connection(struct routing_state *rstate,
|
||||
chan = get_channel(rstate, &scid);
|
||||
if (!chan) {
|
||||
chan = new_chan(rstate, &scid, &nodes[from], &nodes[to],
|
||||
AMOUNT_SAT(1000000));
|
||||
AMOUNT_SAT(1000000), NULL);
|
||||
}
|
||||
|
||||
c = &chan->half[idx];
|
||||
|
@ -134,7 +134,7 @@ get_or_make_connection(struct routing_state *rstate,
|
||||
abort();
|
||||
chan = get_channel(rstate, &scid);
|
||||
if (!chan)
|
||||
chan = new_chan(rstate, &scid, from_id, to_id, satoshis);
|
||||
chan = new_chan(rstate, &scid, from_id, to_id, satoshis, NULL);
|
||||
|
||||
/* Make sure it's seen as initialized (index non-zero). */
|
||||
chan->half[idx].bcast.index = 1;
|
||||
|
@ -142,7 +142,7 @@ static void add_connection(struct routing_state *rstate,
|
||||
|
||||
chan = get_channel(rstate, &scid);
|
||||
if (!chan)
|
||||
chan = new_chan(rstate, &scid, from, to, satoshis);
|
||||
chan = new_chan(rstate, &scid, from, to, satoshis, NULL);
|
||||
|
||||
c = &chan->half[node_id_idx(from, to)];
|
||||
/* Make sure it's seen as initialized (index non-zero). */
|
||||
|
@ -163,7 +163,7 @@ int main(void)
|
||||
if (!mk_short_channel_id(&scid, i, i-1, 0))
|
||||
abort();
|
||||
chan = new_chan(rstate, &scid, &ids[i], &ids[i-1],
|
||||
AMOUNT_SAT(1000000));
|
||||
AMOUNT_SAT(1000000), NULL);
|
||||
|
||||
hc = &chan->half[node_id_idx(&ids[i-1], &ids[i])];
|
||||
hc->bcast.index = 1;
|
||||
@ -183,7 +183,7 @@ int main(void)
|
||||
if (!mk_short_channel_id(&scid, i, 1, 0))
|
||||
abort();
|
||||
chan = new_chan(rstate, &scid, &ids[i], &ids[1],
|
||||
AMOUNT_SAT(1000000));
|
||||
AMOUNT_SAT(1000000), NULL);
|
||||
hc = &chan->half[node_id_idx(&ids[1], &ids[i])];
|
||||
hc->bcast.index = 1;
|
||||
hc->base_fee = 1 << i;
|
||||
|
Loading…
Reference in New Issue
Block a user