Commit Graph

350 Commits

Author SHA1 Message Date
Rusty Russell 6b05436a7a open: use a single transaction when shutdown, so it's atomic.
This covers the case of shutdown during open.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 41d4779abe peer_database_err: helper for database error packet.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell eedf95a8fc state_types: simplify open states.
The state now doesn't differentiate between who is funding.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 1f23905bee peer: move start_closing() function higher in peer.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 99e48c7c87 peer: don't differentiate who is funding via state when waiting for open.
It doesn't actually help here; we only did it because we differentiate
the states later, and with refactoring we do that via the explicit
offer_anchor flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell ea74bac8b8 state: hoist open-they-are-funding states handling into peer.c, remove state.[ch]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell 75ff09b310 state: hoist open-we-are-funding states handling into peer.c
This means we can now do all database changes, including db_set_visible_state,
within a single transaction (ie. atomically).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell 8c5fae2b28 patch remove-bitcoin_release_anchor.patch 2016-11-09 08:04:24 +10:30
Rusty Russell f71f0da19c offer_anchor: store a bool, not am enum state_input.
Since we no longer feed it into state.c, we can just us a bool.
And that's the last of the CMD_* in the enum state_input, so remove them
all.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:24 +10:30
Rusty Russell 847ce8b092 state: move first state transition into peer.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:24 +10:30
Rusty Russell bbd1bbd931 state: remove anchor timeout.
We'll bring it back as a block-based timeout at the end.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:20 +10:30
Rusty Russell b349e2884b state: move anchor-depth-ok code into peer.c
This is the beginning of removing state.c altogether.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 22:03:55 +10:30
Rusty Russell 4151537b71 peer: commit outstanding changes before sending PKT_CLOSE.
Pierre points out that we don't handle this, and it can happen due
to race; the spec says we are not supposed to send PKT_CLOSE with
uncommitted changes.

Closes: #29
Reported-by: Pierre-Marie Padiou
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:59:55 +10:30
Rusty Russell 16cff6951f peer: hoist do_commit and have it return false if it failed.
Next patch will call it from peer_start_shutdown().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:58:55 +10:30
Rusty Russell 92e5f53f4d peer: free packet when we close connection in init_pkt_in.
Otherwise if they reconnect, we hit the assert in recv_body:
	assert(!peer->inpkt);

Found by testing on my build box *without* valgrind (so it was fast
enough to do this).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:48:55 +10:30
Rusty Russell dbd8e07924 broadcast_tx: make sure callers free tx if necessary.
Now broadcast_tx() doesn't take ownership of the tx, make sure callers
free; a bit of refactoring to make it clear when we're making a new tx
vs. accessing an existing one, to make this clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:03:02 +10:30
Rusty Russell 49a80ba457 peer: fail channel if funding transaction broadcast fails.
Closes: #51
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:02:02 +10:30
Rusty Russell 7aa01b0e50 broadcast_tx: add optional failed callback.
And if that's set, don't rebroadcast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:01:02 +10:30
Rusty Russell 04cff14ac8 peer: don't fret about fees too low on testnet.
Testnet fees are all over the place: don't close a connection due to
that.

Closes: #59
Reported-by: Thomas Daede <daede003@umn.edu>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-06 14:47:16 +10:30
Rusty Russell b49b90d5c3 peer: don't ever fail twice.
There are paths where this can happen (eg. db fail), but don't call
peer_breakdown() twice.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-06 14:46:16 +10:30
Rusty Russell 4855af8ba2 peer: don't worry about feechange if we can't do anything about it.
Triggering a commit will just do nothing anyway (same check at the
top of try_commit).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-06 14:45:16 +10:30
Rusty Russell ab11322b39 peer: don't close due to too low fees if we're already closed.
This fixes half of #59 (the part which crashes).  It doesn't fix the
fact that we should never be doing this for testnet.

Reported-by: Thomas Daede <daede003@umn.edu>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-06 14:44:16 +10:30
Rusty Russell 8949290794 Merge remote-tracking branch 'origin/pr/66'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-05 13:48:38 +10:30
Rusty Russell 25bb0f5248 peer: use correct enum in case statement.
These are the same, but we're using the ones from state.h instead of the
packet types directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 12:12:38 +10:30
Rusty Russell a902193874 sphinx: don't leak, especially on failed onion.
Generally, the pattern is: everything returned is allocated off the return
value, which is the only thing allocated off the context.  And it's always
freed.

Also, tal_free() returns NULL, so it's useful for one-line error
cleanups.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:04 +10:30
Rusty Russell ac7d80bbeb peer: don't assign io_data and id twice when connecting out.
peer_first_connected does this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:04 +10:30
Rusty Russell 8a1559a343 peer: free init packet.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:04 +10:30
Rusty Russell 6bda93f99a peer: don't leave initial cstate around.
Attach it to the commit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:04 +10:30
Rusty Russell 64809fb730 peer: free temporary transaction immediately
Don't leave it around until connect is finished.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:03 +10:30
Rusty Russell 8015ceadfd log: add netaddr
Also avoids allocating netaddr_name which otherwise lasts as long
as connection does.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:03 +10:30
Rusty Russell 7d20c4f75b feechange: disable sending of feechange messages.
We've seen intermittant failures on testnet, so disable sending feechanges
for now: we're completely changing it for 0.6 anyway, due to Milan Spec.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-19 12:00:27 +10:30
Rusty Russell 02cb651748 Merge remote-tracking branch 'origin/pr/46'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-17 12:37:20 +10:30
Christian Decker 1d3737055a sphinx: Integrate sphinx OR with lightningd
Now replaces the old cleartext onion routing with the sphinx
implementation.
2016-10-16 16:40:50 +02:00
Rusty Russell 5797dc6496 init: add comments as per updated BOLT #2.
To match 8ad8041990dc "wire-protocol: rename reconnect_pkt to
init_pkt, add feature bits."

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 17:40:04 +10:30
Rusty Russell 5e078a8167 pkt_init: check feature bits.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 17:39:55 +10:30
Rusty Russell ec64e7756e protocol: pkt_reconnect becomes pkt_init, and always send.
Make this always the first packet after auth.  That means there's no
reliance on whether a node remembers an aborted connection.

It also gives us a place to put version bits.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 17:39:34 +10:30
Rusty Russell e5994ad8c1 json_connect: don't return until we're in state normal.
This gives much better errors, and allows us to return the peer id.

Closes: #37
Reported-by: Glenn Willen
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:01:18 +10:30
Rusty Russell a1f1f1eda8 daemon: fix feechange logic.
Firstly, we need to update the staging fee amount when we queue a change.
Secondly we need to remove completed fee updates, otherwise we hit a
database constraint that peer & state are unique.

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:17 +10:30
Rusty Russell e2090f015d peer: don't spin when we want to commit and are not connected.
Instead, stop timer loop, and restart when we connect again.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:17 +10:30
Rusty Russell 25b3dc0038 channel: fix max feelevel calculation.
We were out by 1000, and also derived it from the previous, not current
state.

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:17 +10:30
Rusty Russell ab569c069f peer: add FIXME for the STATE_INIT case.
We store peers in the database for STATE_INIT, but they don't reconnect
properly.  We should not forget STATE_INIT dropped peers, but use some
timeout mechanism if we can't reconnect to clean up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:17 +10:30
Rusty Russell fb99e0ccb0 peer: fail immediately if we detect double-connection.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell 0f6c387899 peer: delete from database if we haven't passed init.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell 1f1bd56e2a peer: add more logging for anchor events.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell 93b72332bd Handle anchor in a run of blocks.
Fix dff50c3a5f2224592d135ad9cc6c11be89e26def: if multiple blocks come between
polling, we'll get called once for the new tip.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 13:53:18 +10:30
Rusty Russell dff50c3a5f peer: do not send anchor depth input twice.
We *should* be in a state which accepts it (could happen with reorg),
and there's no reason to test for greater than depth since we must process
blocks in order.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-13 15:26:44 +09:30
Rusty Russell 7b5806fef2 peer: give more sensible error if anchor is too large.
Currently we get the odd message "Own anchor has insufficient funds".

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-13 12:40:32 +09:30
Rusty Russell 13593d4cbf peer: don't try to change fees while we're still setting up channel.
And add a FIXME about doing feechanges properly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-13 12:40:28 +09:30
Rusty Russell 221a96cdeb getinfo: new RPC command
Useful for getting ID, what port (if not set in config file).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-13 03:37:07 +09:30
Rusty Russell fce9ee29e3 db: always call db_update_our_closing in a transaction.
It's not in a transaction in one caller, so wrap that.
This removes some more error handling code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell 5bcc9047b0 db: save error, return it when we commit transaction.
This saves a lot of error handling, and puts it in the place we care about.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell ea41386ed3 daemon: rename all the low-level commands to dev-
Rename the structs to match (and remove dev-echo).

This makes it clear that they're not the normal API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell 27715f7732 invoice: order by when they were paid.
We need some ordering to deliver them to the JSON "waitinvoice" command;
we use a counter where 0 means "unpaid".

We keep two lists now, one for unpaid and one for paid invoices.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell 68632e6020 Use "msatoshi" not "msatoshis" everywhere.
Including in JSON API.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell 060ff29b45 Rename payment to invoice.
And rename JSON's accept-payment command to invoice.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 16:47:49 +09:30
Rusty Russell ab125f709b db: save and restore accepted payments.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-06 13:47:33 +09:30
Rusty Russell b47fbfead0 db: Always fail HTLC inside a transaction.
This is important when we put payments in the database: they need to be
updated atomically as the HTLC is.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-02 12:02:18 +09:30
Rusty Russell 23049f09a9 db: Always fulfill HTLC inside a transaction.
This is important when we put payments in the database: they need to be
updated atomically as the HTLC is.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-02 12:01:18 +09:30
Rusty Russell 1ed4dbde05 peer: add peer_fail helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-09-02 12:00:18 +09:30
Rusty Russell 15b42b89db peer: fix comparison bug if our connection_fee is negative.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 17:19:41 +09:30
Rusty Russell d8af789bbb channel: remove enum channel_side, rename htlc_side to side.
We had enum channel_side (OURS, THEIRS) for which end of a channel we
had, and htlc_side (LOCAL, REMOTE) for who proposed the HTLC.

Combine these both into simply "enum side".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:32 +09:30
Rusty Russell f8fa8c8dff peer: handle case correctly where they can't handle fees.
When they propose an HTLC to us, they need to be able to cover both it,
and the associated fees.  When it gets acked and applied to them, however,
they may no longer be able to afford the fees; this is OK and expected.

So add a flag to say whether they can dig into fees or not: without
this patch the code calls fatal() on the next patch which tests it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:32 +09:30
Rusty Russell 1518f4424e log: add channel_state logging ability.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:32 +09:30
Rusty Russell 89235e0904 handle_pkt_commit: don't abort on database error.
Simply mark an error with this peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:32 +09:30
Rusty Russell bb0bf2b5ad log: add easy way to log hex blobs.
Use it in one case, and also fix another logging FIXME.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:32 +09:30
Rusty Russell 87af51a422 daemon: remove three fixed FIXMEs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:31 +09:30
Rusty Russell 42cf0ef543 peer: do logging before crypto is on.
We create a logging object when we connect, then carry it through.  If
it comes from the database, we just use the peerid as the log prefix.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:31 +09:30
Rusty Russell 9bd6a10f49 peer: fix close before their sig has been received in corner case.
If we haven't received their closing signature yet, we might try to
send the closing packet anyway (and segfault).  Make sure we have
their signature before trying that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:31 +09:30
Rusty Russell 2610799bda pay: split into getroute and sendpay
This is less convenient to use, but makes far more sense for a real
user (like a wallet).  It can ask about the route, then decide whether
to use it or not.

This will make even more sense once we add a parameter to control how
long we let the HTLC be delayed for, so a client can query for high,
medium and low tolerances and compare results.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:06:08 +09:30
Rusty Russell 012574790d pay: make interface idempotent.
We stopped automatically retransmitting locally-generated add/removes
after a reconnect, but this breaks the "pay" interface as it stands.

The correct solution to this is to make the pay interface idempotent:
you can trigger it as many times as you want and it will only succeed
once.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 16:04:59 +09:30
Rusty Russell 74107ff1ea peer: resend failures on restart/reconnect.
If we've not relayed a failure yet (ie. we relayed it instantly, but it
wasn't confirmed), we need to redo it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 14:51:43 +09:30
Rusty Russell d4ddebd55a htlc: save fail message in HTLC.
It's not currently encrypted, but at least you get some idea now why
an HTLC failed.  We (ab)use HTTP error codes for the moment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 14:51:41 +09:30
Rusty Russell 192d5402ff peer: remove unused arg from our_htlc_failed().
And fix one case where we didn't set htlc r value (onchain redemption).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-30 20:14:57 +09:30
Rusty Russell 7e95637cb5 peer: on restart, resend any fulfilled HTLCs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-30 20:13:57 +09:30
Rusty Russell 1bd2a28caa peer: on restart, only resubmit added HTLCs which weren't already routed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-30 20:12:57 +09:30
Rusty Russell d964ad2d94 daemon: don't restart newhtlc/failhtlc/fulfill htlc commands on reconnect,
These low level commands we restarted on reconnect for ease of
testing.  Don't do that, and check that we're connected when those
commands occur.

This introduces subtle issues with --manual-commit --reconnect: restarting
node1 also forgets uncommitted things from node2, requiring reordering for
some tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-30 20:11:57 +09:30
Rusty Russell 7550ec23ec daemon: new command gethtlcs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-30 20:09:57 +09:30
Rusty Russell b0278d7152 peer: fix maximum htlc value when we disconnect.
If we send an HTLC #1, then get disconnected before a confirm, we will
forget it.  But we've incremented peer->htlc_id_counter, so when we offer
it again we'll make it HTLC #2, which is non-consecutive.

To make this clear, we always start htlc ids at 0 now.  That revealed
the bugs handled in the previous patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-28 12:51:57 +09:30
Rusty Russell 72a9cfbbe2 test: test feerate changes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-26 15:33:47 +09:30
Rusty Russell 1305df6417 daemon: send feechange requests.
This is a bit overzealous, but good for testing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-26 15:33:40 +09:30
Rusty Russell 31bdf384cb daemon: accept feechange packets.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-26 15:33:30 +09:30
Rusty Russell e7b003b499 daemon: handle feechange requests.
I originally overloaded struct htlc for this, as they go through the
same states, but separating them turned out to be clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-26 15:31:19 +09:30
Rusty Russell e40a070014 json_commit: document usage correctly.
It's pretty horrible to hand the entire tx, but at least document it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-19 10:34:12 +09:30
Rusty Russell 319c2ec5fc peer: keep addresses separately from peers.
This makes more sense eventually: we may know the network addresses of
many peers, not just those we're connecting to.  So keep a mapping, and
update it when we successfully connect outwards.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell 9f512f6540 peer: restart from the other side.
Testing this revealed that we can't just reconnect when we have something to
send, as we might be NATed; we should try to reconnect anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell 5f368f1c95 peer: save/load results in database.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +09:30
Rusty Russell be38d3f507 Minor cleanups: things found while debugging the database code.
1. Fix #ifdef DEBUG code in signature.c so it compiles.
2. Don't set peer->closing.our_script in queue_pkt_close_shutdown: it's
   assigned in caller already.
3. Wrap setting of htlc's rval in set_htlc_rval() function.
4. Log where we were when unexpected packet comes in.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 0bb183e028 peer: split and expose new_peer function.
More of a pure allocator, for when we load peers from db.  Also moves
shachain_init out of secrets and into new_peer where it logically
belongs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 9b869a80a1 peer: set up peer->nc only when in state NORMAL.
This ensures we don't try to route before we're set up, or once we're
shutting down.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 87da9634bc routing: use ids, not nodes in interface.
Turns out to be more convenient.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 8a3c9908ce protocol: no signature in update_commit if receiver has no outputs.
So if there are no HTLCs, and the receiver can't spend anyway, don't
sign.  This has the added benefit that no two signed commitment
transactions will ever be identical (the revocation preimage changes).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 5f4b4525b3 peer: use signed values for order.
This gives us a clear way to indicate "invalid", and also sqlite3 stores
signed 64-bit numbers, so it's clearer this way.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 15e8bd5a45 peer: save minimum possible depth for anchor.
We'll save this in the database so we know where to start the chain
from when we reload.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 795601dfcf daemon: reconnect with timeout, try from both sides.
This is dumb, since one side will never succeed.  But in future when
there is a method for nodes to broadcast their public address (or send
their address inline to connected nodes), either side should try to
connect.

Importantly though, there are places which will queue packets at
various times (eg. HTLC timeout), so we need to clear the queue just
before re-transmitting, not when disconnecting.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell 3866d7605c daemon: reconnect support.
To do this we keep an order counter so we know how to retransmit.  We
could simply keep old packets, but this is a little clearer for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:08 +09:30
Rusty Russell fd650ba79d protocol: rename clearing to shutdown.
As per lightning-rfc e277023be40f0dcc7ff7e818cef1e0d23547cb8c.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell bb28bbd470 peer: always initialize commit_info commit number, other fields.
We used to use talz, but that prevents valgrind from noticing when we use
uninitialized fields.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 02cb7abd9d bitcoind: keep running fee estimate.
This avoids us having to query it when we create anchor transaction, and
lets us always use dynamic fee information.

The config options for max and min are now percentages, rather than absolute.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell ab38fd7542 peer: rename closing_onchain to onchain.
The "closing" is implied.  Plus, it's too long.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell e19d5751fe peer: remove commit_info's prev pointer.
This is the final step before removing old commit_infos entirely.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30