Commit Graph

687 Commits

Author SHA1 Message Date
Rusty Russell 8599d63256 sphinx: add brackets around constant definition
Always do this, otherwise "MACRO * foo" can have unexpected results.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-16 14:02:56 +10:30
Rusty Russell 5465b61784 json: fix 32-bit build.
Assume we have strtoull everywhere (it's C99 and was common before).

Fixes: #91
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-16 13:34:56 +10:30
Christian Decker 686ff6edef irc: Switched to LFNet.org IRC server
This is a temporary fix until we finish #88.
2016-11-14 23:19:32 +01:00
Rusty Russell 94adbd241d json_connect: don't try to double-fail if amount insufficient.
Closes: #87
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-14 11:46:09 +10:30
Christian Decker 34b4134cb0 bugfix: Removed spurious printf in peer.c
I must've left that on in. Fixes #89
2016-11-14 00:29:01 +01:00
Christian Decker e5b44ff232 Merge pull request #85 from ElementsProject/whitespace
Whitespace
2016-11-11 16:40:23 +01:00
Christian Decker 9848b4ac3e travis-ci: Added travis-ci config
Added .travis.yml to get travis-ci to build and run tests for us.

In addition this fixes a flaky test due to the fact that when lightning2
connects to lightning3 and we tell lightning3 to restart, then
lightning2 will back-off its reconnection attempts, potentially causing
a timeout to trigger during tests. This was triggered by travis-ci
relatively consistently since the restart would take quite some
time. Now simply restarting them in reverse order and a small timeout
seems to fix this consistently.
2016-11-11 14:25:41 +01:00
Rusty Russell f5c00deec7 Remove trailing whitespace from source.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-11 09:32:04 +10:30
Rusty Russell 716da21f85 chaintopology: reduce how far back we start on testnet.
When initially reading the blockchain, we start 100 back from the
current block, or at the first block with a funding transaction,
whichever is earlier.

This slows testing slightly, so use whatever the "forever" value is
(10 on testnet, still 100 on mainnet).

make check -j12 times:
	Before:	7m52.005s
	After:  6m31.896s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:53:48 +10:30
Rusty Russell ce96812ef0 test.sh: split into multiple scripts.
This significantly reduces re-testing of the same paths, and simplifies
the addition of new tests.

make check -j12 times:
	Before: 9m24.973s
	After:	7m52.005s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:44:49 +10:30
Rusty Russell fae7f68731 helpers.sh: make check_tx_spend able to check for a specific transaction.
It currently takes an unused "who to blame" argument, which doesn't
always make sense.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:34:35 +10:30
Rusty Russell c6a187a5d7 helpers.sh: set up funding in start_lightningd()
Every test wants this anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:33:35 +10:30
Rusty Russell 9e777ae922 test.sh: move core routines to scripts/helpers.sh
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:32:35 +10:30
Rusty Russell 973ef3c932 test.sh: move valgrind PREFIX setting to vars.sh
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:31:35 +10:30
Rusty Russell 700c536a27 Makefile: remove all the old Elements Alpha support.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:30:35 +10:30
Rusty Russell bff81c0ecf lightningd: ignore SIGPIPE.
It can happen when a peer hangs up, but also a JSON connection.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:29:35 +10:30
Rusty Russell e7e7345596 peer: fix steal (penalty tx) generation code.
In particular, we got a segv because we were measuring the wrong
wscript, then we miswired the inputs.  It only worked because our
current steal tests don't have a to_us_idx output.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 23:28:35 +10:30
Rusty Russell 3372645d8e peer_disconnect: simply free if in STATE_INIT.
db_forget_peer() was harmless, but we haven't been entered into the
database yet anyway, and it asserted that we should have been STATE_CLOSED.

Closes: #67
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-10 11:21:16 +10:30
Rusty Russell c2d71497ff opt, utils: new arg for wrappers due to low-level tal change.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:56:38 +10:30
Rusty Russell 9708c7a019 timers: use time_mono, as that's what ccan/timers now wants.
Fixes: #58
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:56:15 +10:30
Rusty Russell 4bed6c8c67 controlled_time: remove
We don't need it for testing at the moment, and if we do it'll have
to change to relative anyway now we're going to use time_mono().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:54:15 +10:30
Rusty Russell c5de5d4c39 timeout: remove absolute timers.
We don't actually use them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:53:15 +10:30
Rusty Russell 3aca5c87e3 init: rebroadcast anchors on restart if we haven't seen them.
It's possible that we won't have sent the anchor, but state is
committed in db.  And our current philosophy is that we retransmit all
the txs dumbly, all the time.

Our --restart --timeout-anchor test trigger this case, too, so
re-enable that now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:52:15 +10:30
Rusty Russell 0f09605e17 test: restore anchor timeout tests.
Importantly, they're now entirely block driven.  We don't use
dev-setmocktime at all any more.

This also fixes a bug if we run the test twice against the same
bitcoind; we need to extract the time from the block header rather
than assuming bitcoind is on the current time.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 17:50:54 +10:30
Rusty Russell 6f360422d4 chaintopology: restore anchor timeout.
Instead of using wall-clock time, we use blocks.  This is simpler and
better for database restores.  And both sides will time out.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 17:14:22 +10:30
Rusty Russell 1fe83f47a9 dev-broadcast: control whether we send out transactions.
Good for testing; we also flush broadcast when it's re-enabled.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 17:14:21 +10:30
Rusty Russell f715752e71 chaintopology: keep txs to send in a struct.
This allows us to add a new field for a callback at the end, but
more subtle, ensures broadcast in order (which simplifies testing).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 17:14:10 +10:30
Rusty Russell 56b0f03c5a peer: fix retransmission before open packet.
Re-enabling the next test revealed bugs: if we need to retransmit the
initial open_commit_sig packet, we currently tried to send it as an
UPDATE_COMMIT, which isn't allowed.  Fixing that revealed that if
we have to retransmit the initial open, we didn't do that either.

Thus the initial open should count towards the ack count, and we should
special case transmissions of 0 (pkt_open) and 1
(pkt_open_commit_sig).

We also save those early state changes to the database.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 41f3f8e067 db: store anchor input.
If we die before we've established connection, we should remember how
we were going to fund it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell adae62e261 peer: determine fees earlier.
Sure, information might be out of date, but at least we can report an
error earlier.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 9463e1b630 wallet: use pubkey as API, not pointer.
Much easier to save/restore to/from database in coming patch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 7f0a56f674 queue_pkt_open: take bool for API.
No need to leak protobuf enum outside.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:28 +10:30
Rusty Russell 536a48940e protocol: don't ever reply to PKT_ERR with PKT_ERR.
The simplest way is to always use peer_received_unexpected_pkt() which
sends the error packet, and ensure it doesn't do so in response to
pkt_err.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:27 +10:30
Rusty Russell d77d5edc07 Makefile: clean gen_ files and ccan/config in make clean.
Not on maintainer-clean; they don't need special tools.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:27 +10:30
Rusty Russell 49809785ca state.h state_types.h: move into daemon/
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:27 +10:30
Rusty Russell fd6c3ce5a3 names: move into daemon/
It was already only referred from that Makefile.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:27 +10:30
Rusty Russell ec072b5d68 gen_pkt_names, gen_state_names: move into daemon/
That's where they're used.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:27 +10:30
Rusty Russell cf91409ff2 start_closing: always switch states inside transaction.
This means checks in multiple places, but ensures atomicity.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 6b05436a7a open: use a single transaction when shutdown, so it's atomic.
This covers the case of shutdown during open.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 41d4779abe peer_database_err: helper for database error packet.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell eedf95a8fc state_types: simplify open states.
The state now doesn't differentiate between who is funding.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 1f23905bee peer: move start_closing() function higher in peer.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +10:30
Rusty Russell 99e48c7c87 peer: don't differentiate who is funding via state when waiting for open.
It doesn't actually help here; we only did it because we differentiate
the states later, and with refactoring we do that via the explicit
offer_anchor flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell ea74bac8b8 state: hoist open-they-are-funding states handling into peer.c, remove state.[ch]
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell 75ff09b310 state: hoist open-we-are-funding states handling into peer.c
This means we can now do all database changes, including db_set_visible_state,
within a single transaction (ie. atomically).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell 6acb4953b1 db: make db_set_visible_state called from within transaction.
We want to do this atomically; this is the first step.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:25 +10:30
Rusty Russell 8c5fae2b28 patch remove-bitcoin_release_anchor.patch 2016-11-09 08:04:24 +10:30
Rusty Russell f71f0da19c offer_anchor: store a bool, not am enum state_input.
Since we no longer feed it into state.c, we can just us a bool.
And that's the last of the CMD_* in the enum state_input, so remove them
all.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:24 +10:30
Rusty Russell 847ce8b092 state: move first state transition into peer.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:24 +10:30
Rusty Russell bbd1bbd931 state: remove anchor timeout.
We'll bring it back as a block-based timeout at the end.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:20 +10:30
Rusty Russell b349e2884b state: move anchor-depth-ok code into peer.c
This is the beginning of removing state.c altogether.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 22:03:55 +10:30
Rusty Russell e21b161ed9 db: add --ignore-dbversion to override database checks.
At your own risk, of course.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 22:02:55 +10:30
Rusty Russell 7b44f2851f db: add version field.
We can get weird errors when we try to load a database of a different
from.  Just slap a git version in there for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 22:01:55 +10:30
Rusty Russell 4151537b71 peer: commit outstanding changes before sending PKT_CLOSE.
Pierre points out that we don't handle this, and it can happen due
to race; the spec says we are not supposed to send PKT_CLOSE with
uncommitted changes.

Closes: #29
Reported-by: Pierre-Marie Padiou
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:59:55 +10:30
Rusty Russell 16cff6951f peer: hoist do_commit and have it return false if it failed.
Next patch will call it from peer_start_shutdown().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:58:55 +10:30
Rusty Russell d3dc5508ad test.sh: run normal tests first.
That shows up obvious breakage, so do it first.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:57:55 +10:30
Rusty Russell 8477bd5a5f test: allow three variants in parallel with parallel make.
This means running 3 bitcoinds, which is slow enough to start on my laptop
that I need to increase the startup wait for 30 to 60 seconds, and similarly
the test.sh check loop.

Before:	real	13m42.868s
After:	real	8m19.563s (make -j3)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:56:55 +10:30
Rusty Russell 9b045dac02 test: shutdown harder.
Sometimes bitcoind takes a while to shutdown.  Just kill it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:55:55 +10:30
Rusty Russell 5f5ad793e9 test: fix unreliable test on slow machines.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:54:55 +10:30
Rusty Russell 2f0651d105 test: use eatmydata for bitcoind and lightningd if available.
Before:	real	17m56.862s
After:	real	13m42.868s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:53:55 +10:30
Rusty Russell 208beab529 test: setup bitcoind once, then run lightning tests.
On my build machine, times are:
Before:	real	22m10.425s
After:	real	17m56.862s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:52:55 +10:30
Rusty Russell 4bd0284a15 test: only start up/shutdown bitcoind if not already running.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:51:55 +10:30
Rusty Russell d8892c4dda test: do version check during setup.
Waiting until lightningd is up is too long: do a --version test in setup,
and then check that all reported versions match later on.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:50:55 +10:30
Rusty Russell 35b2ee9c42 tests: remove obsolete BIP68 detection test.
We've assumed this for ages anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:49:55 +10:30
Rusty Russell 92e5f53f4d peer: free packet when we close connection in init_pkt_in.
Otherwise if they reconnect, we hit the assert in recv_body:
	assert(!peer->inpkt);

Found by testing on my build box *without* valgrind (so it was fast
enough to do this).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:48:55 +10:30
Rusty Russell 69b1b9c562 db: store closing signature correctly.
Running on my build machine, without valgrind, it managed to exchange
closing sigs before restart, and spotted this bug.

Fixes: #76
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 21:27:04 +10:30
Rusty Russell 8b7fa1b663 test: fix dependencies so we generate headers.
Revealed by "make check" on a freshly checked out tree.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 08:34:13 +10:30
Rusty Russell 13b1d922bb chaintopology: fix rebroadcast code.
broadcast_remainder() does two things: get the error message for the
previous transaction, and send the next one (shrinking the array).

But it has two bugs:
1) It logs results on the tx at the end of the array, which is the one
   it is *about* to send, and
2) The initial caller (rebroadcast_txs) hands it the complete array,
   so the first tx gets broadcast twice.

The correct thing to do is to strip the array, then send the tail for
the next callback.  And use nicely-named vars to help document what
we're doing.

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:04:02 +10:30
Rusty Russell dbd8e07924 broadcast_tx: make sure callers free tx if necessary.
Now broadcast_tx() doesn't take ownership of the tx, make sure callers
free; a bit of refactoring to make it clear when we're making a new tx
vs. accessing an existing one, to make this clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:03:02 +10:30
Rusty Russell 49a80ba457 peer: fail channel if funding transaction broadcast fails.
Closes: #51
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:02:02 +10:30
Rusty Russell 7aa01b0e50 broadcast_tx: add optional failed callback.
And if that's set, don't rebroadcast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:01:02 +10:30
Rusty Russell 89131444b3 bitcoind_sendrawtx: hand error code to callback.
So it can determine success or failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 23:00:02 +10:30
Rusty Russell 4cbe9785a8 bitcoind_sendrawtx: don't share callback with retransmission case.
This is in preparation for the next step.

Note that we now don't add it to the linked list of txs we've send
until after it's sent by the immediate callback; this means it won't
get broadcast by the timer until after it's been done by broadcast_tx.

Also, this means we no longer steal the tx in broadcast_tx(); but we'll fix
up the leaks 4 patches later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 22:59:02 +10:30
Rusty Russell 7d1137c45e bitcoind_sendrawtx: tie the sending of the transaction to the particular peer.
Not important just yet, but it will be soon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 22:58:02 +10:30
Rusty Russell cc9ffe6c40 bitcoind: allow callbacks which are tied to an object.
We don't simply parent them on the object, we use a dummy object which tells
us not to call the callback if freed.

This would be better fixed by rewriting ccan/io to handle tal_free() of
a conn; then we could simply parent the entire thing and forget about it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 22:57:02 +10:30
Rusty Russell ef4f7c396b Merge remote-tracking branch 'origin/pr/72'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-07 22:56:02 +10:30
Glenn Willen 2b431b171b config: Allow overriding the transaction fee rate 2016-11-06 10:35:48 -08:00
Rusty Russell 04cff14ac8 peer: don't fret about fees too low on testnet.
Testnet fees are all over the place: don't close a connection due to
that.

Closes: #59
Reported-by: Thomas Daede <daede003@umn.edu>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-06 14:47:16 +10:30
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 5adaf46b19 Merge remote-tracking branch 'origin/pr/65'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-05 13:48:16 +10:30
Glenn Willen 2ce36a070b irc: Fix crash bug in node announcement parsing 2016-11-04 15:01:01 -07:00
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 feecabacce sphinx: fix marshalling/unmarshalling
Unfortunately, this fix will break compatibility.

Found by PVS Studio.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 12:09:31 +10:30
Rusty Russell d14a67addf db: fix leak for initial commit state.
It's only a single cstate, but it need not outlive the commit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:05 +10:30
Rusty Russell b40c4ae766 json_getroute: don't leak.
Allocate the route off the current command, not dstate.  And in the
case where the route is somehow not via a peer, don't leak memory.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:04 +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 de2ffd8985 accept_pkt_open_commit_sig: don't allocate sig.
Caller can allocate and free; this gets the context correct (that
commit).

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 4c7017f607 dns: simplify code by reaping dns child as soon as we have answers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:03 +10:30
Rusty Russell e0368cc82d cryptopkt: don't leak negotiation state.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:03 +10:30
Rusty Russell 319eef266d commit_tx: free temporary wscript, rather than leaving attached to tx.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:17:03 +10:30
Rusty Russell b768de324c commit_tx: plug leak.
Use a tmpctx, and clean up afterwards.  Steal the script onto the tx,
however.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-04 11:16:14 +10:30
Rusty Russell 1d57fa60b8 invoice: print duplicate r value even if we choose it.
This shouldn't happen, but if our RNG is busted and get a duplicate,
r would be NULL.

(scan-build found this)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:34:58 +10:30
Rusty Russell 642a2f2d4e cryptopkt: free output packets after encryption.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:34:58 +10:30
Rusty Russell 95a01670ac cryptopkt: free incoming packet after decryption.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:34:57 +10:30
Rusty Russell 5f32d291bf jsonrpc: free old connections
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:34:57 +10:30
Rusty Russell a4ee683b3e tal_tmpctx: clear marker for temporary contexts.
This makes them stand out in memory dumps.  Also plug two existing
memory leaks.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:34:27 +10:30
Rusty Russell 024e6a5855 feechange: fix db updates.
Found by PVS Studio.

Reported-by: Jon Griffiths <jgriffiths@blockstream.io>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:33:27 +10:30
Rusty Russell c1d6df58aa feechange: fix db updates.
Found by PVS Studio.

Reported-by: Jon Griffiths <jgriffiths@blockstream.io>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:33:27 +10:30
Rusty Russell 5349d2aaa7 routing: fix hash of pubkeys.
Found by PVS Studio.

Reported-by: Jon Griffiths <jgriffiths@blockstream.io>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:33:06 +10:30
Rusty Russell fa402aac31 routing: fix hash of pubkeys.
Found by PVS Studio.

Reported-by: Jon Griffiths <jgriffiths@blockstream.io>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-01 21:33:06 +10:30
Christian Decker f9a4af62e3 irc: Added alias handling for node announcements
Aliases seem to be popular among users wanting to show off their node,
so let's add them :-)
2016-10-28 16:47:01 +02:00
Christian Decker 94fd82dc81 irc: Announce the real expiry time
So far we've been announcing the locktime instead of the min_expiry the
node requires, this results in routes having wrong expiries.
2016-10-28 16:36:20 +02:00
Rusty Russell 48da22ab4b Merge remote-tracking branch 'origin/pr/56'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-25 11:23:34 +10:30
Rusty Russell dfad49bbd7 Merge remote-tracking branch 'origin/pr/55'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-25 11:19:15 +10:30
Rusty Russell 60e7e54f95 Merge remote-tracking branch 'origin/pr/53'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-25 11:16:52 +10:30
Christian Decker 3dd2e0c2b3 jsonrpc: Correctly handle numeric invoice labels
`listinvoice` was not handling numeric labels correctly if they are not
passed in as JSON strings (which was the behavior of
`lightning-cli`). So now we accept both string labels as well as numeric
labels.
2016-10-23 18:52:08 +02:00
Christian Decker de187ecaf7 jsonrpc: Accomodate some pedantic JSON-RPC impls
The JSON-RPC was non-standard compliant in that it omitted the required
`jsonrpc` entry and it was returning both `error` as well as
`result`. This fixes both of these issues.
2016-10-23 16:19:08 +02:00
Christian Decker a97d301155 routing: Refuse self-route
Fixes #50. Was causing a segfault because it was creating an empty route
and was trying to extract the first hop as next hop. Routes through self
can still be created manually, but `sendpay` would still refuse to act
on them due to the missing self-link.
2016-10-23 11:57:50 +02:00
Christian Decker 50807db7aa jsonrpc: Fixed `listinvoice` returning broken JSON
Closes #48.
2016-10-23 10:57:29 +02:00
Rusty Russell 144c40afd0 irc: get much less chatty.
We're going to wean off IRC, but as a quick fix, only announce 0-60 seconds
after we see a join, or every 6 hours.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-21 12:05:33 +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 af9ee44d52 sphinx: memset warning suppression workaround.
Milan summit finalized some changes, so this will be reworked
soon anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-17 12:44:09 +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
Rusty Russell d47d19ef2b Merge remote-tracking branch 'origin/pr/44'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-17 12:31:19 +10:30
Rusty Russell a9df84145e Merge remote-tracking branch 'origin/pr/43'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-17 12:20:03 +10:30
Christian Decker d30f3f1a40 sphinx: Remove obsolete onion implementation 2016-10-16 16:40:54 +02:00
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
Christian Decker 7bb5c279a8 sphinx: Implemented sphinx onion routing
Implements a spec-compliant sphinx onion routing format. The format has
been cross-checked with the go implementation
cdecker/lightning-onion@b9e117e.
2016-10-16 16:40:43 +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 d1c30c45ab getinfo: show block height.
My lightning node was *way* behind, and I couldn't figure out why it
wasn't seeing channel establishment.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:01:18 +10:30
Rusty Russell f66358882a config: different defaults for mainnet and testnet.
In particular, remove fee ranges on testnet (too unreliable) and accept
a single confirm.

(Note that an earlier version of this had a bug when there was no
config file, this version includes the fix).

Closes: #40
Reported-by: Glenn Willen
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:18 +10:30
Rusty Russell c0d0606d66 lightningd: move testnet flag out of config.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:18 +10:30
Rusty Russell 1e6f7059d3 lightningd: allow --commit-fee-max=0 for "no limit"
For testnet, fee estimates are not reliable at all.

Reported-by: Christian Decker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:17 +10:30
Rusty Russell 44282eed16 test.sh: increase timeout, slow down bitcoind polling.
My temporary machine is incredibly slow.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:17 +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 b45b4eaba6 bitcoind: explicit flag to bitcoin-cli for testnet/regtest.
Three days of on and off debugging, before I realized my server was talking
to a non-testnet bitcoind.  There was a bitcoind on that machine running
on testnet, but it uses the same dir and config, so the --bitcoin-datadir
option couldn't help.

This is more certain: specify whether we're testnet on every single query.
Now we can skip the attempt to parse bitcoin.conf, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell 8c8fa2cecd config: make sure that anchor-confirms is non-zero.
We don't actually look into mempool, so setting zero is misleading.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell a19762b55c open: increase verbosity of errors
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 0460f0caca getroute: fix help message to get arg order correct, include riskfactor.
Closes: #38
Reported-by: Glenn Willen
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 14:00:16 +10:30
Rusty Russell 7c9884d292 build: fix parallel initial build.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 13:58:57 +10:30
Rusty Russell 4fcdf6de5c irc: fix check-source.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-10-07 13:56:57 +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
Christian Decker 594eb8109c jsonrpc: Added 'getnodes' to list known nodes.
getnodes returns an object containing a single array of 'nodes'. Each
element contains the node's ID, its hostname and its port. If
unknown (because we haven't seen a node announcement yet) then the port
is 0 and the hostname is null.
2016-10-02 14:52:24 +02:00