Commit Graph

1465 Commits

Author SHA1 Message Date
Rusty Russell 3041cd5915 lightningd/channel.c: clearer functions names, better return values.
We call channel_sent_commit *before* sending (so we know if we need
to), so the name is wrong.  Similarly channel_sent_revoke_and_ack.

We can usefully have them tell is if there is outstanding work to do,
too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell f83c04fdbe lightningd/channel.c: make callbacks clearly generic
Passing through 'struct peer *' was a layering violation.

Reported-by: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell ada1eb5106 lightningd/channel.c: add callbacks for when HTLCs fully committed/removed.
The three cases we care about only happen on specific transitions:
1. They can no longer spend our failed HTLC: we can fail the source now.
2. They are fully committed to their new HTLC htlc: we can forward now.
3. They can no longer timeout their fulfilled HTLC: the funds are ours.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 82a467f131 lightningd/channel: send and receive update_commit
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 0197353bd9 lightningd/Makefile: put timeout into OLD_LIB_SRC for all daemons.
And remove the now-redundant mention in gossipd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 64b50e5cb6 lightningd/channel: handle adding HTLC, generalize handler.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 4839916038 lightningd/cryptomsg: discard unknown odd messages internally.
This saves all callers having to handle it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 47da80fdca lightningd: dev_newhtlc command.
For testing point-to-point HTLCs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 7919279367 lightningd/channel: inter-daemon messages for HTLC handling.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 9b6753173c tools/generate-wire: allow constant multiplier in fields.
Not just len*u8, but 1254*u8 for explicit fixed-length arrays. 

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 185a649572 lightningd: include daemon/sphinx.
We're going to need it to make routes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 075092411e lightningd/channel: generate htlc txs and wscripts as well.
In practice, this is what we want, either to generate or check signatures.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell dd1a81d8bd lightningd/channel: implement channel_fail_htlc.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell d072f2ec06 wire: understand struct preimage, don't treat it as sha256.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 3a9c559dc6 lightningd/channel: quote BOLT #2 for checking expiry.
https://github.com/lightningnetwork/lightning-rfc/pull/138:

	 BOLT 2: htlc-cltv must be in blocks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 8cc7f31d44 Update wire from spec 9e0a0e893db389bfe392b2f4db8097949395fe28
Now we send genesis block in handshake.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell e45bc0ce47 Update wire from spec 9a572ff0a3a4d6bceba9c0a9b859692180ecf18f
Only changes commit_sig to commitment_signed, which we don't implement
yet anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell fb80a5f905 Update wire from spec 06a5e6cbdbb4c6f8b8dab444de497cdb9c7d7f02
Only changes revoke_and_ack, which we don't implement yet anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Christian Decker 6e81da3cd2 gossip: Fix a tag collision for different directions of a channel
Appending the channel direction ensures that the directions will be
treated independently. Without this only one direction would be
forwarded to the peers.
2017-03-29 12:51:15 +02:00
Christian Decker 7793bd1b9d gossip: Consolidated direction bit computation
The direction bit was computed in several spots and was inconsistent
in some cases. Now we compute it just in routing, and once when
starting up `channeld`, this avoids recomputing it all over the place.
2017-03-28 14:06:48 +10:30
Rusty Russell 5e00beaeb4 lightningd/test: fix tests after 62ccf266fa
Now we correctly use the remote revocation basepoint, we need to set
it in run-channel (instead of the local revocation basepoint).

We also update all the comments, as per (pending) spec commit:
	https://github.com/lightningnetwork/lightning-rfc/pull/137

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-24 13:40:36 +10:30
Christian Decker 638594f3c6 jsonrpc: Implemented `getchannels` JSON-RPC call 2017-03-24 13:24:58 +10:30
Christian Decker 60a2227f0d channel: Disable channels that are lost via a channel_update
Before exiting, `channeld` constructs and sends a `channel_update`
marking the channel as disabled. This is the pro-active signalling
that the channel may no longer be used.
2017-03-23 13:34:03 +10:30
Christian Decker c8da420a9d routing: Fill in the `getroute` functionality
Copied the JSON-request parsing from `pay.c`, passing through to
`gossipd`, filling the reply with the `route_hop` serialization, and
serializing as JSON-RPC response.
2017-03-23 13:34:03 +10:30
Christian Decker 2d198e22d0 jsonrpc: Added nested messages for the getroute reply
The `route_hop` struct introduced in the previous refactoring is
reused when returning the reply to a `getroute` request. Since these
are nested messages I added the serialization and deserialization
methods.
2017-03-23 13:34:03 +10:30
Christian Decker 73e65cac4d routing: Refactor get_route into its own method
The JSON-RPC call `getroute` and the functionality to compute the
actual route have been split so that we can reuse it independently of
the JSON-interface. Since this is now a routing-only method I also
moved it into `routing.[ch]` instead of `pay.c`.
2017-03-23 13:34:03 +10:30
Christian Decker 9273b615ab gossip: Added scheleton for `getroute` calls
This includes the request/reply passed from the main daemon to
`gossipd` and the basic handlers.
2017-03-23 13:34:03 +10:30
Christian Decker 23a1d7d475 gossip: Do not log anything, it breaks a daemon connection!
This came up while debugging the gossip daemon breaking upon calling
`getroute`. It turns out that log was still writing to stdout, but
stdout had been reused for an inter-daemon socket, which would
break...
2017-03-23 13:34:03 +10:30
sstone 62ccf266fa bolt 3: use our revocation basepoint when computing their revocation key 2017-03-23 13:19:34 +10:30
Christian Decker 21d7ed0cf6 subd: Do not close STDOUT in sub-daemons
The STDOUT fd being reused as communication sockets with other daemons
was causing some unexpected crashes if the sub-daemon wrote something,
e.g., using `log_*`. Not closing it should avoid that conflict.
2017-03-21 12:26:22 +01:00
Christian Decker d2c626820f channel: Wait for 6 confirmations before sending announcement sigs
The protocol specifies that in order for an announcement to be valid,
the channel has to have at least 6 confirmations.
2017-03-20 17:09:12 +01:00
Christian Decker 5028f7b9d9 fixup! pylightning: RPC returns a failure if the connection is lost 2017-03-20 11:18:00 +10:30
Christian Decker 225f29abf4 pylightning: RPC returns a failure if the connection is lost 2017-03-20 11:18:00 +10:30
Christian Decker 9c7c2a3f2f pytest: Added simple pytest for the new JSON-RPC 2017-03-20 11:18:00 +10:30
Christian Decker b2ea4cfd66 wiregen: Passing ctx to array helpers that require it
Some of the struct array helpers need to allocate data when
deserializing their fields. The `getnodes` reply is one such example
that allocates the hostname. Since the change to calling array helpers
the getnodes call was broken because it was attempting to allocate off
of the entry, which did not have a tal header, thus failing.
2017-03-20 11:18:00 +10:30
Rusty Russell d2e19c3735 lightningd/status: reuse wire code for sending status.
Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 8be18ccfa1 lightningd/msg_queue: rename msg_is_fd to msg_extract_fd
Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell cf6d25cad6 lightningd/connection: rename to lightningd/daemon_conn
To match the structure name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell d616dbbd44 lightningd/connection: remove conn_fd field.
io_conn_fd(conn) will give it to you anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell bdc41f00f3 lightningd/channel: use msg_queue properly for peer.
Use msg_enqueue's wake and msg_queue_wait, and don't clone packets since
msg_enqueue() respects take.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 5637564cd4 lightningd/status: support daemon_conn for status_trace and status_failed.
We remove the unused status_send_fd, and rename status_send_sync (it
should only be used for that case now).

We add a status_setup_async(), and wire things internally to use that
if it's set up: status_setup() is renamed status_setup_sync().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 7442cf7c3e lightningd/channel: use daemon_conn.
This is a little more awkward, as we used to do some work
synchronously (the init message), but it's still pretty clear.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 21498647e2 lightningd/hsm: remove status_send.
Since we use async IO, we can't use status_send.  We keep a pointer to the
master daemon_conn, and use that to send.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 6a0c9875a1 lightningd/hsm: use daemon_conn.
Nice simplification.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell c213ea482d channel: receive gossip fd on exec.
This simplifies things a little: hand the fd on exec rather than over the
request socket.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell f511012e29 lightningd/gossip: don't hand client fd until release.
The gossip subdaemon previously passed the fd after init: this is
unnecessary for peers which simply want to gossip (and not establish
channels).

Now we hand the gossip fd back with the peer fd.  This adds another
error message for when we fail to create the gossip fds.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 7a9df37ef3 lightningd/subd: support multiple fds sent at once in normal messages.
Rather than returning SUBD_NEED_FD, callback returns how many fds it needs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 38bffc0f0c lightningd/subd: support multiple fds sent at once in request reply.
Instead of indicating where to place the fd, you say how many: the
fd array gets passed into the callback.

This is also clearer for the users.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 3938f40274 lightningd/gossip: use daemon_conn for status updates.
We're going to remove status_send (it's sync, and so doesn't play well with
async io).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30
Rusty Russell 1f894b6234 lightningd/gossip: use daemon_conn for master daemon interaction.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-20 07:50:53 +10:30