Commit Graph

1369 Commits

Author SHA1 Message Date
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 e40f864567 lightning.pb-c.c lightning.pb-c.h: don't generate if unchanged.
Just like man pages, git can mess us up here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-08 22:00: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
Christian Decker 6568083edd Merge pull request #68 from gwillen/feature-fix-irc-parse-crash
irc: Fix crash bug in node announcement parsing
2016-11-04 23:02:59 +01:00
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