Commit Graph

1657 Commits

Author SHA1 Message Date
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 b9dcb909b8 routing: Simplify code to read the route back in
This was overly complex since it was off-by-one and we were storing
some information elsewhere. Now this just loads the route as is into
structs, extracts some information for our outgoing HTLC, and then
shifts by the array of structs by one, and finally fills in the last
instruction, which is the terminal.
2017-05-02 11:47:52 +02:00
Christian Decker c32c17701a sphinx: Switching to new onion packet format 2017-05-02 11:47:52 +02:00
Christian Decker f700662a56 routing: Reading the channel_id from routes passed in from JSONRPC 2017-05-02 11:47:52 +02:00
Christian Decker d87ca4121d routing: Returning channel_id to getroute requests
The new onion uses the `channel_id` instead of the `node_id` of the
next hop to identify where to forward the payment. So we return the
exact channel chosen by the routing algo, to avoid having to look it
up again later.
2017-05-02 11:47:52 +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
Christian Decker b3af8d50a7 sphinx: Integrating with the new daemon 2017-05-02 11:47:19 +02:00
Christian Decker c44836ee2f sphinx: Use test vector hop_data
The test vector no longer simply fills the hop_data with 'A', instead
we actually fill in the struct.
2017-05-02 11:47:19 +02:00
Christian Decker 4a468af378 sphinx: Parameterizing the HMAC size
Should have done this a long time ago...
2017-05-02 11:47:19 +02:00
Christian Decker 652d999dbd sphinx: Moving HMAC to the end of the packet
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-05-02 11:47:19 +02:00
Christian Decker 157c2da778 sphinx: Removing old nexthop based on public keys
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-05-02 11:47:19 +02:00
Christian Decker 83e89f0fe5 sphinx: Using hop_data to serialize per-hop information into onion
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-05-02 11:47:19 +02:00
Christian Decker 752f884c23 sphinx: Removed per-hop payloads, will be replaced by hop_data
This is in preparation for the migration to `hop_data` which contains
all fields, and uses the `short_channel_id` instead of the pubkey.
2017-05-02 11:47:19 +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 aa01b7d120 test_lightningd.py: helper to sync blockheight.
We need this to avoid spurious errors in the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-02 11:46:46 +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 d35bf90009 lightningd/pay: Set outgoing_cltv_value for onion.
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
Christian Decker dc7b832e83 pytest: Added gossip test for new daemon 2017-05-02 11:59:24 +09:30
Christian Decker b4beab6537 gossip: Make the broadcast interval configurable
Adds a new command line flag `--dev-broadcast-interval=<ms>` that
allows us to specify how often the staggered broadcast should
trigger. The value is passed down to `gossipd` via an init message.

This is mainly useful for integration tests, since we do not want to
wait forever for gossip to propagate.
2017-05-02 11:59:24 +09:30
Christian Decker 4bc6ee1088 gossip: Fix two bugs in the forwarding of gossip
We were using an uninitialized `broadcast_index` on the peer which
would occasionally result in no forwardings at all, segmenting the
network. And during the `msg_queue` refactor, some wait targets were
not updated, resulting in the waits never to be woken up.
2017-05-02 11:59:24 +09:30
Rusty Russell f61da7eb64 tests/test_lightningd.py: incorporate everything from old test-basic shell test.
This moves all the non-legacy blackbox testing into python.

Before:
	real	10m18.385s

After:
	real	9m54.877s

Note that this doesn't valgrind the subdaemons: that patch seems to cause
some issues in the python framework which I am still chasing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-29 10:30:10 +02:00
Rusty Russell be3b5f11e8 contrib/pylightning: allow getpeer with log level.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-29 10:30:10 +02:00
Rusty Russell 366d67ae6d tests/test_lightningd.py: extract connect and fund_channel helpers.
Common pattern when setting up tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-29 10:30:10 +02:00
Rusty Russell 056f93e2d2 ping: move test to python.
Faster and neater.

Before:
	real	0m11.200s

After:
	real	0m9.101s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-29 10:30:10 +02:00
Rusty Russell 0e6667f3b2 pytest: fix dependencies
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-29 10:30:10 +02:00
Christian Decker 67315be673 travis: Simplified build script
The Dockerfile is now stored in contrib and built using the Docker
Hub. This allows us to simply pull in the finished image from the hub
instead of having to build it ourself. Should shave off about 2
minutes from the build time.

I also switched to running the individual build and check steps in
their own containers, but on the same volume, so travis can group the
commands and run them independently.
2017-04-29 10:29:44 +09:30
Christian Decker cca0e561d6 sphinx: Added unit-testing mode to test_sphinx
Currently hidden behind the `--unit` flag. Tests the onion reply
against the test vectors.
2017-04-28 13:40:43 +09:30
Christian Decker bc0039e8c0 sphinx: Onion reply wrapping and unwrapping
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-04-28 13:40:43 +09:30
Christian Decker e603dba14a sphinx: Fixing makefile for test_sphinx and using lightningd version 2017-04-28 13:40:43 +09:30
Christian Decker 09b31624f0 sphinx: Creating copy of sphinx for new daemon
Keeping both the legacy daemon and the new daemon happy with the
restructure is a lot of work, so we just don't do it :-)
2017-04-28 13:40:43 +09:30
Christian Decker 810e12381a pytest: Simple wrapper around BitcoinProxy to avoid timeouts
Running long integration tests could result in `bitcoind` dropping the
connection inbetween calls, and since python-bitcoinlib does not
reconnect and/or retry, all subsequent tests would fail as well. This
patch switches to throwaway connections, each serving just one
request. It's easier than to reach into the bitcoinlib to reconnect
and reauth, but comes with some overhead, but I think it's acceptable
for the few bitcoin calls we actually perform.
2017-04-28 13:39:45 +09:30
Rusty Russell 09a7064260 daemon/peer: try reconnecting based on bitcoind poll time, not 15 seconds.
We seem to be getting spurious reconnect failures on Travis, this
should fix it (15 seconds may be too long at worst case).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +02:00
Rusty Russell 6d55a17642 lightningd/dev_ping: expand to cover gossipd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +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 d5be8d26f2 lightningd/ping: ping support.
A spec update brings ping support.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +02:00
Rusty Russell a436fa77fc lightningd/msg_queue: add msg_wake helper.
A cleaner wrapper than a raw io_wake.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +02:00
Rusty Russell d967c2ba64 lightningd/gossip: interleave local and gossip messages.
Rather than dumping all gossip messages then handling local ones again.
This should help us give timely ping replies.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +02:00
Rusty Russell 4f0f2c0f4e lightningd/gossip: use msg_queue instead of open-coded queue.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +02:00
Christian Decker 4e0be7a48f pytest: Added dynamic RPC call dispatch
Instead of having to define every single method we can now just call
any method, it'll fail upstream if it does not exist.
2017-04-24 05:18:11 +00:00
Christian Decker 6a072c4c6e Fix a double-free bug in the negotiation phase
The callback on `key_negotiate` was closing the connection under
certain circumstances and would also `free` the key_negotiate, which
would then be freed again once it returns. We steal it off of the
connection during the callback and doing the free manually afterwards
to make sure this can't happen.

Thanks to @jgriffiths for tracking this one down.

Fixes #142

Reported-By: @bjd and @bgorlick
2017-04-24 05:17:13 +00:00
Rusty Russell 52ee36c595 tests: run valgrind on children.
This fails on the old dev-restart tests, so we need to only enable it
for the new tests:

	rusty@rusty-XPS-13-9360:~/devel/cvs/lightning (guilt/ping-pong)$ daemon/test/test-basic --restart --verbose
	...
	{  }
	RESTARTING
	dev-restart failed!
	valgrind: mmap(0x38000000, 2265088) failed in UME with error 22 (Invalid argument).
	valgrind: this can be caused by executables with very large text, data or bss segments.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07: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 d27a5d3212 lightningd/lightningd: shutdown subdaemons on exit.
Especially under valgrind, we should give them some time to exit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07:00
Rusty Russell 3c5a70910a lightningd/hsm: shutdown when master conn is freed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07:00
Rusty Russell 3509f10e30 lightningd/gossip: shut down daemon when status fd closed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07:00
Rusty Russell 15519e5ddf lightningd/channel: set signatures to zero before sending to HSM.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07:00
Rusty Russell d06303c8a2 lightningd/channel: derive local channel_id.
We weren't setting it, but the peer wasn't checking it either.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07:00