Browse Source

Revert "gossipd: handle premature node_announcements in the store."

This reverts commit e2f426903d.

With the new store version, this can't happen.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
json-streaming
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
8455b12781
  1. 31
      gossipd/gossip_store.c
  2. 16
      gossipd/routing.c
  3. 6
      gossipd/routing.h
  4. 10
      tests/test_gossip.py

31
gossipd/gossip_store.c

@ -251,12 +251,9 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
/* We set/check version byte on creation */
off_t known_good = 1;
const char *bad;
size_t stats[] = {0, 0, 0, 0, 0};
size_t stats[] = {0, 0, 0, 0};
int fd = gs->fd;
gs->fd = -1;
bool unknown_node;
size_t num_delayed_na = 0;
u8 **delayed_na = tal_arr(tmpctx, u8 *, num_delayed_na);
if (lseek(fd, known_good, SEEK_SET) < 0) {
status_unusual("gossip_store: lseek failure");
@ -297,18 +294,11 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
stats[1]++;
} else if (fromwire_gossip_store_node_announcement(msg, msg,
&gossip_msg)) {
if (!routing_add_node_announcement(rstate, gossip_msg,
&unknown_node)) {
if (!unknown_node) {
bad = "Bad node_announcement";
goto truncate;
}
/* Defer until later. */
tal_resize(&delayed_na, num_delayed_na+1);
delayed_na[num_delayed_na++]
= tal_steal(delayed_na, gossip_msg);
} else
stats[2]++;
if (!routing_add_node_announcement(rstate, gossip_msg)) {
bad = "Bad node_announcement";
goto truncate;
}
stats[2]++;
} else if (fromwire_gossip_store_channel_delete(msg, &scid)) {
struct chan *c = get_channel(rstate, &scid);
if (!c) {
@ -328,15 +318,6 @@ void gossip_store_load(struct routing_state *rstate, struct gossip_store *gs)
gs->count++;
tal_free(msg);
}
for (size_t i = 0; i < tal_count(delayed_na); i++) {
if (routing_add_node_announcement(rstate, delayed_na[i], NULL)) {
stats[2]++;
stats[4]++;
}
}
status_trace("Successfully processed %zu/%zu unknown node_announcement",
stats[4], tal_count(delayed_na));
goto out;
truncate:

16
gossipd/routing.c

@ -1285,9 +1285,7 @@ static struct wireaddr *read_addresses(const tal_t *ctx, const u8 *ser)
return wireaddrs;
}
bool routing_add_node_announcement(struct routing_state *rstate,
const u8 *msg TAKES,
bool *unknown_node)
bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg TAKES)
{
struct node *node;
secp256k1_ecdsa_signature signature;
@ -1301,21 +1299,15 @@ bool routing_add_node_announcement(struct routing_state *rstate,
if (!fromwire_node_announcement(tmpctx, msg,
&signature, &features, &timestamp,
&node_id, rgb_color, alias,
&addresses)) {
if (unknown_node)
*unknown_node = false;
&addresses))
return false;
}
node = get_node(rstate, &node_id);
/* May happen if we accepted the node_announcement due to a local
* channel, for which we didn't have the announcement yet. */
if (node == NULL) {
if (unknown_node)
*unknown_node = true;
if (node == NULL)
return false;
}
wireaddrs = read_addresses(tmpctx, addresses);
tal_free(node->addresses);
@ -1468,7 +1460,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
status_trace("Received node_announcement for node %s",
type_to_string(tmpctx, struct pubkey, &node_id));
applied = routing_add_node_announcement(rstate, serialized, NULL);
applied = routing_add_node_announcement(rstate, serialized);
assert(applied);
return NULL;
}

6
gossipd/routing.h

@ -312,13 +312,9 @@ bool routing_add_channel_update(struct routing_state *rstate,
* Directly add the node being announced to the network view, without verifying
* it. This must be from a trusted source, e.g., gossip_store. For untrusted
* sources (peers) please use @see{handle_node_announcement}.
*
* Populates *unknown_node if it isn't NULL and this returns false to indicate
* if failure was due to an unknown node_id.
*/
bool routing_add_node_announcement(struct routing_state *rstate,
const u8 *msg TAKES,
bool *unknown_node);
const u8 *msg TAKES);
/**

10
tests/test_gossip.py

@ -823,10 +823,6 @@ def test_gossip_store_load(node_factory):
l1 = node_factory.get_node(start=False)
with open(os.path.join(l1.daemon.lightning_dir, 'gossip_store'), 'wb') as f:
f.write(bytearray.fromhex("03" # GOSSIP_VERSION
"00000099" # len
"12abbbba" # csum
"1002" # WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT
"00950101cf5d870bc7ecabcb7cd16898ef66891e5f0c6c5851bd85b670f03d325bc44d7544d367cd852e18ec03f7f4ff369b06860a3b12b07b29f36fb318ca11348bf8ec00005aab817c03f113414ebdc6c1fb0f33c99cd5a1d09dd79e7fdf2468cf1fe1af6674361695d23974b250757a7a6c6549544300000000000000000000000000000000000000000000000007010566933e2607"
"000001bc" # len
"521ef598" # csum
"1000" # WIRE_GOSSIP_STORE_CHANNEL_ANNOUNCEMENT
@ -834,7 +830,11 @@ def test_gossip_store_load(node_factory):
"00000086" # len
"88c703c8" # csum
"1001" # WIRE_GOSSIP_STORE_CHANNEL_UPDATE
"008201021ea7c2eadf8a29eb8690511a519b5656e29aa0a853771c4e38e65c5abf43d907295a915e69e451f4c7a0c3dc13dd943cfbe3ae88c0b96667cd7d58955dbfedcf43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea33090000000013a63c0000b500015b8d9b440000009000000000000003e8000003e800000001"))
"008201021ea7c2eadf8a29eb8690511a519b5656e29aa0a853771c4e38e65c5abf43d907295a915e69e451f4c7a0c3dc13dd943cfbe3ae88c0b96667cd7d58955dbfedcf43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea33090000000013a63c0000b500015b8d9b440000009000000000000003e8000003e800000001"
"00000099" # len
"12abbbba" # csum
"1002" # WIRE_GOSSIP_STORE_NODE_ANNOUNCEMENT
"00950101cf5d870bc7ecabcb7cd16898ef66891e5f0c6c5851bd85b670f03d325bc44d7544d367cd852e18ec03f7f4ff369b06860a3b12b07b29f36fb318ca11348bf8ec00005aab817c03f113414ebdc6c1fb0f33c99cd5a1d09dd79e7fdf2468cf1fe1af6674361695d23974b250757a7a6c6549544300000000000000000000000000000000000000000000000007010566933e2607"))
l1.start()
# May preceed the Started msg waited for in 'start'.

Loading…
Cancel
Save