mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-03 21:24:22 +01:00
gossip: make channel_announce-set fields unset until channel announce.
Use a negative timestamp as the flag for this, making the test simple. This allows valgrind to detect that we're accessing them prematurely, including across the wire on gossip_getchannels_entry. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
9c35603275
commit
28553308e2
@@ -569,11 +569,13 @@ static struct io_plan *getchannels_req(struct io_conn *conn, struct daemon *daem
|
||||
entries[num_chans].source = n->out[j]->src->id;
|
||||
entries[num_chans].destination = n->out[j]->dst->id;
|
||||
entries[num_chans].active = n->out[j]->active;
|
||||
entries[num_chans].delay = n->out[j]->delay;
|
||||
entries[num_chans].fee_per_kw = n->out[j]->proportional_fee;
|
||||
entries[num_chans].last_update_timestamp = n->out[j]->last_timestamp;
|
||||
entries[num_chans].flags = n->out[j]->flags;
|
||||
entries[num_chans].short_channel_id = n->out[j]->short_channel_id;
|
||||
entries[num_chans].last_update_timestamp = n->out[j]->last_timestamp;
|
||||
if (entries[num_chans].last_update_timestamp >= 0) {
|
||||
entries[num_chans].fee_per_kw = n->out[j]->proportional_fee;
|
||||
entries[num_chans].delay = n->out[j]->delay;
|
||||
}
|
||||
num_chans++;
|
||||
}
|
||||
n = node_map_next(daemon->rstate->nodes, &i);
|
||||
|
||||
@@ -78,6 +78,7 @@ struct node *new_node(struct routing_state *rstate,
|
||||
n->out = tal_arr(n, struct node_connection *, 0);
|
||||
n->alias = NULL;
|
||||
n->node_announcement = NULL;
|
||||
n->last_timestamp = -1;
|
||||
n->addresses = tal_arr(n, struct ipaddr, 0);
|
||||
node_map_add(rstate->nodes, n);
|
||||
tal_add_destructor(n, destroy_node);
|
||||
@@ -230,10 +231,8 @@ struct node_connection *half_add_connection(struct routing_state *rstate,
|
||||
nc->short_channel_id = *schanid;
|
||||
nc->active = false;
|
||||
nc->flags = flags;
|
||||
nc->last_timestamp = -1;
|
||||
nc->min_blocks = 0;
|
||||
nc->proportional_fee = 0;
|
||||
nc->base_fee = 0;
|
||||
nc->delay = 0;
|
||||
return nc;
|
||||
}
|
||||
|
||||
@@ -763,7 +762,7 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update, size_
|
||||
&short_channel_id));
|
||||
tal_free(tmpctx);
|
||||
return;
|
||||
} else if (c->channel_update && c->last_timestamp >= timestamp) {
|
||||
} else if (c->last_timestamp >= timestamp) {
|
||||
status_trace("Ignoring outdated update.");
|
||||
tal_free(tmpctx);
|
||||
return;
|
||||
@@ -856,7 +855,7 @@ void handle_node_announcement(
|
||||
status_trace("Node not found, was the node_announcement preceeded by at least channel_announcement?");
|
||||
tal_free(tmpctx);
|
||||
return;
|
||||
} else if (node->node_announcement && node->last_timestamp >= timestamp) {
|
||||
} else if (node->last_timestamp >= timestamp) {
|
||||
status_trace("Ignoring node announcement, it's outdated.");
|
||||
tal_free(tmpctx);
|
||||
return;
|
||||
|
||||
@@ -24,7 +24,7 @@ struct node_connection {
|
||||
/* Is this connection active? */
|
||||
bool active;
|
||||
|
||||
u32 last_timestamp;
|
||||
s64 last_timestamp;
|
||||
|
||||
/* Minimum number of msatoshi in an HTLC */
|
||||
u32 htlc_minimum_msat;
|
||||
@@ -44,11 +44,12 @@ struct node_connection {
|
||||
struct node {
|
||||
struct pubkey id;
|
||||
|
||||
/* -1 means never; other fields undefined */
|
||||
s64 last_timestamp;
|
||||
|
||||
/* IP/Hostname and port of this node (may be NULL) */
|
||||
struct ipaddr *addresses;
|
||||
|
||||
u32 last_timestamp;
|
||||
|
||||
/* Routes connecting to us, from us. */
|
||||
struct node_connection **in, **out;
|
||||
|
||||
|
||||
@@ -301,16 +301,18 @@ static bool json_getchannels_reply(struct subd *gossip, const u8 *reply,
|
||||
json_add_pubkey(response, "source", &entries[i].source);
|
||||
json_add_pubkey(response, "destination",
|
||||
&entries[i].destination);
|
||||
json_add_bool(response, "active", entries[i].active);
|
||||
json_add_num(response, "fee_per_kw", entries[i].fee_per_kw);
|
||||
json_add_num(response, "last_update",
|
||||
entries[i].last_update_timestamp);
|
||||
json_add_num(response, "flags", entries[i].flags);
|
||||
json_add_num(response, "delay", entries[i].delay);
|
||||
json_add_string(response, "short_id",
|
||||
tal_fmt(reply, "%d:%d:%d/%d", scid->blocknum,
|
||||
scid->txnum, scid->outnum,
|
||||
entries[i].flags & 0x1));
|
||||
json_add_num(response, "flags", entries[i].flags);
|
||||
json_add_bool(response, "active", entries[i].active);
|
||||
if (entries[i].last_update_timestamp >= 0) {
|
||||
json_add_num(response, "last_update",
|
||||
entries[i].last_update_timestamp);
|
||||
json_add_num(response, "fee_per_kw", entries[i].fee_per_kw);
|
||||
json_add_num(response, "delay", entries[i].delay);
|
||||
}
|
||||
json_object_end(response);
|
||||
}
|
||||
json_array_end(response);
|
||||
|
||||
@@ -45,10 +45,12 @@ void fromwire_gossip_getchannels_entry(const u8 **pptr, size_t *max,
|
||||
fromwire_pubkey(pptr, max, &entry->source);
|
||||
fromwire_pubkey(pptr, max, &entry->destination);
|
||||
entry->active = fromwire_bool(pptr, max);
|
||||
entry->fee_per_kw = fromwire_u32(pptr, max);
|
||||
entry->delay = fromwire_u32(pptr, max);
|
||||
entry->last_update_timestamp = fromwire_u32(pptr, max);
|
||||
entry->flags = fromwire_u16(pptr, max);
|
||||
entry->last_update_timestamp = fromwire_u64(pptr, max);
|
||||
if (entry->last_update_timestamp >= 0) {
|
||||
entry->fee_per_kw = fromwire_u32(pptr, max);
|
||||
entry->delay = fromwire_u32(pptr, max);
|
||||
}
|
||||
}
|
||||
|
||||
void towire_gossip_getchannels_entry(
|
||||
@@ -58,8 +60,10 @@ void towire_gossip_getchannels_entry(
|
||||
towire_pubkey(pptr, &entry->source);
|
||||
towire_pubkey(pptr, &entry->destination);
|
||||
towire_bool(pptr, entry->active);
|
||||
towire_u32(pptr, entry->fee_per_kw);
|
||||
towire_u32(pptr, entry->delay);
|
||||
towire_u32(pptr, entry->last_update_timestamp);
|
||||
towire_u16(pptr, entry->flags);
|
||||
towire_u64(pptr, entry->last_update_timestamp);
|
||||
if (entry->last_update_timestamp >= 0) {
|
||||
towire_u32(pptr, entry->fee_per_kw);
|
||||
towire_u32(pptr, entry->delay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,13 @@ struct gossip_getnodes_entry {
|
||||
|
||||
struct gossip_getchannels_entry {
|
||||
struct pubkey source, destination;
|
||||
u32 fee_per_kw;
|
||||
bool active;
|
||||
struct short_channel_id short_channel_id;
|
||||
u32 last_update_timestamp;
|
||||
u32 delay;
|
||||
u16 flags;
|
||||
s64 last_update_timestamp; /* -1 means never */
|
||||
/* These are only set if last_update_timestamp >= 0 */
|
||||
u32 delay;
|
||||
u32 fee_per_kw;
|
||||
};
|
||||
|
||||
void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr,
|
||||
|
||||
Reference in New Issue
Block a user