Commit Graph

13065 Commits

Author SHA1 Message Date
Vincenzo Palazzo fdb676491f pyln-proto: expose the tlv types
Exposing the tlv types to allow public access to it.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-23 13:32:25 +09:30
Matt Morehouse 8991f27497 fuzz: initial fuzz-cryptomsg seeds
Corpus generated by 300+ CPU hours of fuzzing and then minimized.
2023-06-23 13:12:42 +09:30
Matt Morehouse 1d94d2cd5d fuzz: test message encryption and decryption
Add a fuzz test for BOLT 8 message encryption and decryption. The fuzz
test is based on the unit test at common/test/run-cryptomsg.c and uses a
static initial state with fuzzer-generated messages to encrypt or
decrypt.
2023-06-23 13:12:42 +09:30
Matt Morehouse fca50eaebc common: make hdr parameter const
cryptomsg_decrypt_header doesn't modify hdr, so we should make it const.
2023-06-23 13:12:42 +09:30
Matt Morehouse 8d9f033954 fuzz: initial handshake target seeds
Corpora generated for fuzz-connectd-handshake-act{1,2,3} from 300+ CPU
hours of fuzzing and then minimized.
2023-06-22 13:40:45 +09:30
Matt Morehouse 0e2173f1fd fuzz: add handshake act 3 target
The fuzz target uses static keys with a fuzzer-generated Act 3 packet.
2023-06-22 13:40:45 +09:30
Matt Morehouse a203db00ca fuzz: add handshake act 2 target
The fuzz target uses static keys with a fuzzer-generated Act 2 packet.
2023-06-22 13:40:45 +09:30
Matt Morehouse 4bb216a611 fuzz: add handshake act 1 target
The fuzz target uses static keys with a fuzzer-generated Act 1 packet.
2023-06-22 13:40:45 +09:30
Matt Morehouse 2b629b2509 fuzz: add connectd_handshake.h
This header will be used by multiple fuzz targets to fuzz Acts 1, 2, and
3 of the BOLT 8 handshake.

We could make this header into a full library, but considering its
narrow use let's try not to over-engineer things.
2023-06-22 13:40:45 +09:30
Rusty Russell 55d6eb6762 CI: run 2, not 3 UBSAN/ASAN pytests at once.
It seems to reliably be getting a SIGTERM after 17-18 minutes:

```
[gw1] [ 91%] PASSED tests/test_plugin.py::test_forward_event_notification
Error: Process completed with exit code 143.
```

Perhaps this is out of mem?  So, try -n2.  We also make the configure
line explicit, rather than relying on environment vars (we should probably
do this for the other cases, too)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-22 13:23:21 +09:30
Rusty Russell ca9a6b15b5 pay: don't require description for hashdesc invoices (i.e. undeprecate).
Since we didn't hash the descriptions properly (see previous commit), we
cannot immediately deprecate omitting the descriptions (since you'd
have to omit them for backwards compat!).

And move the "must have description or hash" test into bolt11.c core.
Changelog-Deprecated: `pay` has *undeprecated* paying a description-hash invoice without providing the description.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-22 13:23:21 +09:30
Rusty Russell 92ff0fd8c0 pay, decodepay: handle descriptions with " inside them where we use hashed descriptions.
This means we need to push off requring this for another full deprecation cycle!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: JSON-RPC: `pay` and `decodepay` with description now correctly handle JSON escapes (e.g " inside description)
2023-06-22 13:23:21 +09:30
Bryan Ramos 7a57f7024c Added sample config file 2023-06-21 14:57:34 +09:30
Rusty Russell 6287f3e3b1 pytest: test_pay flake fix.
This is almost certainly because the HTLCs are not fully settled, so wait for that:

```
2023-06-20T11:37:56.2332158Z         assert apys_2[0]['our_start_balance_msat'] == Millisatoshi(0)
2023-06-20T11:37:56.2332443Z >       assert apys_1[0]['routed_out_msat'] == apys_2[0]['routed_in_msat']
2023-06-20T11:37:56.2332571Z E       assert 1892216msat == 2810170msat
2023-06-20T11:37:56.2332580Z 
2023-06-20T11:37:56.2332717Z tests/test_pay.py:81: AssertionError
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-21 13:28:49 +09:30
Rusty Russell 35011337eb pytest: fix unexpected reconnection check in test_setconfig()
If we reconnect before the channel is completely closed, we might get
a "reconnected" message, so mine a block after and make sure it's
processed.

```
2023-06-20T11:37:56.1302058Z         if errors.has_errors():
2023-06-20T11:37:56.1302648Z             # Format a nice list of everything that went wrong and raise an exception
2023-06-20T11:37:56.1303781Z             request.node.has_errors = True
2023-06-20T11:37:56.1304091Z >           raise ValueError(str(errors))
2023-06-20T11:37:56.1304370Z E           ValueError: 
2023-06-20T11:37:56.1304624Z E           Node errors:
2023-06-20T11:37:56.1305042Z E            - lightningd-2: had unexpected reconnections
2023-06-20T11:37:56.1305340Z E           Global errors:
```
...
```
2023-06-20T11:37:56.1960525Z lightningd-2 2023-06-20T11:21:28.638Z DEBUG   0266e4598d1d3c415f572a8488830b60f7e744ed9235eb0b1ba93283b315c03518-chan#2: Peer has reconnected, state CLOSINGD_SIGEXCHANGE: connecting subd
```
2023-06-21 13:28:49 +09:30
Rusty Russell 263625872e autoclean: allow dynamic changes to autoclean-cycle.
Slightly less trivial: reset timer unless it's currently running callback.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell f8f8045a06 autoclean: various configuration options now dynamic.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Plugins: `autoclean` configuration variables now settable with `setconfig`.
2023-06-20 20:08:25 +09:30
Rusty Russell a65f2ef22a plugins: libplugin support for dynamic config options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell aa5c7e763f libplugin: make set callback for options take plugin ptr, check correct type.
I added a plugin arg and was surprised that compile didn't break.
This is because typesafe_cb et al are conditional casts: if the type
isn't as expected it has no effect, but we're passing plugin_option() through
varargs, so everything is accepted!

Add a noop inline to check type, and fix up the two cases where we
used `const char *` instead of `char *`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell 630dba8840 lightningd: call setconfig on plugins' dynamic options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell b0c07dff2a plugin: allow plugins to set `dynamic` on options.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell e50e57712a setconfig: hook into plugin infrastructure for setconfig.
If it's a plugin opt, we'll need a callback, so reshuffle logic.  Also
add infra to map option name to plugin and option.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell 703ffdf59b setconfig: comment out now-overridden lines.
Do it slightly intelligently, so if we had set previously using setconfig
we don't keep appending new ones, but replace it in-place.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell 6546be9757 lightningd: setconfig command.
Currently only implemented for min-capacity-sat.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: new command `setconfig` allows a limited number of configuration settings to be changed without restart.
2023-06-20 20:08:25 +09:30
Rusty Russell ecc030f12d lightningd, libplugins: allocate opt strings from tmpctx, not NULL.
Previously, if these failed we always exited; once we have dymamic
configs this would be a (tiny) memory leak, so use tmpctx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell aca893f1eb common: allow configvars to be marked dynamic.
To test, we do min-capacity-sat which is simple.  We also update the
listconfigs man page which contained some obsolete information.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell 9f9f2f1493 lightningd: move listconfigs into configs.c
It mainly clutters up options.c.  The deprecated handling was very tied
to it, so it stays there.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 20:08:25 +09:30
Rusty Russell d09d0112f4 pytest: handle v fast disconnect during test_funding_external_wallet_corners()
We get "disconnected during connection" if we haven't finished processing
the connection when the peer sends error and hangs up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell 771dbca790 ccan: update to fix hang in ./configure with clang.
Also pulls in runes update, but that's harmless.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell c1d35cc0c8 Revert "CI: allow postgres and ASAN longer to run."
This reverts commit 2123a057ac9ad37dfc36f003974bf8238de842f2.
2023-06-20 17:24:48 +09:30
Rusty Russell 2abcd8108e pytest: fix race in test_penalty_rbf_normal
We re-enable sendrawtransaction then mine a block to kick off RBF, but there's
a race where it can get a tx in that block, and then we timeout waiting for
both txs to get into the next block.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell c1d3da889c tools/gossipwith: shutdown, don't close, TCP socket.
This isn't the cause of the test_gossip_ratelimit flake I saw (since
the final gossip msg clearly was received), but it's still good to fix
since it means we might not send the final messages.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell 7820dfdb35 lightningd: tell connectd to disconnect even if it's connecting now.
We were seeing hangs in disconnect in
tests/test_connection.py::test_feerate_stress, and looking at the logs
it's because we're not actually telling connectd to disconnect.

These days, we have a connect counter, so connectd knows to ignore it
if we simply haven't read the message about it already disconnecting.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell 0c3757f3a8 CI: allow postgres and ASAN longer to run.
It seems to time out on tests/test_connection.py::test_feerate_stress.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell 34b9786076 CI: suppress Postgres vacuuming during tests.
build.sh did this, but we didn't carry it across to the new test
matrix, leading to spurious CI failures:

```
lightningd-1 2023-06-06T16:15:34.931Z DEBUG   plugin-bookkeeper: Setting up database at ***localhost:39061/accounts_0_7ccmg745
lightningd-1 2023-06-06T16:15:34.931Z INFO    plugin-bookkeeper: Creating database
lightningd-1 2023-06-06T16:15:34.931Z **BROKEN** plugin-bookkeeper: Error vacuuming db: VACUUM command failed: ERROR:  deadlock detected\nDETAIL:  Process 77248 waits for AccessShareLock on relation 1260 of database 0; blocked by process 77414.\nProcess 77414 waits for RowExclusiveLock on relation 1214 of database 0; blocked by process 77248.\nHINT:  See server log for query details.\n
lightningd-1 2023-06-06T16:15:34.931Z INFO    plugin-bookkeeper: Killing plugin: exited before replying to init
lightningd-1 2023-06-06T16:15:34.931Z **BROKEN** plugin-bookkeeper: Plugin marked as important, shutting down lightningd!
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell cc76cfbb4b CI: Remove unused CI build script.
We now do this directly in .github/workflows

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 17:24:48 +09:30
Rusty Russell 9a77904f66 CHANGELOG.md: updates from 23.05.1 branch.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-20 10:12:53 +09:30
Greg Sanders e125640f43 Persist feature bits across restarts
[ Whitespace fix and remove gratuitous tal_free(peer->their_features) -- RR ]
2023-06-20 10:07:11 +09:30
Christian Decker 9f1e1ada2a py: Update dependencies and relax constraints
We were being very restrictive when describing the dependencies, so let's
relax them a bit.
2023-06-18 11:00:32 +09:30
Rusty Russell ea7d428579 common: add test to generate BOLT formatting vectors.
They needed updating, so let's actually autogenerate them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-15 15:05:42 +09:30
Matt Morehouse cc71f75c4b doc: add section about Clang code coverage 2023-06-15 10:47:56 +09:30
Matt Morehouse d5645d28a7 contrib: script to generate Clang coverage report
The script converts a raw Clang coverage profile to an HTML report.
2023-06-15 10:47:56 +09:30
Matt Morehouse aa9356b961 make: allow Clang coverage instrumentation
Clang's coverage instrumentation [1] is the best I've seen, with
precision down to the expressions within a line of code. Add an option
to use this instrumentation for better coverage reports.

[1] https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
2023-06-15 10:47:56 +09:30
Vincenzo Palazzo 53154a40a5 fix: build on alpine linux
This fixes the compile issue that we are having on
alpine.

```
cc wallet/wallet.c
cc wallet/walletrpc.c
cc wallet/reservation.c
cc wallet/db_sqlite3_sqlgen.c
cc wallet/db_postgres_sqlgen.c
cc common/addr.c
cc common/bolt11.c
cc common/bolt11_json.c
cc common/bolt12.c
cc common/configdir.c
cc common/configvar.c
cc common/scb_wiregen.c
common/configvar.c: In function 'configvar_remove':
common/configvar.c:118:9: error: unknown type name 'ssize_t'; did you mean 'size_t'?
  118 |         ssize_t prev = -1;
      |         ^~~~~~~
      |         size_t
make: *** [Makefile:292: common/configvar.o] Error 1
make: *** Waiting for unfinished jobs....
```

Link: https://github.com/ElementsProject/lightning/issues/6321
Reported-by: @gruve-p
Fixes: 36200a6593
Changelog-None
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-15 09:52:31 +09:30
Vincenzo Palazzo 05c13ddfc5 fix(pyln): regenerate the autogenerated files
I noted in some PR that we are failing during the diff of the autogenerated files.

So this will generate the last version of them!

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-14 16:36:31 +02:00
Vincenzo Palazzo 0b671fb144 Revert "ci: re-enable the compilation workflow"
This reverts commit 1b6f3d687f.
2023-06-14 15:01:53 +02:00
Vincenzo Palazzo 2bf3db623a Revert "ci: add the pre-build check as dependencies on lnprototetest"
This reverts commit 00d9f28a85.
2023-06-14 15:01:53 +02:00
Vincenzo Palazzo 8b30c34d48 ci: add the pre-build check as dependencies on lnprototetest
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-14 13:21:48 +02:00
Vincenzo Palazzo 1b6f3d687f ci: re-enable the compilation workflow
This enable again the compilation workflow
and add the dependencies to the pre-check

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-14 13:21:48 +02:00
Vincenzo Palazzo 85992e6e48 feat(bitcoind): pass the current known block height
When core lightning is asking the information about
the blockchain with `getchaininfo` command lightningd
know already the information about the min and max block height.

the problem is when we have a smarter Bitcoin backend that is able
to switch between different clients in some cases is helpful
give the information about current known height by lightningd and
pass it down to the plugin.

In this way, the plugin knows what is the correct known height from lightnind, and can
try to fix some problems if any exit.

This is particularly useful when you are syncing a new backend from scratch
like https://github.com/cloudhead/nakamoto and we avoid returning the
lower height from the known, and avoid the crash of core lightning.

With this information, the plugin can start to sync the chain and return
the answer back only when the chain is in sync with the current status of
lightningd.

Another reason to add this field and not wait the correct block in core
lightning itself is because Bitcoin Core is extremely slow to sync up,
so the question here is, how long should we wait? The time depends
on various factors.

With this approach of informing the plugin about the height, in some cases,
you can start the syncing but move the execution to another backend until
the previous one is ready.

The problem I want to solve is that I don't want to be left in the dark when
we run `getchaininfo`, and I want to have the opportunity to wait for
the blockchain sync or decide to dispatch the request elsewhere.

Changelog-Added: Pass the current known block height down to the getchaininfo call.
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-13 16:27:10 +02:00