Commit Graph

662 Commits

Author SHA1 Message Date
Rusty Russell bc5800b1c1 state: remove unused fields from union input
And make the add/fail/fulfill arg a pointer to a union htlc_staging
directly, removing struct htlc_progress.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 50bffd67c2 daemon: don't save invalid commit signatures.
We don't want anyone to think the commitment tx is signed, so only
assign ci->sig after validation.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell d1416ea5b5 TAGS: don't go into git dirs.
Things get quite confusing when this happens.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 43db90391a daemon: fix case where commit has nothing to do.
Prevents assert() triggering in queue_pkt_commit().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell b820f5a0dd Makefile: fix submodule.
Christian noted that missing daemon/jsmn/jsmn.h didn't trigger the git
submodule weirdness.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 9046597344 daemon: tighten check for invalid IDs.
We don't have to, but helps debugging.  Language in latest rev of BOLT#2
has been tightened too (aa2e1919de0826beaf92e0b3b441a6ab9fce6261)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-01 11:59:15 +09:30
Rusty Russell 3928cbe30e daemon: fail connection if preimage isn't valid for shachain.
This means they generated it wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-06-25 14:20:15 +09:30
Rusty Russell 6bbd05c001 Merge remote-tracking branch 'origin/pr/25' 2016-06-25 14:19:57 +09:30
Rusty Russell 2436207a7a test: detect segwit correctly, assume master branch.
Segwit was merged, but the strings changed between there and segwit4
(also, my BIP9 patch changed the output).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-06-25 14:13:08 +09:30
sstone be1a230ae8 fix formatting issues 2016-06-23 17:11:10 +02:00
sstone 07e6ed0c16 save received revocation preimages in shachain.
make sure that preimages are generated in reverse order.
2016-06-23 16:38:35 +02:00
Rusty Russell 1dbe001fdc Merge pull request #24 from ocinq/master
Makefile : adding ccan/asort.o target and binary
2016-06-17 05:59:20 +09:30
ocinq bcdab60694 Makefile : ccan/asort is referenced
Added explicit compilation and linking of ccan/asort as needed by daemon/chaintopology
2016-06-14 17:25:07 +02:00
Rusty Russell 49ebed737d daemon/test: test differential fees.
This would have revealed the previous breakage (and I tested that!),
plus now we test negotiate on closing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-30 11:18:46 +09:30
sstone 385c2a5905 setup_first_commit: initialize their remote commit with their commit fee rate 2016-05-27 16:53:01 +02:00
Rusty Russell 9bb070f5b6 0.3 release: Braydon Fuller: Nakamoto's Genesis Coins
Braydon wrote the INSTALL.md file; he gets to name this release,
in line with the theme.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 40b550a9d2 daemon: don't log bogus warning on failed anchors.
We no longer get bitcoind to manage our transactions for us, so we don't
need to -zapwallettxs when an anchor fails.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 773a6088e4 daemon: reorder and collapse functions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 400d415172 daemon: remove pending input and command queues.
we don't use them any more.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 889db659c5 test: test commands during commit phase.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 4110376e87 daemon: allow commands during commit.
There's no real reason to avoid commands for the next commit; this has
the benefit that we can remove the infrastructure to queue commands.
The only exceptions are the commit command and the opening phase.

We still only allow one commit at a time, but that's mainly run off a
timer which can try again later.  For the JSONRPC API used for
testing, we can simply fail the commit if one is in progress.

For opening we add an explicit peer_open_complete() call in place of
using the command infrastructure.

Commands are now outside the state machine altogether: we simply have
it return the new state instead of the command status.  The JSONRPC
functions can also now run commands directly.

This removes the idea of "peercond" as well: you can simply examine
the states to determine whether an input is valid.  There are
fine-grained helpers for this now, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell d4862938c8 daemon: move unacked queue into commit_info struct.
We're about to allow changes while we're waiting for a commit ack.
This means we can't have a single "unacked changes" queue; when we
receive the revocation reply, we need to apply the unacked changes
known at the time we sent the commit, not any we've created since
then.

Note that we still only have a single staged_commit; we never have two
outstanding commits, since for simplicity we will still block
following update_commit pending the reply to the current one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell 36fc62ab81 test: add --crash option to cause nodes to crash dump on test failure.
This causes full logs to be dropped in "crash.log".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell ca9d775f9a lightning-cli: don't print junk on error.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:25 +09:30
Rusty Russell f662424b7b protocol: don't sign initial commitment for non-funder.
As per lightning-rfc commit b8469aa758a1a7ebbd73c987be3e5207b778241b
("re-protocol: don't hand signature to non-funding side initially.")

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 5188b14c7c daemon: fix unwatch anchor depth.
We still need to watch the anchor output in this case: that's what
makes us handle the commit transcction we broadcast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell b9d4f7c0ab daemon: dev-output command.
Useful for controlling conversations between two nodes, by
blocking one's output.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 97bc4ed0cb daemon/test: test mutual close with outstanding HTLCS.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 5aed0e12f8 daemon: remove closing states from state machine.
We already removed the on-chain states, now we remove the "clearing" state
(which wasn't fully implemented anyway).

This turns into two smaller state machines: one for clearing, which
still allows HTLCs to be failed and fulfilled, and one for mutual
close negotiation which only allows close_signature messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 4c63845969 daemon: make funding directions local-centric.
Previous to this, we kept the remote side's 'struct channel_state'
backwards: peer->remote.commit->cstate.side[OURS] was their HTLCs,
and [THEIRS] was our HTLCs.  This made some things easier, but was
horrible for readability.

This inverts things so we keep track of the remote side's state from
our point of view: [OURS] is ours, [THEIRS] is theirs.  Which makes
much more sense.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 148bd793cd daemon/test: test overlapping commits.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 45a6f81c3c protocol: remove ack fields.
As per lightning-rfc commit 8ee09e749990a11fa53bea03d5961cfde4be4616,
we remove the acks from the protocol now they're no longer needed (and
all the infrastructure).

We also place the commit number in the commit_info where it logically
belongs, removing it from the peer struct.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 2bf43f1ebd daemon: handle HTLC as per BOLT #2 algorithm.
From BOLT#2 (rev 8ee09e749990a11fa53bea03d5961cfde4be4616):

   Thus each node (conceptually) tracks:
...
   3. Two *unacked changesets*: one for the local commitment (their proposals) and one for the remote (our proposals)
   4. Two *acked changesets*: one for the local commitment (our proposals, acknowledged) and one for the remote (their proposals, acknowledged).

   (Note that an implementation MAY optimize this internally, for
   example, pre-applying the changesets in some cases).

In our case, we apply the unacked changes immediately into
staging_cstate, and save them in an unacked_changes array.  That array
gets applied to staging_cstate as soon as it's acked (we only allow
one outstanding update_commit, so we only need one array).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell cf7a7a7273 funding: use sides[OURS/THEIRS] instead of a and b.
This is a little clearer, and handling arrays is easier than separate
variables.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 84f5a82eea daemon: use "local" and "remote" instead of "us" and "them".
This is the language used in BOLT#2; be consistent.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell b66d3e263a funding: return pointer to added HTLC.
For convenience.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell b6dbaa409c INSTALL: mention bitcoind needs segwit, Ubuntu 16.04 protobuf fixed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 311ae9b4d8 daemon: remove unused functions.
These were left over from when the state machine handled onchain
transactions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 0ceee86098 daemon: don't allow fulfill/fail on uncommitted HTLCs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell f43cc72d6a Makefile: add generated packet names.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell fabdcaf62b daemon: close correctly when guest fails.
Otherwise we can receive another packet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:25:24 +09:30
Rusty Russell 5a2a9126c3 daemon: don't allow new RPC commands when peer closing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:24:39 +09:30
Rusty Russell b6339af195 daemon: remove unused CMD_REQUEUE.
This was a remnant of the old code which used to alternate priority
for making changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-26 15:23:39 +09:30
Rusty Russell a2ced6c16c test/test_protocol: add actual crossover case.
Not just add-htlc crossing over, but all the commit stages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-18 06:55:28 +09:30
Rusty Russell e46a2ed49a test/test_protocol: rename internally to match updated 02-wire-protocol.md
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-17 15:06:12 +09:30
Rusty Russell 06d2c19c41 test/test_protocol: make pretty(-ish) SVG diagrams.
Could make them much prettier, but they're functional.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-17 15:02:08 +09:30
Rusty Russell 126c91e1b1 test/test_protocol: don't allow multiple commits in flight by default.
Add "nocommitwait" for the two cases we test that, otherwise add
assertions that we never end up dealing with anything other than
the previous commit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-17 15:01:10 +09:30
Rusty Russell a77466aa21 test/test_protocol: Keep pointer to previous state.
Since our pre-change state is always the same as the previous step's
post-change state, we can simply keep a pointer, with a dummy empty
state for the initial one.

We could function-wrap it, but this change is even simpler.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-17 13:58:06 +09:30
Rusty Russell 4c1b50baab test/test_protocol: don't bother keeping acked (outgoing) queue.
We can simply set a boolean to indicate there are changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-17 13:56:08 +09:30
Rusty Russell bc8cd0dce7 test/test_protocol: don't manually reapply changes.
This finished the previous patch by simply copying funding_next to funding
when we want to apply changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-05-17 13:55:58 +09:30