Commit Graph

489 Commits

Author SHA1 Message Date
Rusty Russell 017d199305 funding: record changes so we can abide by BOLT#2
BOLT#2 says we MUST NOT send out commit messages with no changes (and
we drop the connection if the peer does).  But that's harder than it
sounds: we can have changes in theory which cancel out (eg. fee
adjustments, not yet implemented) or others which don't change the
commit tx (eg. dust outputs).  Simplest is to have a generation count,
which also allows us to simply show number of pending changes in RPC.

It's 32 bit, but you can only use it to screw yourself really (each
side can only add 1500 htlcs, so the rest would have to be fee
changes; wrapping will only make us hang up on you).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-31 17:12:20 +10:30
Rusty Russell b7a7234717 packets: remember callbacks for acks on queued packets.
Not used yet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-30 16:57:41 +10:30
Rusty Russell 57689390fb state: queue packets directly.
Rather than creating packets then queueing them, call out to functions
which do both.  This moves us towards doing more work in those functions
where we send out a request, which is sometimes clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-30 16:57:18 +10:30
Rusty Russell 8ed68179a5 funding: add 64-bit id to HTLCs.
This gives us a reliable way to distinguish HTLCs, even in the face of
duplicate R values.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-30 16:55:03 +10:30
Rusty Russell b6943b9198 protocol: remove support for uncompressed pubkeys.
There's no good reason to support them, and this way every key is 33 bytes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-30 16:54:16 +10:30
Rusty Russell 8c468c1e15 daemon: use fee rates rather than absolute fees (BOLT #2)
And divide fees as specified there.

We still use fixed values rather than floating, and we don't send or
handle update_fee messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:12:43 +10:30
Rusty Russell ba2854e835 peer: don't segv if closing before anchor established.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:11:56 +10:30
Rusty Russell 4c3370e023 funding: trivial variable rename
"state" is reserved for lightningd_state; use cstate in
initial_funding() like everywhere else.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:11:26 +10:30
Rusty Russell 04b4eb2f59 daemon/test: Fix printing when getblock doesn't show tx.
Ran into this when machine was under massive load.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:10:42 +10:30
Rusty Russell 994addadce state: INPUT_CONNECTION_LOST
We used to have a hacky close timeout which would immediately fire
when we'd closed because the connection was down.  Far better to have
a specific "connection lost" input, and have it respond like CMD_CLOSE.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:09:44 +10:30
Rusty Russell b423b33236 protocol: implement close as per BOLT #2.
We don't actually implement closing when we have HTLCs (we should
allow it, as that's what the clearing phase is for), since soon we'll
rewrite HTLC to match the async HTLC protocol of BOLT #2.

Note that this folds the close paths, using a simple check if we have
a close transaction.  That's a slight state layer violation, but
reduces code duplication.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:09:41 +10:30
Rusty Russell afedf0e8ac cryptopkt: implement ack callbacks.
For the change to asynchronous updates as specified by BOLT #2, we
need to know when the other side acknowledged a packet.  This creates
a simple callback mechanism for it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:03:44 +10:30
Rusty Russell 8131ff57a8 cryptopkt: don't create clever io routine, embed callback in io_data.
We have a structure, let's use it to store the callback and avoid
lots of complex code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-24 12:02:25 +10:30
Rusty Russell 85e0099aad TODO.md: new file with random thoughts for people to hack on.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-16 16:07:12 +10:30
Rusty Russell 18a9e5bda2 daemon: Implement encryption as per BOLT #1.
This uses libsodium (we could use openssl, but the required primitives
are only in 1.1.0 which is still in alpha).

It doesn't handle reconnections yet, either.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-16 16:06:17 +10:30
Rusty Russell 923313e3d3 crypto: add length prefix to handshake.
As per BOLT#1.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:10:42 +10:30
Rusty Russell 6a062d8527 daemon: check protobuf-c version, report failure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:09:42 +10:30
Rusty Russell 6410b0ac9c test: don't reply on specific bitcoin.conf settings.
I changed mine off regtest, and "make check" broke.  Fix that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:08:42 +10:30
Rusty Russell 8f2e66089b daemon: add --bitcoin-datadir for bitcoin-cli.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:08:40 +10:30
Rusty Russell ab0b9271f0 README.md: Update with reference to BOLT RFCs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:08:38 +10:30
Rusty Russell f8a96ba11f daemon: remove try_command call after queue_cmd.
queue_cmd already calls try_command; this is reduandant.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:08:36 +10:30
Rusty Russell b017ca1240 protocol: include next revocation hash in open packet.
This means we send the first two revocation hashes; this is important
once we move to a commit model as we need to send (unsolicited) the
signature for the *next* commit tx so we need its commit hash.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:08:35 +10:30
Rusty Russell 53a8aef95c daemon: use dynamic array for outgoing queue.
Coming changes to the protocol allow theoretically infinite outstanding
packets, so remove [5].

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:08:31 +10:30
Rusty Russell cc16f46621 daemon: introduce union htlc_staging for proposed changes to HTLCs.
This encapsulates proposals more cleanly, and is important when we change
the protocol to have more than one outstanding at a time.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:07:31 +10:30
Rusty Russell b8911cde98 daemon: don't allocate htlc inside struct newhtlc.
It's overkill.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:07:31 +10:30
Rusty Russell 64e5ce1530 test: remove test_state_coverage
We're going to change the protocol to send multiple changes at once, so
disable this compilation and testing for now.

We can revisit it afterwards once the protocol is stable again.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:07:31 +10:30
Rusty Russell b218e79206 daemon: make find_peer take the raw token.
Cuts duplicate code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:07:31 +10:30
Rusty Russell 71c02c7b4c daemon: make json_get_param() understand which args are compulsory.
So far only one isn't, so this saves us some checks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:07:30 +10:30
Rusty Russell 85147347e2 funding: explicitly mark which side offered the anchor.
The channel funding code needs to know who offered the anchor, as they
are responsible for paying fees until the other side is able to.  This
is actually a hack, but at least now it's internal to funding and not
passed in at every funding_delta() call.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-15 17:07:30 +10:30
Rusty Russell cb0cc80984 patch remove-timeout.patch 2016-03-15 17:07:12 +10:30
Rusty Russell 1f9103c9d3 daemon: rename num_htlcs to commit_tx_counter.
Much clearer name.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:43:15 +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 3494cbfb7c protocol: remove update message
We never do unilateral transfers, except via an HTLC.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:40: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 09358498cd Remove test-cli
We're about to change the protocol again, and I don't want to do the
grunt work to update these.  They were useful for pre-build protocol
testing, though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:37:15 +10:30
Rusty Russell 35ab923163 peer: fix dangling peer->current_htlc->htlc pointer.
It currently points into freed memory once we've make_commit_txs; we
don't currently dereference it after that, but I did in some test code
and got a surprise.  Make a copy in all cases where we set it, so
there can't be lifetime problems.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:36:15 +10:30
Rusty Russell 3fbee72f3a daemon/test: make --verbose flag less verbose.
Just print out the commands we do, not -x which gives TMI.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:35:15 +10:30
Rusty Russell ae82c0a12c daemon/test: Make --gdb1/--gdb2 actually work, clean up params.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:34:15 +10:30
Rusty Russell 16a7e3dc97 daemon/test: always test with valgrind, don't print errors unless a problem.
Unfortunately this seems to require longer sleeps.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:33:15 +10:30
Rusty Russell b280cab6b0 Makefile: clean daemon files with make clean.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:32:15 +10:30
Rusty Russell c1d1b360bf daemon: add memcheck() in various places where we expect things to be initialized.
This just causes valgrind to warn sooner.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:31:15 +10:30
Rusty Russell ab1176d218 jsonrpc: rename "id" to "peerid" everywhere.
To be distinct from HTLC ids.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:30:15 +10:30
Rusty Russell 48a4ec88dd daemon/test/test.sh: remove -x flag, add --verbose option.
--verbose also turns on grep outputs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-03-08 10:29:15 +10:30
Rusty Russell 9544306f5b Merge pull request #19 from braydonf/doc/install
doc: add install notes
2016-03-08 10:28:15 +10:30
Braydon Fuller e0c4d40899 doc: add install notes 2016-02-24 23:59:33 -05:00
Rusty Russell 6750794667 Use #if instead of #ifdef (we already use -Wundef).
This avoids embarassing typos in future.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-27 15:00:50 +10:30
Rusty Russell 1e93da5513 Really enable checklocktimeverify support.
Next patch will make sure this never happens again.

Fixes: #18
Reported-by: Fabrice
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-27 14:52:30 +10:30
Rusty Russell 329f4f7dc2 Correct the formatting of HACKING.md; add top-level files reference.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 09:09:33 +10:30