Commit Graph

2693 Commits

Author SHA1 Message Date
Björge Dijkstra 648e4feee2 Extend json unit test with tests for json_tok_bitcoin_amount() 2018-01-13 00:15:03 +01:00
Björge Dijkstra 82a2d2f0a6 Fix parsing of txout value. Force decimal base. 2018-01-13 00:15:03 +01:00
Christian Decker 160285f3ea gossip: Do not clobber updates attached to a channel announcement
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-12 21:55:50 +01:00
William Casarin 2e796ffa67 peer_control: send addrhints in activate_peer
Since we now have addresses in the database, we can resend them as hints to
gossipd on startup.

Signed-off-by: William Casarin <jb55@jb55.com>
2018-01-12 19:47:36 +01:00
Rusty Russell 6b7b7f1007 test_lightningd.py: fix timing error in test_forward_different_fees_and_cltv
We need to make sure all the updates are known to gossip.  Since
one is the local update, we change that message to look the same.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Rusty Russell d84dc5633a test_lightning.py: make sure gossip has processed channel_updates.
Receiving them in channeld is not enough to avoid the race:

    route = l1.rpc.getroute(l3.info['id'], 4999999, 1)["route"]
...
    ValueError: RPC call failed: Could not find a route

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Rusty Russell 896ecb4da7 test_lightning: don't fire prematurely on test_gossip_jsonrpc.
We wait the the receipt of the CHANNEL_UPDATE message by channeld,
but that doesn't mean it reached gossipd yet, causing spurious test
failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Rusty Russell a4dd523c8b test_lightning.py: fix ambigious log order in test_reconnect_signed.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:46:56 +01:00
Rusty Russell 71f13ab6b0 channeld: ignore spurious open_channel packets.
Currently we peer_failed() which fails the existing channel too!

Fixes: #494
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:43:01 +01:00
Rusty Russell 2bc2502b23 wire: move extract_channel_id to here.
It can be useful for other daemons.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:43:01 +01:00
Rusty Russell e34ec8da2d peer_failed: use towire_errorfmtv() which doesn't add nul terminator.
This code was actually wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-12 09:43:01 +01:00
Christian Decker 7865b4a679 wallet: Use int64 when deserializing output value from db
We were using int32 for msatoshi values for outputs, which would
overflow for values larger than 2^32.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-12 04:11:17 +00:00
Igor Cota e97857847a peer_control: make hardcoded feerates consistent between json_fund_channel and peer_offer_channel
Stops some transactions from failing on the other side due to insufficient funds.
2018-01-12 03:40:31 +00:00
ZmnSCPxj 5f8796af0c test_lightningd.py: Add tests for any-amount invoices. 2018-01-12 01:43:55 +00:00
ZmnSCPxj 816298123f invoice: Allow "any" msatoshi, for amountless invoices.
Fixes: #534
2018-01-12 01:43:55 +00:00
ZmnSCPxj caab95b922 wallet_payment: Make msatoshi field nullable. 2018-01-12 01:43:55 +00:00
ZmnSCPxj 50471bf4fe invoice: Make msatoshi field nullable.
Note that the database itself has the field nullable (sqlite3
does not even have non-nullable columns) but our in-memory
structures did not.
2018-01-12 01:43:55 +00:00
ZmnSCPxj 7221476553 invoice: Clarify comments about the two loops in resolve_invoice. 2018-01-12 01:28:32 +00:00
practicalswift a900551815 Use tal_hex(...) instead of tal_hexstr(...) 2018-01-12 00:55:46 +00:00
Rusty Russell bc4f2da50a test_lightning.py: make sure reconnect doesn't leave multiple peers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:47:47 +01:00
Rusty Russell d4c8210a9e gossipd: don't hang if we try to connect to already-connected peer.
Closes: #287
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:47:47 +01:00
Rusty Russell 43c97187a4 test_lightningd: fix test_gossip_jsonrpc.
A watch constant never changes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell 10b40c524d gossipd: attach updates to pending transactions in preference.
Otherwise, we otherwise end up with out-of-order updates
(ie. preceeding announcements).

I assume that is because of the locally-inserted connections.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell 96ed75d8b2 gossipd: handle channel_update while we're still checking channel_announce.
We only need to keep one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell db30411ba5 gossipd: look up short_channel_id when we see a channel_announcement.
This is done it two parts, since we have to ask the main daemon to do
the lookup for us.

If this becomes a bottleneck, we can have a separate daemon, or even
an RPC pipe to bitcoind ourselves.

Fixes: #403
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell e22dd5ad71 lightningd: implement gossip_get_txout/gossip_get_txout_reply.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell 2b1eb6a677 bitcoind: getoutput so we can check short_channel_ids.
It would be nice if bitcoind had an RPC to do this in one, but that's
a bit much to ask for.  We could also hand around proofs, for lite nodes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell 61be62ddb7 gossipd: ensure node_announcement timestamps always increment.
Covers a possible source of subtle bugs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell bc631166f0 channeld: ensure channel_update timestamps always increment.
Covers a possible source of subtle bugs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell 86e1a61165 json: fix json_tok_bitcoin_amount()
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 23:13:23 +01:00
Rusty Russell 9a8eca4fee Remove obsolete FIXME messages.
1. htlc->fail has been changed to a u8 *.
2. wallet_get_newindex saves to the db.
3. peer->next_htlc_id is saved to the db in peer_save_commitsig_sent() below.
4. We do store commit in peer_save_commitsig_received(peer, commitnum),
   and the fixme below talks about HTLC sigs.
5. We do commit shachain and next_per_commit_point in wallet_shachain_add_hash
   and update_per_commit_point respectively.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell 27e0ea2358 wire: remove special zero-key handling.
We used to use a hack for gossip_resolve_channel_reply, where we'd send
a NULL key on failure.  It's now been neatened to use a counter, so we
don't need this.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell 55909a7a39 lightningd: call peer_last_tx() to update peer->last_tx before saving to db.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell 8cf97e904d lightningd: remove unused "forever_confirms" parameter.
It's 100, but we never wired this up, so remove it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell 7e0bc88e2a gossip: fix default broadcast interval, move option.
This now makes a few more gossip tests time out without --dev-broadcast-interval

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell 171ce689dc lightningd/chaintopology: remove unneeded chain_topology pointer from block.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell 3332cd6395 chain_topology: remove unneeded struct outgoing_tx topo pointer.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell cc60735aee channeld: check short_channel_ids match before announcing channel.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
Rusty Russell b1e93c8838 channeld: remove redundant funding_locked assignment.
This makes no sense here, and yet it was in the original HTLC patch
791927936.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-11 21:39:13 +01:00
ZmnSCPxj fdbf2f41b4 generate-wire.py: Add scare comments to output.
Discourage developers from modifying files generated by generate-wire.py
2018-01-10 23:53:12 +00:00
practicalswift ab0c26be91 Check return value of json_get_params(...) call in json_getlog(...) and json_getpeers(...)
All other users of json_get_params(...) check the return value:

```
lightningd/chaintopology.c:     if (!json_get_params(buffer, params,
lightningd/chaintopology.c:     if (!json_get_params(buffer, params,
lightningd/dev_ping.c:  if (!json_get_params(buffer, params,
lightningd/gossip_control.c:    if (!json_get_params(buffer, params,
lightningd/invoice.c:   if (!json_get_params(buffer, params,
lightningd/invoice.c:   if (!json_get_params(buffer, params,
lightningd/invoice.c:   if (!json_get_params(buffer, params,
lightningd/invoice.c:   if (!json_get_params(buffer, params,
lightningd/invoice.c:   if (!json_get_params(buffer, params, "label", &labeltok, NULL)) {
lightningd/invoice.c:   if (!json_get_params(buffer, params,
lightningd/jsonrpc.c:   if (!json_get_params(buffer, params,
lightningd/pay.c:       if (!json_get_params(buffer, params,
lightningd/pay.c:       if (!json_get_params(buffer, params,
lightningd/peer_control.c:      if (!json_get_params(buffer, params,
lightningd/peer_control.c:      if (!json_get_params(buffer, params,
lightningd/peer_control.c:      if (!json_get_params(buffer, params,
lightningd/peer_control.c:      if (!json_get_params(buffer, params,
lightningd/peer_control.c:      if (!json_get_params(buffer, params,
lightningd/peer_control.c:      if (!json_get_params(buffer, params,
wallet/walletrpc.c:     if (!json_get_params(buffer, params,
wallet/walletrpc.c:     if (!json_get_params(buffer, params, "tx", &txtok, NULL)) {
```
2018-01-10 23:43:50 +00:00
Rusty Russell 467ca0a996 lightningd: suppress feerate debug messages when nothing changes.
Every 30 seconds, these flood the logs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-10 16:55:36 +01:00
practicalswift c53dfc3fde Check return value of derive_simple_privkey(...) call in hsm_unilateral_close_privkey(...)
All other users of derive_simple_privkey(...) check the return value:

```
channeld/channel.c:     if (!derive_simple_privkey(&peer->our_secrets.htlc_basepoint_secret,
lightningd/test/run-commit_tx.c:        if (!derive_simple_privkey(&x_remote_htlc_basepoint_secret,
lightningd/test/run-commit_tx.c:        if (!derive_simple_privkey(&x_local_delayed_payment_basepoint_secret,
lightningd/test/run-commit_tx.c:        if (!derive_simple_privkey(&x_local_htlc_basepoint_secret,
lightningd/test/run-key_derive.c:       if (!derive_simple_privkey(&base_secret, &base_point,
onchaind/onchain.c:     if (!derive_simple_privkey(&secrets->delayed_payment_basepoint_secret,
onchaind/onchain.c:     if (!derive_simple_privkey(&secrets->payment_basepoint_secret,
onchaind/onchain.c:     if (!derive_simple_privkey(&secrets->htlc_basepoint_secret,
onchaind/onchain.c:     if (!derive_simple_privkey(&secrets->payment_basepoint_secret,
onchaind/onchain.c:     if (!derive_simple_privkey(&secrets->htlc_basepoint_secret,
```
2018-01-10 04:05:49 +00:00
practicalswift e8c94c2e29 Check return value of read_all(...) call
All other users of read_all(...) check the return value:

```
hsmd/hsm.c:    if (!read_all(fd, &secretstuff.hsm_secret, sizeof(secretstuff.hsm_secret)))
test/test_protocol.c:    if (!read_all(fd, p, len))
wire/wire_sync.c:    if (!read_all(fd, &len, sizeof(len)))
wire/wire_sync.c:    if (!read_all(fd, msg, wirelen_to_cpu(len)))
```
2018-01-10 04:03:58 +00:00
William Casarin 5043e201b8 emacs: add .dir-locals.el for linux style C
This will automatically configure proper indent settings for new contributors
using emacs.

Signed-off-by: William Casarin <jb55@jb55.com>
2018-01-10 04:01:56 +00:00
Rusty Russell 758317387e HACKING.md: describe take() in more detail.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-10 03:58:46 +00:00
Rusty Russell 9b129f7fb5 doc/HACKING.md: update.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-01-10 03:58:46 +00:00
Christian Decker 90527498bc pytest: Do not re-print logs if we failed to find a log entry
CI always runs with TEST_DEBUG=1 which prints logs anyway, and testing
locally should also be done this way, combined with pytest which
captures the logs. No need to duplicate the functionality of pytest.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-10 03:52:46 +00:00
Christian Decker d0da8a1035 pytest: Remove unused breakpoint shorthand
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-10 03:52:46 +00:00
Christian Decker 55d2e4b1d0 pytest: Spawn a new bitcoind for each test
Since we seem to have some isolation concerns when re-generating the
same HSM secret and re-parsing the blockchain some blocks in the past.

This also alleviates the problem of printing to a logging stream that
has been closed. Previously bitcoind would keep running despite a test
had failed and continue logging to the, now closed, StringIO that
py.test uses when capturing stdout.

The performance impact seems to be 1-3 second per test, not too bad
IMHO for increased test isolation and cleaner logs:

|--------------------+---------------+----------|
|                    | No_valgrind   | Valgrind |
|--------------------+---------------+----------|
| bitcoind per suite | 10 min 24 sec | 46:15.31 |
| bitcoind per test  | 11 min 38 sec | 49:21.64 |
|--------------------+---------------+----------|

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-01-10 03:52:46 +00:00