Commit Graph

770 Commits

Author SHA1 Message Date
Rusty Russell 0bd12b4e97 daemon/packets.h: create from prototypes which were in state.h.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 149fa341be packets.c: accept_pkt_* should do less state-mangling.
Move other logic into caller, but it's not complete (it still needs to
check some things, and still records some results).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 6615db32c0 packets.c: queue_pkt_* only creates and sends packets.
Move other logic into caller: it grew this way because we used to have
a centralized "state" machine which knew nothing of these internal
details.  But now we want to re-queue packets on reconnect, we really
want these routines to be idempotent.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell abf4182ef5 peer: cache txid for commitment_tx.
Minor efficiency and simplification.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 7b2d6925a0 channel: assert htlc direction is correct.
The HTLC state encodes the creator; this should match the side argument.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 1f99268633 commit_tx: expose wscript and scriptpubkey for to_us/to_them payments.
This is useful for locating them given a random on-chain transaction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell d9e825bc2c create_commit_tx: use HTLC map, not cstate HTLC array.
The HTLC state tells us whether a HTLC is in the commitment transaction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 0af04b0576 peer: use commit_tx's newly exposed witness script helpers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell ef77cb8349 commit_tx: expose internals to give access to HTLC witness scripts.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell ca142a0b47 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> 2016-08-18 14:23:45 +09:30
Rusty Russell 440fec099b peer: expose HTLC state through RPC.
This is much more explicit and clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 04fa3a71a9 peer: use peer->htlcs in JSON getpeers output, instead of cstate array.
We're weaning off the cstate arrays; use the htlc map.  But for the
moment we keep the output basically the same.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 0e78ccca56 daemon: don't allow manual fulfill command until both sides committed.
We had an occasional race where we hadn't gotten the remote revocation
before submitting fulfill (spotted by the HTLC state transition code).

Disallow this, but also add to the json output so we can wait for
an HTLC to be irrevocably committed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 4963f277aa daemon/test: prepare for random-ordered htlcs, cleanup parsing.
If we always remove " from JSON, our parsing becomes simpler; turns
out that we did that in some places, and check()'s eval removed them
from the comparison.

We extract check_balance_single() to check the general balance, then
grep for HTLCs separately.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 1af3428c6c peer: keep a single HTLC map for all htlcs.
Not separate "locally-offered" and "remotely-offered" ones; we can
distinguish them by htlc->state now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 4b5ec85c25 daemon: keep enum htlc_state within struct htlc.
And update the state as HTLCs get moved around.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 22976bdd32 daemon: use HTLC states.
Since we only care about the latest commits, we can simply associate a
state with each HTLC, rather than using queues of HTLCs associated
with each commitment transaction.

This works far better in the context of a database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell de7fb4a83f test_protocol: restart support.
We keep a "database" for each side's persistent state.  Upon restart,
each side tells the other where it was up to, in terms of the number
of commit and revocation messages it receives.

Because only one update can be in flight at a time, we can tell w

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 25d9962e81 test_protocol: add --verbose flag.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell 3e34d50339 test_protocol: fix --svg
Had bitrotted, and was completely broken with recent changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:45 +09:30
Rusty Russell ba50776c47 test_protocol: fix up expected test output.
Our implementation now displays things differently, so output changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:44 +09:30
Rusty Russell 73df39e0c9 test_protocol: attach states to each HTLC, rather than using queues.
This is simpler for database representation, and also allows simple
bit-tests for what is happening to a HTLC (eg. am I committed to it?
Are you?  etc.)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:44 +09:30
Rusty Russell d54a59f010 test_protocol: remove support for multiple commits in flight.
Laolu pointed out that we can't have multiple in flight, since we can't
sign without knowing the next revocation preimage.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:44 +09:30
Rusty Russell 836eee048b test_protocol: rename struct funding to struct commit_tx.
This is really what it is.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:44 +09:30
Rusty Russell 60b4543899 peer: fix --port option.
We need SO_REUSEADDR, and we need to memset sockaddr to zero; valgrind
complains for both IPv4 and IPv6, but the invalid sin6_flowinfo causes
the IPv6 bind to fail altogether.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:20 +09:30
Rusty Russell d0285416fb log: ability to log struct rval.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-17 14:46:42 +09:30
Rusty Russell 7b1187d446 check: make (successful) tests less noisy.
Particularly, don't show the output for generating 432 blocks!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-17 14:46:36 +09:30
Rusty Russell dc0efc5c52 Merge remote-tracking branch 'origin/pr/31' 2016-08-14 09:42:34 +09:30
Braydon Fuller 6ac96323fd INSTALL.md: update install details for ubuntu 16.04 2016-08-13 00:55:06 -04:00
Rusty Russell bcd3e5f60e base58: fix check-source header order check.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 15:30:34 +09:30
Rusty Russell 4563ff91e9 lightningd: don't create rpc socket & listening socket until topology known.
We can deref a NULL tip pointer otherwise.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:11:24 +09:30
Rusty Russell 35f83841da chaintopology: make sure we have a tip before continuing.
We can't service peers until we have some chain topology.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:11:22 +09:30
Rusty Russell 441d598dca daemon: broadcast transaction when fulfilling onchain.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:11:19 +09:30
Rusty Russell 748f477508 maintclean: fix depends and typo
Make CORE_OBJS depends on headers, also make them depend on CCAN headers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:11:13 +09:30
Rusty Russell 8345bff825 cryptopkt: revert ack split in authenticate_packet
We need to remember the transmit order anyway, so a single counter works.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:11:11 +09:30
Rusty Russell f00ee00fd8 peer: log unexpected packets properly.
And only try to print the contents if they're PKT_ERR.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:11:10 +09:30
Rusty Russell 4801f78aad INSTALL.md: update to remove openssl dependency, add libbase58
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:10:19 +09:30
Rusty Russell e252f5de7d base58: remove openssl include, and undefined function declaration.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-09 13:10:19 +09:30
Christian Decker 7546fad324 Removing OpenSSL as a dependency. 2016-08-09 13:10:19 +09:30
Christian Decker e37bd38fdd Switched from openssl to sodium for test_onion 2016-08-09 13:10:19 +09:30
Christian Decker 1f4a056009 Switched base58 to use libbase58. 2016-08-09 13:10:19 +09:30
Rusty Russell f086e44358 Fix check-source: reorder includes in alphabetical order.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-20 14:29:53 +09:30
Rusty Russell 6015cedee8 process_estimatefee: fix bad logic.
Refactor the fallback to make it more robust.

Fixes: #28
Reported-by: Jacob <jacobdnd@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-20 11:51:28 +09:30
Rusty Russell 6199b886fa Merge remote-tracking branch 'origin/pr/26' 2016-07-19 12:40:25 +09:30
Rusty Russell 2038104cfc Merge remote-tracking branch 'origin/pr/27' 2016-07-19 12:40:19 +09:30
Rusty Russell 5472f73f9c cryptopkt: update to latest encryption BOLT.
As per lightning-rfc commit b579b16866855da166981192c0f0549517069d4e.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-07-19 12:37:33 +09:30
throckmortonsign 30ed93f2bf Update README.md
fix links to BOLTs
2016-07-07 16:49:05 -05:00
Jacob ae52977e42 fixed whitespace 2016-07-07 13:49:01 -05:00
Jacob dc2d83bfbe Replace OpenSSL's RAND_bytes() with libsodium's randombytes_buf() 2016-07-07 13:42:28 -05:00
Jacob 4751522162 Changed openssl's RAND_bytes() to sodium's randombytes_buf() 2016-07-07 13:22:14 -05:00