Commit Graph

9394 Commits

Author SHA1 Message Date
Rusty Russell
832fed70dc test_state_coverage: test declining an HTLC.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
afc67e1ff1 test_state_coverage: remove depth argument.
We stash it in the trail instead.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
8e468d077d test_state_coverage: keep trail on stack.
Rather than generating it after as we return failure.  This makes
it easier to save it for the next patch where we want to report failure.
Also put num_peer_outputs in there, so we don't have to access
after->peer on reporting.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
65be414d1b test_state_coverage: unset outputs as we use them.
Otherwise hashing might not spot duplicate states.  Doesn't seem to
make much difference in timing in practice though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
2f1414362c state: Don't change priority on decline.
This means it's always reflects the bottom bit (maybe inverted) of the
commit tx number.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
4d74fd165f state: Allow CMD_CLOSE at any time.
As suggested by Anthony Towns.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
188d0b76a4 state: use an enum for the completion.
Instead of overloading complete_data.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
ba73787ecc state: use INPUT_RVALUE instead of CMD_SEND_HTLC_FULFILL during closing.
We'd expect stop_commands to stop all commands, but we (ab)used
CMD_SEND_HTLC_FULFILL to send us R values even in closing state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
80d23a0a61 test/test_state_coverage: traverse main state loop less.
By terminating in either NORMAL state, we halve the time to run the
coverage test.

Before:
	real	0m50.083s
After:
	real	0m28.548s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
97e10e0a18 test/test_state_coverage: don't run both peers once they're independent.
Once both are longer listening to their packets, we don't need to
simulate all variants of what each are doing.

(With -O3 -flto, gcc 5.1) 
Before:
	real	11m40.032s
After:
	real	0m50.083s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
3e9680659e test/test_state_coverage: limit HTLCs in flight to 2.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
5a4d07b921 test/test_state_coverage: cut memory usage dramatically.
For loop detection, we don't need entire state.  So extract a core,
which we can put in hash table.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
565e905bce test/test_state_coverage: better HTLC reporting in errors.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
7d911fe049 test/test_state_coverage: test on-chain htlcs.
This requires our state exerciser to be smarter.  In particular, it
needs to track individual HTLCs rather than just sending random
inputs.

To do this:
1) We keep data associated with packets as they flow (where
   those packets are associated with HTLCs).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:19 +09:30
Rusty Russell
6821b4f31c state: handle on-chain HTLCs.
When a unilateral close occurs, we have to watch on-chain ("live")
HTLCs.  If the other side spends their HTLC output, we need to grab
the rvalue.  If it times out, we need to spend it back to ourselves.
If we get an R value, we need to spend our own HTLC output back to
ourselves.

Because there are multiple HTLCs, this doesn't fit very neatly into a
state machine.  We divide into "have htlcs" and "don't have htlcs",
and use a INPUT_NO_MORE_HTLCS once all htlcs are resolved to transition.

Our test harness now tracks individual HTLCs, so we refined some
inputs (in particular, it won't try to complete/timeout an HTLC before
we have any).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
d4178a389c test/test_state_coverage: more information in error trail.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
bcfd50e28c test/test_state_coverage: temporarily disable decline test.
It will come back better and stronger, later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
31459d6cd2 protocol: rename update_complete_htlc to update_fulfill_htlc.
Complete was an overloaded word.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
ca68c5c47f state: remove non-HTLC updates.
They're still in the base protocol (good for testing), just not here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
0f4ad940ae test/test_state_coverage: remove_event / add_event / have_event helpers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
fbe6e9e0cf state: allow multiple SPENDTHEM.
Malleability, there could be many of these.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
92bb5f03de test_state_coverage: fix dependent events.
These tests are wrong, and are handled properly anyway when they
fire (the other one is disabled).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
42bf766d64 state: hand tx explicitly to bitcoin_watch / bitcoin_watch_delayed
Neater than assuming it's effect->broadcast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
c19839816e test/test_state_coverage: --dump-states
Simple code to dump the state transitions into text form.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
d88f96de17 test/test_state_coverage: speed up dot diagram generation.
We don't need a full test for this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
29f22c165d state: handle simultaneous close.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
066bf1f4e5 test/test_state_coverage: Check for deadlock.
We should always have a packet in flight unless we're in the two
waiting-for-anchor-to-mature states, or at the top of the main loop.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
642c3e36e3 test/test_state_coverage: Check that it terminates.
The state machine is infinite, but if we eliminate the normal inner
state loop, and a couple of other unusual cases where inputs can
repeat, we should be able to traverse it all.

This is slower than simply stopping when we hit a repeated state
though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
786bef9002 test/test_state_coverage: output dot format.
Good for documentation, plus impressive with all the error states...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
11f33ad12f test/test_state_coverage: test the case where we decline an HTLC.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
8308e31d6c test/test_state_coverage: ensure we produce all output packets.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
f51e9c81bf test/test_state_coverage: make sure we test all inputs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
1556315f2e test_state_coverage: simple exhaustive coverage test for state machine.
Makes sure that we visit every state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
5730b118f1 Some more ccan objs.
These are LGPL, but only used for tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
847ef21c07 state: Core state machine for lightning.
It's written in a repetitive and stylized form, for easier testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
669479b671 gen_state_names.h: printable names for state_types enums.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
1fca363b31 state_types: types for state machine.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
1b2de5c830 CCAN: add cdump.
Used to print enums.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
3b0aca81f5 CCAN: update.
Trivial updae.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:51:18 +09:30
Rusty Russell
f0cab4e74b gather_updates: fix rebase error.
Didn't update amount field in d00eeded9f.
Didn't compile test either :(

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-25 11:50:24 +09:30
Rusty Russell
8af4619406 Makefile: neaten
Reduces gratuitous patch conflicts in future.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 15:03:20 +09:30
Rusty Russell
02a563ba82 protocol: renumber.
Use lower numbers and clean up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 15:02:54 +09:30
Rusty Russell
fefe2deea2 protocol: add a third leg to the close operation.
This gives us a neat way to know the other end has received our sig.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 15:02:52 +09:30
Rusty Russell
d00eeded9f protocol: split message update_remove_htlc into update_timedout_htlc and update_routefail_htlc, remove update_remove_htlc_delay.
For the moment, there's no way to remove an in-progress HTLC before
it's timed out.  The other side can remove it with a routefail, but
you can't push for it to be removed.

We may add that later, but by definition it's only a polited request, and
normally we should rely on timeouts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 15:02:49 +09:30
Rusty Russell
807ac38308 protocol: add decline response for HTLC.
We don't have to accept an HTLC they offer; we might not be able to
route it, or it might offer insufficient payment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 15:02:46 +09:30
Rusty Russell
5bc22f0368 protocol: increase HTLC precision to 1/1000 satoshi.
This gets truncated for on-chain transactions (thus, rounding may
contribute to fees).

This also means we currently have an upper bound of 0.04 BTC per HTLC;
this can be increased later if required.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 15:00:47 +09:30
Rusty Russell
58a62e782d bitcoin/script: don't pass value for HTLC script.
We don't need it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 14:56:01 +09:30
Rusty Russell
186736050f test-cli: fix alpha case.
The output of grep confuses the scripts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-24 14:41:55 +09:30
Rusty Russell
bc056fbc4d doc/deployable-lightning: point out that Fig 4 is simplified.
Fixes #4

Reported-by: Pierre <pm+lists@acinq.fr>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-15 04:23:25 +09:30
Rusty Russell
71c56e0360 doc: biblopgraphy update
Thanks to Anthony Towns for digging this up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-11 10:20:47 +09:30