Commit Graph

2134 Commits

Author SHA1 Message Date
Rusty Russell 86ecc6a058 onchaind: move wallet pubkey and private keys into globals.
As we start handling HTLCs, we need access to these from the
"wait_for_resolved" loop.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 2259faf3a9 onchaind: move feerate grinding into its own function.
We'll want to use this for htlc_success txs as well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 561a73328b onchaind: move keyset, feerate and dustlimit into global vars.
As we start handling HTLCs, we need access to these from the
"wait_for_resolved" loop.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 664ce8bfc2 watch: remove peer_debug helper.
This was part of the transition; we can now just log directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 9123d6d45e type_to_string: support preimage.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Rusty Russell 86313383a7 type_to_string: support ripemd160.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-28 13:07:05 +09:30
Christian Decker e418f2a7fe gossip: Make sure timestamp does not change while creating sig
If the HSM is slow it might happen that the timestamp has changed the
second time we come around, so we generate the timestamp externally
and pass it in so we're sure it won't change between calls.

Reported-by: Rusty Russell
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-16 09:02:06 +09:30
Christian Decker 081413e247 pytest: Added test to check node_announcement signatures
Reported-by: Rusty Russell
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-16 09:02:06 +09:30
Rusty Russell d39c27a304 lightningd: search path for our own directory.
Needed slight reformatting of log.h for stubs autogeneration.

Fixes: #277
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-15 13:44:34 +02:00
Rusty Russell 7e1154e1ec hsmd: use debug for backtraces.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell a21e31b2b2 subdaemons: catch backtrace on fatal signals.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell db19873ee4 lightningd: dump backtrace on crash or fatal().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell dba27188b7 external/libbacktrace: new external library for backtrace support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell 584b160cdc lightningd: avoid errors on shutdown.
lightningd can crash on shutdown if it's in the middle of getchaintips;
we free the conn, the finished callback is called (process_chaintips),
and it reports that it received an empty result.

The simplest fix is to set a flag in the struct bitcoind destructor,
and avoid the callback.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell ec63c0d10b lightningd: give option to crash if a subdaemon fails.
Either when it exits with a signal, or sends an error status message.
Then we make test_lightningd.py use it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell 64a26b06e7 tests/test_lightningd.py: fail on crash.log.
We simply kill lightningd; we should stop it properly and have a timeout
to kill it if that fails.  However, that's beyond my python skills :(

So we just look for crash.log.  Unfortunately, we usually kill
lightningd before it's finished writing it.  So we look for it and
don't kill lightningd, just wait in this case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell ef28b6112c status: use common status codes for all the failures.
This change is really to allow us to have a --dev-fail-on-subdaemon-fail option
so we can handle failures from subdaemons generically.

It also neatens handling so we can have an explicit callback for "peer
did something wrong" (which matters if we want to close the channel in
that case).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 23:00:53 +02:00
Rusty Russell f219955dc6 wallet: fix spending of change.
We recorded our own change as P2SH; it's not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 22:59:24 +02:00
Rusty Russell be90364f7f log: remove struct helpers.
They predated (and inspired) type_to_string(), which is more general.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 22:59:24 +02:00
Rusty Russell afabbe0cb0 log: add ltmp convenience context.
It's sometimes nicer where you don't have a convenient tmpctx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-12 22:59:24 +02:00
Rusty Russell dfa062b06a Makefile: make default correctly build $(ALL_PROGRAMS) and $(ALL_TEST_PROGRAMS).
We can't reference the variables until after they're set, so hence the
two-step.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-11 14:29:20 +02:00
Rusty Russell 4f5e7a4d92 lightningd/Makefile: clean up.
1. Remove reference to old $(LIGHTNINGD_OLD_LIB_OBJS) var (in handshaked too).
2. Make check depend directly on unit tests, insteadof weird lightningd/tests
   variable.
3. check-source-bolt and check-whitespace are automatic for $(ALL_TEST_PROGRAMS)
   so we don't need them here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-11 14:29:20 +02:00
Rusty Russell 4f6ae3209b common/test/test_sphinx: build fixes.
It isn't currently included in make check, so fix it to build and do that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-11 14:29:20 +02:00
Christian Decker 47a7fac29f make: Add cli/lightning-cli to default make target
Closes #270

Reported-by: @sumBTC
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-11 14:29:20 +02:00
Christian Decker fa13190595 wallet: Hook into the hsm_funding_sig to extract change outputs
This is the step where we broadcast the transaction to the network and
a nice place to extract the change from the transaction.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-10 10:48:53 +09:30
Christian Decker d14c9d30cd moveonly: Move make wallet_extract_owned available publicly
This was so far only used in the walletrpc, but we'll need it in a few
places.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-10 10:48:53 +09:30
Christian Decker 006d664b59 channeld: Make sure status_setup_sync is called before status_failed
This was still happening if reading the `channel_init` message failed.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-10 10:48:53 +09:30
Christian Decker 48b876e401 doc: cli is no longer in the daemon subdirectory
Closes #271

Reported-by: @sumBTC
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-09 19:22:01 +02:00
Rusty Russell cc34f572ca channeld: fix sync write to master.
We hit:
	assert(!peer->handle_master_reply);

#4  0x000055bba3b030a0 in master_sync_reply (peer=0x55bba41c0030, 
    msg=0x55bba41c6a80 "", replytype=WIRE_CHANNEL_GOT_COMMITSIG_REPLY, 
    handle=0x55bba3b041cf <handle_reply_wake_peer>) at channeld/channel.c:518
#5  0x000055bba3b049bc in handle_peer_commit_sig (conn=0x55bba41c10d0, 
    peer=0x55bba41c0030, msg=0x55bba41c6a80 "") at channeld/channel.c:959
#6  0x000055bba3b05c69 in peer_in (conn=0x55bba41c10d0, peer=0x55bba41c0030, 
    msg=0x55bba41c67c0 "") at channeld/channel.c:1339
#7  0x000055bba3b123eb in peer_decrypt_body (conn=0x55bba41c10d0, 
    pcs=0x55bba41c0030) at common/cryptomsg.c:155
#8  0x000055bba3b2c63b in next_plan (conn=0x55bba41c10d0, plan=0x55bba41c1100)
    at ccan/ccan/io/io.c:59

We got a commit_sig from the peer while waiting for the master to
reply to acknowledge the commitsig we want to send
(handle_sending_commitsig_reply).

The fix is to go always talk to the master synchronous, and not try to
process anything but messages from the master daemon.  This avoids the
whole class of problems.

There's a fairly simple way to do this, as ccan/io lets you override
its poll call: we process any outstanding master requests there, or
add the master fd to the pollfds array.

Fixes: #266
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-09 10:31:31 +09:30
Rusty Russell 5acbc04ec8 channeld: assert we're not somehow nonblocking in init_channel.
Christian reported seeing a zero-length packet come in; this seems the
most likely possibility.  

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-09 10:31:31 +09:30
Christian Decker 6d1bcc2c32 Removing the --ignore-dbversion option
It's no longer used and we definitely do not want to run with an
outdated or future db, so we'll terminate if we can't upgrade or
the version is newer than what we understand.

Signed-off-by: Christian Decker <decker.christian@gmai.com>
2017-09-08 17:02:04 +09:30
Christian Decker a9f02a8985 sphinx: Remove annoying warning when MACs do not match
This was printing to stderr during the tests.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-08 17:02:04 +09:30
Christian Decker f2d67f88c0 pytest: Run sendpay in a future so it doesn't complain about failing
For the permfail tests the sendpay call is supposed to fail, so this
was printing stacktraces upon success. Running in futures captures any
thrown exceptions and rethrows them when calling `result()`, in our
case we just ignore them.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-08 17:02:04 +09:30
Christian Decker 641a3b64cf channel: Use min_cltv_expiry in the channel announcements
So far we were always using the deadline in the announcements, that's
obviously not good, so this introduces the parameter as per spec.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-08 17:02:04 +09:30
Christian Decker a44f893838 sphinx: Switch to version 0x00 like the spec says
We were using the wrong version, oops.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-08 17:02:04 +09:30
Christian Decker d75733f7fb fix: Make sure peer->owner is always set 2017-09-08 17:02:04 +09:30
Christian Decker 0137aea7fc test: Don't assume size_t == u64 in tests 2017-09-08 16:56:07 +09:30
Christian Decker 058600bee6 travis: Added 32bit variant 2017-09-08 16:56:07 +09:30
Christian Decker e56ca11624 docker: Added 32bit travis builder dockerfile 2017-09-06 18:06:58 -07:00
Rusty Russell 80c6db865b openingd: set channel_id on failure messages.
"zero" means all channels, which works, but is overkill.

Fixes: #262
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-06 19:57:53 +02:00
Rusty Russell b19a4516d4 lightningd: fix crash when old openingd still around.
We weren't killing it.  Eventually it would die, and peer_owner_finished()
would access subd->peer->owner, but that peer was freed already.

Closes: #261
Reported-by: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-06 19:11:21 +02:00
Rusty Russell 5889ad5fc4 dev-disconnect: add blackhole option.
To reproduce the next bug, I had to ensure that one node keeps thinking it's
disconnected, then the other node reconnects, then the first node realizes
it's disconnected.

This code does that, adding a '0' dev-disconnect modifier.  That means
we fork off a process which (due to pipebuf) will accept a little
data, but when the dev_disconnect file is truncated (a hacky, but
effective, signalling mechanism) will exit, as if the socket finally
realized it's not connected any more.

The python tests hang waiting for the daemon to terminate if you leave
the blackhole around; to give a clue as to what's happening in this
case I moved the log dump to before killing the daemon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-06 19:11:21 +02:00
Rusty Russell e8dadbc0fb lightningd: fix reconnect while openingd still live.
In this case, we unset the old subd->peer, then freed subd.
peer_owner_finished dereferenced subd->peer->owner, and boom:

test_disconnect_funder (__main__.LightningDTests) ... Fatal signal 11. Log dumped in crash.log

------------------------------- Valgrind errors --------------------------------
Valgrind error file: valgrind-errors.2882
==2882== Invalid read of size 8
==2882==    at 0x413F74: peer_owner_finished (peer_control.c:679)
==2882==    by 0x41EA2C: destroy_subd (subd.c:381)
==2882==    by 0x459700: notify (tal.c:240)
==2882==    by 0x459BB1: del_tree (tal.c:400)
==2882==    by 0x459FC0: tal_free (tal.c:509)
==2882==    by 0x413796: peer_reconnected (peer_control.c:493)
==2882==    by 0x413A6A: add_peer (peer_control.c:592)
==2882==    by 0x40ED1F: handshake_succeeded (new_connection.c:186)
==2882==    by 0x41E3DD: sd_msg_reply (subd.c:262)
==2882==    by 0x41E6BB: sd_msg_read (subd.c:318)
==2882==    by 0x41E4E6: read_fds (subd.c:283)
==2882==    by 0x44DEB4: next_plan (io.c:59)
==2882==  Address 0x838 is not stack'd, malloc'd or (recently) free'd
==2882==

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-06 05:14:38 +09:30
Christian Decker 71618d07e6 jsonrpc: Add listfunds RPC command
Addresses #207 by adding a method to retrieve available funds from the
wallet.

Reported-by: @jl777
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-06 05:14:38 +09:30
Christian Decker 4b59c4f857 fix: Do not assume size_t == u64
This was causing some compilation trouble on 32bit systems, see #256.

Reported-by: @shsmith
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-05 18:12:28 +02:00
Christian Decker b0c0e28a43 gossip: Simplify announce_signature exchange
The logic of dispatching the announcement_signatures message was
distributed over several places and daemons. This aims to simplify it
by moving it all into `channeld`, making peer_control only report
announcement depth to `channeld`, which then takes care of the
rest. We also do not reuse the funding_locked tx watcher since it is
easier to just fire off a new watcher with the specific purpose of
waiting for the announcement_depth.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-05 12:47:25 +09:30
Rusty Russell 56d89b02c7 chainparams: fix order of chain hashes.
See https://github.com/lightningnetwork/lightning-rfc/issues/237

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-05 00:35:38 +02:00
Rusty Russell 4e81d2431b channeld: fix corruption when dealing with queued packets.
master is not actually a tal object!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-04 20:46:26 +02:00
Rusty Russell c92dd56dd5 ccan: update for better tal debugging checks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-09-04 20:46:26 +02:00
Christian Decker 1047e891b7 cleanup: Remove IRC flags from default options
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-09-04 08:47:13 +02:00