Commit Graph

219 Commits

Author SHA1 Message Date
Christian Decker 126839886a routing: Use a pointer to a shared_secret htlc_end 2017-05-06 10:16:07 +09:30
Christian Decker 870b83f67f sphinx: Incrementally wrap replies in new onion layers 2017-05-06 10:16:07 +09:30
Christian Decker 79f848145c sphinx: Passing shared secret of the HTLC up to the master
This is needed so we can create error messages and wrap them on the
way back.
2017-05-06 10:16:07 +09:30
Rusty Russell 162dac1271 peer_control: don't complete fundchannel command until broadcast.
Under stress, the tests can mine blocks too soon, and the funding never
locks.  This gives more of a chance, at least.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-05 16:11:46 +09:30
Rusty Russell cd90c8408c lightningd/gossip: clean up channel resolve failure handling.
We were getting an assert "!secp256k1_fe_is_zero(&ge->x)", because
an all-zero pubkey is invalid.  We allow marshal/unmarshal of NULL for
now, and clean up the error handling.

1. Use status_failed if master sends a bad message.
2. Similarly, kill the gossip daemon if it gives a bad reply.
3. Use an array for returned pubkeys: 0 or 2.
4. Use type_to_string(trc, struct short_channel_id, &scid) for tracing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-05 16:11:44 +09:30
Rusty Russell 103ac79c34 lightningd: expose channel in getpeers.
Lets us manually construct routes, for testing, and replaces the 'locked'
flag as well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-03 11:47:09 +09:30
Rusty Russell 09e489030c channeld: implement malformed HTLC message.
I implemented this because a bug causes us to consider the HTLC malformed,
so I can trivially test it for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-02 12:19:35 +02:00
Christian Decker 39115717f6 channeld: Passing additional info to channeld
The CLTV delta was hardcoded until now, which was causing me some head
scratching. I guess I asked for it ^^
2017-05-02 11:49:14 +02:00
Christian Decker 25f1cba3cf routing: Ask gossipd to resolve channel_id and forward HTLCs
Since we now use the short_channel_id to identify the next hop we need
to resolve the channel_id to the pubkey of the next hop. This is done
by calling out to `gossipd` and stuffing the necessary information
into `htlc_end` and recovering it from there once we receive a reply.
2017-05-02 11:49:14 +02:00
Christian Decker f24aab1916 sphinx: Updating daemon to new sphinx implementation
Mainly switching from the old include to the new include and adjusting
the actual size of the onion packet. It also moves `channel.c` to use
`struct hop_data`.

It introduces a dummy next hop in `channel.c` that will be replaced in
the next commit.
2017-05-02 11:47:52 +02:00
Rusty Russell 778b756369 channel: support HTLC forwarding.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-02 11:47:19 +02:00
Rusty Russell 8016dbbc91 lightningd: check amt_to_forward and outgoing_cltv_value
These must be checked whether we're the final hop or not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-02 11:46:46 +02:00
Rusty Russell 961987b046 lightningd: partial BOLT update.
Not the new onion stuff for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-02 11:46:46 +02:00
Rusty Russell 8f358b7a91 lightningd: add dev_ping command for channeld.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +02:00
Rusty Russell ba12e316f1 lightningd: fix minimum depth.
Only the side *accepting* the connection gives a `minumum_depth`, but both
sides are supposed to wait that long:

BOLT #2:

	### The `funding_locked` message
...
	#### Requirements
	
	The sender MUST wait until the funding transaction has reached
	`minimum-depth` before sending this message.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07:00
Rusty Russell fc98d797d2 hsm: new fd type for channeld.
Instead of reusing HSMFD_ECDH, we have an explicit channeld hsm fd,
which can do ECDH and will soon do channel announce signatures as well.

Based-on: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-11 16:56:27 -07:00
Rusty Russell e2dc10f98d lightningd: pay support.
The previous code was very tied to the old daemon, so this copies a large
part of it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell f3dbc75eb3 lightningd: send message on HTLC failure, relay to peer.
We don't do the encryption wrapping we're supposed to do yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 1c0b43f04d channel: tell master about the HTLC fulfillment.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 826fb0c2dc lightningd: track HTLC ends.
This lets us link HTLCs from one peer to another; but for the moment it
simply means we can adjust balance when an HTLC is fulfilled.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 86da7c3a4d lightningd/channel: send and receive htlc_fulfilled messages.
Includes a fix for the direction we fulfill.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 85fd8218e2 lightningd: track channel balance.
This is an approximate result (it's only our confirmed balance, not showing
outstanding HTLCs), but it gives an easy way to check HTLCs have been
resolved.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell be4af38d0c channel: unwrap and send incoming HTLCs to master.
So far it just looks it up, marks it resolved, then does nothing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell fed25cc540 lightningd/subd: add a context to requests.
If a peer dies, and then we get a reply, that can cause access after free.
The usual way to handle this is to make the request a child of the peer,
but in fact we still want to catch (and disard) it, so it's a little
more complex internally.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell a815500653 lightningd: hand HSM fd to channeld.
For the moment, it's just to do ECDH to read the onion.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell e36a65a189 lightningd/subd: msgcb return -1 to close channel.
They can't free it while we're using it, but they can return a value
to close it.

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 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
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
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
Christian Decker 8d5591f110 channel: Create gossip announcement upon channel establishment 2017-03-15 12:45:11 +10:30
Christian Decker 5a1fbb7aaf channel: Passing through the endpoint node_ids
This is used to generate the announcements.
2017-03-15 12:45:11 +10:30
Christian Decker 34c96399b0 channel: Passing gossipd client fd to channeld 2017-03-13 11:26:48 +01:00
Rusty Russell da5c7e0a08 daemon/subdaemon: remove in favor of daemon/subd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-11 07:19:41 +10:30
Rusty Russell 14505594b5 lightningd/channel: convert to subd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-11 07:19:41 +10:30
Rusty Russell 1781983be1 lightningd/opening: convert to subd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-11 07:19:41 +10:30
Rusty Russell e467afce06 lightningd/handshake: convert to subd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-11 07:19:41 +10:30
Rusty Russell 5dc8cb12be lightningd/gossip: convert to subd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-11 07:19:40 +10:30
Rusty Russell 7f406ea80d lightningd/hsm: convert to subd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-11 07:19:32 +10:30
Rusty Russell f0c838d250 lightningd: more updates to match latest BOLT2/3.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 16:22:34 +10:30
Rusty Russell 9035d281c6 lightningd/lightningd: hook in channel daemon.
Doesn't do much yet except wait for funding confirmation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 12:01:43 +10:30
Rusty Russell c0b4bb1387 daemon/lightningd: store more state in peer.
We need to keep more information about the peer for handing off to the
channel daemon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:39:53 +10:30
Rusty Russell 5a73380e64 lightningd/subdaemon: keep peer pointer for one-per-peer daemons.
This is really useful to map daemon back to peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:39:03 +10:30
Rusty Russell 5f07e8405a lightningd/opening: fix theoretical race.
We should start watching for the transaction before we send the
signature; we might miss it otherwise.  In practice, we only see
transactions as they enter a block, so it won't happen, but be
thorough.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:35:03 +10:30
Rusty Russell 9eeb76e185 lightningd: broadcast transaction once we're told to.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:33:55 +10:30
Rusty Russell b937793555 lightningd/funding_tx: output number is 16 bit.
It's actually always 0 or 1, but the spec wants 16 bits, so use that here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:33:24 +10:30
Rusty Russell ccff3ac437 lightningd/funding_tx: fill in scriptsigs for p2sh UTXOs.
This is a bit tricky: for our signing code, we don't want scriptsigs,
but to calculate the txid, we need them.  For most transactions in lightning,
they're pure segwit so it doesn't matter, but funding transactions can
have P2SH-wrapped P2WPKH inputs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:31:55 +10:30
Rusty Russell afc31cd68f lightningd: export bitcoin_pubkey as bip32_pubkey.
We're going to need it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:29:16 +10:30
Rusty Russell d77e7963f9 funding_tx: permute inputs, don't re-calculate fees
built_utxos needs to calculate fees for figuring out how many utxos to
use, so fix that logic and rely on it.

We make build_utxos return a pointer array, so funding_tx can simply hand
that to permute_inputs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:28:09 +10:30
Rusty Russell 5dc0402a44 Update to lightning-rfc to dc0b529161561c6be3ff53c5f8574b23c3305a04
Only minor changes, but I add some more spec text to
lightningd/test/run-commit_tx.c to be sure to catch if it changes
again.

One reference isn't upstream yet, so had to be commented out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell fd258fe495 lightningd: wire up opening daemon.
Now we can actually open a channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-24 16:22:56 +10:30
Rusty Russell c8df820e58 lightning/peer_control: set logging level for peers to match global.
That way it's controlled by --log-level=

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-24 16:22:56 +10:30
Rusty Russell 90737371d0 lightningd/cryptomsg: split raw crypto_state vs peer_crypto_state
Raw crypto_state is what we send across the wire: the peer one is for
use in async crypto io routines (peer_read_message/peer_write_message).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-24 16:22:56 +10:30
Rusty Russell ac1890136c hsm: rename the hsmctl_hsmfd_ecdh_response to hsmctl_hsmfd_fd_response
We want to use it for other HSM fd requests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-21 15:15:29 +10:30
Rusty Russell 9fd40da38c generate-wire: don't hand unknown structures specially.
It's awkward to handle them differently.  But this change means we
need to expose them to the generated code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-21 15:15:19 +10:30
Rusty Russell a600b1a30f handshake: hand in client fd on exec instead of gratuitous fd passing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-02 14:48:00 +10:30
Rusty Russell 1e34e5344d lightningd/lightningd: add getpeers command.
This has an optional log level if you want to see logs for the peers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:34 +10:30
Rusty Russell dc8b174e3a lightningd/lightningd: maintain a per-peer log.
At the moment we just log each condition change.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell 83b156517f lightningd/lightningd: maintain "condition" for each peer.
This lets us return better messages to the connect json command on failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell 7aaffda779 lightningd/lightningd: finish connect command once gossip started.
This is after the INIT message is received, so we know there are no
incompatible features.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell c536616bee lightningd/lightningd: wire up lightningd_gossip.
Now we hand peers off to the gossip daemon, to do the INIT handshake and
re-transmit/receive gossip.  They may stay there forever if neither we nor
them wants to open a channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell 1800e84db7 subdaemon: callback to handle subdaemon status updates.
It's a bit messy, since some status messages are accompanied by an FD:
in this case, the handler returns STATUS_NEED_FD and we read that then
re-call the handler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell 03758af4e1 lightningd/lightningd: create unique ID for each peer.
This distinguishes them before they have an ID, and also if the daemon
doesn't know the ID.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell bf118f1b86 lightningd/lightningd: add connect command.
Unlike the old daemon, this just connects; a separate command will be needed
to create a channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30
Rusty Russell 211491f4d7 lightningd/lightningd: add lightning_handshake.
Now we do crypto handshake when peer comes in.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-10 15:38:33 +10:30