Commit Graph

70 Commits

Author SHA1 Message Date
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