Commit Graph

281 Commits

Author SHA1 Message Date
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