Commit Graph

1347 Commits

Author SHA1 Message Date
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
Christian Decker b26afcb3df Merge pull request #83 from ElementsProject/fix-67-crash-on-forget
peer_disconnect: simply free if in STATE_INIT.
2016-11-10 13:57:35 +01:00
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 74d471d4e4 ccan: update.
This gives us a slew of -Wextra fixes (not all of them though!) but
we're actually doing it for the monotonic version of timers.

This breaks some stuff, so we fix that up next.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:55: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 c1e04eb43b state_input: remove unused enum.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 08:04:26 +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 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