Commit Graph

1356 Commits

Author SHA1 Message Date
Lagrang3 c9c03dedb7 remove amount_accumulate and amount_reduce
These two functions would make 'pay_flow' dependent on 'pay'
which is not cool, 'pay_flow' should be lower level.
2024-01-22 15:10:08 +10:30
Lagrang3 c4cbc10cfa remove flow dependency on payment 2024-01-22 15:10:08 +10:30
Christian Decker 451a1465ed rs: Temporarily remove a test that is failing due to log changes 2024-01-17 20:55:03 +01:00
Christian Decker 60e1532dd8 cln-plugin: Switch from `env_logger` to `tracing-subscriber`
This switches the logging implementation from using the `log`-facade
to using the `tracing-subscriber` instead. This allows us to also tap
into the tracing instrumentation if desired, which was not possible
with `log`.

Changelog-Changed cln-plugin: The logging adapter now uses tracing-subscriber allowing the `tracing` ecosystem to be used. No format changes.
2024-01-16 18:36:12 +01:00
Erik De Smedt 0d877ffb71 cln-plugin: Allow setting `usage` of RPC-method
The `cln-plugin` can be used to create a plugin that registers
additional rpc-methods. However, it doesn't allow to specify the `usage`
of the command.

This change makes it possible to specify the `usage`. It should not
contain any breaking changes.

I've opted to add a new method called `rpcmethod_from_builder` to the
`Builder` struct. This approach allows us to add new parameters in the
future.
2024-01-16 16:55:06 +01:00
Erik De Smedt 0da26933ac `cln_plugin` : Add basic test to `cln_plugin` 2024-01-15 15:32:16 +01:00
Christian Decker 05105d404c rs: Bump versions of `cln-plugin` and `cln-rpc` 2023-12-15 10:01:57 +10:30
Christian Decker c8fd911e79 grpc: Add metadata to Cargo.toml 2023-12-15 10:01:57 +10:30
Rusty Russell 36b631699b plugins: re-enable listchannels local info in deprecated mode.
We only deprecated this, we didn't actually remove it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell c8e30de513 topology: deprecate overriding `active` in `listchannels` with `listpeerchannels` info.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: `listchannels` no longer uses local knowledge to set `active` to false if disconnected.
2023-12-14 09:16:56 +10:30
Rusty Russell 4b92c773df common: gossmap now always ignores private gossip_store messages.
In the next PR, they'll be removed, but for now all our code doesn't
want them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell 58a1c4c012 topology: don't show private nodes in listchannels.
This alters a few remaining tests, as well.

[ Inclused even more test fixes from Alex Myers <alex@endothermic.dev>! ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: JSON-RPC: `listchannels` listing private channels: use listpeerchannels
2023-12-14 09:16:56 +10:30
Rusty Russell ea0d00e677 topology: don't show private nodes in listnodes.
This breaks our tests a bit, which assumed we can always see ourselves
even if we don't have a proper channel.

Usually we would deprecate this first, but it's unlikely to break
anyone since it's a bit obscure that this worked at all.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: JSON-RPC: `listnodes` no longer shows private (peer) nodes: use listpeers
2023-12-14 09:16:56 +10:30
Rusty Russell 6ee59629f9 lightningd: make listincoming use gossmods_from_listpeerchannels().
We temporarily use a second gossmap so we can just switch private info off
for listincoming and not listchannels.

Note that listchannels now uses the local alias (if no scid), so we have
to change that in the routehint caller.

Since we now *always* use a channel alias in hints if one exists, a
test broke, so fix that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell bac02b462b plugins/renepay: use gossmods_from_listpeerchannels instead of private gossip_store records.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell c8eb46fe30 plugins/renepay: add localmods later.
We will get localmods from gossmods_from_listpeerchannels in the next commit,
so we need to save routehints to add to that later.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell 8738d78c86 plugins/pay: use gossmods_from_listpeerchannels instead of private gossip_store records.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell 3fdae99524 libplugin-pay: make sure get_gossmap calls are balanced by put_gossmap.
This will become important when we apply localmods to the gossmap at these points.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell a5c0563612 plugins/fetchinvoice: use gossmods_from_listpeerchannels instead of private gossip_store records.
[ Includes use-after-free fix from Alex Myers <alex@endothermic.dev> ]

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell 5256690c6f plugins/topology: temporary hack to allow per-access private gossmap suppression.
We have multiple different routines here, and we want to wean them off private
gossip one at a time.  This converts `getroute`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell cdaad1bf2a common: generic routine to turn listpeerchannels into gossmap local updates.
This is more thorough than the minimal one required for getroute(), including the feerates
and cltv deltas.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Alex Myers 8e897746e2 gossipd: pass remote private channel update to ld
and stash in the database.

Rusty: I added the bad gossip message so we would see unknown updates in CI, and made sure we don't send our own generated updates to lightningd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell 674684369f common: prepare unit tests for lack of private channels.
Created a new canned gossmap without private channels, updated tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Rusty Russell a12e41a930 compiler: fix for -O3 errors.
CI revealed one:

```
cc plugins/libplugin-pay.c
plugins/libplugin-pay.c: In function ‘payment_getroute’:
plugins/libplugin-pay.c:888:17: error: ‘errstr’ may be used uninitialized [-Werror=maybe-uninitialized]
  888 |                 payment_fail(p, "%s", errstr);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plugins/libplugin-pay.c:851:21: note: ‘errstr’ was declared here
  851 |         const char *errstr;
      |                     ^~~~~~
cc1: all warnings being treated as errors
```

My local compiler gave another:

```
channeld/channeld.c: In function ‘resume_splice_negotiation’:
channeld/channeld.c:3734:23: error: ‘final_tx’ may be used uninitialized [-Werror=maybe-uninitialized]
 3734 |                 msg = towire_channeld_splice_confirmed_signed(tmpctx, final_tx,
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3735 |                                                               chan_output_index);
      |                                                               ~~~~~~~~~~~~~~~~~~
channeld/channeld.c:3461:28: note: ‘final_tx’ was declared here
 3461 |         struct bitcoin_tx *final_tx;
      |                            ^~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:298: channeld/channeld.o] Error 1
```

So fix both.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-12-14 09:16:56 +10:30
Erik De Smedt a48e2258c7 Implement `is_some` for `cln_rpc::options::Value`
Can be used to check if a configuration is set
2023-12-12 17:17:10 +01:00
Peter Neuroth eb3b1b8134 clnrest: Import sys in except clause explicitly
This fixes a crash on startup of core-lightning where gevent could not
be imported. This happens before sys is imported and throws us into the
except clause which calls sys.
By importing it explicitly in the except clause we are not dependend of
the order of imports in the try bracket.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>

Changelog-Fixes: Plugin: clnrest crashed on startup when gevent was
missing.
2023-11-21 08:24:09 +01:00
Peter Neuroth 8f8202daa7 meta: Update release checklist
Add a version bump for clnrest and the main poetry.lock to the makefile
and update the release checklist to include the new target.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2023-11-16 15:20:33 +01:00
ShahanaFarooqui cc2665da7f clnrest: prefixing all rest config options with `cln`
This will allow users to use clnrest with c-lightning-REST without conflicts.
It was required for applications to have enough time for migrating from c-lightning-REST to clnrest.

Changelog-Changed:
config option `rest-certs` changed to `clnrest-certs`
config option `rest-protocol` changed to `clnrest-protocol`
config option `rest-host` changed to `clnrest-host`
config option `rest-port` changed to `clnrest-port`
config option `rest-cors-origins` changed to `clnrest-cors-origins`
config option `rest-csp` changed to `clnrest-csp`
2023-11-16 11:21:04 +01:00
ShahanaFarooqui 9e9c3dbc00 clnrest: add gevent ssl monkey patch to remove warning log 2023-11-16 09:07:07 +01:00
Rusty Russell 8b84c8945b clnrest: don't convert *_msat fields to strings.
We have a global JSON encoder hack, which means that any field ending in msat gets special treatment (so we can safely talk to lightningd, even if a field expects satoshi amounts, we are explicit).  However, requests uses the JSON parser and DOES NOT want this conversion when sending it out as an HTTP response!

The simplest local fix we could find was Shahana's suggestion to iterate and covert away from Millisatoshi(): the reverse of what our JSON encoder does.

Fixes: https://github.com/ElementsProject/lightning/issues/6848
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-11-16 09:07:07 +01:00
Rusty Russell f2f6c73977 clnrest: don't try to handle plugin.rpc.call results.
It already throws an exception or error, or decodes the JSON response:
we can simply pass it through.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-11-16 09:07:07 +01:00
Peter Neuroth 02ca226f88 CHANGELOG.md: Update for 23.11rc1
Update changelog, pyln versions, clnrest version and poetry.lock.

Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
2023-11-03 14:49:12 +01:00
niftynei 48bb2d831b dual-fund: don't re-notify plugin on arrival of sigs (2nd time)
When we got our peer's sigs, if we were the remote, we would re-notify
the plugin, which in turn would re-send the tx-sigs to use.

In the case of CLN, we'd then
- break, because we'd re-forward the sigs to the `openchannel` plugin,
  which was then in the wrong state (MULTIFUNDCHANNEL_SIGNED)

    spenderp: plugins/spender/openchannel.c:598: json_peer_sigs: Assertion `dest->state == MULTIFUNDCHANNEL_SECURED' failed.
    spenderp: FATAL SIGNAL 6 (version 5880d59-modded)

In the case of eclair, they'd just see our 2nd TX_SIGS message and
@t-bast would complain:

	> This test works, with one minor issue: on reconnection, cln sends its tx_signatures twice (duplicate?).

This commit does two things:
	- has the openchannel / spender plugin log a broken instead of
	  crashing when the state is not what we're expecting
	- stops us from calling the `funder` plugin if this is a
	  replay/second receipt of commit-sigs.
2023-11-02 19:32:05 +10:30
niftynei 4e63d36e08 mfc, nit: print out the error reason when an open fails
Makes it easier to see why things are failing in the logs.
2023-11-02 19:32:05 +10:30
Tony Aldon baa9a96eb1 clnrest: code refactoring for:
- certificate generation
- config options validation
- log level from 'error' to 'info'
- sending method as None instead ""
- added `listclnrest-notifications` for websocket server rune method

Changelog-Fixed: websocket server notifications are available with
restriction of `readonly` runes
2023-10-31 10:21:22 -07:00
Chris Guida 4f667e8a62 cln-plugin: don't require redundant method reference
also eliminate a rust warning
2023-10-30 18:24:23 +01:00
Chris Guida c6262189b7 cln-plugin: Add test for cln-plugin send_custom_notification
Also fix Makefile for rust plugin examples

Also add in a missing assert in the test_plugin_start test
2023-10-30 18:24:23 +01:00
Chris Guida 80ba3a573d cln-plugin: implement registering and sending custom notifications to lightningd
This functionality already exists in the Python framework; this feature
enables it for Rust plugins as well.

Changelog-Added: cln-plugin: Implement send_custom_notification to allow sending custom notifications to other plugins.
2023-10-30 18:24:23 +01:00
Aditya Sharma d130982aad plugins/offers: Extend the capability of decode to decrypt the contents of emergency.recover file.
Changelog-Added: JSON-RPC: `decode` can now decide emergency.recover files (clnemerg1...)
2023-10-27 16:05:28 +10:30
Christian Decker 1621c6216f rs: Fix the manifests for publication 2023-10-26 15:51:07 +02:00
Christian Decker ee8fe11fbd cln-plugin: Make logging optional
Under some circumstances we may want to not log to `lightningd`
directly, but rather configure the logging ourselves. This is useful
for example if we want to use `tracing` and `tracing-subscriber` to
add custom handling, or add opentelemetry span tracing.

Changelog-Changed: cln-plugin: Suppress internal logging handler via `with_logging(false)`
2023-10-26 12:26:01 +02:00
niftynei 411bb2884a fallback: json add fallback cleanup
Expand to handle P2TR addresses, use the common script encoding utility
function instead of reimplementing it.
2023-10-26 19:11:17 +10:30
Christian Decker 535d3d953d rs: Bump crates cln-rpc and cln-grpc to 0.1.5 and cln-plugin to 0.1.6 2023-10-24 10:24:52 +10:30
Rusty Russell c0782ee841 clnrest: correctly omit `method` to checkrune call if none is supplied.
Specifying the empty string is very different from not specifying it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-17 14:58:40 +10:30
Tony Aldon 7bea339f2f cln-grpc: do not generate cerficates when no autostart.
Changelog-None
2023-10-13 10:25:36 +02:00
Rusty Russell 7d3f13ec0d renepay: work around change in fundchannel in tests.
The tests will wait until it's locally enabled, but it might not have
the update in the gossip store.  So have renepay enhance its local
view even if it already knows about the channel (this is correct
anyway, it just isn't very important usually).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-04 08:02:33 +10:30
Rusty Russell bb60c77859 plugins/topology: convert listpeerchannels into local overlay.
This prepares us for when the gossmap doesn't contain private channel info.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-04 08:02:33 +10:30
Rusty Russell 8c0932e46a plugins/topology: split getroute logic.
Mechanical change to bundle into struct getroute_info for next
patch which uses callback.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-04 08:02:33 +10:30
Rusty Russell ddb16991ee plugins/topology: remove unused fuzz factor.
This breaks Dijkstra, which is presumably why it was actually
disabled.  Remove the code altoghether, instead.

Changelog-Fixed: JSON-RPC: `getroute` now documents that it ignores `fuzzpercent`.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-04 08:02:33 +10:30
Rusty Russell e11b35cb3a common/memleak: implement callback arg for dump_memleak.
This makes it easier to use outside simple subds, and now lightningd can
simply dump to log rather than returning JSON.

JSON formatting was a lot of work, and we only did it for lightningd, not for
subdaemons.  Easier to use the logs in all cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-03 10:05:55 +02:00
ShahanaFarooqui 77e3c3a38e plugin/clnrest: Adjusting flask-cors install after rebase 2023-09-29 16:00:05 +09:30
ShahanaFarooqui e010eece1b plugins/clnrest: Updated clnrest's requirements.txt
Even after migrating from pip install to poetry install for clnrest,
we still need to keep `plugins/clnrest/requirements.txt` for Fedora-28-amd64
build. `Dockerfile.builder.fedora` does not have poetry and will need
requirements.txt to install libraries with pip.

It is also required for non-developers who want to build cln from a tagged or master version.
2023-09-29 16:00:05 +09:30
ShahanaFarooqui 6a756256c0 plugins/clnrest: Adding pyproject.toml for Poetry install
Reference links:
https://github.com/ElementsProject/lightning/issues/6637
https://github.com/nix-community/poetry2nix

Changelog-Changed: Upgraded clnrest to poetry project.
2023-09-29 16:00:05 +09:30
Rusty Russell 577161a4fa renepay: remove custom debug, in favor of normal operations.
As a bonus, unit tests no longer leave files in /tmp.

Reported-by: https://github.com/whitslack
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-25 13:59:13 +09:30
Rusty Russell 2bcae6fc76 plugins/renepay: remove DEVELOPER build-time, in favor of runtime.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 20:08:24 +09:30
Rusty Russell f725edad62 plugins: remove #if DEVELOPER.
And rename dev-only-option `use_shadow` to `dev_use_shadow`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 20:08:24 +09:30
Rusty Russell ef87999f9a common: add option for dev-only parameters.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 20:08:24 +09:30
Rusty Russell 1ecf31bae7 db: remove #if DEVELOPER in favor of runtime flag inside db struct.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 20:08:24 +09:30
Rusty Russell a9f26b7d07 common/daemon.c: remove #ifdef DEVELOPER in favor of runtime flag.
Also requires us to expose memleak when !DEVELOPER, however we only
ever used the memleak tracking when the LIGHTNINGD_DEV_MEMLEAK
environment variable was set, so keep that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 20:08:24 +09:30
Rusty Russell c8c6dd183d common/bolt12: roll all necessary checks into offer_decode.
Some of these were done by fetchinvoice (and it did some that
offer_decode already did).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-21 13:31:03 +09:30
ShahanaFarooqui 3108ff93b8 plugins/clnrest: Update content security policy for server 2023-09-19 11:40:15 +09:30
ShahanaFarooqui 51578e1f77 plugins/clnrest: Add `rest-csp` option for config 2023-09-19 11:40:15 +09:30
ShahanaFarooqui eca3a33e69 plugins/clnrest: Update Websocket server to dynamically add CORS settings
Changelog-Added: New configurable Cross-Origin-Resource-Sharing(CSP) header for clnrest
2023-09-19 11:40:15 +09:30
ShahanaFarooqui b0430cc897 plugins/clnrest: Update App server to dynamically add CORS settings 2023-09-19 11:40:15 +09:30
ShahanaFarooqui 632e7abd05 plugins/clnrest: Add `rest-cors-origins` option for config 2023-09-19 11:40:15 +09:30
ShahanaFarooqui 224a5dcbcf plugins/clnrest: Add CORS library 2023-09-19 11:40:15 +09:30
ShahanaFarooqui 6aa697ea3d plugins/clnrest: Rune authentication for websocket server 2023-09-19 11:40:15 +09:30
ShahanaFarooqui 9147996372 plugins/clnrest: Generate all three certs if missing
Generate client, server and CA certs for https and trusted CA update
2023-09-19 11:40:15 +09:30
ShahanaFarooqui 761172001b plugin/clnrest: Deleting redundant README.md 2023-09-12 16:10:15 +09:30
Rusty Russell a4644550a2 clnrest: don't require nodeid (FIXME: needs screenshot updates!)
This was a misunderstanding: nodeid is useful for commando, where it's the
peer's nodeid, and Noise-XK guarantees that we know who that is.  It's
not useful for clnrest, so don't require it (it was our node id, which
is redundant).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-09-12 15:19:02 +09:30
ShahanaFarooqui e788f76f99 plugin/clnrest: do not read json payload if data length is zero
OpenAPI readme always includes `content-type: application/json` header, even when body parameters are empty.
But the server expects data if the content-type has been sent.
This results in a "Server Error" response for non-param requests from readme doc.
This only affects readme requests as it is designed to send the header by default.

Changelog-None
2023-08-31 16:13:35 +09:30
Rusty Russell f4f4ab34f3 renepay: fix case where shadow increases amount past payment amount.
Without this, sendpay will refuse to pay.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 16:13:21 +09:30
Rusty Russell 3285aa0eea renepay: fix shadow route extension logic.
pseudorand(1) is always 0, and capacity test was the wrong way.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 16:13:21 +09:30
Rusty Russell 7a92eb2d89 renepay: calculate fee and delay accumulation correctly.
1. When we add a shadow amount, we were using the wrong channel for
   the fee calculation.
2. Similarly, when calculating the delay amount.

The result is that we can get WIRE_INCORRECT_CLTV_EXPIRY repeatedly
from nodes.

Reported-by: https://github.com/Sjors
Fixes: #6620
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changlog-Experimental: Fixed: `renepay` handles ctlv correctly when it varies along a path.
2023-08-31 16:13:21 +09:30
Rusty Russell 14e28a51ce renepay: don't crash if we get failure from sendpay.
This happened while I was hacking (it shouldn't normally!): cmd here is NULL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-31 16:13:21 +09:30
Christian Decker 8e2e7b1c51 rs: Bump crate versions before publishing
Changelog-None
2023-08-28 11:19:30 +02:00
Dusty Daemon 8d5be61fcb clnrest: Change process method to fork
On mac the clnrest plugin hangs on log messages, causing it to never run.

This guide suggests switching to fork’ing instead of spwan’ing
https://superfastpython.com/multiprocessing-common-errors/#Error_2_print_Does_Not_Work_In_Child_Processes

Switching to fork fixes the hang on Mac.

Changelog-None
2023-08-24 19:36:42 +09:30
Rusty Russell 7cd4359521 renepay: hack in workaround spendable reduction for release.
```
Flow 391: amount=23528000msat prob=0.000 fees=1023msat delay=140 path=-2471854x37x4/1(min=max=23528783msat)->-2414928x98x0/0->
Flow 391: Failure of 23529023msat for 2471854x37x4/1 capacity [23528783msat,23528783msat] -> [23528783msat,23528783msat]
```

We added fees and went over capacity!  This screams of a deeper logic
bug, but renepay is experimental and it's release day so hack around
it for now...

Reported-by: https://github.com/daywalker90
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 13:22:27 +09:30
Rusty Russell a984202576 plugins/renepay: don't drop min to 0 if it's shown wrong, but drop 50%.
Eduardo is on holiday right now, but he pinged me asking for this.  It
makes some sense, and using half the *failed value* covers the case where
it's less than half what we expected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell 32f5ae8d1f renepay: remove remaining calls to debug_paynote in favor of payflow_note().
Some are redundant, others simply convert.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell 574716dfd5 plugins/renepay: convenience routing to log when we disable a chan.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell 00e9af57f5 plugins/renepay: neaten the command notifications.
It now looks like (for test_hardmpp):

```
# we have computed a set of 1 flows with probability 0.328, fees 0msat and delay 23
#   Flow 1: amount=1800000000msat prob=0.328 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0->-103x3x0/1->
#   Flow 1: Failed at node #1 (WIRE_TEMPORARY_CHANNEL_FAILURE): failed: WIRE_TEMPORARY_CHANNEL_FAILURE (reply from remote)
#   Flow 1: Failure of 1800000000msat for 103x5x0/0 capacity [0msat,3000000000msat] -> [0msat,1799999999msat]
# we have computed a set of 2 flows with probability 0.115, fees 0msat and delay 23
#   Flow 2: amount=500000000msat prob=0.475 fees=0msat delay=12 path=-103x6x0/0(min=max=4294967295msat)->-103x1x0/1->-103x4x0/1->
#   Flow 3: amount=1300000000msat prob=0.242 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0(max=1799999999msat)->-103x3x0/1->
#   Flow 3: Failed at node #1 (WIRE_TEMPORARY_CHANNEL_FAILURE): failed: WIRE_TEMPORARY_CHANNEL_FAILURE (reply from remote)
#   Flow 3: Failure of 1300000000msat for 103x5x0/0 capacity [0msat,1799999999msat] -> [0msat,1299999999msat]
# we have computed a set of 2 flows with probability 0.084, fees 0msat and delay 23
#   Flow 4: amount=260000000msat prob=0.467 fees=0msat delay=12 path=-103x6x0/0(500000000msat in 1 htlcs,min=max=4294967295msat)->-103x1x0/1(500000000msat in 1 htlcs)->-103x4x0/1(500000000msat in 1 htlcs)->
#   Flow 5: amount=1040000000msat prob=0.179 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0(max=1299999999msat)->-103x3x0/1->
#   Flow 5: Failed at node #1 (WIRE_TEMPORARY_CHANNEL_FAILURE): failed: WIRE_TEMPORARY_CHANNEL_FAILURE (reply from remote)
#   Flow 5: Failure of 1040000000msat for 103x5x0/0 capacity [0msat,1299999999msat] -> [0msat,1039999999msat]
# we have computed a set of 2 flows with probability 0.052, fees 0msat and delay 23
#   Flow 6: amount=120000000msat prob=0.494 fees=0msat delay=12 path=-103x6x0/0(760000000msat in 2 htlcs,min=max=4294967295msat)->-103x1x0/1(760000000msat in 2 htlcs)->-103x4x0/1(760000000msat in 2 htlcs)->
#   Flow 7: amount=920000000msat prob=0.105 fees=0msat delay=12 path=-103x2x0/1(min=max=4294967295msat)->-103x5x0/0(max=1039999999msat)->-103x3x0/1->
#   Flow 7: Success
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell 7db6aaa523 renepay: clarify chan_extra_can_send.
I am doing to add more more debugging, but sent here is 0.
Document that clearly, and put a real value in sent.

Also: since we already sub 1 msat from x, amount_msat_less_eq should
be amount_msat_less (it may be equal to our min, in theory).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell 7287ade705 plugins/renepay: use struct short_channel_id_dir.
No changes, just use this convenience type for handing
around, and arrays.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell a6c2cd77a1 plugins/renepay: clean up unused fmt_payflows.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell eef57488f9 pay_flow: downgrade messages about shadow route delays.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell 4196f97571 plugins/renepay: Add infra for per-flow notes.
And set logging levels.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-23 10:47:28 +09:30
Rusty Russell 763ec6ad43 plugins/renepay: don't free waiting-for-addgossip flow!
```
Aug 18 13:45:13  lightningd: 0x7fa921f8ffcf ???
Aug 18 13:45:13  lightningd:         ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
Aug 18 13:45:13  lightningd: 0x55b3bb54e6d3 pay_flow_finished_adding_gossip
Aug 18 13:45:13  lightningd:         plugins/renepay/pay_flow.c:675
Aug 18 13:45:13  lightningd: 0x55b3bb54af25 addgossip_done
Aug 18 13:45:13  lightningd:         plugins/renepay/pay.c:171
```

The assert we fail is almost certainly due to the flow being freed:

```
struct pf_result *pay_flow_finished_adding_gossip(struct pay_flow *pf)
{
	assert(pf->state == PAY_FLOW_FAILED_GOSSIP_PENDING);
```

Reported-by: https://github.com/daywalker90
Fixes: #6567
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-21 21:13:48 +09:30
Vincenzo Palazzo d2e39f7af8 meta: ignore renepay binary
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-08-21 10:35:41 +09:30
Rusty Russell 685c413b61 renepay: reduce minimum "known" if it proves incorrect.
There's a fascinating bug report which suggests this happens on local channels,
implying spendable_msat is wrong?

See-also: #6567
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 20:29:55 +09:30
Rusty Russell b5d1708900 plugins/sql: make testing-only sqlfilename option `dev-sqlfilename`.
dev options don't need to be documented, and this is only for debugging
the plugin itself.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 20:29:34 +09:30
Rusty Russell bcea0a9580 listchannels: also list splicing channels as active: true.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 17:09:54 +09:30
Rusty Russell 0147b3ba94 pay: don't filter out local channels which are splicing.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 17:09:54 +09:30
Rusty Russell 71a09138b6 renepay: splicing channels are also usable for payments.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-18 17:09:54 +09:30
Rusty Russell d3c7d48acb pay: don't discard high-htlc_min channels when searching for routehint starts.
As side-effect, getroute(0) is special too.

Reported-by: MiddleW4y in Discord
Fixes: #6577
Changelog-Fixed: `pay` will still use an invoice routehint if path to it doesn't take 1-msat payments.
2023-08-18 14:55:32 +09:30
Rusty Russell af6b535efd pay: still use channels for routehints even if peer says it's disabled.
We have a report that LND said our (unannounced) channel was disabled, so we didn't
use it for routehints.  We're better off ignoring that in this case (if the peer is
actually not connected, the routehint code will check that and ignore anyway).

Fixes: #6555
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: pay: use channels in routehints even if peer says they're "disabled" (LND compat)
2023-08-15 06:22:53 +09:30
Rusty Russell 8dc8416ed7 plugins/renepay: fix gcc-12.3.0 -O3 warning.
Compiler can't tell that we always set have_state[PAY_FLOW_FAILED_FINAL]
when we set this:

```
plugins/renepay/payment.c: In function ‘payment_reconsider’:
plugins/renepay/payment.c:287:25: error: ‘final_error’ may be used uninitialized [-Werror=maybe-uninitialized]
  287 |                         payment_fail(payment, final_error, "%s", final_msg);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plugins/renepay/payment.c:194:30: note: ‘final_error’ was declared here
  194 |         enum jsonrpc_errcode final_error, ecode;
      |                              ^~~~~~~~~~~
plugins/renepay/payment.c:287:25: error: ‘final_msg’ may be used uninitialized [-Werror=maybe-uninitialized]
  287 |                         payment_fail(payment, final_error, "%s", final_msg);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plugins/renepay/payment.c:195:21: note: ‘final_msg’ was declared here
  195 |         const char *final_msg;
      |                     ^~~~~~~~~
```
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-15 06:21:23 +09:30
Rusty Russell aac8905afd plugins/renepay/test: fix access-after-free.
We cannot carry pointers into the gossmap across localmod addition
or removal.

We didn't notice because the map->chan_arr is not normally resized,
but if we change gossmap.c line 689 to only allocate 1 to start, we see this:

```
VALGRIND=1 valgrind -q --error-exitcode=7 --track-origins=yes --leak-check=full --show-reachable=yes --errors-for-leak-kinds=all plugins/renepay/test/run-mcf > /dev/null
==2349744== Invalid read of size 4
==2349744==    at 0x1788C2: gossmap_chan_scid (gossmap.c:558)
==2349744==    by 0x1872A2: get_chan_extra_half_by_chan (flow.c:346)
==2349744==    by 0x187797: remove_completed_flow (flow.c:488)
==2349744==    by 0x187927: remove_completed_flow_set (flow.c:518)
==2349744==    by 0x18DF4D: main (run-mcf.c:393)
==2349744==  Address 0x4b80f38 is 88 bytes inside a block of size 136 free'd
==2349744==    at 0x4848C63: realloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==2349744==    by 0x173D71: tal_resize_ (tal.c:744)
==2349744==    by 0x177E36: next_free_chan (gossmap.c:336)
==2349744==    by 0x177ED3: new_channel (gossmap.c:351)
==2349744==    by 0x178441: add_channel (gossmap.c:458)
==2349744==    by 0x1798D4: gossmap_apply_localmods (gossmap.c:904)
==2349744==    by 0x18DEDB: main (run-mcf.c:388)
==2349744==  Block was alloc'd at
==2349744==    at 0x4848C63: realloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==2349744==    by 0x173D71: tal_resize_ (tal.c:744)
==2349744==    by 0x177E36: next_free_chan (gossmap.c:336)
==2349744==    by 0x177ED3: new_channel (gossmap.c:351)
==2349744==    by 0x178441: add_channel (gossmap.c:458)
==2349744==    by 0x178B6D: map_catchup (gossmap.c:635)
==2349744==    by 0x178F45: load_gossip_store (gossmap.c:697)
==2349744==    by 0x179D71: gossmap_load (gossmap.c:978)
==2349744==    by 0x18D22F: main (run-mcf.c:295)
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-15 05:32:22 +09:30
Rusty Russell 4f16f50353 renepay: don't free adg twice after adding gossip.
It will usually be freed by the call to pay_flow_finished_adding_gossip.

```
cln-renepay: FATAL SIGNAL 6 (version 862dac2-modded)
0x561f232f32f8 call_error
	/home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:95
0x561f232f3df8 check_bounds
	/home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:169
0x561f232f2281 to_tal_hdr
	/home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:179
0x561f232f2189 tal_free
	/home/runner/work/lightning/lightning/ccan/ccan/tal/tal.c:514
0x561f2327f801 addgossip_done
	/home/runner/work/lightning/lightning/plugins/renepay/pay.c:170
0x561f23292d9b handle_rpc_reply
	/home/runner/work/lightning/lightning/plugins/libplugin.c:871
0x561f23292a90 rpc_read_response_one
	/home/runner/work/lightning/lightning/plugins/libplugin.c:1048
0x561f23292811 rpc_conn_read_response
	/home/runner/work/lightning/lightning/plugins/libplugin.c:1072
0x561f232dc0f2 next_plan
	/home/runner/work/lightning/lightning/ccan/ccan/io/io.c:59
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-15 05:31:46 +09:30
Rusty Russell d032a23647 plugins/renepay: don't require raw_message in error reply.
It's not there if it's a local error:

```
{
   "code": 202,
   "message": "Parsing '{message:%,data:{erring_index:%,failcode:%,raw_message:': object does not have member raw_message"
}
```

Reported-by: https://github.com/daywalker90
Fixes: #6553
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-08-15 05:31:46 +09:30