Commit Graph

2722 Commits

Author SHA1 Message Date
Christian Decker 6c82d1b8b0 pylightning: Subclass ValueError to access to the returned error 2018-07-01 04:13:04 +00:00
Rusty Russell ce5b4bddf2 tests: fix to work with bitcoind master branch.
E               ConnectionRefusedError: [Errno 111] Connection refused

And in debug.log:

2018-05-17T04:06:35Z Warning: Config setting for -rpcport only applied on regtest network when in [regtest] section.

Unfortunately, current versions including 0.16.1 *ignore* the contents of
a '[regtest]' section, so we need it in *both* places.

Also remove the misleading 'rpcport' initialization which we always
override.

Note that we don't fix this message though:

	2018-05-17T04:06:35Z Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-21 13:43:32 +02:00
Rusty Russell 91d62ad697 pytest: create only a single config file.
For some reason, we created a second bitcoin.conf in the regtest/ directory,
which AFAICT nothing uses.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-21 13:43:32 +02:00
Rusty Russell 2375302534 pytest: move regtest argument into config file.
It's not optional for our test setup, and this makes it easier to invoke
bitcoin-cli manually, for example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-21 13:43:32 +02:00
Rusty Russell c78afa9201 onchaind: use lowball fee instead of donating to miners.
As of bitcoind 0.16.1, you can't send a single-input OP_RETURN output,
as you get 'tx-too-small'.

	sendrawtx exit 26, gave error code: -26?error message:?tx-size-small (code 64)?'

So instead we use the minimum fee we can, but otherwise ignore it and
don't wait for it to be mined.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-21 13:43:32 +02:00
Christian Decker e556bf4f36 pytest: Disable DNS lookups during test runs
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-06-21 11:21:16 +02:00
Mark Beckwith 8f0ef1636f Added wallet related error codes
New codes: FUND_MAX_EXCEEDED, FUND_CANNOT_AFFORD, FUND_DUST_LIMIT_UNMET.

The error message "Cannot afford fee" was not exactly correct because
it would also occur if the amount requested could not be afforded.  So
I changed it to the more generic "Cannot afford transaction".

Other things:

* Fixed off-by-one satoshi in fundchannel manpage.
* Changed 'arror' to 'error' because we are not pirates.
2018-06-18 12:33:25 +02:00
Christian Decker 583c1c50f8 pytest: Explicitly state the max fee multiplier we assumed in tests
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-06-14 00:59:42 +00:00
Christian Decker 4dca6daf34 opts: Bump locktime_max so we don't disagree as much with lnd
I still believe that 2 weeks is way too much, but we were promised that these
defaults would be slowly reduced to saner values as the stability increases.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-06-14 00:59:42 +00:00
Rusty Russell 8183590cdb pytest: test_onchaind_replay needs to wait for tx broadcast.
Waiting for 'Disabling channel' is not enough, since it's async to the
actual tx broadcast: I caught a case where the unilateral close wasn't
in the block, and so failed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-13 16:22:23 +02:00
Rusty Russell 965c20caae tests: reenable developer tests.
72d103d6bb deprecated DEVELOPER env var
in favor of config.vars, but didn't update test_closing.py or test_gossip.py.

5d0a54b7f0 then removed the explicit
DEVELOPER= setting from Travis.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-13 16:22:23 +02:00
Christian Decker 135bd962f7 pytest: Mark test_closing_different_fees as flaky
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-06-09 13:39:27 +02:00
Rusty Russell 72d103d6bb Makefile: import config.vars.
We leave VALGRIND env var as an override for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-08 17:56:01 +02:00
Christian Decker de3b359782 pytest: Use pytest fixtures for the test directory and clean it up
The modern, pytest based, tests now clean up after themselves by removing
directories of successful tests and the base directory if there was no failure.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-06-06 03:32:27 +00:00
Christian Decker 38b7a0e2d2 pytest: Remove directories of successful tests
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-06-06 03:32:27 +00:00
Rusty Russell e4457e59ed pytest: test_gossip_jsonrpc can always test aliases.
The whole test is under DEVELOPER anyway, but even if it weren't it
would work fine.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell 383b309a00 utils: make subd_pid return the *last* pid, in case we restarted daemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell e9483f12b6 test_lightningd.py: actually make sure we do zlib encoding.
Previous replies weren't large enough; add another channel and then
use IO tracing to make sure the reply is zlib encoded.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell 9e51e196c1 gossipd: dev-set-max-scids-encode-size to artificially force "full" replies.
We cap each reply at a single one, which forces the code into our
recursion logic.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell 118f099dd8 gossip: dev-query-channel-range to test query_channel_range.
We keep a crappy bitmap, and finish when their replies cover
everything we asked.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell c34b49c356 gossipd: add dev-send-timestamp-filter command for testing timestamp filtering.
Since we currently only (ab)use it to send everything, we need a way to
generate boutique queries for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell c633cbe2ee tests: add dev-query-scids
And write the test for it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell c2189229ca gossipd: only broadcast channel_announcement once we have a channel_update.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell 601a855543 tests/test_lightningd.py: test new delayed gossip channel_announce behaviour.
The gossip-query spec enhancements say not to forward an channel_announcement until
you have receive a channel_update.  This test fails for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Rusty Russell 498ad91318 tests: new helper to get pid of a particular subdaemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-06-06 03:25:56 +00:00
Christian Decker 27a186be9c pytest: Stabilize LightningNode.openchannel for multiple channels
When opening a number channels from a single node we could end up not waiting
for the funding tx to make it into the mempool, instead triggering on a previous
`sendrawtransaction` or `CHANNEL_NORMAL` in the logs. This now checks that the
actual funding transaction makes it into the mempool and that we wait for the
depth change for that specific channel.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-31 02:30:27 +00:00
Christian Decker c17848a3f3 gossip: Disable local channels after loading the gossip_store
We don't have any connection yet, so how could they be active? Disable both
sides to avoid trying to route through them or telling others to use them as
`contact_points` in invoices.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-31 02:30:27 +00:00
Christian Decker 202ce5e4ea pytest: Replace wait_for_channels with an actual check
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-31 02:30:27 +00:00
Christian Decker 568cd9ff36 pytest: Making test_routing_gossip less flaky
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-31 02:30:27 +00:00
ZmnSCPxj 0087105d6c test_lightningd: Test forget-if-fundee behavior. 2018-05-23 14:37:32 -07:00
Christian Decker f2b89a9965 pytest: Simplify test_routing_gossip
Settling first and then asserting is longer than just waiting for it to succeed.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker 1a45efd0a9 pytest: Use utils.TIMEOUT when settling in test_routing_gossip
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker 2e8b3066e4 pytest: Filter out some unimportant log lines
Mostly `lightningd` complaining about not being able to estimate fees. Safes us
a lot of log space when some tests time out, and safes us a few context switches
between log appender and log watchers.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker 1a9c7783b7 pytest: Yet another instance where we wait only on one side
Waiting on one end and then just asserting on the other is racy.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker f1c64db5e7 pytest: Wait on both sides in test_peerinfo
We were sort of assuming that one side telling it's ok would automagically make
the other side succeed as well.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker eb869cf144 pytest: Make test_sendpay less flaky
While 1 second is very generous, it resolving the HTLCs may take longer, so we
just loop over this instead of making it one-shot

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker a35cc9a79f pytest: Stabilize test_autocleaninvoice
The RPC calls aren't really free, so let's wait for absolute times, computed
from the `start_time` instead.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker dcbd27e7cf pytest: Actually wait for payments to confirm in benchmark
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker 126f024cda pytest: Added a few more benchmarks
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker 4d40ff37aa pytest: Fix the benchmark script
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Christian Decker c4ca2ab4b9 pytest: Fix the benchmark script
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-23 00:20:19 +00:00
Rusty Russell 90dc5173d5 test_lightningd.py: remove 5 slowest tests from non-developer mode.
We can restore them once we get parallel testing on Travis, but meanwhile
we time out because of the 30 seconds bitcoind poll.

Running on my laptop with --duration=5:

=========================== slowest 5 test durations ===========================
184.07s call     tests/test_lightningd.py::LightningDTests::test_multiple_channels
156.66s call     tests/test_lightningd.py::LightningDTests::test_forward
155.77s call     tests/test_lightningd.py::LightningDTests::test_closing
126.83s call     tests/test_lightningd.py::LightningDTests::test_waitinvoice
126.11s call     tests/test_lightningd.py::LightningDTests::test_waitanyinvoice

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-20 02:32:42 +00:00
Rusty Russell a2dc3d02a8 locktime-blocks: rename to watchtime-blocks.
And clarify the descriptions for end users.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-20 02:32:42 +00:00
Rusty Russell fd86fbf2fc lightningd: rename --anchor-confirms to --funding-confirms.
That nomenclature won out in Milan.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-20 02:32:42 +00:00
Rusty Russell 8739b4cbe8 lighningd: Remove --debug-subdaemon-io.
We can use SIGUSR1, even in non-developer builds.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-20 02:32:42 +00:00
Rusty Russell edf1b3cec9 More option cleanups.
Because we have too many which are never used and I don't want to document
them.

1. Remove unused anchor_onchain_wait.  When implemented, it should be
   hardcoded to 100 or more.
2. Remove anchor_confirms_max.  10 always reasonable, and we can readd
   an override option should someone need it.
3. max_htlc_expiry should be the same as locktime_max (which increases
   from 3 to 5 days by default): they're both a limit on how long
   funds can be locked up.
4. channel_update_interval should always be a dev option.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-20 02:32:42 +00:00
Rusty Russell 0aa22741df option cleanup: --dev-override-fee-rates
Make --override-fee-rates a dev option.  We use default-fee-rate in
its place, which (since bitcoind won't give fee estimates in regtest
mode for short chains) gives an effective feerate of 15000/7500/3750.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-20 02:32:42 +00:00
Rusty Russell c8cc8fd83f option cleanup: --dev-bitcoind-poll
Make --bitcoind-poll a dev option.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-20 02:32:42 +00:00
Rusty Russell 85a062164a test_lightningd: test_closing_torture timeout increase.
I hit this timeout on pytest and valgrind with -n5; use the timeout variable
from utils.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-19 15:52:56 -04:00
Rusty Russell c546b1bbb6 gossipd: specify origin of updates in errors.
@cdecker points out that in test_forward, where we manually create a route,
we get an error back which contains an update for an unknown channel.

We should still note this, but it's not an error for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-19 15:52:56 -04:00
Rusty Russell 8ee60e2d8e testing: make sure we don't see gossip in bad order.
This is something which generally shouldn't happen, but we didn't
notice it previously.

We ignore this warning in the case where a channel was deleted: this
happens because one side can send an update while the other notices
that the channel is closed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-19 15:52:56 -04:00
Rusty Russell cdded4f53d tests/utils.py: make default timeout configurable via $TIMEOUT
This is useful when you're expecting a test to fail, you've just added
diagnostics.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-10 21:35:53 +02:00
Rusty Russell c33bbb2639 test_lightningd.py: wait longer test_permfail for l2 to notice new blocks.
Reproduced this failure locally: l2 hadn't seen the block yet.  Timeout
was too aggressive.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-09 06:13:49 +00:00
Rusty Russell 2caeab506b tests/test_lightningd.py: make test_blockchaintrack safe to re-run.
It gets confused if re-run due to flaky, since:
1. Using the same HSM, it generates the same spend and sees a previous one.
2. The block height numbers are off.

Fixes: #1479
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-09 06:13:49 +00:00
Rusty Russell ecebbe700b tests/test_lightningd.py: remove unneeded btc variable.
We have a 'bitcoind' global: getting it from inside one of the daemons
was a mistake I've copied widely.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-09 06:13:49 +00:00
ZmnSCPxj 757c059cd4 test_lightningd: Add closingd torture test. 2018-05-09 04:43:21 +00:00
Christian Decker 783327622f pytest: Mark test_blockchaintrack as flaky
The flakyness is probably due to timing issues when reorging.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-08 22:06:04 +02:00
Christian Decker fac1d24ce3 pytest: Use the port from the lightning node
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-08 22:06:04 +02:00
Christian Decker 5f7b0fdf92 pytest: Marking `test_permfail` as flaky
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-08 22:06:04 +02:00
Christian Decker 104645ba3a pytest: Fix flaky `test_closing_id` test
It simply wasn't waiting for us to register the peer before attempting to open a
connection. Moved into a separate test to be able rerun multiple times.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-08 05:43:35 +00:00
Rusty Russell 79902b48c7 test_lightningd.py: remove gratuitous 'addr' option from test_connect_by_gossip.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Rusty Russell d40d22b68e gossipd: don't try to connect to non-routable addresses.
Someone could try to announce an internal address, and we might probe
it.

This breaks tests, so we add '--dev-allow-localhost' for our tests, so
we don't eliminate that one.  Of course, now we need to skip some more
tests in non-developer mode.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Rusty Russell af065417e1 gossipd: handle wildcard addresses correctly.
If we're given a wildcard address, we can't announce it like that: we need
to try to turn it into a real address (using guess_address).  Then we
use that address.  As a side-effect of this cleanup, we only announce
*any* '--addr' if it's routable.

This fix means that our tests have to force '--announce-addr' because
otherwise localhost isn't routable.

This means that gossipd really controls the addresses now, and breaks
them into two arrays: what we bind to, and what we announce.  That is
now what we return to the master for json_getinfo(), which prints them
as 'bindings' and 'addresses' respectively.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Rusty Russell 52917ff6c9 More flexible address wildcards, only add wildcard if nothing else.
1. Add special option where an empty host means 'wildcard for IPv4 and/or IPv6'
   which means ':1234' can be used to set only the portnum.
2. Only add this protocol wildcard if --autolisten=1 (default)
   and no other addresses specified.
3. Pass it down to gossipd, so it can handle errors correctly: in most cases,
   it's fatal not to be able to bind to a port, but for this case, it's OK
   if we can only bind to one of IPv4/v6 (fatal iff neither).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Rusty Russell fe96fe10c7 Clean up network options.
It's become clear that our network options are insufficient, with the coming
addition of Tor and unix domain support.

Currently:

1. We always bind to local IPv4 and IPv6 sockets, unless --port=0, --offline,
   or any address is specified explicitly.  If they're routable, we announce.
2. --addr is used to announce, but not to control binding.

After this change:

1. --port is deprecated.
2. --addr controls what we bind to and announce.
3. --bind-addr/--announce-addr can be used to control one and not the other.
4. Unless --autolisten=0, we add local IPv4 & IPv6 port 9735 (and announce if they are routable).
5. --offline still overrides listening (though announcing is still the same).

This means we can bind to as many ports/interfaces as we want, and for
special effects we can announce different things (eg. we're sitting
behind a port forward or a proxy).

What remains to implement is semi-automatic binding: we should be able
to say '--addr=0.0.0.0:9999' and have the address resolve at bind
time, or even '--addr=0.0.0.0:0' and have the port autoresolve too
(you could determine what it was from 'lightning-cli getinfo'.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Rusty Russell 00537fde43 lightningd: deprecate --ipaddr in favor of --addr.
We're going to add sockets, and later onion addresses, so the current name
is bad.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Rusty Russell 6ba9a7cb57 tests/test_lightningd.py: move port into node.
We're about to change the JSONRPC, so let's put an explicit 'port' into
our node class.

We initialize it at startup time: in future I hope to use ephemeral ports
to make our tests more easily parallelizable.

Suggested-by: @cdecker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Rusty Russell 7d27501c94 tests/utils.py: remove unused connect routine.
It's broken anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-07 22:37:28 +02:00
Christian Decker 6231e9969f pytest: Give lightningd nodes a numeric ID to prefix logs
This used to be the port, but since we no longer have fixed ports, and we start
them in random order we can't easily distinguish them by the port anymore. Just
use a numeric ID that matches their lightning-dirs.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker 65cac1ba85 pytest: Add flaky dependency and mark as test_closing_different_fees
This is mainly just a stopgap solution until we get to stabilize the test.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker e00c7012cc pytest: Ensure unique test directories per test even if rerun
We add an attempt number to the test directory to improve the test-isolation and
allow for multiple reruns of the same test, without re-using any of the
lightning-dirs or bitcoin-datadirs.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker 071ef628db pytest: Use random ports for bitcoind and lightningd to allow parallel testing
Adds a new dependency, but totally worth it :-)

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker bbeb44faac pytest: Make the directory of the NodeFactory configurable
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker 727d115296 pytest: Add py.test fixtures and migrate first example test
This is the first example of the py.test style fixtures which should allow us to
write much cleaner and nicer tests.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker b307df0002 pytest: Let `connect` start nodes in parallel
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker e3bac12683 pytest: Allow stdout to be dropped for bitcoind
We never really look at the output, and it's rather noisy, so we just stop
writing to the log.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker 4f63acc77c pytest: Add helper to start a number of nodes in parallel
Especially with valgrind this allows us to safe quite some time on multi-core
machines since startup is about the most expensive operation in the tests. In a
simple test spinning up 3 nodes this gave me about 25% - 30% test time
reduction. The effects will be smaller for single core machines, hoping Travis
handles these gracefully.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker 81b715aae9 pytest: Move wait_for to utils.py and make fund_channel a member
Slowly moving towards a more pythonic approach to the testing code.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 02:40:50 +00:00
Christian Decker 7aa13cc949 channel: Queue a channel_update to the peer upon funding_locked
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-05-07 01:10:48 +00:00
Rusty Russell ac51231166 lightningd: remove --dev-hsm-seed option.
We can create the hsm file from python directly; that works even if we
don't have DEVELOPER set, and is simpler.

We add a test that the aliases are correct.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-05 17:55:10 +02:00
ZmnSCPxj b1ffcc3b52 test_lightningd: Update close to use scid, add test for peer id and full cid. 2018-05-03 22:47:07 +02:00
Rusty Russell c6af2a8cb2 lightningd: loosen feerate minimum.
We're getting spurious closures, even on mainnet.  Using --ignore-fee-limits
is dangerous; it's slightly less so to lower the minimum (which is the
usual cause of problems).

So let's halve it, but beware the floor.

This is a workaround, until we get independent feerates in the spec.

Fixes: #613
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-05-01 18:45:04 +02:00
ZmnSCPxj 69cdfba3c8 gossip: Use gossiped node_announcement to locate nodes.
So we can get via address hint, DNS seed, or node_announcement
gossip.
2018-04-26 11:45:38 +00:00
Rusty Russell c6483a57d0 gossipd: give more distinct errors.
At least say whether we failed to connect at all, or failed cryptographic
handshake, or failed reading/writing init messages.

The errno can be "Operation now in progress" if the other end closes the
socket on us: this happens when we handshake with the wrong key and it
hangs up on us.  Fixing this would require work on ccan/io though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-26 05:47:57 +00:00
Rusty Russell a134ca9659 gossipd: use exponential backoff on reconnect for important peers.
We start at 1 second, back off to 5 minutes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-26 05:47:57 +00:00
Rusty Russell bc4809aa85 gossipd: make sure master only ever sees one active connection.
When we get a reconnection, kill the current remote peer, and wait for the
master to tell us it's dead.  Then we hand it the new peer.

Previously, we would end up with gossipd holding multiple peers, and
the logging was really hard to interpret; I'm not completely convinced
that we did the right thing when one terminated, either.

Note that this now means we can have peers with neither ->local nor ->remote
populated, so we check that more carefully.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-26 05:47:57 +00:00
Rusty Russell 72c459dd6c gossipd: keep reaching struct only when we're actively connecting, and don't retry
1. Lifetime of 'struct reaching' now only while we're actively doing connect.
2. Always free after a single attempt: if it's an important peer, retry
   on a timer.
3. Have a single response message to master, rather than relying on
   peer_connected on success and other msgs on failure.
4. If we are actively connecting and we get another command for the same
   id, just increment the counter

The result is much simpler in the master daemon, and much nicer for
reconnection: if they say to connect they get an immediate response,
rather than waiting for 10 retries.  Even if it's an important peer,
it fires off another reconnect attempt, unless it's actively
connecting now.

This removes exponential backoff: that's restored in next patch.  It
also doesn't handle multiple addresses for a single peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-26 05:47:57 +00:00
Rusty Russell 5db8454755 test_lightningd.py: make tests more robust by suppressing reconnects.
Got some intermittant failures, mainly caused by the tests being slow
enough that the peer reconnected.  We should always suppress
reconnection if we can, and not stress too much in the !DEVELOPER case
where we can't.

We should turn off dev-no-reconnect *always* unless told we will
reconnect, and since we can't if !DEVELOPER, don't do the connection
check there.

Instead of adding an option to line_graph, we remove it in favor
of connect (since we only use it with n=2 anyway).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-26 05:47:57 +00:00
ZmnSCPxj 079778e357 invoice: Check duplicate preimage when explicitly sprcified.
Reported-by: @mcudev
2018-04-26 05:47:09 +00:00
Christian Decker ac9e5581c8 pytest: Start nodes with --rescan=1
This shaves off about 15% of our integration testing suite on my machine. It
assumes we never reorg below the first block the node starts with, which is true
for all tests, so it's safe.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-25 14:33:38 +02:00
Christian Decker 74fa107578 pytest: Add a test for the new --rescan option
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-25 14:33:38 +02:00
Christian Decker 96352858d6 chaintopology: Simplify rescan offset computation
Simplification of the offset calculation to use the rescan parameter, and rename
of `wallet_first_blocknum`. We now use either relative rescan from our last
known location, or absolute if a negative rescan was given. It's all handled in
a single location (except the case in which the blockcount is below our
precomputed offset), so this should reduce surprises.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-25 14:33:38 +02:00
Christian Decker 8e7ac53f5a pytest: test onchaind restarts from the DB 2018-04-25 14:33:38 +02:00
ZmnSCPxj eb42804fcc invoice: Support providing preimage when making invoice. 2018-04-24 11:54:02 +02:00
Rusty Russell e2ba1d2290 test_lightningd.py: test_closing_different_fees must wait for txs to hit mempool
Careful log examination revealed that we were generating a block before one
of the mutual close txs had entered the mempool.  This is rare because it
means that both peers have to be too slow.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell d0bfd8407a test_lightningd.py: catch unexpected reconnections.
I had a weird failure which was caused by an unexpected disconnect and
reconnecct.  Since we are prersistend and recover from these, they can
slip through our tests; most tests don't involve reconnection, so we
need to catch this explicitly.

For the connect() helper, we always suppress reconnection; tests which
want it all want other options so don't use this helper anyway.  (Actually,
after I said that, test_closing_while_disconnected was added when I
rebased, which did require it, so I had to open-code that one).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
ZmnSCPxj, ZmnSCPxj jxPCSmnZ d6bf7930b8 Loosen` close` timeout in `test_closing_different_fees` 2018-04-23 05:24:46 +00:00
ZmnSCPxj 0b331a2b60 test_lightningd.py: Clean up some uses of 'close' RPC. 2018-04-23 05:24:46 +00:00
Rusty Russell 68758a5d42 json_close: test that it works while disconnected.
It should, indeed, close once they reconnect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 05:24:46 +00:00
ZmnSCPxj 2cee1ab20f peer_control: Make close wait for complete closure, with timeout.
Also report tx and txid, and whether we closed unilaterally or
bilaterally, if we could close the channel.

Also make a manpage.

Fixes: #1207
Fixes: #714
Fixes: #622
2018-04-23 05:24:46 +00:00
ZmnSCPxj 78a074af5a test_lightningd: Also test receive of P2WPKH is correct.
For completeness.
Existing test will check P2SH-P2WPKH address only.
P2WPKH seems OK but test it anyway in case of regression.
2018-04-22 12:51:03 +02:00
ZmnSCPxj 3bf626a750 walletrpc: Correct generation of P2SH-P2WPKH addresses for listfunds. 2018-04-22 12:51:03 +02:00
ZmnSCPxj c2e85cd051 test_lightningd: Check listfunds address matches newaddr paid to. 2018-04-22 12:51:03 +02:00
Christian Decker 140123b4c8 pytest: Add local_add tests to test_gossip_persistence and cleanup
Mixing the test into the existing test allows us to reduce the execution, but
adds a bit of complexity, so I added two small helpers.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-22 12:50:34 +02:00
Christian Decker 2de7f622cb gossip: Add an explicit debug message when handing back a peer
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-09 00:21:20 +00:00
Christian Decker 1757732236 pytest: Fix flaky test_blockchaintrack test
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-09 00:21:20 +00:00
Rusty Russell 09c4203767 bolt11: allow multiple fallback addresses.
We can have more than one; eg we might offer both bech32 and a p2sh
address, and in future we might offer v1 segwit, etc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-06 14:26:53 +02:00
Christian Decker 4da3d407b4 pytest: Use a dict to pass options to lightningd
This allows us to have some default options that can then be overridden easily
on a per-test basis.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-06 06:52:22 +00:00
Rusty Russell 5f1c77d249 test_lightning.py: add test for onchain with different feerates.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-04 02:31:41 +00:00
Rusty Russell 1f9ad06056 lightningd: allow us to close channel while still awaiting lockin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-03 23:22:59 +02:00
Rusty Russell 71de234255 test_lightningd.py: test shutdown while lockin.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-03 23:22:59 +02:00
Christian Decker e41d565103 pytest: Add a test for the gossip perstistence
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-30 16:35:00 +02:00
Christian Decker 428f5608fa pytest: Testing for a node whose channels were closed will not work
In the next commit we remove channels whose outpoint was spent from our network
view, so checking for it will not work anymore.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-30 16:35:00 +02:00
Christian Decker 1b604d5dd6 pytest: Wait for the funding transaction to be in the mempool
This can lead to failures in the valgrind configuration.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-30 16:34:31 +02:00
Rusty Russell a85ead7058 invoice: allow numeric labels again.
Fixes: #1291
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-30 00:01:10 +02:00
Christian Decker f341b508e1 pytest: Add checks that funding change and to_us get confirmed
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-27 23:17:17 +00:00
Rusty Russell ed9093fcbd json: allow strange characters through our JSON parser.
Fixes: #387
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-26 00:20:53 +00:00
Rusty Russell 54431d2b08 lightningd: escape our own alias when we print it in logs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-26 00:20:53 +00:00
Rusty Russell 4139f06780 json_getnodes: escape the alias when we print it out.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-26 00:20:53 +00:00
Rusty Russell a077c3defb lightningd: test for weird aliases.
Test has inverted conditions to make it "pass", we fix as we go.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-26 00:20:53 +00:00
Rusty Russell 8c838ebd76 test_lightning: Write test for invoices with weird characters.
It's currently expected to fail.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-26 00:20:53 +00:00
Mark Beckwith 489d8d04a6 Fund all (#1249)
* Funding channel with "all"
* Added test for fund all
2018-03-21 00:06:04 +01:00
ZmnSCPxj 5557958c47 test_lightningd: Add test for autocleaninvoice. 2018-03-20 17:25:51 +01:00
ZmnSCPxj de853b4847 test_lightningd.py: Test delexpiredinvoice. 2018-03-20 17:25:51 +01:00
ZmnSCPxj 6391645b83 test_lightningd: Check payment fields of pay return value. 2018-03-19 00:27:55 +00:00
ZmnSCPxj 234d67da34 channel_fail_permanent: Use a channel-level error, not an all-channels error.
Fixes: #1229
2018-03-17 13:26:58 +01:00
Rusty Russell 1b9791f0f5 pay: delete HTLC when we delete payment.
This fixes the root cause of https://github.com/ElementsProject/lightning/issues/1212
where we deleted the payment because we wanted to retry, then retry failed
so we had an (old) HTLC without a matching payment.  We then fed that
HTLC to onchaind, which tells us it's missing, and we try to fail the
payment and deref a NULL pointer.

Fixes: #1212
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-16 04:01:06 +00:00
Rusty Russell d8cecf03dd test_lightningd.py: add test to trigger crash bug.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-16 04:01:06 +00:00
ZmnSCPxj f2aa15ffee test_lightningd.py: Check additional fields of sendpay. 2018-03-16 01:24:43 +00:00
ZmnSCPxj ed3984f444 test_lightningd.py: Modify test_payment_duplicate_uncommitted.
`pay` command will now wait for payment to succeed if the
payment has been initiated.
2018-03-14 05:33:09 +00:00
ZmnSCPxj 752b7f5277 test_lightningd.py: Update for nonblocking sendpay. 2018-03-14 05:33:09 +00:00
Christian Decker 3e9e19951b pytest: Re-enable formerly flaky test_reconnect_normal
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-08 05:53:58 +01:00
Rusty Russell 25cb8caae8 onchaind: fix confusing message about delayed txs.
We say "in N blocks" but we actually mean "N blocks after this tx" which is
actually N-1 or less.  Change wording and tighten tests which misunderstood
this.

Also, the 'assert not l1.daemon.is_in_log('onchaind complete, forgetting peer')'
are unlikely to work until the daemon has actually seen the block, so add
sync_blockheight before all of those.

These changes reveal some sloppy testing, which we fix.
  
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-07 18:55:51 +01:00
Rusty Russell a48c300df2 onchaind: fix too-eager OUR_HTLC_TIMEOUT_TX.
With the following patch applied, we could clearly see onchaind try to
broadcast the timeout tx one block too early:

	sendrawtx exit 26, gave error code: -26?error message:?non-final (code 64)?

This is because of an out-by-one error in calculating the relative
depth required, since the out->tx_blockheight is already 1 before the
current block.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-07 18:55:51 +01:00
Rusty Russell eb52dde5b5 onchaind: add a new state for where we're not producing an output.
DONATING_TO_MINERS is pretty clear, I think.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-07 18:55:51 +01:00
Rusty Russell 0489aabfbe test_lightningd.py: test onchaind when all turn into fees.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-07 18:55:51 +01:00
Rusty Russell 27c4e926bd test_lightningd.py: test case where onchaind restarts with different fees.
This was revealed in #1114; onchaind isn't actually completely idempotent
due to fee changes (and the now-fixed change in keys used).

This triggers the bug by restarting with different fees, resulting in
onchaind not recognizing its own proposal:

	2018-03-05T09:38:15.550Z lightningd(23076): lightning_onchaind-022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59 chan #1: STATUS_FAIL_INTERNAL_ERROR: THEIR_UNILATERAL/OUR_HTLC spent with weird witness 3

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-07 18:55:51 +01: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 9a2950628d test: disconnect command 2018-03-07 16:14:01 +01:00
Christian Decker c9985805cd pytest: Add blockchain tracking test
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-06 18:59:27 +01:00
ZmnSCPxj 8e8d7c2aba pay/sendpay: Use spec names for rhash and r. 2018-03-05 20:21:37 +00:00
ZmnSCPxj c03f584e19 test_lightningd.py: Adapt to new help output. 2018-03-03 19:40:22 +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 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
John Barboza 35ce13179c Add tests for peer information containing alias 2018-03-02 02:25:30 +00:00
John Barboza 6f14736803 revert 0e40c8 and renable test_withdraw
I initially disabled this until 0.16 because the withdraw command
was modified to require 'brct1' addresses for regtest.
But commit bd07a9 allows a regular testnet address to work
just as well. So renable this check.
2018-03-01 23:32:58 +01:00
Rusty Russell 742885c95e test_lightning.py: reduce 121 to 101 blocks, remove segwit comment.
FWIW, the tests without valgrind take 662 seconds before we reduced
the number of blocks, and only 648 seconds now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-03-01 03:52:21 +00:00
Jan Sarenik 0017b9b363 test_lightningd.py: Enable bech32 test for DEVELOPER
Since bitcoind 0.16 is already released it is safe to enable
this test already.
2018-03-01 03:52:21 +00:00
Christian Decker 565059a12f pytest: Require bitcoin-0.16.0 and reduce number of generated blocks
0.16.0 is required since we rely on it for some tests and the block
reduction allows us to waste less time during setup. 121 blocks were
chosen so that we have at least one mature output to spend.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-03-01 03:52:21 +00:00
ZmnSCPxj, ZmnSCPxj jxPCSmnZ 590a9a657d test_lightningd.py: Silence F841
Just do not assign to variable.
2018-02-28 11:17:08 +01:00
ZmnSCPxj 6792acf04c test_lightningd: Add some more testing for waitinvoice. 2018-02-28 11:17:08 +01:00
Rusty Russell c7718aa2e4 test_lightningd.py: repair flaky test_bitcoin_failure
If bitcoind is still fetching blocks, we might accidentally inject
the failure between getblockhash and getblock.  That's OK, but
it's not the failure we test for.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-28 01:51:40 +00:00
Rusty Russell 58fae47868 test_lightningd.py: more minor flake8 fixes.
Looks like rebasing the flake8 branch caused breakage, as new violations
had occurred since that check was written

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-26 22:36:05 +01:00
practicalswift d2109bfe0c Fix flake8 warnings 2018-02-26 12:38:00 +01:00
John Barboza 0e40c85691 Disable test until 0.16
This test generates a pre-bip173 testnet P2PKH address with bitcoin 0.15.1
which fails under the new verification checks for the bip173 network name.
This should be renabled with bitcoin 0.16 which can generate a bip173 address
for regtest with the bcrt prefix.
2018-02-26 03:09:15 +00:00
John Barboza b028a0a439 invoice: add fallback address to invoice command
* Modifies invoice command to have the following format
  invoice <msatoshi> <label> <desc> <?expiry> <?fallbackaddr>
* Adds support for Segwit bcrt1 addresses for withdraw
* Add test case for fallback address in invoice creation
* Create a common json_tok_address_scriptpubkey to be used
  by invoice and withdraw commands.
2018-02-26 03:09:15 +00:00
practicalswift bb12c234f2 Fix recently introduced PEP-8 violations 2018-02-24 11:44:32 +01:00
Christian Decker 330682abfe pytest: Remove any existing lightning-dirs before running
This was causing some issue when automatically rerunning tests on
travis.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-02-24 10:40:03 +01:00
Rusty Russell 737a7148b5 test_lightningd.py: make sure we recover from transient bitcoin failures.
We can do similar tricks to test other things, even to run without a
real bitcoind for faster testing, but for now we simply exit if a magic
file says so.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-24 10:37:28 +01:00
Rusty Russell 309dc96f97 fixup! More test fixups from last patch. 2018-02-23 18:02:00 +01:00
Rusty Russell cccdb53bec channel_states: fold all the ONCHAIND states into one.
The billboard is now far more useful to tell what's going on, and this
gets us closer to a state == owner mapping.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-23 18:02:00 +01:00
Rusty Russell 866ba00445 test_lightning.py: test in billboard in various closing cases.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-23 18:02:00 +01:00
practicalswift e18948a6a9 Remove unused variables. Fix flake8 warnings. 2018-02-22 22:21:31 +01:00
Rusty Russell b8c636514b pong: embed version string into ping replies if DEVELOPER=1.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-22 12:24:26 +01:00
Rusty Russell 85f1a9b825 lightningd: append (as much as we can) version into default name if DEVELOPER=1
This helps for bug reporting, where we may need to diagnose the other
end.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-22 12:24:26 +01:00
practicalswift ae7d857c44 Make Python code conform to the Python PEP 8 style guide 2018-02-22 10:47:19 +01:00
Rusty Russell b536e97df2 dev_ping: don't crash with silly values.
It's a dev command, but still.

Fixes: #985
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-22 01:10:09 +00:00
Rusty Russell 4cf274b1c0 lightningd/opening_control: routines to control openingd (move from peer_control.c)
We also fold opening_got_hsm_funding_sig() into the caller; it was
previously a callback before we decided to always use the HSM
synchronously.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-20 22:36:21 +01:00
Rusty Russell d47d85fa30 wallet: add list of upgrades.
Useful for debugging a db.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-20 01:38:32 +00:00
ZmnSCPxj ea3ee01215 peer_control: Support xxx@yyy:zzz form for connecting. 2018-02-19 11:59:11 +01:00
Rusty Russell 4653493507 test_lightningd: make test_payment_failed_persistence more reliable.
We don't want the invoice to fail locally, which can happen if we're
slow enough.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-19 02:56:51 +00:00
Rusty Russell e17b0ebcb4 channeld: map htlc add/remove errors to names.
I couldn't figure out what 'Bad peer_add_htlc: 7' meant!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-19 02:56:51 +00:00
Rusty Russell 8db8c51201 lightningd: struct uncommitted_channel for opening channels.
Each peer can have one 'uncommitted' channel, which is in the process
of opening.  This is used for openingd, and then on return we convert
it into a full-fledged struct channel and commit it into the database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-19 02:56:51 +00:00
Anton Astafiev 8787766d44 Pylightning (#1003)
* Fix dev_setfees to set slow and normal fees correctly.

Due to a bug def_setfees(100, slow=100) would instead set immediate and
normal fees to 100. This behavior has been updated to set fees to
correct values, make the values truly optional as per documentation and
unit test this behavior.

* Fix pay() to set msatoshi, description and risk factor properly

Due to a bug pay(invoice, description='1000') resulted in payment of
1000 msatoshi instead. This was fixed and covered with tests.

* Fix named args in listpayments, listpeers and connect

* Do not pass None to methods where it is default value

* Make description on invoice and pay match.

Suggested-by: @ZmnSCPxj

* Fix dev_setfees to set slow and normal fees correctly.

Due to a bug def_setfees(100, slow=100) would instead set immediate and
normal fees to 100. This behavior has been updated to set fees to
correct values, make the values truly optional as per documentation and
unit test this behavior.

* Fix pay() to set msatoshi, description and risk factor properly

Due to a bug pay(invoice, description='1000') resulted in payment of
1000 msatoshi instead. This was fixed and covered with tests.

* Fix named args in listpayments, listpeers and connect

* Do not pass None to methods where it is default value

* Make description on invoice and pay match.

Suggested-by: @ZmnSCPxj
2018-02-16 22:40:55 +01:00
Rusty Russell 43ec3f0761 jsonrpc: allow multiple commands in-flight from single JSON connection.
We now keep a list of commands for the jcon instead of a simple
'current' pointer: the assertions become a bit more complex, but
the rest is fairly mechanical.

Fixes: #1007
Reported-by: @ZmnSCPxj
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-16 17:51:04 +01:00
ZmnSCPxj 0489c7eb93 test_lightningd: Change test_pay0 to use sendpay. 2018-02-16 13:08:29 +01:00
ZmnSCPxj d9163dbb4f test_lightningd: Modify test to remove repeated pay attempt. 2018-02-16 13:08:29 +01:00
Rusty Russell df4c669a60 test: test for funds sent while we were offline.
As described by @lvaccaro in #990.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-16 13:07:12 +01:00
Rusty Russell c8f9ea7bf7 fixup: test_multirpc does not terminate.
We need to set expiry, otherwise waitinvoice would take 1 hr, and we
can't read once for every cmd, since each read may consume more than
a single result, and we block.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-16 12:56:48 +01:00
Christian Decker cab7e3e43a pytest: Add failing test with JSON-RPC requests crossing each other
Suggested-By: @ZmnSCPxj
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-02-16 12:56:48 +01:00
Rusty Russell a08bcfdbd3 jsonrpc: don't crash on multiple commands at once.
Once we read a command, we are supposed to io_wait until it finishes.
However, we are actually woken in two places: when it's complete
(which is correct), and when it's written out (which is wrong).

We don't care when it's written out, only when it's finished:
refactor to make json_done() free and NULL the old ->current,
rather than have the callers do it.  Now it's clear that it's
ready for both new output and new input.

Fixes: #934
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-16 12:56:48 +01:00
Christian Decker db5c0aa6c1 pytest: Make pep8 happy(er)
A number of fixes to make our code more pythonic
Signed-off-by: Christian Decker <decker.christian@gmail.com>
Co-authored-by: Guido Dassori @gdassori
2018-02-15 23:56:38 +00:00
Christian Decker 0e40b9b08c pylightning: Switch to dict-based params instead of positional
Signed-off-by: Christian Decker <decker.christian@gmail.com>
Co-authored-by: Guido Dassori @gdassori
2018-02-15 23:56:38 +00:00
Rusty Russell d822ba1eee lightningd: allow a new channel open from peer if no *active* channels.
And return the correct error message for the channel they give, if
they try to re-establish on an error channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-14 11:31:58 +01:00
Rusty Russell e20fff9340 lightningd: remove almost all other peer2channel / channel2peer shims.
This final sweep only keepl peer2channel within peer_control.c for
the reconnect case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-14 11:31:58 +01:00
Rusty Russell 32411de90e lightningd: split struct peer into struct peer and struct channel.
Much like the database; peer contains id, address, channel contains
per-channel information.  Where we create a channel, we always create
the peer too.

For the moment, peer->log and channel->log coexist side-by-side, to
reduce some of the churn.

Note that this changes the API to dev-forget-channel: if we have more
than one channel, we insist they specify the short-channel-id.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-14 11:31:58 +01:00
Christian Decker 96667a3028 fixup! pytest: Test storing last_htlc_sigs and onchaind fund recovery 2018-02-11 01:13:07 +01:00
Christian Decker ea9aa95625 pytest: Test storing last_htlc_sigs and onchaind fund recovery
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-02-11 01:13:07 +01:00
Rusty Russell d5effcb961 test_lightning: fix race on testing, esp. test_closing_different_fees.
We get intermittant failure: WIRE_UNKNOWN_NEXT_PEER (First peer not ready)
because CHANNELD_NORMAL and actually telling gossipd that the channel
is available are distinct things: we need both.

(For test_closing_different_fees, we were testing CHANNELD_NORMAL on
the peer, not on l1, too).

But we may also directly send the announcement sigs if the height is
sufficient, so the simplest is to unify the messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-09 13:01:19 +01:00
practicalswift 4f4756bd20 Fix a-vs-an typos 2018-02-08 22:49:34 +01:00
Rusty Russell cc9ca82821 status: separate types for peer failure vs "impossible" failures.
Ideally we'd rename status_failed() to status_fatal(), but that's
too much churn for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-08 19:07:12 +01:00
Rusty Russell 6ca0c6e0ec test_lightningd: race fix for activation of channels in test_gossip_jsonrpc
```
>       assert [c['active'] for c in l2.rpc.listchannels()['channels']] == [True, True]
E       AssertionError: assert [True, False] == [True, True]
E         At index 1 diff: False != True
E         Full diff:
E         - [True, False]
E         + [True, True]
```

We don't actually wait that l2's gossipd has also processed the message.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-08 19:07:12 +01:00
Christian Decker b3d4e161b5 pytest: Add test for `dev-forget-channel`
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-02-07 00:47:13 +00:00
Rusty Russell d77972e827 test_lightningd.py: test io logging and toggling with SIGUSR1
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-07 00:46:49 +00:00
ZmnSCPxj 711d8822b0 test_lightning: Update to new error message format. 2018-02-06 17:05:12 +01:00
Rusty Russell b3534462e0 test_lightningd.py: fix race in test_fee_limits.
Sometimes the super-low-fee commitment tx succeeds, and we see
that 'sendrawtx exit 0' instead of the one we're expecting.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-06 02:50:30 +00:00
Rusty Russell 07c275e436 test_lightningd: fix race in test_closing_different_fees
fundrawtransaction returns before the actual sendrawtx, so we can
end up mining blocks before it's sent, thus not having enough confirms.

We handle this correctly in fund_channel, but this test open-codes it
for speed with multiple peers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-06 02:50:30 +00:00
ZmnSCPxj dcafce81ad test_lightningd: Increase times in expiration waiting test.
Fixes: #916

Makes it less flaky, as, the increased times reduce the
relative delay in processing by slower machines.
2018-02-06 02:50:30 +00:00
Rusty Russell 37670c04e0 test_lightning.py: disable test which needs bitcoind 0.16 (for now!)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-06 01:37:58 +00:00
William Casarin 3d27bbb47d test: test_bech32_funding
1. Test wallet funding to a bech32 p2wpkh address
2. Test channel opening with this address

Signed-off-by: William Casarin <jb55@jb55.com>
2018-02-06 01:37:58 +00:00
William Casarin 0e59e091e7 test: switch invoice tests to use proper bip173 name
Signed-off-by: William Casarin <jb55@jb55.com>
2018-02-06 01:37:58 +00:00
Christian Decker 81551b2e60 pytest: Increate timeout when waiting for gossip
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-02-05 18:28:39 +00:00
Christian Decker 739e78a8c7 gossip: Reduce verbosity
Now we only report serious failures, or messages that actually changed
the local view.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-02-05 18:28:39 +00:00
ZmnSCPxj 0925e404d6 test_lightningd.py: Test new expiration system in more detail. 2018-02-05 08:52:42 +00:00
ZmnSCPxj 4ac5d123d6 test_lightningd: Test missing arguments. 2018-02-02 23:45:18 +00:00
Rusty Russell a497a9943d test_lightning.py: speed up test_closing_different_fees
It was taking over 10 minutes under valgrind, causing Travis to time it out.

This shrinks it to its essential tests, and also batches.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 20:33:49 +01:00
Rusty Russell f527f39613 test_lightning: add tests for closing with differetn feerates.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 20:33:49 +01:00
alaniz b7856e3512 Onboarding: tweak grammar conventions for RPC responses 2018-02-02 06:16:23 +00:00
Rusty Russell d1ab2e05f4 test_lightningd.py: test lightning-cli.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 00:05:00 +01:00
Rusty Russell 327e2b8fd8 JSONRPC: listconfigs command.
With the new 'human-readable' mode of lightning-cli, this actually produces
a valid config file.  It's a bit hacky though...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 00:05:00 +01:00
Rusty Russell 0600aac68f lightningd: rename --no-reconnect to --dev-no-reconnect.
It's a dev option.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-02-02 00:05:00 +01:00
cornwarecjp 6112df3a90 Bring back the time-out on the start-up of bitcoind, but make it 60 seconds instead of the original 10 seconds. This is much larger than the normal start-up time of bitcoind (so we should never hit the time-out), but still lets a test terminate in a reasonable time in the unlikely case that bitcoind hangs. 2018-02-01 23:00:43 +01:00
cornwarecjp 896f7ef37d Make it possible to run the test suite in Python 3.4 (bytes.hex was introduced in 3.5) 2018-02-01 23:00:43 +01:00
cornwarecjp 0b0708d86a Bitcoind should always eventually finish starting, but there is no guarantee on how long it takes, so don't apply a time-out. In case bitcoind hangs indefinitely, the test will hang indefinitely too, but this should be solved in bitcoind, not in the test code. 2018-02-01 23:00:43 +01:00
cornwarecjp 859070a5ed Terminate LightningD if, for some reason, it doesn't start properly. This cleans up the environment for future test runs. 2018-02-01 23:00:43 +01:00
cornwarecjp 71581ff96e Terminate BitcoinD if, for some reason, it doesn't start properly. This cleans up the environment for future test runs. 2018-02-01 23:00:43 +01:00
ZmnSCPxj 87726d5b89 test_lightningd: Add test for reporting routing failures 2018-02-01 00:46:06 +00:00
ZmnSCPxj 131283af6e test_lightningd: Move 0-payment test to its own test. 2018-02-01 00:46:06 +00:00
gdassori 72dd1461a0 async param is unwanted here 2018-01-31 12:38:18 +01:00
gdassori b9b0b7ebe0 fix LightningRpc signatures according to tests 2018-01-31 12:38:18 +01:00
Rusty Russell 9825dddd18 test_lightning: test that we unwatch txs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-31 11:37:22 +01:00
Rusty Russell 6d0fd84c63 walletrpc: don't assert() when we pay ourselves.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-31 11:37:22 +01:00
Rusty Russell 0d3eaef945 tests: add argument to is_in_log so we can check only recent log entries.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-31 11:37:22 +01:00
Rusty Russell dd044f826b channeld: handle unexpected messages better.
In particular, decode error messages correctly and do the right thing with
messages about other channels.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-30 19:47:27 +00:00
windsok fc73b1eb72 remove stray semicolons in python tests 2018-01-30 08:11:51 +00:00
practicalswift 7e8f1945f2 Adjust tests to new log text 2018-01-29 03:22:27 +00:00
practicalswift 689db5b7c1 Onboarding: Make log output texts friendlier to new users 2018-01-29 03:22:27 +00:00
Christian Decker 45c935ddba pytest: Have the db_query helper work on a copy of the DB
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-27 02:27:35 +00:00
Christian Decker 2e5047f74b pytest: Fix test_pay_disconnect
We are now too quick in disabling the channel for us to attempt a
payment. We need to separate into getroute and sendpay to trigger this
now.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-26 01:09:44 +00:00
Christian Decker dafd000c2a pytest: Check that we disable on closing and permfail.
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-26 01:09:44 +00:00
Rusty Russell e66bd25b5c test_lightningd.py: test lockin while we're not running.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-25 12:52:06 +01:00
Christian Decker 7b0d806d71 pytest: Check that we forget irrevocably settled channels
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-25 00:14:23 +00:00
Rusty Russell f03dbde354 test_lightningd.py: Test 0-msatoshi pay
Based-on-patch-by: ZmnSCPxj <ZmnSCPxj@protonmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-24 19:34:46 +01:00
practicalswift 96d093fb30 Fix typos 2018-01-24 17:29:40 +01:00
Christian Decker ee850f38d6 pytest: Fix test_fee_limits
This was flaky because we didn't wait for the fee update to complete
and were using the old, way too small, fees, which upset bitcoind.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-19 22:26:58 +00:00
Rusty Russell 8797159825 Use consistent names for timestamps.
Old fields still there, just deprecated.

Invoice commands:
	paid_timestamp -> paid_at
	expiry_time -> expires_at

decodepay:
	timestamp -> created_at

getlog:
	creation_time -> created_at

listpayments:
	timestamp -> created_at

Suggested-by: @shesek
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 4f1dc91ba5 lightningd: rename --deprecated-apis to --allow-deprecated-apis.
Suggested-byL practicalswift
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Christian Decker 0c9d29065c pytest: Remove some debug print statements 2018-01-19 22:23:45 +00:00
Christian Decker b8b4998f7a pytest: Temporarily disable alias and color checking for DEVELOPER=0
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-19 22:23:45 +00:00
Rusty Russell 5e0a5c9111 JSONRPC: delinvoice: have a status argument.
delinvoice was orginally documented to only allow deletion of unpaid
invoices, but there might be reasons to delete paid ones or unexpired ones.

But we have to avoid the race where someone pays as it's deleted: the
easiest way is to have the caller tell us the status, and fail if
it's wrong.

Fixes: #477
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell c8c68cfb7c JSONRPC: listpeers multiple channels, output improvements.
We're going to have to support multiple channels per peer, even if only
when some are onchain.  This would break the current listpeers, so
change it to an array (single element for now).

Other cleanups:

1. Only set connected true if daemon is not onchaind.
2. Only show netaddr if connected; don't make it an array, call it `address`
   in comparison with `addresses` in listnodes.
3. Rename `channel` to `short_channel_id`
4. Add `funding_txid` field for voyeurism.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 78672738ff test_lightningd.py: remove deprecated APIs.
Individual tests can always re-enable them, though.

[ More test fallout fixes by Christian Decker ]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell bd010d4b96 listinvoices: deprecate 'complete' in favor of 'status' trinary.
[ Manpage regen fixup by Christian Decker ]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 67b7362986 test_lightningd.py: switch to listinvoices instead of listinvoice.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 962514c3a0 addfunds: remove.
We now detect funds, so this is just confusing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 2f2cacef0d JSONRPC: output from listpeers should be 'id' not 'peerid'.
That's what we use everywhere else.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 5698a133c2 JSONRPC: rename getpeers to listpeers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 34a994c7db JSONRPC: listpayments not return a naked array.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 6e703ad977 JSONRPC: listpayments can list just a specific bolt11 or payment_hash.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 06c4f6ddca JSONRPC: add optional short_channel_id argument to listchannels
In order to just list one (though it may return two entries, one for each
channel direction!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell 7fdb30cbda JSONRPC: rename getchannels to listchannels
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell e1e7f289fb JSONRPC listnodes: return timestamp, alias and color.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
Rusty Russell ced572b973 JSONRPC: getnodes: rename to listnodes.
Like listinvoice, and add optional 'id' parameter to ask about a
specific node.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-19 22:23:45 +00:00
practicalswift aefc887521 Fix typos 2018-01-18 20:50:07 +01:00
ZmnSCPxj a88c73a41b invoices: Add `paid_timestamp` field.
Fixes: #615
2018-01-18 17:37:10 +01:00
Rusty Russell 15aaf9f49a test_lightning.py: shutdown tail thread before killing.
Seems to avoid the nasty python resource warnings, as well as the
fatal 'ValueError: PyMemoryView_FromBuffer(): info->buf must not be NULL'

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-17 23:55:35 +01:00
Rusty Russell 4b178621e2 test_lightningd.py: test that payments are pending even before HTLC committed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-17 23:55:35 +01:00
Rusty Russell 469faa476e test_lightning.py: test for persistence.
Also note that failing an in-progress payment (instead of waiting) is
pretty weird.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-17 23:55:35 +01:00
Christian Decker ad5eb1f7e1 pytest: Skip test_fee_limits for DEVELOPER=0
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-16 12:22:06 +01:00
Rusty Russell 79dc44713b channeld: --ignore-fee-limits as a hack for fee disparities.
This, of course, should never be used.  But it helps maintain connections
for the moment while we dig deeper into feerates.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-16 12:22:06 +01:00
practicalswift 145e26371d Add test for too-short decodepay (credit: @ZmnSCPxj) 2018-01-15 19:32:00 +00:00
Rusty Russell fc151e10cd test_lightning.py: check error on too-large funding tx.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-15 12:45:12 +01:00
Christian Decker 6f4fca3a6f pytest: Verify that we forget nodes that have no channels anymore
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-14 23:40:04 +00:00
Christian Decker 4fe83cd405 pytest: Test for channel removal in test_gossip_pruning
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-14 23:40:04 +00:00
Christian Decker 6e001d88c2 pytest: Add simple gossip pruning test
For now this just tests that we are sending out keepalive
channel_updates for all local channels.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-14 23:40:04 +00:00
Rusty Russell a1a0b33577 pay: allow 'null' msatoshi field.
Since most callers use positional arguments, we should allow a 'null'
literal where we require no value at all.

Also adds some more value tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-14 23:10:10 +00:00
Rusty Russell 2f2fb0c2a1 invoice: add msatoshi_received field.
Paid invoices need to know how much was actually paid: both for the case
where no 'msatoshi' amount was specified, and for the normal case, where
clients are permitted to overpay in order to help them disguise their
payments.

While we migrate the db, we leave this field as 0 for old paid
invoices.  This is unhelpful for accounting, but at least clearly
indicates what happened if we find this in the wild.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-14 23:10:10 +00:00
Rusty Russell 66885163c9 JSON: Rename rhash to payment_hash in delinvoice, invoice, listinvoice, waitinvoice, waitanyinvoice.
'rhash' is the old terminology, but 'payment_preimage' and
'payment_hash' were decided on for the BOLTs, so we should fix that here.

We still use rhash internally, but that's much easier to fix.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-14 23:10:10 +00:00
Rusty Russell 7c5dec01fe test_lightning.py: use wait_for_routes() helper more widely.
It uses the correct method to avoid races, so use it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-13 00:40:10 +01:00
Rusty Russell 6cea8d2e5b test_lightning.py: test_onchain_middleman must wait for route propagation
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-13 00:40:10 +01:00
Rusty Russell 6a1ea14441 test_lightningd.py: make sure l2 has seen announcements in test_gossip_jsonrpc
>       assert [c['active'] for c in l2.rpc.getchannels()['channels']] == [True, True]
E       AssertionError: assert [False, True] == [True, True]
E         At index 0 diff: False != True
E         Full diff:
E         - [False, True]
E         + [True, True]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-13 00:40:10 +01:00
Rusty Russell 6b7b7f1007 test_lightningd.py: fix timing error in test_forward_different_fees_and_cltv
We need to make sure all the updates are known to gossip.  Since
one is the local update, we change that message to look the same.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Rusty Russell d84dc5633a test_lightning.py: make sure gossip has processed channel_updates.
Receiving them in channeld is not enough to avoid the race:

    route = l1.rpc.getroute(l3.info['id'], 4999999, 1)["route"]
...
    ValueError: RPC call failed: Could not find a route

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Rusty Russell 896ecb4da7 test_lightning: don't fire prematurely on test_gossip_jsonrpc.
We wait the the receipt of the CHANNEL_UPDATE message by channeld,
but that doesn't mean it reached gossipd yet, causing spurious test
failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Rusty Russell a4dd523c8b test_lightning.py: fix ambigious log order in test_reconnect_signed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Igor Cota e97857847a peer_control: make hardcoded feerates consistent between json_fund_channel and peer_offer_channel
Stops some transactions from failing on the other side due to insufficient funds.
2018-01-12 03:40:31 +00:00
ZmnSCPxj 5f8796af0c test_lightningd.py: Add tests for any-amount invoices. 2018-01-12 01:43:55 +00:00
Rusty Russell bc4f2da50a test_lightning.py: make sure reconnect doesn't leave multiple peers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:47:47 +01:00
Rusty Russell 43c97187a4 test_lightningd: fix test_gossip_jsonrpc.
A watch constant never changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell 7e0bc88e2a gossip: fix default broadcast interval, move option.
This now makes a few more gossip tests time out without --dev-broadcast-interval

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Christian Decker 90527498bc pytest: Do not re-print logs if we failed to find a log entry
CI always runs with TEST_DEBUG=1 which prints logs anyway, and testing
locally should also be done this way, combined with pytest which
captures the logs. No need to duplicate the functionality of pytest.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-10 03:52:46 +00:00
Christian Decker d0da8a1035 pytest: Remove unused breakpoint shorthand
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-10 03:52:46 +00:00
Christian Decker 55d2e4b1d0 pytest: Spawn a new bitcoind for each test
Since we seem to have some isolation concerns when re-generating the
same HSM secret and re-parsing the blockchain some blocks in the past.

This also alleviates the problem of printing to a logging stream that
has been closed. Previously bitcoind would keep running despite a test
had failed and continue logging to the, now closed, StringIO that
py.test uses when capturing stdout.

The performance impact seems to be 1-3 second per test, not too bad
IMHO for increased test isolation and cleaner logs:

|--------------------+---------------+----------|
|                    | No_valgrind   | Valgrind |
|--------------------+---------------+----------|
| bitcoind per suite | 10 min 24 sec | 46:15.31 |
| bitcoind per test  | 11 min 38 sec | 49:21.64 |
|--------------------+---------------+----------|

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-10 03:52:46 +00:00
Rusty Russell a8de8a3140 json_getchannels: add public flag.
Fixes: #509
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-08 18:09:31 +01:00
Christian Decker 5c91a3449a pytest: Add withdraw test after permfail to test unilateral_close
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-08 17:19:25 +01:00
Christian Decker 85eb743e02 wallet: Detect close transactions and track their outputs in DB
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-08 17:19:25 +01:00
Christian Decker 3e0efb6f8d pytest: Avoid leaking stdout fds 2018-01-08 14:36:33 +01:00
practicalswift 6757255ba4 Use deterministic command-line ordering when executing lightningd from tests 2018-01-07 17:28:34 +01:00
practicalswift d9266afcda Fix typo: "disonnect" 2018-01-07 13:01:09 +01:00
Rusty Russell 824f8517ac onchaind: fix all_irrevocably_resolved test.
I was examining a test_onchain_timeout failure, and realized that we
were forgetting a peer even though we'd just spent the HTLC_TIMEOUT_TX!

This reveals that we weren't resolving an output when we stole the preimage
from it, like we should.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-05 16:08:50 +01:00
Rusty Russell fb81e6c14b chaintopology: always start 100 blocks back.
Since we panic when we see our root reorg out, even if we're not doing
anything yet, restoring the 100 block margin is the simplest fix.

Unfortunately this means adding a 100-block spacer in the tests, so things
don't get confused.

Fixes: #511
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-05 15:05:21 +01:00
Rusty Russell 822a2cf030 test_lightningd: make sure we keep watching after peer restart.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-05 15:05:21 +01:00
ZmnSCPxj 5eceaa7be9 invoice: Modify waitanyinvoice interface to use pay_index. 2018-01-03 01:12:49 +00:00
practicalswift 3d39312212 Fix typos 2018-01-02 15:09:36 +01:00
Rusty Russell b7e8ee4445 test_lightningd: make sure onchaind recognizes outputs in htlc onchain tests.
We stopped too early; we should continue and make sure it all goes well.

This means we have to fix them to be deterministic: by generating 2
blocks at once in test_htlc_in_timeout, we raced between fulfill and
timeout on the HTLC.  Now it's always fulfilled.

Also, fixed confusing comments: l1 doesn't drop to chain.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-02 13:21:25 +01:00
Rusty Russell 72a52b0b59 onchaind: fix label on HTLC timeout tx.
OUR_HTLC_TIMEOUT_TO_US = normal tx, used to timeout htlc in their commit tx.
OUR_HTLC_TIMEOUT_TX = dual-sig tx with delay, used to timeout htlc in our commit tx.

Only one test looks at that string, so fix that too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-02 13:21:25 +01:00
ZmnSCPxj 280c0e53ef test_lightningd.py: Add test for waitinvoice. 2018-01-02 00:36:16 +00:00
ZmnSCPxj 7f24e36dd9 test_lightningd.py: Test paying invoice in reverse order of creation. 2018-01-01 23:13:31 +00:00
ZmnSCPxj ea1cea6366 wallet: Minor testing of pay_index column. 2018-01-01 23:13:31 +00:00
practicalswift 6c50d70e68 Remove trailing semicolons in Python code 2017-12-28 19:29:58 +01:00
Christian Decker a44e1e456f pytest: remove useless debugging print 2017-12-23 14:51:33 +01:00
Christian Decker 71c62e726e fixup! pytest: Temporarily disable test_reconnect_normal due to flakyness 2017-12-23 06:15:33 +00:00
Christian Decker 45691a50b8 pytest: Temporarily disable test_reconnect_normal due to flakyness
The test_reconnect_normal test is failing rather consistently on 32bit
architectures, disabling to reduce noise. Issue #468 tracks progress.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-12-23 06:15:33 +00:00
Christian Decker 2a7ba010c3 pytest: Use the bitcoind config file to read RPC params from
With python-bitcoinlib==0.9.0 it appears that the URL based auth
information is no longer used, so we fall back to reading the config
file for the bitcoind daemon instead.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-12-23 06:15:33 +00:00
Rusty Russell 31153e9506 test_lightning.py: fix running test_withdraw twice.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-20 12:56:15 +01:00
Rusty Russell e695e5db09 lightningd: require explicit LIGHTNINGD_DEV_MEMLEAK env var to do memleak.
Otherwise every allocation and free is slowed down.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-20 12:43:10 +01:00
Rusty Russell 6b9c525f35 lightningd: use env var not cmdline to suppress backtrace.
We now set it up *before* parsing cmdline, so this is more convenient.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-20 12:43:10 +01:00
Christian Decker ed9e580358 pytest: test_shutdown requires DEVELOPER=1
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-12-20 12:43:10 +01:00
Rusty Russell ed7108df15 test_lightningd.py: fail if nodes leak.
killall() was pretty broken, so I had to rewrite it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-20 12:43:10 +01:00
Christian Decker 1ec916076f pytest: Change test_gossip_jsonrpc to cover local-only gossip
Relatively simple: until we reach funding-depth the channels should be
known locally, so we can already route through them, but they should
not be announced to peers to which the connection is non-local.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-12-20 06:14:53 +00:00
Rusty Russell 3da93319fb withdraw: make rpc call accept 'all' as a value.
Closes: #409
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-20 01:41:22 +00:00
Rusty Russell 477a529856 pay: make sure we don't think payment in progress if it immediately fails.
If send_htlc_out() fails, it doesn't initialize pc->out; that can
make us think it's still in progress.

Reported-by: Jonas Nick
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-19 14:40:26 +01:00
Christian Decker e154f4a019 pytest: Minor cleanup
Now using assertRaisesRegex instead of try-except and added restart to
nodes.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-12-17 02:44:20 +00:00
Christian Decker 32a96973a5 pytest: Fix a flaky channel_reenable test
It was relying on the message order instead of waiting the desired
state.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-12-17 02:44:20 +00:00
Rusty Russell 67aa95c194 gossipd: hand back peer, don't hand a new peer.
All peers come from gossipd, and maintain an fd to talk to it.  Sometimes
we hand the peer back, but to avoid a race, we always recreated it.

The race was that a daemon closed the gossip_fd, which made gossipd
forget the peer, then master handed the peer back to gossipd.  We stop
the race by never closing the gossipfd, but hand it back to gossipd
for closing.

Now gossipd has to accept two fds, but the handling of peers is far
clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-17 02:44:20 +00:00
Rusty Russell 8ed511b3c7 test_lightningd: add test for funding failures.
We should not disconnect from a peer just because it fails opening; we
should return it to gossipd, and give a meaningful error.

Closes: #401
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-17 02:44:20 +00:00
ZmnSCPxj 44c37b60e4 Add test for withdrawing to P2WPKH and P2WSH. 2017-12-14 03:36:40 +00:00
ZmnSCPxj 757d45c8a3 Test withdrawal to P2SH address. 2017-12-13 03:10:04 +00:00
Rusty Russell 0610f66c34 bolt11: handle r value fee spec change.
We don't use it yet, but now we'll decode correctly.

See: https://github.com/lightningnetwork/lightning-rfc/pull/317
lightning-rfc commit: ef053c09431442697ab46e83f9d3f86e3510a18e

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-12 11:45:44 +01:00
practicalswift 61c47c09d0 Fix typos 2017-12-08 13:07:20 +01:00
Rusty Russell 5444084625 onchaind: fix reversed CSV delays.
Our config -> their CSV delay, their config -> our CSV delay.

Fixes: #395
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-04 13:00:57 +01:00
Rusty Russell af5dbbc9f8 json_connect: separate port arg so we can parse IPv6 addresses.
Fixes: #391
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-04 11:15:59 +01:00
Rusty Russell 70cebb8653 test_addfunds_from_block: fix test flakiness.
If you run locally, it fails occasionally; presumably because it
sees previous funds.  Use a random HSM key for that teste.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-12-02 12:52:18 +01:00
Christian Decker 12944ffc9b pytest: Switch to 'Hello world' as startup marker
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-29 14:39:12 +01:00
Christian Decker 88ecae301c pytest: Add a test for funds coming from blocks
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-29 14:39:12 +01:00
Rusty Russell cfde208e82 tests: prepare for bitcoind 0.16.
I noticed some breakage with git master:
1. getinfo no longer supported (for us, use getblockchaininfo)
2. generate no longer supported (use generatetoaddress)

Both these options are supported at least in 0.15, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-28 12:15:22 +01:00
Christian Decker 547d3f0a0b pytest: Attempting to fix the flaky gossip test
This seems to happen when we manage to check between the
channel_announcement and the channel_update being processed.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-23 23:45:28 +00:00
Christian Decker 25725c0aa4 pytest: Add benchmarks for direct payments
Add two simple tests: one for a single direct payment and one with
hundreds of parallel payments, reusing the same route.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-23 23:45:28 +00:00
Rusty Russell 6c79550c22 test_lightningd.py: test updating feerates.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 88af0f5bf8 tests: change --override-fee-rate to --override-fee-rates and use in tests.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 12:40:32 +01:00
Rusty Russell 35a6ab8151 invoice: don't allow payments in expired invoices.
Fixes: #363
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-23 00:11:04 +01:00
Christian Decker 4d8ad4e17d pytest: Test that upon reconnect the channel gets re-enabled
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-20 06:13:45 +00:00
Christian Decker f524df721d pytest: Add test for waitanyinvoice
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-15 00:07:44 +00:00
Christian Decker 07e5a9ef9f htlc: Allow for exactly min_final_cltv_expiry cltv delta
We are announcing that we are willing to accept incoming payments with
current_height + min_final_cltv_expiry + slack, assuming that the
sender adds some slack. In particular we'd reject the payment if
slack=0 which is allowed by the spec.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-11 01:28:03 +00:00
Christian Decker d6af14a869 pytest: Valgrind errors trump exit value errors
Raising the exception about non-zero exit values into the
teardown. This was previously masking the valgrind errors. Now
valgrind errors > crash errors > non-zero return value.

Still hoping to catch that elusive [7, 0] return value on travis.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-11-10 02:20:00 +00:00
Rusty Russell 8cef36cbd7 lightningd: fail htlcs we fulfill if peer unresponsive after deadline.
Closes: #241
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell 1142c44c29 lightningd: fail htlcs we offer if peer unresponsive after deadline.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell c14b159166 lightningd: remove --deadline-blocks option.
We will derive it from other factors.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-03 05:18:49 +00:00
Rusty Russell e1dc75e954 pay: new all-in-one RPC command.
Closes: #240
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell d577769350 invoice: provide bolt11 invoice.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 8d09734536 bolt11: add decodepay RPC helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 7ed81cdf7b pay: factor out actual payment sending from json part of sendpay.
We're going to reuse this for the new 'pay' all-in-one command.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-11-01 01:09:23 +00:00
Rusty Russell 0000dc5908 lightningd: Allow in excess of ctlv_expiry.
We add a test which both overpays and over-sets the delta on the
intermediate and final nodes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-31 14:36:50 +01:00
Rusty Russell 71e794a046 lightningd: split ctlv_expiry and final_cltv.
These need to be different for testing the example in BOLT 11.

We also use the cltv_final instead of deadline_blocks in the final hop:
various tests assumed 5 was OK, so we tweak utils.py.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-31 14:36:50 +01:00
Rusty Russell b257b8960b test_lightning.py: more debugging for the tx decoding fail under travis.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-31 04:14:33 +00:00
Rusty Russell 390bf6359e test_lightning.py: don't get confused by valgrind core files.
I run with ulimit -c unlimited, and valgrind leaves core files like
valgrind-errors.22114.core.22114 which test_lightning.py tries to
parse as log files.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-31 04:14:33 +00:00
Rusty Russell bc9918ad46 dev: option not to do backtracing.
It crashes under valgrind, causing a valgrind error: valgrind gives us a
backtrace anyway, so we don't need it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-31 04:14:33 +00:00
Rusty Russell 2aadd351f8 test_lightningd.py: more information when we fail to find payment.
Travis has been hitting this intermittantly, can't reproduce here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-28 13:33:00 +02:00
Rusty Russell 0c7ca9ab7c gossipd: call to return all connected peers.
And we report these through the getpeers JSON RPC again (carefully: in
our reconnect tests we can get duplicates which this patch now filters
out).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-26 21:01:09 +00:00
Rusty Russell 3c6eec87e3 Add DEVELOPER flag, set by default.
This is a bit messier than I'd like, but we want to clearly remove all
dev code (not just have it uncalled), so we remove fields and functions
altogether rather than stub them out.  This means we put #ifdefs in callers
in some places, but at least it's explicit.

We still run tests, but only a subset, and we run with NO_VALGRIND under
Travis to avoid increasing test times too much.

See-also: #176
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-26 12:53:09 +02:00
Rusty Russell b6a2b8c58b Add --rgb and --alias options.
And derive random ones from nodeid if they don't choose.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-25 09:16:14 +00:00
Rusty Russell 66a0c55322 test_lightning.py: fix float insanity with values.
When is 0.01 != 0.01?  When there are floats involved!  Jenkins hit an
error once, I have no idea why.

This works around the following intermittant error:

ERROR: test_closing_negotiation_reconnect (__main__.LightningDTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "tests/test_lightningd.py", line 1601, in test_closing_negotiation_reconnect
self.fund_channel(l1, l2, 10**6)
File "tests/test_lightningd.py", line 241, in fund_channel
raise ValueError("Can't find {} payment in {}".format(amount, tx))
ValueError: Can't find 1000000 payment in 02000000000101b0b27be92916faee59f197c263e1ae7b44c0e59acdf2c385c55b5b04670ac026010000001716001401fad90abcd66697e2592164722de4a95ebee165ffffffff02651d0f0000000000160014c2ccab171c2a5be9dab52ec41b825863024c546640420f00000000002200205b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cd02473044022017bd19a0ee85532f67a280c71ed02d1321f08975334bd281527478022265225702202ec448bf9c0890a31a26f0ef4f03d298c8ec16b277faff09a70ddd335df44b6e012103d745445c9362665f22e0d96e9e766f273f3260dea39c8a76bfa05dd2684ddccf00000000

For testing, that tx decodes to:
{
  "txid": "0165e92be762b352b665b76b9872d5189e1b2a8faf4918ab3cca7cd5d4b6a5fa",
  "hash": "8af9a36c79ee5243468c5cbed1c80f10238fba405f0ad957a0c2cfc46fb632f5",
  "version": 2,
  "size": 257,
  "vsize": 176,
  "locktime": 0,
  "vin": [
    {
      "txid": "26c00a67045b5bc585c3f2cd9ae5c0447baee163c297f159eefa1629e97bb2b0",
      "vout": 1,
      "scriptSig": {
        "asm": "001401fad90abcd66697e2592164722de4a95ebee165",
        "hex": "16001401fad90abcd66697e2592164722de4a95ebee165"
      },
      "txinwitness": [
        "3044022017bd19a0ee85532f67a280c71ed02d1321f08975334bd281527478022265225702202ec448bf9c0890a31a26f0ef4f03d298c8ec16b277faff09a70ddd335df44b6e01",
        "03d745445c9362665f22e0d96e9e766f273f3260dea39c8a76bfa05dd2684ddccf"
      ],
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00990565,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 c2ccab171c2a5be9dab52ec41b825863024c5466",
        "hex": "0014c2ccab171c2a5be9dab52ec41b825863024c5466",
        "type": "witness_v0_keyhash"
      }
    },
    {
      "value": 0.01000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 5b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cd",
        "hex": "00205b8cd3b914cf67cdd8fa6273c930353dd36476734fbd962102c2df53b90880cd",
        "type": "witness_v0_scripthash"
      }
    }
  ]
}

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-24 16:12:22 +02:00
Rusty Russell c2dd0cb295 test_lightningd.py: return short channel id from fund_channel helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-24 16:12:22 +02:00
Rusty Russell c3bed51b2d test_lightningd.py: make HSM seeds constant for tests.
Makes it easier to compare before/after failures.  Ideally, we should
run under Travis both with this option and with the seed based on the
entire tmp path (which is still reproducible with determination, but
not fixed every run like this is).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-24 16:12:22 +02:00
Rusty Russell 5a256c724a subd: simplify and cleanup lifetime handling.
There are now only two kinds of subdaemons: global ones (hsmd, gossipd) and
per-peer ones.  We can handle many callbacks internally now.

We can have a handler to set a new peer owner, and automatically do
the cleanup of the old one if necessary, since we now know which ones
are per-peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-20 18:31:32 +02:00
Rusty Russell 474887512d gossipd: rewrite to do the handshake internally.
Now the flow is much simpler from a lightningd POV:

1. If we want to connect to a peer, just send gossipd `gossipctl_reach_peer`.
2. Every new peer, gossipd hands up to lightningd, with global/local features
   and the peer fd and a gossip fd using `gossip_peer_connected`
3. If lightningd doesn't want it, it just hands the peerfd and global/local
   features back to gossipd using `gossipctl_handle_peer`
4. If a peer sends a non-gossip msg (eg `open_channel`) the gossipd sends
   it up using `gossip_peer_nongossip`.
5. If lightningd wants to fund a channel, it simply calls `release_channel`.

Notes:
* There's no more "unique_id": we use the peer id.
* For the moment, we don't ask gossipd when we're told to list peers, so
  connected peers without a channel don't appear in the JSON getpeers API.
* We add a `gossipctl_peer_addrhint` for the moment, so you can connect to
  a specific ip/port, but using other sources is a TODO.
* We now (correctly) only give up on reaching a peer after we exchange init
  messages, which changes the test_disconnect case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-20 18:31:32 +02:00
Rusty Russell 2273ce783e dev_disconnect: support multiple disconnects in the same daemon.
We currently assume the daemon gives up; gossipd won't, and we want to
test it there too.

This reveals a bug (returning io_close() is bad if the call is to
duplex()), and breaks a test which now continues after dropping a
packet..

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-20 18:31:32 +02:00
Rusty Russell 6ceec17943 dev_disconnect: make commit suppression a "-nocommit" modifier.
Useful if we want to drop & suppress, for example.  We change '=' to mean
do nothing to the packet.

We use this to clean up the test_reconnect_sender_add test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-20 18:31:32 +02:00
Rusty Russell 98ad6b9231 lightningd: change connect RPC args.
We're going to make the ip/port optional, so they should go at the end.
In addition, using ip:port is nicer, for gethostbyaddr().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-20 18:31:32 +02:00
Rusty Russell 871d0b1d74 lightningd: simplify peer destruction.
We have to do a dance when we get a reconnect in openingd, because we
don't normally expect to free both owner and peer.  It's a layering
violation: freeing a peer should clean up the owner's pointer to it,
to avoid a double free, and we can eliminate this dance.

The free order is now different, and the test_reconnect_openingd was
overprecise.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-20 18:31:32 +02:00
Rusty Russell 8f057f7fc7 Revert "gossip: send the *other* node's cltv_expiry_delta in channel_announce."
This reverts commit 297e278132.
2017-10-11 11:54:50 +02:00
Rusty Russell 297e278132 gossip: send the *other* node's cltv_expiry_delta in channel_announce.
Include tests from example doc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-10 20:17:37 +02:00
Rusty Russell cd8edd1716 test_lightningd: allow multiple extra options to lightningd
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-10 20:17:37 +02:00
Christian Decker f5a412d90d pytest: Change the channel persistence test to add inflight HTLCs
Now that we have HTLC persistence we'd also like to test it. This
kills the second node in the middle of an HTLC, it'll recover and
finish the flow.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Christian Decker a4967d74f1 pytest: Added a simple breakpoint shorthand
I was typing this over and over again, adding this shorthand mainly to
remember it :-)

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Christian Decker cf15670c3f pytest: Disabling test_penalty_outhtlc since it is too flaky
The test fails very often and causes the CI build to die. Needs to be
fixed.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Rusty Russell 243fc2c05a utils: save log file on failure.
This broke somewhere in the recent changes, because we override
TailalbleProc stop().  Break out log extractor.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-03 12:56:08 +02:00
Christian Decker 5029f95066 pytest: Use futures to wait for failing sendpays
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-29 10:06:56 +09:30
Christian Decker 0b350d2f5f pytest: Integrate with known/allowed failures
Moved the flagging for allowed failures into the factory getter, and
renamed into `may_fail`. Also stopped the teardown of a node from
throwing an exception if we are allowed to exit non-cleanly.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-29 10:06:56 +09:30
Christian Decker c1f4c86589 pytest: Make sure to clean up all lightningds after failures
A failed returncode check could result in the cleanup for other
lightningds to be skipped. Now make sure to cleanup all and then
rethrow an exception that contains all returncodes.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-29 10:06:56 +09:30
Christian Decker 11eaabdbe6 pytest: Stopping daemon cleanly
We used to simply kill the daemon, which in some cases could result in
half-written crashlogs and similar artifacts such as half-completed
RPC calls. Now we ask lightningd to stop nicely, give it some time and
only then kill it. We also return the returncode of the daemon.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-29 10:06:56 +09:30
Rusty Russell 2fe2a0bcf9 peer_control: don't double-free on permanent fail of non-persistent peer.
peer_fail_permanent() frees peer->owner, but for bad_peer() we're
being called by the sd->badpeercb(), which then goes on to
io_close(conn) which is a child of sd.

We need to detach the two for this case, so neither tries to free the
other.

This leads to a corner case when the subd exits after the peer is gone:
subd->peer is NULL, so we have to handle that too.

Fixes: #282
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 15:37:43 +02:00
Rusty Russell 8741043a0e test_lightningd: rename has_failed to allow_failure.
Note that it should really be a flag to daemon on construction, too,
but that may interfere with another concurrent branch so I've deferred.

Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 96a85a786c opening: save the correct commitment tx when we are the fundee.
We were saving *our* commitment tx, not theirs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell aea77653d3 onchaind: update bolt #5, and implement failure of timed-out onchain HTLCs.
We re-use the value for reasonable_depth given by the master, and we
tell it when our timeout transactions reach that depth.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 5666ba551f onchaind: fail htlcs which are not included in commitment tx.
As per update 149cf020d6

Fixes: #249
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 1ac9e0b532 onchain: implement penalty transaction.
Fixes: #242
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell d640dc3a6f test_lightningd.py: fix wait_for_logs with duplicate entries.
In the next test, we wait for multiple 'sendrawtx exit 0' which
doesn't work because we use a set not a list, and the current code
would match multiple against the same thing.  The result was we didn't
wait for the final sendrawtransaction, and occasionally had test
failures as a result.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell cbe72b658e onchaind: extract payment_preimage from onchain HTLC redemption.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell f96a04e2a6 onchaind: resolve HTLC transactions.
When we sent out an HTLC-Timeout or HTLC-Success tx, we need to spend
it after the timeout so it's safely in our wallet.

We generalize the tx_type OUR_UNILATERAL_TO_US_RETURN_TO_WALLET to
OUR_DELAYED_RETURN_TO_WALLET, since we use it for HTLC transactions too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell a76a53a933 onchaind: fulfill HTLCs onchain.
When we see an offered HTLC onchain, we need to use the preimage if we
know it.  So we dump all the known HTLC preimages at startup, and send
new ones as we discover them.

This doesn't cover preimages we know because we're the final
recipient; that can happen if an HTLC hasn't been irrevocably
committed yet.  We'll do that in a followup patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Christian Decker 081413e247 pytest: Added test to check node_announcement signatures
Reported-by: Rusty Russell
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-16 09:02:06 +09:30
Rusty Russell 584b160cdc lightningd: avoid errors on shutdown.
lightningd can crash on shutdown if it's in the middle of getchaintips;
we free the conn, the finished callback is called (process_chaintips),
and it reports that it received an empty result.

The simplest fix is to set a flag in the struct bitcoind destructor,
and avoid the callback.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell ec63c0d10b lightningd: give option to crash if a subdaemon fails.
Either when it exits with a signal, or sends an error status message.
Then we make test_lightningd.py use it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell 64a26b06e7 tests/test_lightningd.py: fail on crash.log.
We simply kill lightningd; we should stop it properly and have a timeout
to kill it if that fails.  However, that's beyond my python skills :(

So we just look for crash.log.  Unfortunately, we usually kill
lightningd before it's finished writing it.  So we look for it and
don't kill lightningd, just wait in this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell f219955dc6 wallet: fix spending of change.
We recorded our own change as P2SH; it's not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 22:59:24 +02:00
Christian Decker fa13190595 wallet: Hook into the hsm_funding_sig to extract change outputs
This is the step where we broadcast the transaction to the network and
a nice place to extract the change from the transaction.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-10 10:48:53 +09:30
Christian Decker f2d67f88c0 pytest: Run sendpay in a future so it doesn't complain about failing
For the permfail tests the sendpay call is supposed to fail, so this
was printing stacktraces upon success. Running in futures captures any
thrown exceptions and rethrows them when calling `result()`, in our
case we just ignore them.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-08 17:02:04 +09:30
Christian Decker 641a3b64cf channel: Use min_cltv_expiry in the channel announcements
So far we were always using the deadline in the announcements, that's
obviously not good, so this introduces the parameter as per spec.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-08 17:02:04 +09:30
Rusty Russell b19a4516d4 lightningd: fix crash when old openingd still around.
We weren't killing it.  Eventually it would die, and peer_owner_finished()
would access subd->peer->owner, but that peer was freed already.

Closes: #261
Reported-by: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-06 19:11:21 +02:00
Rusty Russell 5889ad5fc4 dev-disconnect: add blackhole option.
To reproduce the next bug, I had to ensure that one node keeps thinking it's
disconnected, then the other node reconnects, then the first node realizes
it's disconnected.

This code does that, adding a '0' dev-disconnect modifier.  That means
we fork off a process which (due to pipebuf) will accept a little
data, but when the dev_disconnect file is truncated (a hacky, but
effective, signalling mechanism) will exit, as if the socket finally
realized it's not connected any more.

The python tests hang waiting for the daemon to terminate if you leave
the blackhole around; to give a clue as to what's happening in this
case I moved the log dump to before killing the daemon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-06 19:11:21 +02:00
Rusty Russell 40fc95921d Cleanup: remove unused IRC flag.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-04 08:47:13 +02:00
Rusty Russell 5a5e23c011 test_lightning.py: use NO_VALGRIND instead of NOVALGRIND.
This variable also turns of valgrind on the unit tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-03 02:01:54 +02:00
Rusty Russell 1cf33eefe2 lightningd: handle case where channeld fails locally-generated HTLC.
jl777 reported a crash when we try to pay past reserve.  Fix that (and
a whole class of related bugs) and add tests.

In test_lightning.py I had to make non-async path for sendpay() non-threaded
to get the exception passed through for testing.

Closes: #236
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-30 11:36:37 +02:00
Rusty Russell bbed5e3411 Rename subdaemons, move them into top level.
We leave the *build* results in lightningd/ for ease of in-place testing though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-29 17:54:14 +02:00
Rusty Russell 88bb38f63b daemon/lightningd: remove building, and main files
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-29 17:54:14 +02:00
Christian Decker 4b64b7f2aa lightningd: Fix channel-persistence for channels with commits
I was hoping to defer HTLC updates until we actually store HTLCs, but
we need to flush to DB whenever balances update as well.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-08-26 16:37:53 +09:30
Rusty Russell 0a88948849 test_lightningd: explicitly test the new commit point case.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-23 17:38:22 +02:00
Rusty Russell e7633613a9 test_lightningd: onchain tests.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-23 17:38:22 +02:00
Christian Decker e51d261f51 lightningd: Load persisted channels on startup
This is the big one, and it's completely anticlimactic: it loads all
channels that have reached opening and are not marked as
closingd_complete into memory, that's it.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-08-23 10:23:54 +09:30
Christian Decker 29785d4990 pytest: Added a simple channel-persistence test
This test opens a channel, stops the nodes and the restarts them to
see if we can successfully reload the channel state from the database.
2017-08-23 10:23:54 +09:30
Christian Decker c0aefad8e3 pytest: Add a small helper to run queries against the node's DB
This should simplify checking that some actions have been persisted to
DB.
2017-08-23 10:23:54 +09:30
Christian Decker 121595935a pytest: Reduce noise from bitcoind
I was hoping to trigger on more things from the bitcoind process, but
stuff like mempool is hard to trigger on. Reducing to info so we can
work a bit easier with pdb and the log becomes less noisy.
2017-08-23 10:23:54 +09:30
Rusty Russell fc24c71196 tests/test_lightningd.py: add async option for pay command.
We'll need this for testing nodes going down during payment.

However, there's no good way to silence the threads that I can tell,
so we get a nasty backtrace from it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-20 13:06:41 +09:30
Rusty Russell 8e0c19c76a lightningd: add dev-fail command to inject permenant failure.
A couple of double-free bugs founnd doing this, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-20 13:06:41 +09:30
Rusty Russell 1ad960413d test_lightningd: fix valgrind detection on children.
I tracked down a bug, and couldn't figure out why valgrind wasn't
finding it.

From man valgrind:

       --log-file=<filename>
           Specifies that Valgrind should send all of its messages to the
           specified file. If the file name is empty, it causes an abort.
           There are three special format specifiers that can be used in the
           file name.

           %p is replaced with the current process ID. This is very useful for
           program that invoke multiple processes. WARNING: If you use
           --trace-children=yes and your program invokes multiple processes OR
           your program forks without calling exec afterwards, and you don't
           use this specifier (or the %q specifier below), the Valgrind output
           from all those processes will go into one file, possibly jumbled
           up, and possibly incomplete.

"possibly incomplete" indeed!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-20 13:06:41 +09:30
Christian Decker 9ad8365589 pytest: Split test_disconnect
These were in part reusing some of the nodes, and creating new
instances for other, so I split them to avoid having cross pollution
between the tests.
2017-08-17 10:31:55 +09:30
Christian Decker 943b6526c7 pytest: Configure non-legacy tests correctly and filter legacy 2017-07-12 11:30:23 +09:30
Christian Decker 843e21826a opts: Remove --regtest flag and pass chainparams to bitcoind 2017-07-12 11:30:23 +09:30
Christian Decker 8e043fc448 pytest: Consolidating sync_blockheight and fixing flaky test 2017-07-12 11:00:26 +09:30
Christian Decker 1a1e29a4bc gossip: Re-initiate the broadcast timer upon reconnect
We weren't registering reconnecting peers for broadcasts. Just
starting a timer is enough. Also added an integration test to check
that the gossip sync is being resumed.
2017-07-12 11:00:26 +09:30
Rusty Russell f04222cb12 test_lightningd.py: make pay helper use random label if we don't care.
Suggested-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-12 10:21:16 +09:30
Rusty Russell 87232ec25c lightningd: new peer state CLOSINGD_COMPLETE.
This is a transitional state, while we're waiting to see the
closing tx onchain (which is To Be Implemented).

The simplest way to do re-transmission is to re-use closingd, and just
disallow any updates.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-12 10:21:16 +09:30
Rusty Russell 87f6a57d75 tests/test_lightningd.py: test closing and shutdown reconnection.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-12 10:21:16 +09:30
Rusty Russell a827d2b2bb lightningd: add in support for closingd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-12 10:21:16 +09:30
Rusty Russell d40334ce18 tests/test_lightningd.py: add pay helper for making payments.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-12 10:21:16 +09:30
Rusty Russell 6fa90c926a channeld: exit after shutdown when no more HTLCs.
Ready for the introduction of closingd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-12 10:21:16 +09:30
Rusty Russell 4a3c309e84 tests/test_lightningd.py: fix assumption about gossip order
Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-03 19:43:34 +09:30
Rusty Russell 9fae82c175 tests: generalize wait_for_log into wait_for_logs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-03 19:43:34 +09:30
Rusty Russell c05f63a4db peer_control: fix double-state transition on reconnect.
We actually don't need to transition if we're reconnecting, and logic
to go to CHANNELD_NORMAL was wrong: we checked that we'd seen funding tx
locked, but not that we'd received a msg from the remote peer.

We need to fix the tests now we no longer double-transition, too.

Fixes: #188
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-07-03 19:43:34 +09:30
Rusty Russell 5edc14ee1a tests/test_lightningd.py: make test less flaky.
When we drop an HTLC_ADD packet, sometimes the commit timer fires
before we try to read from the fd.  In this case, the payment is
considered committed and we don't fail.

We need manual commit to work around this, and also we'd need to do
the pay command asynchronously from python because it will block.
That's a bit out of scope for now, so just handle either way.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Rusty Russell 866ac79850 channeld: shutdown support.
We keep the scriptpubkey to send until after a commitment_signed (or,
in the corner case, if there's no pending commitment).  When we
receive a shutdown from the peer, we pass it up to the master.

It's up to the master not to add any more HTLCs, which works because
we move from CHANNELD_NORMAL to CHANNELD_SHUTTING_DOWN.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-27 10:25:53 +09:30
Christian Decker 462d936f25 wallet: Add unit test for withdrawal 2017-06-23 16:02:20 +09:30
Rusty Russell e80ef7dc19 test_lightningd.py: test reconnections on receiver, and htlc_fulfill.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 6dbaa3ace6 test_lightningd.py: test reconnection on htlc_add.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 6b61e9ab0a channeld: exchange channel_reestablish.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell a55b58d0d5 lightningd: track balance in way which matches channeld.
Currently it's fairly ad-hoc, but we need to tell it to channeld when
it restarts, so we define it as the non-HTLC balance.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell ae62509b58 lightningd: remove dev-newhtlc command.
It added another path to the local-htlc handling, and we have full
invoice support now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 4a161b710d channeld: pass htlcs to master daemon in batches.
When adding their HTLCs, it needs all the information.  When failing,
it needs the id as key and the failure reason.  When fulfilling, it
needs the id and payment preimage.

It also needs to know when we have received an revoke_and_ack or a
commitment_signed, to place in the database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 733e0aeccf tests/utils.py: wait_for_log automatic offset.
I have a test which waits for multiple occurrences of the same string,
but doesn't want them to overlap.  Make wait_for_log() do the right thing,
so that it only looks for log entries since the last wait_for_log.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell e161c11e40 tests/utils.py: poll mempool instead of sleeping.
On my laptop under load, 5 seconds was no longer enough for legacy.
But this breaks async (they all see mempool increase, and fire
prematurely), so stop doing that.

I can't get this test to work at all, in fact, without this patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 87fc3439c4 test_lightningd.py: fix obscure corner case in gossip.
I actually hit this very hard to reproduce race: if we haven't process
the channeld message when block #6 comes in, we won't send the gossip
message.  We wait for logs, but don't generate new blocks, and timeout
on l1.daemon.wait_for_log('peer_out WIRE_ANNOUNCEMENT_SIGNATURES').

The solution, which also tests that we don't send announcement signatures
immediately, is to generate a single block, wait for CHANNELD_NORMAL,
then (in gossip tests), generate 5 more.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-07 09:19:04 +09:30
Christian Decker b1d5283ac7 pytest: Testing addfunds json-rpc call 2017-06-06 09:16:10 +09:30
Rusty Russell 06bc035f59 Minor fixes: feedback from Christian
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell 7d5b923719 test_lightningd.py: test reconnect after funding_signed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell 1df40156f6 test_lightningd.py: disconnection tests.
In particular, we test the cases where it will simply forget the old peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell 780b3870ad lightningd: peer state cleanup.
1. We explicitly assert what state we're coming from, to make transitions
   clearer.
2. Every transition has a state, even between owners while waiting for HSM.
3. Explictly step though getting the HSM signature on the funding tx
   before starting channeld, rather than doing it in parallel: makes
   states clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell 662dfef436 lightningd/gossip: Move INIT message handling to handshake daemon.
We need to do this on every connection, whether reconnecting or not,
so it makes sense for the handshake daemon to handle it and return
the feature fields.

Longer term I'm considering having the handshake daemon handle the
listening and connecting, and simply hand the fds back once the peers
are ready.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell f6495d3310 lightningd/peer_control: don't create peer struct until we've connected.
We currently create a peer struct, then complete handshake to find out
who it is.  This means we have a half-formed peer, and worse: if it's
a reconnect we get two peers the same.

Add an explicit 'struct connection' for the handshake phase, and
construct a 'struct peer' once that's done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell 34e6e56471 lightningd: introduce peer_state enum.
The actual state names are place holders for now, really.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Christian Decker 80486a6669 pytest: Do not check for valgrind errors if disabled
Checking for valgrind errors if we disabled valgrind will kill the
teardown, so don't!
2017-05-20 19:59:16 +09:30
Rusty Russell 3d2f166364 test_lightningd.py: don't fail if valgrind turned off.
eg:
test_routing_gossip (__main__.LightningDTests) ... ERROR

======================================================================
ERROR: test_routing_gossip (__main__.LightningDTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_lightningd.py", line 150, in tearDown
    err_count += self.printValgrindErrors(node)
  File "tests/test_lightningd.py", line 137, in printValgrindErrors
    errors, fname = self.getValgrindErrors(node)
  File "tests/test_lightningd.py", line 132, in getValgrindErrors
    with open(error_file, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/lightning-l106st0a/test_routing_gossip/lightning-1/valgrind-errors'

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-19 13:30:32 +02:00
Christian Decker f6d60b9076 pytest: Fail tests that produce valgrind errors
Check and print all valgrind errors and fail tests that produce
errors. We abort using an exception since `fail()` is not allowed in
the teardown.
2017-05-10 12:38:12 +09:30
Rusty Russell 42601c29d7 test_lightning.py: run valgrind on child daemons too
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-09 11:43:20 +09:30
Christian Decker 6d06303789 pytest: Remove obsolete test and fix two flaky tests 2017-05-07 12:06:56 +09:30
Christian Decker 23da30a2a4 pytest: Better dealing with env variables to configure tests 2017-05-07 12:06:56 +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 6dcd7f9d6d tests: dump more information when we fail to find something in logs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-05 16:11:46 +09:30
Rusty Russell 2641ecaafa test_lightningd.py: dump logs on error.
I couldn't actually figure out how to just dump them on error, so I
dump all the time.  When running 3 lightningd + bitcoind, this separates
the logs nicely.

TODO: We should delete the directories on success!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-03 11:47:10 +09:30
Rusty Russell 39fb7d82fb test_lightningd.py: re-enable and fix forwarding test.
But it breaks:

	test_forward (__main__.LightningDTests) ... lightningd_channel: Computed MAC does not match expected MAC, the message was modified.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-03 11:47:10 +09:30
Christian Decker f700662a56 routing: Reading the channel_id from routes passed in from JSONRPC 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
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
Christian Decker dc7b832e83 pytest: Added gossip test for new daemon 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 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
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
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 b6fea5b429 pytest: Check that channels are announced and activated correctly 2017-04-11 16:56:27 -07: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 9c7c2a3f2f pytest: Added simple pytest for the new JSON-RPC 2017-03-20 11:18:00 +10:30
Christian Decker b5c2d7d47d pytest: Gossip subdaemon had a flaky test
Whenever we were checking for the status before the daemon was
initialized the test would fail. Now just waiting for the state
transition.
2017-02-08 16:59:57 +01:00
Christian Decker c7e6f197b0 pytest: Chaning startup sentinel for bitcoind.
By looking for 'Done loading' in the log output we should actually be
called after `SetRPCWarmupFinished` in bitcoind. Only then is it safe
to make RPC calls. This resulted in the test suite being a bit flaky.
2017-02-08 16:59:56 +01:00
Christian Decker 66175c7361 Merge pull request #115 from ElementsProject/pytest-pathfix
pytest: don't assume paths of valgrind and bitcoind.
2017-01-24 14:22:23 +01:00
Rusty Russell 1575181ef5 pytest: don't assume paths of valgrind and bitcoind.
In particular, my bitcoind is in /usr/local/bin

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-01-24 14:37:56 +10:30
Christian Decker 1948062250 pytest: Using python-bitcoinlib instead of python-bitcoinrpc
The latter is unmaintained and has a number of problems.
2017-01-23 10:37:34 +01:00
Christian Decker 180c96776b pytest: Split the python integration tests into new and legacy 2017-01-23 10:37:34 +01:00
Christian Decker cf1c03f4d9 pytest: Implemented initial python integration tests. 2017-01-23 10:45:36 +10:30
Christian Decker 41a5e74db9 pytest: Implement utilities for python unittests 2017-01-23 10:45:36 +10:30