mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
gossipd: use u32 for timestamp.
We used an s64 so we could use -1 and save a check, but that's just silly as we have adjacent non-u64 fields: wastes 7 bytes per node and 16 per channel. Interestingly, this seemed to make us a little slower for some reason. MCP results from 5 runs, min-max(mean +/- stddev): store_load_msec:35569-38776(37169.8+/-1.2e+03) vsz_kb:2621808 store_rewrite_sec:35.870000-40.290000(38.14+/-1.6) listnodes_sec:0.740000-0.800000(0.768+/-0.023) listchannels_sec:29.820000-32.730000(30.972+/-0.99) routing_sec:30.110000-30.590000(30.346+/-0.18) peer_write_all_sec:52.420000-59.160000(54.692+/-2.5) MCP notable changes from previous patch (>1 stddev): -store_load_msec:32825-36365(34615.6+/-1.1e+03) +store_load_msec:35569-38776(37169.8+/-1.2e+03) -vsz_kb:2637488 +vsz_kb:2621808 -store_rewrite_sec:35.150000-36.200000(35.59+/-0.4) +store_rewrite_sec:35.870000-40.290000(38.14+/-1.6) -listnodes_sec:0.590000-0.710000(0.682+/-0.046) +listnodes_sec:0.740000-0.800000(0.768+/-0.023) -peer_write_all_sec:49.020000-52.890000(50.376+/-1.5) +peer_write_all_sec:52.420000-59.160000(54.692+/-2.5) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
70623076b8
commit
617c23e735
3 changed files with 13 additions and 19 deletions
|
@ -388,7 +388,6 @@ static void send_node_announcement(struct daemon *daemon)
|
||||||
u32 timestamp = time_now().ts.tv_sec;
|
u32 timestamp = time_now().ts.tv_sec;
|
||||||
secp256k1_ecdsa_signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
u8 *msg, *nannounce, *err;
|
u8 *msg, *nannounce, *err;
|
||||||
s64 last_timestamp;
|
|
||||||
struct node *self = get_node(daemon->rstate, &daemon->id);
|
struct node *self = get_node(daemon->rstate, &daemon->id);
|
||||||
|
|
||||||
/* BOLT #7:
|
/* BOLT #7:
|
||||||
|
@ -397,14 +396,8 @@ static void send_node_announcement(struct daemon *daemon)
|
||||||
* - MUST set `timestamp` to be greater than that of any previous
|
* - MUST set `timestamp` to be greater than that of any previous
|
||||||
* `node_announcement` it has previously created.
|
* `node_announcement` it has previously created.
|
||||||
*/
|
*/
|
||||||
if (self)
|
if (self && self->node_announcement && timestamp <= self->last_timestamp)
|
||||||
last_timestamp = self->last_timestamp;
|
timestamp = self->last_timestamp + 1;
|
||||||
else
|
|
||||||
/* last_timestamp is carefully a s64, so this works */
|
|
||||||
last_timestamp = -1;
|
|
||||||
|
|
||||||
if (timestamp <= last_timestamp)
|
|
||||||
timestamp = last_timestamp + 1;
|
|
||||||
|
|
||||||
/* Get an unsigned one. */
|
/* Get an unsigned one. */
|
||||||
nannounce = create_node_announcement(tmpctx, daemon, NULL, timestamp);
|
nannounce = create_node_announcement(tmpctx, daemon, NULL, timestamp);
|
||||||
|
@ -438,7 +431,7 @@ static bool node_announcement_redundant(struct daemon *daemon)
|
||||||
if (!n)
|
if (!n)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (n->last_timestamp == -1)
|
if (!n->node_announcement)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (tal_count(n->addresses) != tal_count(daemon->announcable))
|
if (tal_count(n->addresses) != tal_count(daemon->announcable))
|
||||||
|
@ -2062,10 +2055,12 @@ static void append_node(const struct gossip_getnodes_entry ***entries,
|
||||||
|
|
||||||
e = tal(*entries, struct gossip_getnodes_entry);
|
e = tal(*entries, struct gossip_getnodes_entry);
|
||||||
e->nodeid = n->id;
|
e->nodeid = n->id;
|
||||||
e->last_timestamp = n->last_timestamp;
|
|
||||||
/* Timestamp on wire is an unsigned 32 bit: we use a 64-bit signed, so
|
/* Timestamp on wire is an unsigned 32 bit: we use a 64-bit signed, so
|
||||||
* -1 means "we never received a channel_update". */
|
* -1 means "we never received a channel_update". */
|
||||||
if (e->last_timestamp >= 0) {
|
if (!n->node_announcement)
|
||||||
|
e->last_timestamp = -1;
|
||||||
|
else {
|
||||||
|
e->last_timestamp = n->last_timestamp;
|
||||||
e->globalfeatures = n->globalfeatures;
|
e->globalfeatures = n->globalfeatures;
|
||||||
e->addresses = n->addresses;
|
e->addresses = n->addresses;
|
||||||
BUILD_ASSERT(ARRAY_SIZE(e->alias) == ARRAY_SIZE(n->alias));
|
BUILD_ASSERT(ARRAY_SIZE(e->alias) == ARRAY_SIZE(n->alias));
|
||||||
|
|
|
@ -231,7 +231,6 @@ static struct node *new_node(struct routing_state *rstate,
|
||||||
n->globalfeatures = NULL;
|
n->globalfeatures = NULL;
|
||||||
n->node_announcement = NULL;
|
n->node_announcement = NULL;
|
||||||
n->node_announcement_index = 0;
|
n->node_announcement_index = 0;
|
||||||
n->last_timestamp = -1;
|
|
||||||
n->addresses = tal_arr(n, struct wireaddr, 0);
|
n->addresses = tal_arr(n, struct wireaddr, 0);
|
||||||
node_map_add(rstate->nodes, n);
|
node_map_add(rstate->nodes, n);
|
||||||
tal_add_destructor2(n, destroy_node, rstate);
|
tal_add_destructor2(n, destroy_node, rstate);
|
||||||
|
@ -1193,7 +1192,7 @@ static void set_connection_values(struct chan *chan,
|
||||||
u32 delay,
|
u32 delay,
|
||||||
u8 message_flags,
|
u8 message_flags,
|
||||||
u8 channel_flags,
|
u8 channel_flags,
|
||||||
u64 timestamp,
|
u32 timestamp,
|
||||||
struct amount_msat htlc_minimum,
|
struct amount_msat htlc_minimum,
|
||||||
struct amount_msat htlc_maximum)
|
struct amount_msat htlc_maximum)
|
||||||
{
|
{
|
||||||
|
@ -1658,7 +1657,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->last_timestamp >= timestamp) {
|
if (node->node_announcement && node->last_timestamp >= timestamp) {
|
||||||
SUPERVERBOSE("Ignoring node announcement, it's outdated.");
|
SUPERVERBOSE("Ignoring node announcement, it's outdated.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1853,6 +1852,8 @@ void route_prune(struct routing_state *rstate)
|
||||||
if (!is_chan_public(chan))
|
if (!is_chan_public(chan))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* Rare case where we examine timestamp even without update;
|
||||||
|
* it's used to prune channels where update never arrives */
|
||||||
if (chan->half[0].last_timestamp < highwater
|
if (chan->half[0].last_timestamp < highwater
|
||||||
&& chan->half[1].last_timestamp < highwater) {
|
&& chan->half[1].last_timestamp < highwater) {
|
||||||
status_trace(
|
status_trace(
|
||||||
|
|
|
@ -25,8 +25,7 @@ struct half_chan {
|
||||||
/* Delay for HTLC in blocks.*/
|
/* Delay for HTLC in blocks.*/
|
||||||
u32 delay;
|
u32 delay;
|
||||||
|
|
||||||
/* -1 if channel_update is NULL */
|
u32 last_timestamp;
|
||||||
s64 last_timestamp;
|
|
||||||
|
|
||||||
/* Minimum and maximum number of msatoshi in an HTLC */
|
/* Minimum and maximum number of msatoshi in an HTLC */
|
||||||
struct amount_msat htlc_minimum, htlc_maximum;
|
struct amount_msat htlc_minimum, htlc_maximum;
|
||||||
|
@ -114,8 +113,7 @@ HTABLE_DEFINE_TYPE(struct chan, chan_map_scid, hash_scid, chan_eq_scid, chan_map
|
||||||
struct node {
|
struct node {
|
||||||
struct node_id id;
|
struct node_id id;
|
||||||
|
|
||||||
/* -1 means never; other fields undefined */
|
u32 last_timestamp;
|
||||||
s64 last_timestamp;
|
|
||||||
|
|
||||||
/* IP/Hostname and port of this node (may be NULL) */
|
/* IP/Hostname and port of this node (may be NULL) */
|
||||||
struct wireaddr *addresses;
|
struct wireaddr *addresses;
|
||||||
|
|
Loading…
Add table
Reference in a new issue