Commit Graph

200 Commits

Author SHA1 Message Date
Rusty Russell 39c781aebb gossipd: allow calling of peer_error on peers which aren't local.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-13 16:34:55 +01:00
Rusty Russell 81e55065d9 gossipd: don't die if we get a bad msg from another daemon.
We don't trust them, by design (except master and hsmd).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-13 16:34:55 +01:00
Christian Decker 74a444eb7a jsonrpc: Return the channel capacity for listchannels
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-12 22:34:51 +00:00
Christian Decker 2abf72e7df gossip: Store channel capacity in the routing table
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-12 22:34:51 +00:00
Christian Decker a8e553098a gossip: Pass output value to gossipd
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-12 22:34:51 +00:00
John Barboza 30b290cb8f Explicit error message when disconnect fails
Whether the peer is not connected or not gossiping.
2018-03-07 16:14:01 +01:00
John Barboza 0a1351fd51 gossipd: command to disconnect from a gossiping peer
lightning-cli disconnect <peer id>
2018-03-07 16:14:01 +01:00
Rusty Russell dace9bfdcf gossipd: the great renaming.
We already have 'struct node', so rename 'struct routing_channel' to
'struct chan', and 'struct node_connection' to 'struct half_chan'.

Other minor changes:
1. rstate->channels -> rstate->chanmap.
2. 'connections' -> 'half'.
3. connection_to -> half_chan_to
4. connection_from -> half_chan_from

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-04 23:25:53 +01:00
Rusty Russell 61bcb054e0 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>
2018-03-04 23:25:53 +01:00
Rusty Russell 172af04247 gossip: remove short_channel_id from struct node_connection.
It's in the containing routing_channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-04 23:25:53 +01:00
Rusty Russell 21b2f37dfb routing: return entire routing_channel array from find_route.
Returning the separate first routing_channel was a weird API: just
return the entire array.  Sure, we have to treat the first node a bit
differently (because we don't charge ourselves fees), but it's still
simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-04 23:25:53 +01:00
Rusty Russell 56349ab008 routing: work with struct routing_channel not struct node_connection.
To remove the redundant fields in `struct node_connection` (ie. 'src'
and 'dst' pointers) we need to deal with `struct routing_channel`.
This means we get a series of channels, from which the direction is
implied, so it's a bit more complex to decode.  We add a helper
`other_node` to help with this, and since we're the only user of
`connection_to` we change that function to return the index.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-04 23:25:53 +01:00
Rusty Russell fd9c0c8543 routing: move struct node_connection into struct routing_channel.
No need to have pointers since they're always there.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell be14b52423 routing: connections are now never null; simplify.
Failure and pruning were the two places where a node_connection could
be freed; now they both deal with entire channels, we can remove the
NULL checks, and the destructor.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell d7b5882f61 routing: don't free a single nc on prune, only entire channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell d0f68ffb15 routing: free entire channel, not just node_connection on PERM error.
And do it by reparenting onto the tmpctx, restoring some simpliciy.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 00194b6130 handle_disable_channel: don't use get_connection_by_scid.
This removes the final user, so we remove it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 74ee448bda routing: expose setter for struct node_connection fields.
And use it in gossip's handle_local_add_channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 1e4959af1f gossipd: fix case where we get an update on a pruned channel.
We discarded it; we should populate it.  The comment is wrong, since
local_add_channel() doesn't add public channels, and we test that above.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 961321a6d8 gossipd: move route pruning to routing.c.
And reimplement it to walk the channels map rather than the nodes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 33726b0a08 gossip: instead of refresh interval, have routing know prune_timeout.
This is twice the 'update_channel_interval' we get handed.

We delete the non-existent channel_add_connection and delete_connection
declarations from the header too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell b7bf414ac4 gossipd: prune announced-but-not-updated channels eventually.
We currently give them a free pass.  The simplest fix is to give them
an old timestamp on initialization.

We still skip unannounced channels, on the assumption that they're
ours.  And we set the last_update_timestamp to -1 when we convert to
gossip_getchannels_entry to indicate no update.

This breaks the DEVELOPER=1 pruning test, since we hardcode the 1
week timeout.  That's fixed in the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell b7ec2c8c9c node_connection: move channel_announcement field into struct routing_channel.
We don't actually *use it*, mind you: the copy in the broadcast message
is the one we use.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 942d04ba87 gossipd: simplify channel_announce handling.
We make new_routing_channel() populate both connections
(active=false), so local_add_channel becomes simpler.  We also
suppress listchannels output of active=false unannounced channels, to
avoid breaking tests (also, these are unusable, so it makes sense to
omit them)

It also seems the logic in add_channel_direction is legacy: a
channel_announce cannot replace the scid (that would be a different
channel), we don't allow duplicate announcements, and the announcement
is never NULL.

And since we disallow repeated channel_announce already, I believe
'forward' is always true, greatly simplifying the logic in
handle_pending_cannouncement.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 6dec2ed1c1 gossipd: hoist new_node_connection above new_routing_channel.
This is moveonly, wanted for next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell fc410eff60 resolve_channel_req: use get_channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell a79879637a gossipd: local_add_channel can just use get_channel()
Also upgrade the status messages in the weird cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 6bc634badf gossip: handle_get_update can just use get_channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell a9b1d73148 getchannels_req: iterate over channel map rather than nodes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 5f5d0b3e25 gossip_local_add_channel: remove unused flags field.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 9b900138d0 gossip: put 'routing_channel' in charge of 'node_connection'.
This makes 'routing_channel' the primary object in the system; it can have
one or two 'node_connection's attached, and points to two nodes.

The nodes are freed when no more routing_channel refer to them.  The
routing_channel are freed when they contain no more 'node_connection'.
This fixes #1072 which I surmise was caused by a dangling
routing_channel after pruning.

Each node contains a single array of 'routing_channel's, not one for
each direction.  The 'routing_channel' itself orders nodes in key
order (conveniently the index is equal to the direction flag we use),
and 'node_connection' with source in the same order.

There are helpers to assist with common questions like "which
'node_connection' leads out of this node?".

There are now two ways to find a channel:
1. Direct scid lookup via rstate->channels map.
2. Node key lookup, followed by channel traversal.

Several FIXMEs are inserted for where we can now do things more optimally.

Fixes: #1072
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell f8426600a6 gossipd: don't create a routing_channel while we're waiting.
We're going to make it a first-class citizen, and pending routing_channel
are not real ones (in particular, we don't want to create pending nodes).

We had a linked list called rstate->pending_cannouncement which we didn't
actually use, so put that back for now and add a FIXME to use a faster
data structure.

We need to check that list now in handle_channel_update, but we never
have a real routing_channel and a pending, unless the routing_channel
isn't public.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
Rusty Russell 2ec38ec687 gossip: factor out appending code in getchannels_req().
This moveonly makes a coming cleanup easier.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-03 19:29:35 +01:00
John Barboza b50912d8b1 Print node alias when listing peers 2018-03-02 02:25:30 +00:00
Rusty Russell ca4603455b short_channel_id: remove short_channel_id_to_uint accessor.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-01 23:33:56 +01:00
Rusty Russell c5d41a23d7 short_channel_id: just use structeq.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-01 23:33:56 +01:00
Rusty Russell affc1be4d6 gossipd: get_channel() wrapper for channel lookup.
We rename the current routing.c get_channel to find_channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-01 23:33:56 +01:00
Rusty Russell be5d945e97 gossip: only send out gossip to non-local peers when we're supposed to.
This hook is called when the queue is empty; we should only send gossip
according to the gossip timer.  We're currently dribbling it out after
every message, in violation of the spec.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell c8390ca403 gossipd: fix obsolete comments.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell a073c201e0 gossip: expose and use get_node() helper.
It's a trivial helper function from routing.c, but let's expose it
and use it in gossip.c too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell 5970890fae gossipd: use status levels for unusual reporting.
Now we have them, let's use them.  I missed one case deliberately, since
that causes merge conflicts when I replace it in a following patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell 04eb101aa6 routing: handle pending replies which are missing.
I'm not completely conviced that we can't end up removing pending things,
so change asserts to simple returns.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell 60e20b502e gossipd: simplify pruning code.
If we make destroy_node() remove itself from the map, then we simply
need to free it.

We can batch the frees (as we need) simply by reparenting all the pruned
nodes onto a single temporary parent, then freeing it, relying on tal's
internal datastructures.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell 792feb8532 gossip: Only do a single lookup in channel_update.
get_connection_by_scid() and update_to_pending() both do the same
lookup which we did in handle_channel_update().

Do the lookup once, and simplify the others.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell 76ff52b601 routing: remove unused txout_state field in struct routing_channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 12:48:45 +01:00
Rusty Russell cf3f19524e gossip: formalize passing of siphash_seed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-26 06:35:02 +00:00
ZmnSCPxj 6767434ea9 routing: Use siphash24 for route randomization
Primary idea by @rustyrussell
2018-02-26 02:36:27 +00:00
ZmnSCPxj aff52ce5a8 gossipd: Implement improved randomization of routes.
Fixes: #928
2018-02-26 02:36:27 +00:00
ZmnSCPxj 216c52940d gossipd: Add fuzz and seed to getroute request. 2018-02-26 02:36:27 +00:00
Christian Decker d499c34db2 fixup! options: Add `--offline` to disable listening and auto-reconnection 2018-02-23 06:30:15 +00:00