Commit Graph

721 Commits

Author SHA1 Message Date
Christian Decker 0ed23c46a9 gossip: Implemented routing table sync with newly connected peers 2017-01-03 15:08:05 +10:30
Christian Decker 5ce1f7c2f3 gossip: Set announce timeout to 5 hours 2017-01-03 15:08:05 +10:30
Christian Decker 71a18fdd2e gossip: Trigger announce on channel establishment
Since we ultimately want to have a very long re-announcement timeout
we better trigger an announcement upon channel state change to normal.
2017-01-03 15:08:05 +10:30
Christian Decker e54c0adced gossip: Do not consider half-open connections for routes
Connections are in a half-open state after receiving the
`channel_announcement` and before the `channel_update` makes them
usable, so we need to ignore channels that are not yet fully open.
2017-01-03 15:08:05 +10:30
Christian Decker 611f4833c5 gossip: Implemented the staggered broadcast 2017-01-03 15:08:05 +10:30
Christian Decker fca9bf1a16 gossip: Partially sign channel_announcements
We can already add our own signatures, will have to defer remote
signatures until we implement the channel setup messages from the spec.
2017-01-03 15:08:05 +10:30
Christian Decker d93ce12afa gossip: Broadcasting and handling gossip messages 2017-01-03 15:08:05 +10:30
Christian Decker e8d68757f6 gossip: Tracking tx index in topology
The txlocator was reporting the index in the purged array of
transactions instead of the index in the original block.
2017-01-03 15:08:05 +10:30
Christian Decker 57d5ae96a4 routing: Added channel_id and directions to connections
The gossip protocol spec refers to channels by their `channel_id` and
a direction. Furthermore, inbetween the `channel_announcement` and the
`channel_update` for either direction, the channel direction is in an
undefined state and cannot be used, so added the `half_add_connection`
function and an `active` flag to differentiate usable connections from
unusable ones.
2017-01-03 15:08:05 +10:30
Christian Decker db481d881a proto: Added handling for nested packets 2017-01-03 15:08:05 +10:30
Rusty Russell a44e4fb631 daemon/json, test/test_protocol: avoid gcc -O warnings.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-15 11:49:51 +10:30
Rusty Russell e109977df7 peer: don't print uninitialized commit_num.
Reported-by: Lucas Betschart <lucasbetschart@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-15 11:44:48 +10:30
Rusty Russell 2a68a984c3 peer: fix unassigned error packet on receiving non-ASCII error.
Reported-by: Lucas Betschart <lucasbetschart@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-15 11:42:24 +10:30
Rusty Russell 1b170c85bb Revert "Fix -Wsometimes-uninitialized and -Wuninitialized"
This reverts commit ff9cdda4fa.

These are real bugs, so I prefer to fix them explicitly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-15 11:41:31 +10:30
Lucas Betschart 900ab78d46 Fix -Wtautological-constant-out-of-range-compare 2016-12-14 08:47:21 +01:00
Lucas Betschart ff9cdda4fa Fix -Wsometimes-uninitialized and -Wuninitialized 2016-12-14 08:45:40 +01:00
Lucas Betschart c163fe04ac Fix -Wenum-conversion 2016-12-14 08:43:48 +01:00
Lucas Betschart 33d6cbe6bc Fix -Wgnu-variable-sized-type-not-at-end 2016-12-14 08:41:30 +01:00
Rusty Russell 45ec071e58 lightningd: remove whitespace failing make check-source.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-05 14:03:06 +10:30
Rusty Russell 36c8fc7ef8 lightningd: remove secpctx
Use the global in the few remaining places.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-02 18:13:27 +10:30
Rusty Russell a4fdaab5b3 Use global secp256k1_ctx instead of passing it around.
If I'd known how large this patch would be (though trivial), I'd
have done it in parts.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-02 18:12:58 +10:30
Rusty Russell c938ebb5c0 utils: add a global secp, fix wire to use it.
This repairs make check.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-02 18:11:06 +10:30
Rusty Russell 1f447688bc test: make generic driver for unit tests.
Not just in daemon.  This fixes 'make check' when it tries to
run 'make wire-tests'

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-12-02 18:10:13 +10:30
Christian Decker e40509c6c3 wire: Linking against wire objs 2016-12-01 13:50:02 +10:30
Rusty Russell 0ba93cb948 lightningd: don't listen at all if no port number set.
When we support the Milan protocol, we'll use a default port.  But
for now, don't listen at all unless a port is specified.

Fixes: #54
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-18 17:13:29 +10:30
Rusty Russell fe14b3f4d9 Merge remote-tracking branch 'origin/pr/92'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-18 17:05:42 +10:30
Rusty Russell 97a155bad5 Merge remote-tracking branch 'origin/pr/97'
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-18 14:28:22 +10:30
Christian Decker 42a33df42e irc: Checking for param count before accessing 2016-11-16 22:55:29 +01:00
Christian Decker 188b3c3e19
sphinx: Fixed a buffer overflow in hmac generation
Our HMACs are truncated to 20 byte, but sodium still generates 32 byte
HMACs and we were handing in a buffer that was too small, so we
overflowing the buffer by 12 bytes. This manifested itself only in the
32 bit variant because of different alignment in the 64bit version.

Fixes #94.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2016-11-16 14:41:19 +01:00
Christian Decker b2a3e8010f Merge pull request #96 from ElementsProject/minor-sphinx-cleanups
Minor sphinx cleanups
2016-11-16 14:35:19 +01:00
Christian Decker bf81f7af15 Merge pull request #93 from ElementsProject/fix-87-open-too-small-for-fee
json_connect: don't try to double-fail if amount insufficient.
2016-11-16 13:04:26 +01:00
Rusty Russell 41299b679c sphinx: process_onionpacket doesn't modify the packet.
Make it const.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-16 14:22:14 +10:30
Rusty Russell 423572190b sphinx: use assignment instead of memcpy where possible.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-16 14:22:08 +10:30
Rusty Russell 6f9dedbe7f sphinx: remove redundant initialization
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-16 14:04:50 +10:30
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