Commit Graph

12861 Commits

Author SHA1 Message Date
Christian Decker 2e5ad0f417 pyln: Exclude all `cln-` plugins from valgrind 2023-04-13 18:13:28 -07:00
Christian Decker 0687fecf0d make: Use the CLN_PLUGIN_EXAMPLES variable for testbin
Listing things multiple times is error-prone, so use the variable we
already have :-)
2023-04-13 18:13:28 -07:00
Christian Decker f69da84256 rs: Run hooks, methods and notification handlers in tokio tasks
Changelog-Changed: cln-plugin: Hooks, notifications and RPC methods now run asynchronously allowing for re-entrant handlers
2023-04-13 18:13:28 -07:00
Christian Decker db3707f957 pytest: Highlight the re-entrancy issue for cln-plugin events
This was pointed out by Daywalker [1]: we are synchronously processing
events from `lightningd` which means that if processing one of the
hooks or requests was slow or delayed, we would not get notifications,
hooks, or RPC requests, massively impacting the flexbility.

This highlights the issue with a failing test (it times out), and in
the next commit we will isolate event processing into their own task,
so to free the event loop from having to wait for an eventual
response.

[1] https://community.corelightning.org/c/developers/hold-invoice-plugin#comment_wrapper_16754493
2023-04-13 18:13:28 -07:00
Alex Myers 54bd024910 gossip_store: remove now-redundant push bit
The push bit was convenient for connectd to send our own gossip
to peers upon connecting by naively traversing the gossip_store
and sending anything flagged `push`.  This function is now
performed by gossipd leaving no use for the push bit.

Changelog-Changed: `gossipd`: gossip_store PUSH bit is no longer set.
2023-04-13 08:48:50 -07:00
Alex Myers bec8586dce connectd: remove handling of push only gossip
This is now handled by gossipd on initial connection to peer.
2023-04-13 08:48:50 -07:00
Rusty Russell 6a446a94c6 connectd: implement timestamp-as-trinary.
This implements the proposal to simply use timestamp as "all", "none"
or "stream".  There's also a rough spec draft which I will post soon.

This *also* removes the last place where we would sometimes sweep the
entire gossip_store looking for their given timestamps.

We could also get rid of the actual timestamp filtering logic in
gossip_store_next if we want to, as it's now basically unused.

Changelog-Changed: Protocol: Simplify gossip_timestamp_filter handling to "all", "none" or "recent" instead of exact timestamp.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 08:48:50 -07:00
Rusty Russell 00f75d6ee1 connectd: no longer stream our own generated gossip, let gossipd do it.
This removes the sweep logic as soon as they connect.  This should save
connectd a significant number of CPU cycles and make @whitslack finally
stop hitting me.

Changelog-Changed: `connectd` no longer sweeps gossip_store file when peer connects, saving CPU for large nodes.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 08:48:50 -07:00
Rusty Russell 46bb6beee7 gossipd: make sure we also spam private channels with the peer involved.
Probably not required, but nice to have.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 08:48:50 -07:00
Rusty Russell 8ef4b36a1f gossipd: send our own gossip aggressively when a new peer connects.
This was previously the role of connectd, but it's actually more
efficient for us to do it: connectd has to sweep through the entire
gossip_store, but we have datastructures for this already.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 08:48:50 -07:00
Rusty Russell ba7901bebd pytest: fix up test_gossip_ratelimit.
We were in fact feeding l1 its own gossip, which it doesn't ratelimit (this was
a bit fuzzy before, but definitely is the case now!).

So make this node actually l3, so we test what we expected to test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 08:48:50 -07:00
Rusty Russell 58c624d067 pytest: fix test_penalty_htlc_tx_timeout accounting flake.
This test makes l2 save db, make a payment, then rollback.
*Sometimes* under CI (but not here) we don't shutdown fast enough
after the payment, so the moves.json from the coin_movements.py
records it.  Sure enough, the result is the node ends up with
a -10000msat balance.

Validated by putting a time.sleep(5) between:

```
    l2.rpc.pay(inv['bolt11'])

    import time
    time.sleep(5)
    # stop both nodes, roll back l2's database
```

The answer, of course, is to save and rollback *both* the db and
moves.json file.

Here's the error:
```
    def test_penalty_htlc_tx_timeout(node_factory, bitcoind, chainparams):
...    
        assert account_balance(l3, channel_id) == 0
>       assert account_balance(l2, channel_id) == 0

tests/test_closing.py:1527: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/utils.py:184: in account_balance
    m_sum -= Millisatoshi(m['debit_msat'])
contrib/pyln-client/pyln/client/lightning.py:197: in __sub__
    return Millisatoshi(int(self) - int(other))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = -10000msat, v = -10000
...    
        if self.millisatoshis < 0:
>           raise ValueError("Millisatoshi must be >= 0")
E           ValueError: Millisatoshi must be >= 0

contrib/pyln-client/pyln/client/lightning.py:82: ValueError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 09:03:13 +09:30
Rusty Russell 2e7ecb98f4 pytest: make sure we wait for all feerates to be gathered.
We need to wait until we're sure bcli has handed results to lightningd:

```
>       assert feerates['perkw']['mutual_close'] == 5000
E       assert 6250 == 5000

tests/test_misc.py:1617: AssertionError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 09:03:13 +09:30
Rusty Russell 6f17d8bf0c lightningd: fix 100% CPU hang on shutdown.
This finally happened on my test box; tests simply stopped.  Turns out
we were spinning here, with waitpid returning -1.

Since this is during shutdown, that also explains why pytest under CI
would hang, since timeouts don't apply during test teardown!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-13 09:03:13 +09:30
Rusty Russell 2c9b043be9 Makefile: remove plugins/sql-schema_gen.h and plugins on `make clean`
Reported-by: @chrisguida
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-11 22:04:18 -07:00
Rusty Russell 2de5b84370 plugins/Makefile: don't use echo -n.
MacOS in particular doesn't like this!

Reported-by: @chrisguida
Fixes: #6171
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-11 22:04:18 -07:00
Matt Morehouse 3c4b20e3a3 ci: run fuzz regression tests
There are several benefits of doing this:
- prevent fuzz target bit rot
- more test coverage in CI
- greater visibility of fuzz tests, encouraging contributions to the
  seed corpus and tests themselves
2023-04-11 21:46:00 -07:00
Rusty Russell 3f95b559a3 doc: document that urgent doesn't use the 2-block estimate, but the 6-block.
Turns out this was accidentally changed for v0.10.1 in
d8e68893f5 where we made fee levels less
aggressive.

Oops.  I guess we can fix the docs.  And we now have "2blocks" if you
want it really fast!

Closes: #6129
Changelog-Fixed: JSON-RPC: `feerates` document correctly that urgent means 6 blocks (not 2), and give better feerate examples.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-11 12:01:27 -07:00
Rusty Russell 49b7afe58f doc: give helpful examples for feerate values.
mempool.info gives sat/vB, which is 1000 too low for us!

See-also: #6161 (complains setting feerate to 5 doesn't work)

See-also: #6129
Suggested-by: @lightingorb
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-11 12:01:27 -07:00
Rusty Russell 62d9ecb6d3 hsmtool: makerune command.
You still need to actually make a rune when lightningd starts, as
commando (for safety) won't work unless you actually generate a rune
(that it knows of!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: hsmtool: `makerune` command to make a master rune for a node.
2023-04-11 11:19:13 -07:00
Rusty Russell 441b38c9ea hsmtool: move sodium_init() to top level.
This way we always call it (we weren't for some paths!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-11 11:19:13 -07:00
Rusty Russell e5c76f829e hsmtool: rework common hsm_secret fetch/decode.
1. Rename get_hsm_secret to get_unencrypted_hsm_secret.
2. Create a common helper for fetching full file contents.
3. Create new routine to decrypt if necessary: get_hsm_secret().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-11 11:19:13 -07:00
Joel Klabo c0d3eeb789 Fix Typo in startup_regtest.sh 2023-04-11 13:39:51 +09:30
Greg Sanders e30f2cb4a4 have towire_wally_psbt and fromwire_wally_psbt set safe psbt version 2023-04-11 11:23:17 +09:30
Christian Decker 650443e4d5 ld: Add a couple of logging statements when forwarding
We were debugging a number of issues related to the forwarding logic,
when using public scids on private channels, and we noticed that we
are very verbose everywhere, except where it counts, i.e., what
decisions are being taken. So we add a couple of debug logs, and a
final info one that tells the operator which resolution was chosen in
the end.
2023-04-11 11:22:30 +09:30
Christian Decker 6d76642f7e cln: Fix routehints conversion from cln-rpc and cln-grpc
Fixes #6143
Changelog-Fixed: clnrs: Fixed an issue converting routehints in keysend
2023-04-10 17:34:54 +09:30
Christian Decker b42984afe1 pytest: Reproduce #6143 2023-04-10 17:34:54 +09:30
Rusty Russell 75ec1bebee lightningd: use channel_type as we're supposed to for forward descisions.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell 7acaccfb36 wallet: add channel_type field to db.
This was always the intent, but now we have to reconstruct from the
disparate fields.

This means `option_anchor_outputs` is now redundant.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell 355aa8f497 zeroconf: don't accept channel_type with option_zeroconf unless we're really zeroconf.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Protocol: we will upfront reject channel_open which asks for a zeroconf channel unless we are going to do a zerconf channel.
2023-04-10 17:26:47 +09:30
Rusty Russell 7e5146ab0c common/channel_type: routines to set known variants, set scid_alias.
I tested this indeed breaks if we don't accept it, then implemented
the code to accept it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: protocol: We now correctly accept the `option_scid_alias` bit in `open_channel` `channel_type`.
Changelog-Deprecated: protocol: Not setting `option_scid_alias` in `option_channel` `channel_type` for unannounced channels.
2023-04-10 17:26:47 +09:30
Rusty Russell f1deeda123 wallet: allow psbt_using_utxos to take a starter psbt.
It will append inputs to this PSBT instead of allocating a new one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell d502a7ecbb bitcoin: bitcoin_tx_remove_output()
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell 34f25db435 lightningd: fix parent reporting for memleaks.
This was confusing!  We reported every second one.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell 89b96e8ac0 pyln-testing: add support to tell bitcoind not to include txs if fee is too low.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell 2fb942d21c bitcoin: rename confusing functions.
1. anchor_to_remote_redeem => bitcoin_wscript_to_remote_anchored,
   which matches other witness script producing functions and makes
   it clear that it's a to_remote variant.
2. is_anchor_witness_script => is_to_remote_anchored_witness_script
   makes it clear that it's about a to_remote output (as altered
   when anchors are enabled) not an anchor output!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell 57b2cbcb32 lightningd: expose default_locktime for wider usage.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell 8493ee5e1a db: print nice message and not just backtrace on bad column name.
Happens more than I expected!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell c45eb62b57 lightningd: create small hsm_sync_req() helper for hsm queries.
Commonalizes a small piece of code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 17:26:47 +09:30
Rusty Russell cf80f0520a connectd: dev-report-fds to do file descriptor audit.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 09:41:56 +09:30
Rusty Russell e514a5d43c common: lookup function for symnames.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 09:41:56 +09:30
Rusty Russell 3e49cb01bd connectd: don't leak fds if we have both IPv4 and IPv6.
We accept that we will fail to listen if we bind both IPv6 and IPv4 to
the same socket on a dual-stack machine (e.g. normal Linux), but we weren't
closing the fd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 09:41:56 +09:30
Rusty Russell ed58c24bc7 connectd: log broken if TCP_CORK fails.
But not if we're a developer using dev_disconnect, which substitutes the fd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 09:41:56 +09:30
Rusty Russell 295557ac50 connectd: don't try to set TCP_CORK on websocket pipe.
Most of this is piping the flag through so we know it's a websocket!

Reported-by: @ShahanaFarooqui
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 09:41:56 +09:30
Rusty Russell a000ee015a lightningd: do RBF again for all the txs.
Now we've set everything up, the replacement code is quite simple.

Some tests now have to deal with RBF though, and our rbf tests need work
since they look for the old onchaind messages.

In particular, when we can't afford the fee we want, we back off to
the next blockcount estimate, rather than spending all on fees
(necessarily).  So test_penalty_rbf_burn no longer applies.

Changelog-Changed: Protocol: spending unilateral close transactions now use dynamic fees based on deadlines (and RBF), instead of fixed fees.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 07:31:12 +09:30
Rusty Russell 62fa91e23b lightningd: rebroadcast all pending txs each 30-60 seconds.
We also do it on every block, but since bitcoind can't always be counted
to rebroadcast for us, we might as well be aggressive!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 07:31:12 +09:30
Rusty Russell 3754e283f8 lightningd: remember if they set "allowhighfees" when we rebroadcast.
We would only set it the first time, which was OK for how we were using it
before.  Now we want to also set it for rebroadcast.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 07:31:12 +09:30
Rusty Russell 5582970715 lightningd: split the simple onchain tx signing code.
Splitting into onchaind_tx() into onchaind_tx_unsigned() and
sign_and_get_witness() makes it easier to reuse for RBF.

Adding more information in onchain_signing_info is required too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 07:31:12 +09:30
Rusty Russell 819d9882aa lightningd: base feerate for onchain txs on deadlines, not fixed fees. 2023-04-10 07:31:12 +09:30
Rusty Russell 3a3370f4c1 feerates: add `floor` field for the current minimum feerate bitcoind will accept
Changelog-Added: JSON-RPC: `feerates`: added `floor` field for current minimum feerate bitcoind will accept
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-04-10 07:31:12 +09:30