Rusty Russell
212f8ee022
daemon: fail if we enter an error state.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
b76858c1a1
daemon: implement HTLC expiry.
...
We do the simplest thing: a timer goes off, and we check all HTLCs for
one which has expired more than 30 seconds ago.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
1018823f97
daemon: HTLC expiry limits.
...
Don't accept an HTLC which is about to expire, nor one which will take
too long to expire.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
a3e3f83d9f
daemon: dev-mocktime command
...
Useful for precise timing control for testing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
f3c5aa7634
daemon: don't close conn until we've sent all the output packets.
...
Otherwise we won't finish the conversation. In fact, only the writer
side should ever close: we wake it if we want to close and it tests
peer->cond.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
8b666ea449
daemon: queue commands rather than executing them immediately.
...
When the only commands are via JSON, you might argue that we should
simply insist the user not operate on the same peer in parallel. That
would suck, and also we need to handle the case of a command from
a timer (eg. HTLC expiry!) or a bitcoin event.
So, we need a queue for commands, but also we need to do some of the
command checking just before the command runs: the HTLC we're dealing
with might have vanished for example.
The current command is wrapped in an anonymous "curr_cmd" struct
for extra clarity.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
2346f6bf14
daemon: routefail command.
...
This should be renamed: it's actually any kind of after-the-fact failure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
86f4bd772c
daemon/test/test.sh: check_status() helper for HTLC status checks.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
1e82799852
daemon: fulfillhtlc command
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
17359279b2
daemon: getpeers: list HTLCs.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
e1f772a443
peer: implement committed_to_htlcs().
...
Simply count how many HTLCs are in our current funding state.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:28 +10:30
Rusty Russell
9efdbbb21b
peer: use funding.h's struct channel_htlc.
...
Instead of our own fields for the current htlc.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
fc4c94cb06
daemon: simple close support for the case of one side closing transaction.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
6ba5c3cc3b
timeout: oneshot timer support.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
9f560a9494
daemon: --closing-fee
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
6bdaa5d1ca
daemon: newhtlc command.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
645958920e
peer: make_commit_txs() helper.
...
We need to call it in several places, so unify it into a single function.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
5acb3c9848
daemon: dev-rhash command.
...
Useful for creating SHA256(r) from scripts.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
8f0e10309a
daemon: --bitcoind-poll=<seconds>
...
Speeds up testing significantly.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
6443629f6a
daemon/test/test.sh: add --valgrind and --gdb options.
...
We add a second to the sleep, as valgrind can be a little slow.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
f5538bd1d2
daemon: test scripts.
...
We comment out the peer_create_close_tx() abort for now, so we
can test.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:27 +10:30
Rusty Russell
3c9fd4fbe6
daemon: code to open channel and watch anchor.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:45:05 +10:30
Rusty Russell
ecbe671688
peer: keep current commit txs, anchor state, channel funding and their sig.
...
This lets us implement accept_pkt_anchor().
Also had to predeclare sha256 in commit_tx.h, revealed by the new
includes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:44:27 +10:30
Rusty Russell
871e4d5172
secrets: peer_sign_theircommit() helper.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:44:26 +10:30
Rusty Russell
90e381f750
bitcoind: try gettransaction as well as getrawtransaction.
...
Because with walletbroadcast=0, getrawtransaction doesn't see them.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:44:26 +10:30
Rusty Russell
ae04116883
daemon: send open_pkt on initialization.
...
This gets us to the creation of the anchor transaction, where we stop.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:44:25 +10:30
Rusty Russell
12b9d39b76
daemon: store revocation hashes in the peer_visible_state structure.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:44:24 +10:30
Rusty Russell
abc002ff15
daemon: add state.c.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:44:13 +10:30
Rusty Russell
a5e08e7f79
lightning-cli: give error message when lightningd produces non-object response.
...
Nicer than assert() failing without showing the response.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
0dbbd81430
bitcoind: tell bitcoind_poll_transactions's callback if tx is a coinbase.
...
In this case, the inputs aren't valid transactions, so don't try to
find them.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
5b9f8d8bbd
bitcoind: serialize requests.
...
bitcoind has a limit of 16 requests at once, by default, so our simplest
solution is to serialize them.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
980d0d2bf1
bitcoind: warn if their bitcoin config not on testnet/regtest.
...
Otherwise you get weird errors as bitcoind refuses our testnet addresses.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
34e32978b8
bitcoind: warn if their bitcoin config doesn't have walletbroadcast=0.
...
Because we use the bitcoin wallet to create the anchor transaction, we
need to make sure it doesn't broadcast it; safest to check their config
for the option.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
c51a8d804f
bitcoind: routine to send to a specific address.
...
We use this to create our anchor payment.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
c0766061fa
dns: don't allow non-stream sockets.
...
It was "connecting" to "localhost 30000" successfully, because it was
using UDP. Oops.
This reveals another issue: init_conn() uses the wrong address to
connect to, as we'd already incremented the pointer in try_connect_one().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
d5328c7577
bitcoind: routine to broadcast a transaction.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
fc49e3fd74
daemon: rename 'state' to 'dstate' everywhere.
...
This is the daemon state, not the state machine state.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
5ac1d5df00
state: include daemon/peer (only if !TEST_COVERAGE).
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
b04392609a
daemon: encapsulate each side's state in a struct.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
0376e08fea
daemon: peer needs to know who offered the anchor.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
e9237f94b1
daemon/watch: API to watch various bitcoin transactions.
...
This uses the functions in bitcoind to provide callbacks when various
things happen.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
5ec8ff91e4
daemon/bitcoind: communication with bitcoind.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
24602459b1
daemon/config: add testnet.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
d303393d67
daemon/peer: save their commit key too.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
a5aa7b9abd
daemon: config file support.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:49 +10:30
Rusty Russell
bf3080ca09
secrets: handle per-peer secrets as well.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:48 +10:30
Rusty Russell
08ccb4b6f0
getpeers: new command.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:48 +10:30
Rusty Russell
d8959b3117
peer: make connect command an async command.
...
So it can return failure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:48 +10:30
Rusty Russell
366f8a5f3f
dns: add failure callback.
...
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:48 +10:30
Rusty Russell
d68ae0b612
jsonrpc: adapt it to be async.
...
This allows for JSON commands which aren't instantaneous.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-01-22 06:41:48 +10:30