Commit Graph

66 Commits

Author SHA1 Message Date
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 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 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 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 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 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 29f22c165d state: handle simultaneous close.
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 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