Commit Graph

741 Commits

Author SHA1 Message Date
Christian Decker 28030c3d6b bitcoind: peer argument to bitcoind_sendrawtx is unused
This was a bit misleading, and we were passing in NULL sometimes
anyway. Removed unused argument.
2017-06-23 16:02:20 +09:30
Rusty Russell 3f65f0f000 lightningd: fix up malformed onion handling.
In the case where we can't decrypt the onion, we can't fail it in the
normal way (which is encrypted using the onion shared secret), we need
to respond with a update_fail_malformed_htlc message.

Moreover, we need to remember this for persistence.  This means that
we really have three conclusions for an HTLC: fulfilled, failed,
malformed.  Fix up the logic everywhere which assumed failed or
fulfilled.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 7c9b66e67f lightningd: peer_htlcs.c
Move HTLC handling out of peer_control.c.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 9327aa1df4 lightningd: fix logging of peer death.
We used level -1 to mean "append to log", but that doesn't actually
work, and results in an assert if we try to prune the logs:

	lightningd: daemon/pseudorand.c:36: pseudorand: Assertion `max' failed.

Expose logv_add and use that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-23 09:29:42 +09:30
Rusty Russell 6f181e0dc1 BOLT update for 8-byte satoshi values, and other updates.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-07 09:19:04 +09:30
Rusty Russell 7389aae26a Massive BOLT text underscore and formatting updates.
This brings us up to 61b5b3f7b4145c9d6d66973b6bfbf28e6c0a0791.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-06-07 09:19:04 +09:30
Rusty Russell 58bf67c310 dns: expose multiaddress connect code.
Internally the dns code has the ability to try connecting to multiple
addresses in a sequence.  Expose this, as we'll want it for reconnection.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell 0c8b24cf97 daemon/dns: hand netaddr we connected to through to callback.
That way it doesn't have to extract it from fd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Rusty Russell 61a2ed97e1 lightningd/peer_control: start of reconnect logic.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-25 14:24:47 +09:30
Christian Decker 05e951d748 wire: Correct the short channel id serialization to use 3+3+2
Fixes the `short_channel_id` being serialized as 4 bytes block height,
3 bytes transaction index and 1 byte output number, to use 3+3+2 as
the spec says.

The reordering in the unit test structs is mainly to be able to still
use `eq_upto` for tests.
2017-05-20 20:01:34 +09:30
Christian Decker b8ba8f003c logging: Removed automatic subprocess logging for bitcoind
This was responsible for a huge number of loglines simply because we
log every subprocess start and termination. Moving the logging
upstream to where it is really needed gets rid of the polling, that
are successful. A highly unscientific test shows a reduction in
loglines produced by lightningd from 17000 to 10000 lines.
2017-05-20 19:59:16 +09:30
Christian Decker 2d76b066c2 routing: Cleaning up old hostname and port handling
The single string-based hostname and port has been retired in favor of
having multiple `struct ipaddr`s from the `node_announcement`. This
breaks the hostnames and ports from IRC, but I didn't bother to
backport ipaddr for it since it is only used in the legacy daemon.
2017-05-10 12:37:44 +09:30
Christian Decker e972b208c7 routing: Passing back all addresses on getnodes 2017-05-10 12:37:44 +09:30
Christian Decker 26892e79bb routing: Reading multiple addresses from node_announcements 2017-05-10 12:37:44 +09:30
Christian Decker ed9668339d routing: Add command line option to specify external IP address
We don't currently have a good way to determine our external IP
address so let's at least give people an option to manually specify
it.
2017-05-10 12:37:44 +09:30
Christian Decker daf8866eb5 gossip: Implement the basic node_announcement
Rather a big commit, but I couldn't figure out how to split it
nicely. It introduces a new message from the channel to the master
signaling that the channel has been announced, so that the master can
take care of announcing the node itself. A provisorial announcement is
created and passed to the HSM, which signs it and passes it back to
the master. Finally the master injects it into gossipd which will take
care of broadcasting it.
2017-05-10 12:37:44 +09:30
Rusty Russell b99c5620ef struct secret: use everywhere.
We alternated between using a sha256 and using a privkey, but there are
numerous places where we have a random 32 bytes which are neither.

This fixes many of them (plus, struct privkey is now defined in terms of
struct secret).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-09 11:43:35 +09:30
Christian Decker f700662a56 routing: Reading the channel_id from routes passed in from JSONRPC 2017-05-02 11:47:52 +02:00
Christian Decker d87ca4121d routing: Returning channel_id to getroute requests
The new onion uses the `channel_id` instead of the `node_id` of the
next hop to identify where to forward the payment. So we return the
exact channel chosen by the routing algo, to avoid having to look it
up again later.
2017-05-02 11:47:52 +02:00
Rusty Russell aa01b7d120 test_lightningd.py: helper to sync blockheight.
We need this to avoid spurious errors in the next patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-05-02 11:46:46 +02:00
Rusty Russell 09a7064260 daemon/peer: try reconnecting based on bitcoind poll time, not 15 seconds.
We seem to be getting spurious reconnect failures on Travis, this
should fix it (15 seconds may be too long at worst case).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-25 22:00:28 +02:00
Christian Decker 6a072c4c6e Fix a double-free bug in the negotiation phase
The callback on `key_negotiate` was closing the connection under
certain circumstances and would also `free` the key_negotiate, which
would then be freed again once it returns. We steal it off of the
connection during the callback and doing the free manually afterwards
to make sure this can't happen.

Thanks to @jgriffiths for tracking this one down.

Fixes #142

Reported-By: @bjd and @bgorlick
2017-04-24 05:17:13 +00:00
Rusty Russell 52ee36c595 tests: run valgrind on children.
This fails on the old dev-restart tests, so we need to only enable it
for the new tests:

	rusty@rusty-XPS-13-9360:~/devel/cvs/lightning (guilt/ping-pong)$ daemon/test/test-basic --restart --verbose
	...
	{  }
	RESTARTING
	dev-restart failed!
	valgrind: mmap(0x38000000, 2265088) failed in UME with error 22 (Invalid argument).
	valgrind: this can be caused by executables with very large text, data or bss segments.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-12 09:09:19 -07:00
Christian Decker a215cb47f1 gossip: Verify channel_update signatures 2017-04-11 16:56:27 -07:00
Christian Decker 58196b5a32 gossipd: Verify signatures for incoming channel_announcements 2017-04-11 16:56:27 -07:00
Rusty Russell 8a84e961ed daemon/sphinx: support modern v0 hop payload.
This just means we put the outgoing_cltv_value where we used to put zeroes.
The old daemon simply ignores this, but the new one should check it as per
BOLT 4.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 8146b838e8 daemon/sphinx: split handling.
We want to use HSM to do the ECDH part, so split that out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell eb61446ec8 daemon/invoice: wean off dstate (a little), link into new daemon.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Rusty Russell 27764b65f9 lightningd: fix shachain to be 48-bits, with hack for legacy.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-04-01 23:59:46 +10:30
Christian Decker 6e81da3cd2 gossip: Fix a tag collision for different directions of a channel
Appending the channel direction ensures that the directions will be
treated independently. Without this only one direction would be
forwarded to the peers.
2017-03-29 12:51:15 +02:00
Christian Decker 7793bd1b9d gossip: Consolidated direction bit computation
The direction bit was computed in several spots and was inconsistent
in some cases. Now we compute it just in routing, and once when
starting up `channeld`, this avoids recomputing it all over the place.
2017-03-28 14:06:48 +10:30
Christian Decker 60a2227f0d channel: Disable channels that are lost via a channel_update
Before exiting, `channeld` constructs and sends a `channel_update`
marking the channel as disabled. This is the pro-active signalling
that the channel may no longer be used.
2017-03-23 13:34:03 +10:30
Christian Decker 73e65cac4d routing: Refactor get_route into its own method
The JSON-RPC call `getroute` and the functionality to compute the
actual route have been split so that we can reuse it independently of
the JSON-interface. Since this is now a routing-only method I also
moved it into `routing.[ch]` instead of `pay.c`.
2017-03-23 13:34:03 +10:30
Rusty Russell 39993f229d bitcoin/script: rename bitcoin_redeem_p2wpkh -> bitcoin_redeem_p2sh_p2wpkh
This is its full name, and less confusing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:35:48 +10:30
Rusty Russell e0d9b6efdf daemon/watch: fix macro clash.
'peer' vs 'struct peer' works iff the argument is actually called 'peer'.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:27:09 +10:30
Rusty Russell 484c45a8a1 chain_topology: fix double-free when peer dies.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-07 11:25:48 +10:30
Rusty Russell 7419fde9a0 Update to new spec: differentiate channel_id and short_channel_id.
The spec 4af8e1841151f0c6e8151979d6c89d11839b2f65 uses a 32-byte 'channel-id'
field, not to be confused with the 8-byte short ID used by gossip.  Rename
appropriately, and update to the new handshake protocol.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell 2ce6a4bcca daemon/peer: move struct peer to internal header.
We use a different 'struct peer' in the new daemons, so make sure
the structure isn't assumed in any shared files.

This is a temporary shim.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell 8d7acdc367 struct topology -> struct chain_topology
Topology also refers to the lightning network, be clear.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell e2c7925e0e daemon/chaintopology.c: remove last remaining lightningd_state references.
We put a topology pointer into struct outgoing_tx and struct block for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell 38cc6c2f21 daemon/chaintopology: move dev_no_broadcast from lightningd_state to here.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell 61e576ef12 daemon/chaintopology: use struct topology for more functions, not lightningd_state
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell 923526baf3 daemon/watch.c: move list of watched txs/txouts into struct topology.
This weans daemon/watch.c off relying on struct lightningd_state.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell d34dade8bb daemon/chaintopology: don't leave outgoing txs in peer structure.
The peer structure is only for the old daemon; instead move the list
of all outgoing txs for rebroadcasting into struct topology (still
owned by peers, so they are removed when it exits).

One subtlety: on exit, struct topology is free before the peers,
so they end up removing from a freed list.  Thus we actually free
every outgoing tx manually on topology free.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell e6efcdf5bd daemon/bitcoind: wean off struct lightningd_state.
We want to use this in the new daemon, so use 'struct bitcoind'
everywhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell 9387609c7b daemon/pseudorand: be more paranoid with isaac64 output.
There's no reason to think that the seed isn't reproducable from the
output: we don't want to give away our siphash seed and allow hashbombing,
so seed isaac with the SHA of the seed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell 293bebbe2d daemon/peer: handle narrow reconnect race on close.
Usually if we get a packet while closing (onchain event), we're going
through pkt_in which discards it.  However, if we're reconnecting, we
simply process the init packet and get upset because they've forgotten
us.

Hard to reproduce, but here's the log (in this case, test-routing --reconnect
and we have just done mutual close):

We reconnect in STATE_MUTUAL_CLOSING, send INIT pkt:

   +19.397025114 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Init with ack 1 opens + 9 sigs + 8 revokes + 1 shutdown + 1 closing

While waiting for response, we see the mutual close...
   +19.398732602 lightningd(4637):DEBUG: reaped 6370: bitcoin-cli -regtest=1 -datadir=/tmp/bitcoin-lightning2 getblock 2a63b209e17aedc5b1bcc6c2f9e044f97c9c3ca136fc64a719f704d2f632df5f false
   +19.401834422 lightningd(4637):DEBUG: Adding block 5fdf32f6d204f719a764fc36a13c9c7cf944e0f9c2c6bcb1c5ed7ae109b2632a
   +19.405167334 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Got UTXO spend for 8bb48a:0: 7f5e422f...

   +19.412543610 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: anchor_spent: STATE_MUTUAL_CLOSING => STATE_CLOSE_ONCHAIN_MUTUAL

And we also see it buried "forever" (10 blocks in test mode), so we forget peer:
   +19.423045014 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Anchor at depth 13
   +19.426775063 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: check_for_resolution: STATE_CLOSE_ONCHAIN_MUTUAL => STATE_CLOSED
   +19.427613109 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: db_forget_peer(023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898)
   +19.428130685 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: db_start_transaction(023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898)
   +19.501027511 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: db_commit_transaction(023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898)

Now, we get their reply, but they've forgotten us:
   +19.520208608 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Decrypted header len 5
   +19.520872035 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Received packet LEN=5, type=PKT__PKT_INIT
   +19.520999082 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Our order counter is 19, their ack 0
   +19.521078913 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: They acked 0, remote=16 local=15
   +19.521447174 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Queued pkt PKT__PKT_OPEN (order=19)
   +19.522563794 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Queued pkt PKT__PKT_OPEN_COMMIT_SIG (order=19)
   +19.523517319 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:BROKEN: Can't rexmit 2 when local commit 15 and remote 16
   +19.524613177 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:UNUSUAL: Sending PKT_ERROR: invalid ack
   +19.526638447 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: Queued pkt PKT__PKT_ERROR (order=19)
   +19.527508022 023ec94fb93c669154ba7b08907276e8c8661b2e65d80fc2c089215d5395574898:DEBUG: peer_comms_err: STATE_CLOSED => STATE_ERR_BREAKDOWN

We should never transition from STATE_CLOSED to STATE_ERR_BREAKDOWn,
and that's what this check prevents.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-03-02 22:51:49 +10:30
Rusty Russell c8df820e58 lightning/peer_control: set logging level for peers to match global.
That way it's controlled by --log-level=

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-24 16:22:56 +10:30
Rusty Russell edc30b12ea lightningd: --dev-debugger=<subdaemon>
Or for blackbox tests --gdb1=<subdaemon> / --gdb2=<subdaemon>.

This makes the subdaemon wait as soon as it's execed, so we can attach
the debugger.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-24 16:22:56 +10:30
Rusty Russell a72dd8d9de daemon/options: split option registration and parsing.
This allows us to add extra options before parsing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-02-24 16:22:56 +10:30