Commit Graph

13128 Commits

Author SHA1 Message Date
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
Christian Decker 8c02d9587d msggen: Extend support range to v0.10.1 and mark address, added in v23.02 2023-06-13 11:28:35 +09:30
Rusty Russell 2d53707611 openingd: work harder to intuit OPT_SCID_ALIAS.
option_scid_alias inside a channel_type allows for more private
channels: in particular, it tells the peer that it MUST NOT allow
routing via the real short channel id, and MUST use the alias.

It only makes sense (and is only permitted!) on unannounced channels.

Unfortunately, we didn't set this bit in the channel_type in v12.0
when it was introduced, instead relying on the presence of the feature
bit with the peer.  This was fixed in 23.05, but:

1. Prior to 23.05 we didn't allow it to be set at all, and
2. LND has a limited set of features they allow, and this isn't allowed without
   option_anchors_zero_fee_htlc_tx.

We could simply drop this channel_type until we merge anchors, *but*
that has nasty privacy implications (you can probe the real channel id).

So, if we don't negotiate anchors (we don't!), we don't set this
channel_type bit even if we want it, and *intuit* it, based on:

1. Is this a non-anchor channel_type?
2. Did we both send channel_type?
3. Is this an unannounced channel?
4. Did both peers announce support for scid aliases?

In addition, while looking at the previous backwards-compat code, I
realized that v23.05 violated the spec and send accept_channel with
OPT_SCID_ALIAS if it intuited it, even if it wasn't offered.  Stop
doing this, but allow our peers to.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Fix incompatibility with LND which prevented us opening private channels
Fixes: #6208
2023-06-09 10:35:06 +09:30
Vincenzo Palazzo 13836ddd2f fix: increase version cryptography python dep
Due to a security report by github, we should increase
our cryptography lib version.

This may impact potential another version that is stuck
with a cryptography version.

Link: https://github.com/ElementsProject/lightning/issues/6164
Reported-by: @dni
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-07 21:06:44 +02:00
Matt Morehouse 4b6c5c06e7 ci: run integration tests with sanitizers
Running with sanitizers in CI will help prevent us from introducing new
memory safety errors.
2023-06-07 18:47:40 +02:00
Matt Morehouse 117b80d508 ci: run unit tests with sanitizers
Running with sanitizers in CI will help prevent us from introducing new
memory safety errors.
2023-06-07 18:47:40 +02:00
Matt Morehouse debec7d6e9 tools: fix memory leaks in hsmtool
Detected by ASan in test_hsmtool_generatehsm:

==58698==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 120 byte(s) in 1 object(s) allocated from:
    #0 0x4e6247 in malloc
    #1 0x7f078452d672 in getdelim

SUMMARY: AddressSanitizer: 120 byte(s) leaked in 1 allocation(s).
2023-06-07 18:47:40 +02:00
Rusty Russell e457681f3a lightningd: allow `false` as a default for flags.
defaults were deprecated in 0df97547dd, but that was a bit
harsh as several plugins do that (summary, for example).  So allow false, but warn
that we ignore anything else.

Reported-by: @microsatoshi on Discord.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: Plugins: ...actually, `default` `false` still accepted on `flag` type parameters.
2023-06-07 13:16:08 +09:30
Rusty Russell 55119e6ca0 pytest: mark test_commando_stress as slow.
It sometimes takes > 1800 seconds under valgrind.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-06 19:47:08 +09:30
Rusty Russell 33be5c8d80 commando: integer command parameters can be compared with < and >.
Previously any attempt would result in "is not an integer field"; we
now recognize valid JSON integers as integer fields.

Changelog-Fixed: Plugins: `commando` runes can now compare integer parameters using '<' and '>' as expected.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-06 19:47:08 +09:30
Rusty Russell 0f72542967 pytest: test for amount comparison.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-06 19:47:08 +09:30
Rusty Russell 5f6933d1c4 doc: document that we strip punctuation from parameter names.
This lead to confusion about how to specify `amount_msat`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-06 19:47:08 +09:30
Adi Shankara e83782f5de doc: Add guides and GitHub workflow for doc sync
This PR:
- adds all the guides (in markdown format) that is published at https://docs.corelightning.org/docs
- adds a github workflow to sync any future changes made to files inside the guides folder
- does not include API reference (json-rpc commands). Those will be handled in a separate PR since they're used as manpages and will require a different github workflow

Note that the guides do not exactly map to their related files in doc/, since we reorganized the overall documentation structure on readme for better readability and developer experience. For example, doc/FUZZING.md and doc/HACKING.md#Testing are merged into testing.md in the new docs. As on the creation date of this PR, content from each of the legacy documents has been synced with the new docs. Until this PR gets merged, I will continue to push any updates made to the legacy documents into the new docs.

If this looks reasonable, I will add a separate PR to clean up the legacy documents from doc/ (or mark them deprecated) to avoid redundant upkeep and maintenance.

Changelog-None
2023-06-06 12:40:19 +09:30
Vincenzo Palazzo 15e86f2bba fix: prefixing external build dir
This is a simplification for our build system
that allows for managing and cleaning the external
build artefacts in an easy way.

We have a hard time with the suffix `-modded` inside the
version with some architecture when building a tagged version.

Link: https://discord.com/channels/899980449231814676/899989729183940629/1110957992158965770
Reported-by: @ctrlbreak-
Suggested-by: Rusty Russell <rusty@rustcorp.com.au>
Co-developed-by: @jsarenik
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-06 11:26:03 +09:30
Matt Morehouse 4f30857401 lightningd: close plugin dir on return
Memory leak detected by ASan:

==880002==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32816 byte(s) in 1 object(s) allocated from:
    #0 0x5039e7 in malloc (lightningd/lightningd+0x5039e7)
    #1 0x7f2e8c203884 in __alloc_dir (/lib64/libc.so.6+0xd2884)
2023-06-05 16:16:21 +02:00
Matt Morehouse e81bf8b89f devtools: call common_setup in main
Fixes nullability errors detected by UBSan:

wire/fromwire.c:173:46: runtime error: null pointer passed as argument 1, which is declared to never be null
external/libwally-core/src/secp256k1/include/secp256k1.h:432:3: note: nonnull attribute specified here
    #0 0x65214a in fromwire_secp256k1_ecdsa_signature wire/fromwire.c:173:6
    #1 0x659500 in printwire_secp256k1_ecdsa_signature devtools/print_wire.c:331:1
    #2 0x646ba2 in printwire_channel_update wire/peer_printgen.c:1900:7
    #3 0x637182 in printpeer_wire_message wire/peer_printgen.c:128:11
    #4 0x65a097 in main devtools/decodemsg.c:85:10
2023-06-05 16:16:21 +02:00
Matt Morehouse 3edb092bd8 plugins: initialize destination_reachable
Otherwise we later copy the uninitialized memory to descendants,
triggering undefined behavior:

plugins/libplugin-pay.c:2882:34: runtime error: load of value 190, which is not a valid value for type 'bool'
2023-06-05 16:16:21 +02:00
Matt Morehouse 45cb2b149c db: avoid calling memcpy on NULL
It is possible for db_column_bytes() to return 0 and for
db_column_blob() to return NULL even when db_column_is_null() returns
false. We need to short circuit in this case.

Detected by UBSan:

  db/bindings.c:479:12: runtime error: null pointer passed as argument 2, which is declared to never be null
  /usr/include/string.h:44:28: note: nonnull attribute specified here

  #0 0x95f117 in db_col_arr_ db/bindings.c:479:2
  #1 0x95ef85 in db_col_channel_type db/bindings.c:459:32
  #2 0x852c03 in wallet_stmt2channel wallet/wallet.c:1483:9
  #3 0x81f396 in wallet_channels_load_active wallet/wallet.c:1749:23
  #4 0x81f03d in wallet_init_channels wallet/wallet.c:1765:9
  #5 0x72f1f9 in load_channels_from_wallet lightningd/peer_control.c:2257:7
  #6 0x672856 in main lightningd/lightningd.c:1121:25
2023-06-05 16:16:21 +02:00
Matt Morehouse a5afb4f811 common: remove json_stream_log_suppress
The function is tiny and was only used in one location. And that one
location was leaking memory.

Detected by ASan:

==2637667==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 7 byte(s) in 1 object(s) allocated from:
    #0 0x4cd758 in __interceptor_strdup
    #1 0x64c70c in json_stream_log_suppress_for_cmd lightning/lightningd/jsonrpc.c:597:31
    #2 0x68a630 in json_getlog lightning/lightningd/log.c:974:2
    ...

SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).
2023-06-05 16:16:21 +02:00
Matt Morehouse c05d7e4f78 bitcoin: avoid adding to NULL
Detected by UBSan:

$ UBSAN_OPTIONS=print_stacktrace=1 ./wallet/test/run-psbt_fixup

bitcoin/psbt.c:733:2: runtime error: applying zero offset to null pointer
    #0 0x53c829 in psbt_from_bytes lightning/bitcoin/psbt.c:733:2
    #1 0x5adcb0 in main lightning/wallet/test/run-psbt_fixup.c:174:10

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior bitcoin/psbt.c:733:2
2023-06-05 16:16:21 +02:00
Shahana Farooqui 73b73483bf doc: making release document update 2023-06-05 14:54:32 +02:00
Rusty Russell 50a7681171 doc/Makefile: restore CI check for schema changes.
We now know the base reference, and we've rebased, so we can do a
simple diff.  Also, this means we can use a magic commit message
`No-schema-diff-check` to suppress false positives.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-05 09:25:57 +09:30
Rusty Russell e0d2c39565 CI: use rebasing instead of merge.
This reflects what we actually do when we apply the commit, and also
means we can easily iterate the commits.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-05 09:25:57 +09:30
Rusty Russell 3ac949d4c3 listconfigs: add `plugin` field if config is for a plugin.
I chose the full path name, not just the basename.

Suggested-by: @SimonVrouwe
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell 6275dd384c lightningd: deprecate listconfigs direct fields.
Changelog-Deprecated: JSON-RPC: `listconfigs` direct fields, use `configs` sub-object and `set`, `value_bool`, `value_str`, `value_int`, or `value_msat` fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell 8d02f33d28 reckless: use modern listconfigs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell ea928bfca1 pytest: use modern listconfigs.
Use the configs object, as the others are about to be deprecated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell 9cb2b2f13a listconfigs: show plugin options in 'configs' with normal options.
This integrates them with configvars properly: they almost "just work"
in listconfigs now, and we don't put them in a special sub-object
under their plugin.

Unfortunately, this means `listconfigs` now has a loose schema: any
plugin can add something to it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Plugins: reloaded plugins get passed any vars from configuration files.
Changelog-Deprecated: Config: boolean plugin options set to `1` or `0` (use `true` and `false` like non-plugin options).
2023-06-03 10:50:29 +09:30
Rusty Russell 1b252f349f config: replace accept-htlc-tlv-types with accept-htlc-tlv-type
We use multi-specifiable options elsewhere, this is just another.
Otherwise you can't add, you can only set them all.

Changelog-Added: Config: `accept-htlc-tlv-type` (replaces awkward-to-use `accept-htlc-tlv-types`)
Changelog-Deprecated: Config: `accept-htlc-tlv-types` (use `accept-htlc-tlv-type` multiple times)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell 0df97547dd lightningd: don't simply ignore defaults on flags, deprecate.
Changelog-Deprecated: Plugins: `default` no longer accepted on `flag` type parameters (it was silently ignored, so just don't set it).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell b9270c564a lightningd: listconfigs update, using configvars code.
listconfigs is convenient, but it doesn't handle multi-options well: it
outputs an object with duplicate fields in this case (e.g. log-file), nor
is it extensible to show more than raw values.

However, listconfigs doesn't do what other list commands do (use a
sub-object "configs") so we can put the new values under that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `listconfigs` now has `configs` subobject with more information about each config option.
2023-06-03 10:50:29 +09:30
Rusty Russell f1e994a095 lightningd: fix `listconfigs` `rpc-file-mode`
It literally contained \" to avoid it being interpreted as a literal;
now we have OPT_SHOWINT we no longer need this hack.

It's obscure, so I'm not bothering with a deprecation cycle.

Changelog-Fixed: JSON-RPC: `listconfigs` `rpc-file-mode` no longer has gratuitous quotes (e.g. "0600" not "\"0600\"").
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell 8281008b08 lightningd: annotate configuration settings which contain JSON literals.
We have hacky code to show some listconfigs values as literals; instead
explicitly encode the types.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell 86abb4c4bd lightningd: use OPT_EXITS for options which exit.
Clearly, listconfigs shouldn't list these.

Also, hoist the opt_hidden check since it's independent of whether
there's an arg or not.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell de148febb1 lightningd: make `--clear-plugins` override prior plugin configvars.
It's an obscure command, but this we won't see old plugin commands in
listconfigs (once it uses configvars).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell 5a0994c2d0 lightningd: allow --regtest.
Developers, rejoice (we already have --testnet, --signet and --mainnet!).

Changelog-Added: Config: `--regtest` option as alias for `--network=regtest`
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell edbaa944da lightningd: switch parsing to common/configvar
Now we wire in the code which gathers configvars and parses from there;
lightningd keeps the array of configuration variables for future use.

Note that lightning-cli also needs to read the config, but it has its
own options (including short ones!) and doesn't want to use this
configvar mechanism, so we have a different API for that now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30
Rusty Russell f54e4f3084 lightningd: explicitly mark developer-only options with OPT_DEV.
This is a nod towards moving to runtime-developer-mode, and also
quite clear; we currently have all these options prefixed with dev,
but this flags makes handling explicit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-06-03 10:50:29 +09:30