Commit Graph

266 Commits

Author SHA1 Message Date
Rusty Russell
5de21f80de Regenerate PDF.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-11-20 06:45:19 +10:30
Douglas Roark
6394d2de16 Minor "Reaching the Ground With Lightning" fixes.
- Added a reference to BIP112 and to the deployment of BIP68.
- Minor typo, grammar and formatting fixes.
2015-11-18 09:54:41 +10:30
Rusty Russell
6b2d844f2a bitcoin: use ccan/mem instead of rolling own check_mem function.
Reported-by: John Newbery
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-10-26 21:06:23 +10:30
Rusty Russell
be58e45ee4 README.md: A few more details about what we're doing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-10-24 14:41:10 +10:30
Rusty Russell
2ab9e3bd7f doc/deployable-lightning: corrections and fixes.
1) Note incorrect label in txs in Fig1 of LN paper.
2) "an atomic-swap an on-chain.." -> "an atomic-swap *to* an on-chain"
3) "By using a dual anchor and escape transactions" -> "By using a rebalanced single anchor"
4) References to appendices fixed.
5) Move escape transaction scripts out to escape appendix.
6) Fix URL in bibliography (missing comma).

Reported-by: John Newbery
Closes: #11
Closes: #12
Reported-by:
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-10-19 10:54:49 +10:30
Rusty Russell
57f0c3b38c test-cli/scripts: use setmocktime.
TIL about setmocktime.

Suggested-by: Gavin <gavinandresen@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-10-16 11:59:45 +10:30
Rusty Russell
32fe988fe8 bitcoin: signature fixes.
The libsecp change broke signature checking.  Disable it for now,
with a big FIXME.  The next version should have a method for S value
checking, and also compact serialization.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-10-12 10:45:02 +10:30
Rusty Russell
0b50a7c9eb Fix test scripts for alpha.
Doesn't support getblockheader, also some occasional weirdness
with sequence enforcement for mempool?  Occasionally I could get
my spend tx into the mempool (doesn't happen with bitcoin).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-10-02 10:40:07 +09:30
Rusty Russell
f36ba8f8e1 Makefile: only erase protobuf and PDF files with maintainer-clean.
Reported-by: Anthony Towns
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:39:02 +09:30
Rusty Russell
401bde5c6b secp256k1: add "ignored" files.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:39:02 +09:30
Rusty Russell
3120bc6231 secp256k1: update to cc3141a00368c8d83dc35243f4936694304d62dc
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:39:02 +09:30
Rusty Russell
81d35294f4 test/test_onion: demo program to show onion routing crypto.
We can make this more efficient, but this works for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:39:02 +09:30
Rusty Russell
b47d4bbe6a ccan: add ccan/mem.
Onion test program wants memcheck().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:39:02 +09:30
Rusty Russell
c895d4a135 ccan: update to latest.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:39:01 +09:30
Rusty Russell
242fa1b2dd pubkey: pubkey_eq helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:38:58 +09:30
Rusty Russell
e7856e6e69 Update libsecp to git@github.com:bitcoin/secp256k1.git 52fd03f
We want the ecdh stuff for onion routing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 16:37:21 +09:30
Rusty Russell
17f457568a Makefile: generate libsecpk1 properly.
And clean it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 10:54:54 +09:30
Rusty Russell
454a3867e5 BIP68 support (nSequence enforcement)
The latest version of the BIP doesn't use inversion, but does use
bitshifts.

It also uncovered a bug in the test scripts: the block timestamps
creep forward when we generate large numbers of blocks (UpdateTime
insists it be > GetMedianTimePast() so it's valid).  We need to take
this into account when waiting for the median to move (reduced it from
60 to 30 seconds, since that adds about 14 seconds).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-30 10:54:11 +09:30
Rusty Russell
845d09ce68 check: simple Makefile target.
This makes it much easier to run all the test scripts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-29 17:02:02 +09:30
Rusty Russell
1ac08e3b11 test_state_coverage: test all accept_pkt failure paths.
Reveals a number of places where we don't handle errors correctly.

Note: this takes about 14.5 GB to test on my x86-64 box.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-29 09:47:56 +09:30
Rusty Russell
82e25a31cb test/test_state_coverage: reduce memory usage for failure branches.
Not much help yet, but vital when we increase the number of fail points.

Before:
	Maximum resident set size (kbytes): 1080148
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 271614
	Voluntary context switches: 1
	Involuntary context switches: 1083

After:
	Maximum resident set size (kbytes): 1062344
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 266236
	Voluntary context switches: 1
	Involuntary context switches: 2509

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-28 16:33:54 +09:30
Rusty Russell
0b3f74509a test_state_coverage: fail() adds failpoints itself.
And we use a hash table to tell if we've failed here before.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-09-28 16:11:09 +09:30
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