Commit Graph

67 Commits

Author SHA1 Message Date
practicalswift 4f4756bd20 Fix a-vs-an typos 2018-02-08 22:49:34 +01:00
Rusty Russell f5c00deec7 Remove trailing whitespace from source.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-11 09:32:04 +10:30
Rusty Russell a4ee683b3e tal_tmpctx: clear marker for temporary contexts.
This makes them stand out in memory dumps.  Also plug two existing
memory leaks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:34:27 +10:30
Rusty Russell cb0cc80984 patch remove-timeout.patch 2016-03-15 17:07:12 +10:30
Rusty Russell 983000428f daemon: rename CMD_SEND_HTLC_UPDATE to CMD_SEND_HTLC_ADD
There are other updates than just adding an HTLC; make this explicit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:42:15 +10:30
Rusty Russell 4f67b59c26 protocol: rename routefail to fail.
It's a generic "I couldn't complete this" failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:41:15 +10:30
Rusty Russell 40361e3dd8 state: explicit callback to check pkt_open_complete.
For now, this always succeeds, but include the hook for completeness.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:39:15 +10:30
Rusty Russell a2f4000d22 state: cleanup after anchor has been transmitted.
If something goes wrong after we've broadcast the anchor tx, we need to use
the commit tx to spend it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:38:15 +10:30
Rusty Russell 5ac1d5df00 state: include daemon/peer (only if !TEST_COVERAGE).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell 65cc6bbd50 pkt_err: make it variadic.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 79e1c9bb62 state: make bitcoin_commit() take a non-const peer.
We have to sign the commit at this stage, so easiest if peer isn't const
so we can sign it in-place.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 6a7a046f60 state: add peer_unwatch_close_timeout() call.
This tell us to disarm the INPUT_CLOSE_COMPLETE_TIMEOUT: either we hit
an error and are going to unilateral close, or we received their signature
successfully.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 144ab3bef4 state: make tx arguments const.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell ebf2bc57d8 state: add async anchor creation.
Actually generating the anchor transaction in my implementation
requires interaction with bitcoind, which we want to be async.  So add
a callback and a new state to wait for it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 0db3c03ed1 state: fix BITCOIN_HTLC_TOTHEM_SPENT idata.
We use both union fields idata->btc and idata->htlc, which is clearly
wrong.  Have peer_tx_revealed_r_value return the HTLC it's talking
about.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 2b3d5b4049 state: remove all traces of struct state_effect.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 63ea6bfd7a state: add callbacks for adding/removing watches.
This lets us eliminate struct state_effect altogether (the next patch
removes the now-unused arguments).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 1a20e8094f state: return tx to be queued directly.
Instead of effect->broadcast_tx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell e984df486d state: return Pkt to be queued directly.
Instead of effect->send_pkt.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:47 +10:30
Rusty Russell 7383da5f87 state: remove update_theirsig effect.
They get this from accept_pkt_update_accept() or accept_pkt_update_signature().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 63cb0667f6 state: use callbacks for htlc management.
We only have one htlc in flight at a time, but sometimes it changes:
particularly when we are lowpriority and a highpriority request comes
in.  Handle this using a set of callbacks for htlc handling.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell f48adb097e state: use peer_unexpected_pkt() for an unexpected packet.
Instead of effect->in_error.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 4d9041e62a state: fix case where we replied to an error with an error.
Found by fixing bogus test in test_state_coverage.c

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 9013a7d872 state: set peer->state directly.
Instead of new_state effect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 4c9a9f8982 state: return status of current command.
We temporarily move effect to the end of the arg list: we'll get rid
of it eventually.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 03268014b4 state: use PEER_BUSY when doing a command.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 14ede84d87 state: set peercond in peer directly.
Instead of stop_packets or stop_commands effects.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 50a4b14a9a test/test_state_coverage.c: remove deferred packet handling.
We no longer defer packets.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 3ab4ba1e6f state: add _THEYCOMPLETED states to reflect receiving PKT_OPEN_COMPLETE
This is cleaner than deferring the packet receive and asking for it later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell fd370075f2 state: use STATE_INIT and separate inputs to decide on anchor.
This is conceptually cleaner, especially since it means we're running
a command until we're set up (which prevents other commands, so no
special case needed).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell caa27f1d93 names.h/names.c: wrappers to get name for states/inputs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:46 +10:30
Rusty Russell 15c5fca876 state: take struct peer instead of struct state_data.
Just a name change for the test code, but this is what we'll be using
for the daemon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:45 +10:30
Rusty Russell 2c356fde55 state: remove unnecessary set_errpkt() helper.
This was needed when idata->pkt wasn't a tal pointer, for testing,
but now it always is anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:45 +10:30
Rusty Russell 85f4a7cf14 state: simplify effect.
Make it a linked list of effects, rather than one big union.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:45 +10:30
Rusty Russell 4d22b4e3eb pkt_open: use flag to indicate whether packet will offer anchor.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:45 +10: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 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 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