Commit Graph

825 Commits

Author SHA1 Message Date
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
Rusty Russell 7275aa9c32 channel: use u64 for fee_rate everywhere.
It fits in a u32, but we mix it with other values which could cause
overflow, so let's just use u64 everywhere.

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 9448358cfd chaintopology: wait for full blockchain load before start.
Caught because we generated an HTLCs which had already expired, since
we didn't know the latest block.  Other errors are certainly possible,
so it's safest to load the entire thing before going live.

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
Rusty Russell 19be4dbfe6 channel: remove htlcs array.
We could put it back later for debugging, but we should be using the global
state not this array.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 7cd9272ba9 htlc: htlc_is_dead() helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 23f9c7c209 permute_tx: don't save permutation map.
We no longer need it anywhere.  This simplifies things to the point where
we might as well just not include dust outputs as we go, rather than
explicitly removing them, which gets rid of remove_dust.c as well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell dca6c8efc1 peer: don't use permutation map for their unilateral spends.
Similar to the way we derive which outputs are which for old transactions
we steal, we derive them even for their current transaction.

We keep track of this information in peer->closing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 2e9a039789 peer: make closing_onchain.resolved[] in tx-output order.
At the moment, for our or their unilateral close, we create a resolved[]
entry for our output, their output, and each HTLC, in cstate order.  Some
of these outputs might not exist (too small), so it's actually better
to simply keep a resolved[] entry for each of the tx's actual outputs.

(We already changed the steal resolved[] array to work like this, but
these are trickier, since we rely on that order if we need to fulfill an
on-chain HTLC).

It also helps as we are weaning off knowing the cstate and permutation
mapping for each commitment transaction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 4319f3ac70 peer: explicitly store the previous revocation hash when sending new update.
We want to stop keeping old commitment information (except the minimal
txid to commitment-number mapping).  One place we currently use it is
after sending a commitment signature, and before we've received the
revocation for the old commitment.  For this duration, there are two
valid commitment transactions.

So we store "their_prev_revocation_hash" explicitly for this duration.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell d45161b07b daemon: use htlc id for fulfillhtlc and failhtlc commands.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell dd895e3c07 newhtlc command: return the HTLC id.
This is in preparation for using the HTLC id in other low-level JSON commands.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 2aaf0cb817 peer: remove unacked_changes and acked_changes queues.
These are now implied by the htlc state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 7709eb9b4a protocol: use separate ack packet.
It's a data-leak to send ack before we have verified identity of peer.
Plus, we can't send it until we know which peer it is, anyway!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-08-18 14:23:46 +09:30
Rusty Russell 5c9dfd5206 netaddr: routines to linearize/delinearize.
For putting them in the database.

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