Commit Graph

14417 Commits

Author SHA1 Message Date
Christian Decker 9a50c7745c ci: Fetch tags while building so the binaries know
We weren't compiling with tags, causing the version command to just
return the git commit hash, rather than a valid version string.
2024-02-09 14:55:02 +01:00
Christian Decker 8375a7e9a5 fixup! pyln: Add a version parser to pyln-testing 2024-02-09 14:55:02 +01:00
Christian Decker ad34528b73 fixup! pyln: Override the PATH envvar to determine CLN binaries 2024-02-09 14:55:01 +01:00
Christian Decker b973121784 pyln: Override the PATH envvar to determine CLN binaries 2024-02-09 14:55:01 +01:00
Christian Decker d9f7067576 pyln: Make version a property and defer early_opts 2024-02-09 14:55:01 +01:00
Christian Decker b9b020384a pyln: Add a version parser to pyln-testing
We changed the way we configure CLN to run in developer mode, which
promptly broke anything that wasn't v23.11 and later. So we parse the
version, and make it comparable, so we can determine what to do on the
fly, and maintain a better backwards compatibility.

Changelog-Changed: pyln-testing: pyln-testing is now version-aware and can customize the run based on the version.
2024-02-09 14:55:00 +01:00
Christian Decker f73f94511d pyln: Apply `early_opts` just like `opts` in `TailableProc` 2024-02-09 14:55:00 +01:00
Christian Decker 91a703db67 pyln: Add a `system-postgres` DB provider
Spinning `postgres` up and down for the tests can be rather slow, and
forces us to switch user away from `root`. The forced switch away
from `root` is generally a good idea, but rather annoying in CI,
where the file permissions often just take on `root` as default.

The system-wide postgres requires extra config, the DB DSN, but allows
us to have either a remote DB, or a system-provided one, or another
container in `docker-compose`.

Changelog-Added pyln-testing: Added a `system-postgres` DB provider to run tests against a system-wide or even remote DB.
2024-02-09 14:54:59 +01:00
Christian Decker 1e023a171d msggen: Regenerate with correct protobuf version 2024-02-09 14:19:43 +01:00
Christian Decker 4c4c74fa32 msggen: Regenerate to include `offer` and `listoffers`
Changelog-None Unrelease, so no notes needed.
2024-02-09 12:20:45 +01:00
Christian Decker cfea45d827 make: Add missing dependency between schemas and schema bundle
Reported-by: microsatoshi
2024-02-09 12:20:45 +01:00
Erik De Smedt 3f4306eea9 `cln_plugin` : Test default values for ConfigOptions 2024-02-08 15:37:44 +01:00
Erik De Smedt a9797a4ff2 cln_plugin: Add documentation 2024-02-08 15:37:44 +01:00
Erik De Smedt 74d13bb334 cln_plugin: Request value as rust primitive
In the old version requesting the config-value of an option
was a little bit tricky.

Let's say we want to have a plugin which uses a default
port of 1234.

```rust
let value = plugin.option("plugin-port");
match value {
   Some(Value::Integer(_)) => {},
   Some(Value::String(_)) => {},  // Can never happen
   Some(Value::Boolean(_)) => {}, // Can never happen
   None => {},		          // Can never happen
}
```

Many users of the `cln_plugin` crate are overly cautious
and handle all these error scenario's. Which is completely unneeded.
Core Lightning will complain if you put a `String` where an `Integer` is
expected and will never send the value to the plug-in.

This change makes the API much more ergonomical and actually motivates
some of the changes in previous commits.

```
const MY_OPTION : ConfigOption<i64> = ConfigOption::new_i64_with_default(
	"plugin-port',
	1235,
	"Description");

let value : Result<i64> = plugin.option(MY_OPTION);
```

The result will provide a proper error-message.
It is also safe to `unwrap` the result because it will
only be triggered if the user neglected to provide the
option to the `Builder`.
2024-02-08 15:37:44 +01:00
Erik De Smedt 543e67495c Allow `ConfigOption` to be specified as const
This is the first part of two commits that attempts to simplify
the API that is used to retrieve configuration values.

Previously, we encouraged the following pattern to build a plugin.

```rust
let configured_plugin =
  Builder::new(
      tokio::io::stdin(),
      tokio::io::stdout())
  .option(ConfigOption::new_i64_with_default("some-option", 0, "Description"))
  .configure();

let value = configured_plugion.option("some-option");
match value {
  Some(Integer(i)) => {}, // Config provided
  None => {}, 		  // No config set
  _ => {}, 	          // This should never happened
}
```

This commit helps to move to the following pattern

```rust
const SOME_OPTION : ConfigOption<i64> = ConfigOption::new_i64_with_default(
                           "some-option",
			   "description");

async fn main() -> Result<()> {
    let plugin = Builder::new(tokio::io::stdin(), tokio::io::stdoout())
    	.option(SOME_OPTION)
	.configure()
	.await?;

    let value : i64 = plugin.option(SOME_OPTION)?;
}
```
2024-02-08 15:37:44 +01:00
Erik De Smedt 4ae18b2cfa cln_rpc: Refactor `ConfigOption` and `Value`
Breaking changes here.

This improves the semantics of `ConfigOption` and `options::Value`
drastically.

We've been using `options::Value` for 2 purposes
1. To specify the type and default value of an option
2. Coummunicate how a user configured an option

We fall here in the pit-fall of being poor at both purposes.
I've edited the code to ensure
- `options::Value` -> To read or specify the value of an option
- `option::ValueType` -> To specify the type of an option

**Configure an option**

Let's create an string-typed option create an option named `"required-string-opt"` the
developer has to use the following code.

```rust
let option = ConfigOption::new("required-string", Value::OptString, "description");
```

The semantics of `OptString` might falsely suggest that it is optional to specify the config.
However, we use `OptString` to say we are not providing a default-value.

After this commit we can use instead

```rust
let option = ConfigOption::new_str_no_default("required-string", "description");
```

For reading a configured value the `option::Value` is somewhat
cumbersome. The old version of had 6 different types of value

```rust
let value = plugin.option("required-string");
match value {
  String(s) => {}, 	// User has configured string value or default
  Integer(i) => {},	// User has configured int value or default
  Boolean(b) => {},	// User has configured bool value or default
  OptString => {},      // User has not configured value and no default
  OptInteger = {}, 	// User has not configured value and no default
  OptBOolean => {}, 	// User has not configured value and no default
}
```

This has been changed to

```rust
let value = plugin.option("required-string");
match value {
  Some(String(s)) => {},
  Some(Integer(i)) => {},
  Some(Boolean(b)) => {},
  None => {},
}
```
2024-02-08 15:37:44 +01:00
Erik De Smedt dcc406c557 cln_rpc: Store ConfigOptions in HashMap
We used to store all `ConfigOptions` in a `Vec`.
I decided to use a `HashMap` isntead because it will be easier to
implement dynamic options later on.
2024-02-08 15:37:44 +01:00
Christian Decker a87643f3bf ci: Install python build dependencies in alpine image 2024-02-08 15:05:18 +01:00
Dusty Daemon 2cbf426296 make: always generate proto files sans rust
Generating the msggen proto files doesn’t require rust (even though it generates rust files).

Changelog-None
2024-02-08 15:05:18 +01:00
Christian Decker 00fbd5977f msggen: Start making the `msggen` library a standalone tool
There are quite some things we want to generate from the schema
definitions, both inside and outside of CLN itself. By bundling the
schemas into the library we can make use of the tooling without
running in the CLN source tree. This is in part used to generate some
of the interfaces in Greenlight.

Changelog-None
2024-02-08 15:03:34 +01:00
Rusty Russell b5bd907245 wallet: ensure all established channels have aliases.
Commit dac8964093 set aliases for channels at
creation time, but neglected to convert channels in the database.  Do that now!

Fixes: #7039
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 14:15:57 +01:00
saisuraj27 34aaa9c7ba Fixed indentation errors. 2024-02-08 12:37:34 +01:00
saisuraj27 a35006e701 Fixed raising TypeError instead of ValueError when there is an invalid type. 2024-02-08 12:37:34 +01:00
Rusty Russell a005ec1e84 pytest: fix flake in test_htlc_in_timeout with anchors.
If we try to reuse the same UTXO for the HTLC as the anchor, it will clash.
One block later we can spend the anchor change, all good.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 06:32:01 +10:30
Rusty Russell bbf6a89579 pytest: fix bad gossip flake in test_closing_specified_destination.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 06:32:01 +10:30
Rusty Russell 689e596036 options: make anchors enabled by default, ignore experimental-anchors.
We still want to test non-anchor channels, as we still support them, but
we've made it non-experimental.  To test non-anchor channels, we
use dev-force-features: -23.

Changelog-Added: Protocol: `option_anchors_zero_fee_htlc_tx` enabled, no longer experimental.
Changelog-Changed: Config: `experimental-anchors` now does nothing (it's enabled by default).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


Header from folded patch 'fixup!_options__make_anchors_enabled_by_default,_ignore_experimental-anchors.patch':

fixup! options: make anchors enabled by default, ignore experimental-anchors.
2024-02-08 06:32:01 +10:30
Rusty Russell 0a2f03ac1e pytest: changed tests if we're using experimental-anchors.
This is in anticipation of changing the defaults for non-elements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 06:32:01 +10:30
Rusty Russell 149be88b6e lightningd: allow dev-force-features to unset even if not set.
This simplifies our tests which will want to turn off anchors,
even though they won't be set for elements.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 06:32:01 +10:30
Rusty Russell 8c52efce37 funder: don't try to spend emergency_reserve
We might have (or be getting!) anchor channels, so keep this aside when funding.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 06:32:01 +10:30
Rusty Russell e4d3cc8b04 wallet: be a little more flexible with change for emergency reserve.
We used to look for either other outputs which are sufficient for
reserve, *or* be able to create sufficient change to meet the
emergency reserve.  Allow the sum of both to meet the requirements:
otherwise test_funder_contribution_limits can flake.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 06:32:01 +10:30
Rusty Russell 162a0abef4 lightningd: correctly handle case where we have no fee estimates opening anchor channel.
We tried to open a channel with feerate 0 in this case!  Rework so it's
clear that we have two different feerates here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-08 06:32:01 +10:30
Christian Decker 99aa1e827e msggen: Fix the `offer` schemas
I had to do some trickery with the interchangeability between string
and int, but now it works as expected.
2024-02-07 20:38:29 +01:00
Christian Decker 09d32ecff5 doc: Fix schema for `offer.amount`, it can be a non-BTC unit too
The `amount` field is intended to be either a native unit (`msat`,
`sat` or `btc`) or it can also be a non-native unit that needs to be
converted into native when creating the invoice. As such limiting the
`amount` to only be native is very restrictive.
2024-02-07 20:38:29 +01:00
vacwmX 317cf4d430 feat: added listoffers grpc command 2024-02-07 20:38:29 +01:00
vacwmX d1052e3924 doc: adding schema to create offer requests 2024-02-07 20:38:29 +01:00
vacwmX 5eacb5b22e feat: adding offer command to pyln-testing and msggen 2024-02-07 20:38:29 +01:00
vacwmX 68bb1ff586 feat: grpc - adding support for `Offer` command 2024-02-07 20:38:29 +01:00
vacwmX 3ae3243517 fix: fixing start_any_period type for offer recurrence 2024-02-07 20:38:29 +01:00
Alex Myers 61e1e0c89c doc: update reckless documentation 2024-02-07 13:24:34 +01:00
Alex Myers 140e33b13a pytest: add tests for pip and poetry installed virtual envs
Also test checkout of a git tag on installation.
2024-02-07 13:24:34 +01:00
Alex Myers 3879d7b9bd reckless: update timeouts 2024-02-07 13:24:34 +01:00
Alex Myers 90a20ff6e3 reckless: create virtual environments for python plugins
This uses pip to install to a venv when the dependencies are specified
with requirements.txt and poetry when it's present on the system and the
plugin has a pyproject.toml.

The directory structure will be:
reckless/
    source/                (original plugin code here)
        plugin_entrypoint  (original entrypoint)
    plugin_name            (symlink or wrapper to activate venv)
    .metadata              (installation information)
    .venv/                 (python virtual environment)

The wrapper matches the naming of the original plugin entrypoint. The
shebang is modified to use the virtual environment's python binary,
then the original plugin is imported as a module and executed as though
it was run directly.

Changelog-Changed: reckless installs python plugins in virtual environments
2024-02-07 13:24:34 +01:00
Alex Myers 03e78ce6d9 reckless: add option to check out a specific commit
... using the syntax reckless install <plugin_name>@<commit hash>
2024-02-07 13:24:34 +01:00
Alex Myers d5ed7b7b5c reckless: add installation metadata
The metadata includes an original retrieval source, timestamp, and commit
hash.  This will allow a future update command to more easily evaluate the
status of the existing installation.
2024-02-07 13:24:34 +01:00
Alex Myers 2b502ebcbc reckless: add staging directory and symlink
This creates a separate staging directory from the one used to clone
the source.  A symlink is then added to the plugin's entrypoint which is
now in the source directory.
2024-02-07 13:24:34 +01:00
Alex Myers c043bf2255 reckless: properly remove entry from reckless sources
Fixes a bug introduced in 6163138420 which
avoided gratuitous rewrites of the lightningd config
2024-02-07 13:24:34 +01:00
Graham Krizek f5ddb89d83 Add a method to the pyln-client for using the sendcustommsg api 2024-02-07 13:17:30 +01:00
Rusty Russell f56b9e9b73 lightningd: deprecate @-prefix hack for offer recurrence_base.
Christian points out that this makes the type harder, and it's just awkward.

Changelog-EXPERIMENTAL: JSON-RPC: Deprecated `offer` parameter `recurrence_base` with `@` prefix: use `recurrence_start_any_period`.
Changelog-EXPERIMENTAL: JSON-RPC: Added `offer` parameter `recurrence_start_any_period`.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-07 09:21:00 +10:30
Rusty Russell 1d0a0f6600 common: don't insist on unique param() arguments.
It can actually be useful for more complex parameter parsing, as we're about to see.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-02-07 09:21:00 +10:30
Sergi Delgado Segura 23bd03c62b cln-grpc: Patches rpc-file path
`cln-gprc` is assuming the `rpc-file` path is set as default, which may not always
be the case. Set the path the what the plugin manager reports
2024-02-06 14:19:39 +01:00