Commit Graph

996 Commits

Author SHA1 Message Date
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 3c75bf550a TODO: remove done items.
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 43c0cdb5e4 test: check overlapping HTLC fails.
This triggered an assert until the last patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-31 14:51:44 +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 169c6b53cb protobuf_convert: expose helpers for unwrapping protobufs into tal heirarchies
It's still ugly, but at least it's encapsulated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-30 20:15:57 +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 92187ae5e7 test: print output of commands which fail.
We capture the output in case we need to resubmit the command after restarting,
but we weren't printing it out on failure (set -e means we'd stop immediately).

As a side-effect of this change, we don't restart after failed
commands, which caused another bug: we were writing the 2->3 route to
the config file, but not restarting again, so we lost the route.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-30 20:10: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 555a753564 db: don't assume HTLCs in order when reconstructing channel state.
We don't have an ordering of HTLCs between peers: we don't know
whether your HTLC 0 or my HTLC 0 occurred first.  This matters,
as we play them all back to reconstruct state (probably overkill anyway).

So we add force_* operators which don't do bounds checks, and do
bounds checks at the end.  We also note that we don't need to apply
fee changes: that should be in the database already.

Also relax db constraints: IDs are not unique, they are unique per
side (we can both have HTLC #0).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-28 09:34:47 +09:30
Rusty Russell b22bdfcbe8 test: use random port/rpcport for bitcoind.
This means we don't get confused if a testnet bitcoind already running.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-26 15:44:04 +09:30
Christian Decker 754616c45a routing: Fix for single hop routes segfaulting.
The first hop is being stripped from computed routes, however the
first channel of the route is being used to get our peer address. This
results in segfaults if the route is just one hop, i.e., has no first
channel to get the peer's address from. Fixed by simply using an
existing pointer to our peer.
2016-08-26 15:39:35 +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 2c7256ac69 protocol: add feechange packet.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-25 11:39:46 +09:30
Rusty Russell c11c81a920 daemon: first unit test, infrastructure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-25 11:39:46 +09:30
Rusty Russell 24298a4278 channel: approx_max_feerate and can_afford_feerate
Routines for getting maximum feerate we should offer, and checking if their
offer is valid.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-25 11:39:46 +09:30
Rusty Russell c7f8ce9d3b Merge pull request #32 from braydonf/master
README.md: include libmysql-dev
2016-08-19 11:50:41 +09:30
Braydon Fuller 607922f2b8 README.md: include libmysql-dev 2016-08-18 22:07:35 -04:00
Rusty Russell 8d2776376a 0.4: Wright's Cryptographic Proof
Christian Decker moved us to libbase58 and off openssl; he got to name
this release.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-19 11:13:10 +09:30
Rusty Russell f1c34c2ec5 INSTALL: update requirements.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-19 11:05:32 +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 830a65de46 daemon: --add-route option.
This allows hardcoded routes in the config file, which is required until
we get route advertisements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:14 +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 f68607d10b db: forget peer properly.
Otherwise, if they reconnect, we get a database error.

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 190b30e958 daemon: test restarting.
We add a "dev-restart" command which causes the daemon to close fds
and exec itself.  Then we do it after every command, with the caveat
that we always send a commit before newhtlc, because if not committed,
that is forgotten.  Fulfillhtlc and failhtlc get resent, since they're
idempotent.

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 71b8a07c56 db.c: database API.
These tables could use a rework, as they largely reflect our internal
state.  But it's a start.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +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 ab2fac3714 peer: add flag to indicate whether we created anchor.
Useful for database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:25:13 +09:30
Rusty Russell f4fe42e977 commit_tx: more debugging.
Sometimes you need a bigger hammer.

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