Commit Graph

3782 Commits

Author SHA1 Message Date
Rusty Russell e2ba1d2290 test_lightningd.py: test_closing_different_fees must wait for txs to hit mempool
Careful log examination revealed that we were generating a block before one
of the mutual close txs had entered the mempool.  This is rare because it
means that both peers have to be too slow.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell 16d5015d56 lightningd: fix shutdown with unconfirmed channel.
We free the peers explicitly, but we don't free the unconfirmed channel:
the result is that it gets freed twice.

The workaround is to free the unconfirmed channel explicitly, but really
the peer should be tal_link'ed as it's basically a reference counted
structure.

1.974911451 lightningd(17906):INFO: 03b4bca72572889d4b44cd0f194f73d54972af367e1917579283122ee10fa05f54 chan #1: Owning subdaemon lightning_openingd died (62464)
1.980118094 lightningd(17906):BROKEN: FATAL SIGNAL 6
1.980150447 lightningd(17906):BROKEN: backtrace: common/daemon.c:42 (crashdump) 0x432ba0
1.980161268 lightningd(17906):BROKEN: backtrace: (null):0 ((null)) 0x7faeb18ff4af
1.980167045 lightningd(17906):BROKEN: backtrace: (null):0 ((null)) 0x7faeb18ff428
1.980171271 lightningd(17906):BROKEN: backtrace: (null):0 ((null)) 0x7faeb1901029
1.980175847 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:98 (call_error) 0x47543e
1.980181814 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:170 (check_bounds) 0x4755fb
1.980188065 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:180 (to_tal_hdr) 0x475649
1.980193756 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:504 (tal_free) 0x47600d
1.980199402 lightningd(17906):BROKEN: backtrace: lightningd/peer_control.c:118 (delete_peer) 0x423990
1.980205498 lightningd(17906):BROKEN: backtrace: lightningd/opening_control.c:574 (destroy_uncommitted_channel) 0x419df3
1.980212380 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:240 (notify) 0x4757b0
1.980218052 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:400 (del_tree) 0x475c61
1.980223398 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:511 (tal_free) 0x476093
1.980229174 lightningd(17906):BROKEN: backtrace: lightningd/opening_control.c:549 (opening_channel_errmsg) 0x419d1a
1.980236227 lightningd(17906):BROKEN: backtrace: lightningd/subd.c:590 (destroy_subd) 0x42cf43
1.980242348 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:240 (notify) 0x4757b0
1.980247771 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:400 (del_tree) 0x475c61
1.980252814 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:410 (del_tree) 0x475cb1
1.980258356 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:410 (del_tree) 0x475cb1
1.980263311 lightningd(17906):BROKEN: backtrace: ccan/ccan/tal/tal.c:511 (tal_free) 0x476093
1.980269189 lightningd(17906):BROKEN: backtrace: lightningd/lightningd.c:412 (main) 0x4144ed

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell d2b4e09e27 lightningd: re-allow closing negotiation when CLOSINGD_COMPLETE
d822ba1ee accidentally removed this case, which is important: if the
other side didn't get our final matching closing_signed, it will
reconnect and try again.  We consider the channel no longer "active"
and thus ignore it, and get upset when it send the
`channel_reestablish` message.

We could just consider CLOSINGD_COMPLETE to be active, but then we'd
have to wait for the closing transaction to be mined before we'd allow
another connection.

We can't special case it when the peer reconnects, because there
could be (in theory) multiple channels for that peer in CLOSINGD_COMPLETE,
and we don't know which one to reestablish.

So, we need to catch this when they send the reestablish, and hand
that msg to closingd to do negotiation again.  We already have code
to note that we're in CLOSINGD_COMPLETE and thus ignore any result
it gives us.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell 5551c161ca gossipd: finish startup before master prints that it's ready.
We're about to remove automatic retrying of connect, and that uncovered
that we actually print out our "Server started" message before we create
the listening socket.

Move the init higher (outside the db transaction) and make it a
request/response, the loop until it's done.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell 8e976150ad json_fundchannel: fix release vs connect/nongossip race.
The new connect code revealed an existing race: we tell gossipd to
release the peer, but at the same time it connects in.  gossipd fails
the release because the peer is remote, and json_fundchannel fails.

Instead, we catch this race when we get peer_connected() and we were
trying to open a channel.  It means keeping a list of fundchannels which
are awaiting a gossipd response though.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell bee795ed68 channeld: don't do explicit state update.
We missed it in some corner cases where we crashed/were killed between
being told of the lockin and sending the channel_normal_operation message.
When we were restarted, we were told both sides were locked in already,
so we never updated the state.

Pull the entire "tell channeld" logic into channel_control.c, and make
it clear that we need to keep waching if we cant't tell channeld.  I think
we did get this correct in practice, since funding_announce_cb has the
same test, but it's better to be clear.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell 22fe2c921f lightningd: commit short-channel-id to db when we create it.
We'd usually commit to the db soon, but there's a window where it
could be missed.

Also moves loc into the block it's used and make it tmpctx to avoid
an explicit free.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell 7604f27fb8 lightningd: make sure openingd and uncommitted_channel free each other.
Without this, we can get errors on shutdown:

Valgrind error file: valgrind-errors.27444
==27444== Invalid read of size 8
==27444==    at 0x1950E2: secp256k1_pubkey_load (secp256k1.c:127)
==27444==    by 0x19CF87: secp256k1_ec_pubkey_serialize (secp256k1.c:189)
==27444==    by 0x14FED9: towire_pubkey (towire.c:59)
==27444==    by 0x15AAFB: towire_gossipctl_peer_disconnected (gen_gossip_wire.c:969)
==27444==    by 0x1253EF: opening_channel_errmsg (opening_control.c:526)
==27444==    by 0x1386A3: destroy_subd (subd.c:589)
==27444==    by 0x18222C: notify (tal.c:240)
==27444==    by 0x1826E1: del_tree (tal.c:400)
==27444==    by 0x182733: del_tree (tal.c:410)
==27444==    by 0x182733: del_tree (tal.c:410)
==27444==    by 0x182B1F: tal_free (tal.c:511)
==27444==    by 0x11FC53: main (lightningd.c:410)
==27444==  Address 0x6c3af98 is 72 bytes inside a block of size 216 free'd
==27444==    at 0x4C30D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27444==    by 0x1827BC: del_tree (tal.c:421)
==27444==    by 0x182B1F: tal_free (tal.c:511)
==27444==    by 0x11F3C7: shutdown_subdaemons (lightningd.c:211)
==27444==    by 0x11FC27: main (lightningd.c:406)
==27444==  Block was alloc'd at
==27444==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27444==    by 0x182296: allocate (tal.c:250)
==27444==    by 0x182863: tal_alloc_ (tal.c:448)
==27444==    by 0x12F2DF: new_peer (peer_control.c:74)
==27444==    by 0x125600: new_uncommitted_channel (opening_control.c:576)
==27444==    by 0x125870: peer_accept_channel (opening_control.c:668)
==27444==    by 0x13032A: peer_sent_nongossip (peer_control.c:427)
==27444==    by 0x116B9E: peer_nongossip (gossip_control.c:60)
==27444==    by 0x116F2B: gossip_msg (gossip_control.c:172)
==27444==    by 0x138323: sd_msg_read (subd.c:503)
==27444==    by 0x137C02: read_fds (subd.c:330)
==27444==    by 0x175550: next_plan (io.c:59)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell d0bfd8407a test_lightningd.py: catch unexpected reconnections.
I had a weird failure which was caused by an unexpected disconnect and
reconnecct.  Since we are prersistend and recover from these, they can
slip through our tests; most tests don't involve reconnection, so we
need to catch this explicitly.

For the connect() helper, we always suppress reconnection; tests which
want it all want other options so don't use this helper anyway.  (Actually,
after I said that, test_closing_while_disconnected was added when I
rebased, which did require it, so I had to open-code that one).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
Rusty Russell 05ba976a41 lightningd: --dev-no-reconnect needs to always suppress reconnection.
It didn't in the restore-from-db case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 20:18:15 +00:00
ZmnSCPxj, ZmnSCPxj jxPCSmnZ d6bf7930b8 Loosen` close` timeout in `test_closing_different_fees` 2018-04-23 05:24:46 +00:00
ZmnSCPxj 0b331a2b60 test_lightningd.py: Clean up some uses of 'close' RPC. 2018-04-23 05:24:46 +00:00
Rusty Russell 68758a5d42 json_close: test that it works while disconnected.
It should, indeed, close once they reconnect.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-23 05:24:46 +00:00
ZmnSCPxj 2cee1ab20f peer_control: Make close wait for complete closure, with timeout.
Also report tx and txid, and whether we closed unilaterally or
bilaterally, if we could close the channel.

Also make a manpage.

Fixes: #1207
Fixes: #714
Fixes: #622
2018-04-23 05:24:46 +00:00
BT 4673ba6a0a Add in sudo apt-get update into ubuntu
Add in sudo apt-get update into ubuntu instructions because sometimes the process fails if not updated
2018-04-22 21:18:16 +02:00
ZmnSCPxj 78a074af5a test_lightningd: Also test receive of P2WPKH is correct.
For completeness.
Existing test will check P2SH-P2WPKH address only.
P2WPKH seems OK but test it anyway in case of regression.
2018-04-22 12:51:03 +02:00
ZmnSCPxj 990ef729b0 walletrpc: Refactor out encoding of pubkey to address. 2018-04-22 12:51:03 +02:00
ZmnSCPxj 3bf626a750 walletrpc: Correct generation of P2SH-P2WPKH addresses for listfunds. 2018-04-22 12:51:03 +02:00
ZmnSCPxj c2e85cd051 test_lightningd: Check listfunds address matches newaddr paid to. 2018-04-22 12:51:03 +02:00
Christian Decker 140123b4c8 pytest: Add local_add tests to test_gossip_persistence and cleanup
Mixing the test into the existing test allows us to reduce the execution, but
adds a bit of complexity, so I added two small helpers.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-22 12:50:34 +02:00
Christian Decker 64fbea1528 gossip_store: Save local_add_channel messages and replay them
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-22 12:50:34 +02:00
Christian Decker 7497f972f1 moveonly: Move handle_local_add_channel to routing.h
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-22 12:50:34 +02:00
Christian Decker ddbf016152 gossip: Pass rstate to handle_local_add_channel directly
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-22 12:50:34 +02:00
conanoc 7170521895 change spaces to tabs, align function parameters 2018-04-21 15:55:00 +02:00
conanoc 0733770559 Adjust indents 2018-04-21 15:55:00 +02:00
ZmnSCPxj 0a586acf6e lightning-autocleaninvoice.7: Properly generate instead of using an empty file.
Strange behavior where `a2x` sometimes does not work at all.
2018-04-18 12:37:15 +02:00
ZmnSCPxj 774af5f817 payalgo: Describe `maxdelay` argument of `pay`. 2018-04-17 17:29:36 +02:00
ZmnSCPxj, ZmnSCPxj jxPCSmnZ 11ca729d85 wallet, payalgo: Save detail of payment failures for later reporting. (#1345)
Pointless for remote failures as those are never sent by
the erring node, but for local failures we can give more
detail.
2018-04-16 15:29:40 +02:00
practicalswift 0eff28c80f Assert our parse_wireaddr assumptions in run-ip_port_parsing.c
We assume that the parse_wireaddr(...) calls return true.
Otherwise addr.port will be uninitialized.
2018-04-15 17:45:47 +02:00
conanoc b2f7e9af4a Support debugging with lldb
Running with lldb cause SIGINT, which makes waitpid() returns
error with errno as EINTR. This patch retry waitpid() to ignore
EINTR errors.
2018-04-15 17:42:24 +02:00
Rusty Russell a6c76f9079 closingd: even with old clients, still require funding offer < commitment fee.
For older clients we could do more exhaustive checks, but effort is better
spent on removing this altogether post 0.6 as clients upgrade.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-15 15:32:14 +02:00
Rusty Russell 1faec99c59 closingd: make sure we restrict feerange with initial offer.
@ZmnSCPxj points out that this is allowed, though invalid:

1. commitment_fee = 1000
2. funder: 800
3. fundee: 200
4. funder: 900

We need to adjust the feerange using the initial funder offer.
2018-04-15 15:32:14 +02:00
Rusty Russell 7ca4422d7d closing_control: always prefer lower fee, not closest to ideal.
We had an intermittant test failure, where the fee we negotiated was
further from our ideal than the final commitment transaction.  It worked
fine if the other side sent the mutual close first, but not if we sent
our unilateral close first.

ERROR: test_closing_different_fees (__main__.LightningDTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/test_lightningd.py", line 1319, in test_closing_different_fees
    wait_for(lambda: p.rpc.listpeers(l1.info['id'])['peers'][0]['channels'][0]['status'][1] == 'ONCHAIN:Tracking mutual close transaction')
  File "tests/test_lightningd.py", line 74, in wait_for
    raise ValueError("Error waiting for {}", success)
ValueError: ('Error waiting for {}', <function LightningDTests.test_closing_different_fees.<locals>.<lambda> at 0x7f4b43e31a60>)

Really, if we're prepared to negotiate it, we should be prepared to
accept it ourselves.  Simply take the cheapest tx which is above our
minimum.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-15 15:32:14 +02:00
Rusty Russell 90364a8cc6 closingd: Correct whose turn it is when moving from initial negotiation to continuous negotiation.
[minor neatening by Rusty]

Fixes: #1361
Reported-by: @nayuta-ueno
Implemented-by: @ZmnSCPxj
2018-04-15 15:32:14 +02:00
Rusty Russell 6424b2decd closing: initialize feerange->allow_mistakes.
This exists for compatiblity with older versions, but it's currently
uninitialized.

Fixed-by: @ZmnSCPxj
2018-04-15 15:32:14 +02:00
Christian Decker f27cd3e43f topo: Remove in-memory txs from the block struct
The only use for these was to compute their txids so we could notify depth
in case of reorgs.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Christian Decker 23984ecde4 chaintopology: Use the DB to locate transactions and rebroadcast txs
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Christian Decker 86b6402e5c chaintopology: Refactor get_tx_depth to use the DB backed tx store
We are slowly hollowing out the in-memory blockchain representation to make
restarts easier.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Christian Decker aa696370af txwatch: Switch to passing only txid into the depth callbacks
All of the callback functions were only using the tx to generate the txid again,
so we just pass that in directly and save passing the tx itself.

This is a simplification to move to the DB backed depth callbacks. It'd be
rather wasteful to read the rawtx and deserialize just to serialize right away
again to find the txid, when we already searched the DB for exactly that txid.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Christian Decker 85fbab2fab wallet: Add function to retrieve a watched transaction's blockheight
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Christian Decker 50600ae241 wallet: Store transactions we are watching, broadcast or own
This will later allow us to determine the transaction confirmation count, and
recover transactions for rebroadcasts.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Christian Decker 633ffeec6f wallet: Add methods to add transactions to the DB
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Christian Decker 0f89653ce8 db: Add table for transactions we are interested in
Currently these are either transactions we sent ourselves or transactions that
we are watching because they are part of a channel.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2018-04-13 00:04:37 +02:00
Rusty Russell b0c2e3cd5c gossipd: use a separate CSV file for the gossip_store types.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-11 15:58:18 +02:00
Rusty Russell 57b38cac71 gossip_store: empty, don't truncate, on error.
Christian points out that we don't get spend notifications for old
channels if we truncate the store.  We'd need more work to do this,
either validating the channels are still unspent, or replaying old
blocks from the truncation point.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-11 15:58:18 +02:00
Rusty Russell d5767fb3bb gossipd: print stats even if we truncate store.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-11 15:58:18 +02:00
Rusty Russell 2b8293c9f6 gossipd: don't use pwrite, better error messaging on init.
Since we open with O_APPEND, any write() will append as we want it to.

But we want to distinguish a new store creation from a truncation due
to bad version.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-11 15:58:18 +02:00
Rusty Russell 7d0a76c533 goossipd: make store load truncate on errors.
We don't need pread, we just need read, and we can loop internally.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-11 15:58:18 +02:00
Rusty Russell 3e1b584e73 gossipd: always add message internally before store.
If something goes (fatally) wrong, we won't add it to the store.

This reveals a latent bug in routing_add_channel_announcement() and
friend which did a take() on msg, which it doesn't own.  TAKES means
that it will take ownership IF the caller requests, not an unconditional
ownership transfer (which is an antipattern).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-11 15:58:18 +02:00
Rusty Russell abbbfac8e2 gossipd: return bool from message announce routines.
Now we can tell if they fail, so we can respond appropriately if we're
loading from the store.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2018-04-11 15:58:18 +02:00