Commit graph

15187 commits

Author SHA1 Message Date
Alex Myers
1d9ff8b022 reckless-rpc: read lightningdir and network from listconfigs 2024-08-12 18:10:45 -07:00
Alex Myers
f69c4d6385 reckless-rpc: initial boilerplate
Trying a single command first - reckless-search to test
launching a reckless process and processing the result.
2024-08-12 18:10:45 -07:00
Lagrang3
5073942eef askrene: memleak: scan reserved htable
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-13 09:12:40 +09:30
Lagrang3
cf3375c701 askrene: change reserve_hash for reserve_htable
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-13 09:12:40 +09:30
Rusty Russell
4f49143f24 openingd: don't ask for scid_alias in channel type if remote doesn't tell us they support it.
This is actually totally fair, and LND, which does not support it without an option, rejects.

Thanks to Vincenzo and roasbeef for debugging this for me!

Fixes: https://github.com/ElementsProject/lightning/issues/7221
Changelog-Fixed: Protocol: we can now open unannounced channels with LND nodes again.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-12 16:02:31 -07:00
Lagrang3
4ac85b2cd1 askrene: inform-channel fixes argument order
The documentation and the implementation of inform-channel have
different orders for the arguments minimum_msat and maximum_msat.
We change the order in the documentation to match that of the
implementation: minimum_msat comes before maximum_msat.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 14:17:22 -07:00
Lagrang3
3f32f9ea10 renepay: fix strange gossmap_refresh log
Often I find this in the logs:
DEBUG   plugin-cln-renepay: gossmap ignored 94692259263600 channel updates

Apparently gossmap_refresh does not initialize the input variable num_channel_updates_rejected.
Fix this by explicitely initializing it before calling gossmap_refresh.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
5e4eb7bdc3 renepay: fix double free of tal object
routefail object allocation was linked to route,
we had a crash of the plugin with the following error:

0x561f424fc07a send_backtrace
	common/daemon.c:33
0x561f424fc102 crashdump
	common/daemon.c:75
0x7f5b0e7dc04f ???
	???:0
0x7f5b0e82ae2c ???
	???:0
0x7f5b0e7dbfb1 ???
	???:0
0x7f5b0e7c6471 ???
	???:0
0x561f4252581f call_error
	ccan/ccan/tal/tal.c:95
0x561f425258c8 check_bounds
	ccan/ccan/tal/tal.c:169
0x561f425258f9 to_tal_hdr
	ccan/ccan/tal/tal.c:179
0x561f42526283 tal_free
	ccan/ccan/tal/tal.c:525
0x561f424e5379 routefail_end
	plugins/renepay/routefail.c:52
0x561f424e557b handle_failure
	plugins/renepay/routefail.c:431

apparently there was a race condition for which the route was first
freed before we arrived to routefail_end where we manually free
routefail. I don't see how this could have happened, but anyways
this subtle bug can be avoided by linking the routefail to the payment.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
c4d0447773 renepay: remove __PRETTY_FUNCTION__
Remove __PRETTY_FUNCTION__ in favor of __func__

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
cc9b8b0a19 renepay: bugfix finalized routes
Changelog-Fixed: renepay: finalized routes have to be processed and
determine the payment status even after the payment goes into the
background (no current command active). Not doing so leads to finalized
routes getting stuck in the payment internal data structure and their
associated HTLCs in the uncertainty network don't get released.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
04bf0ae29d renepay: remove unnecessary payment list
We rather have a payment hash table to look up payments based on the
payment hash than having a list.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
6a1776d312 renepay: rm HTLCs from uncertainty on route free
Add remove_htlc in the route destructor.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
d6667e305b renepay: review routetracking
Add missing uncertainty update after payment success.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
ccb70de4eb renepay: minor fix
Use success_data_from_listsendpays to check if there are "complete"
sendpays instead of imposing the presence of "complete" sendpays as a
precondition for success_data_from_listsendpays.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
0c685f541e renepay: rethink the computed routes storage
Simply move the "computed routes" array from the payment to the
routetracker. It makes sense to put all temporary stages of routing into
a single data structure: the routetracker.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
1052945ac0 renepay: remove unnecessary rpc calls
There were some dummy rpc calls to waitblockheight in the payment workflow
to allow the function stack to clear. But it is better if some steps in
the payment are executed "atomically" to avoid strange race conditions.
For example: all steps between getting pending sendpays, computing new
routes and sending those routes.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
a339e553e8 renepay: listsendpay before computing routes
It feels unsafe to rely on the internal state of the plugin's database
to tell how many pending sendpays there are for the current payment.
The safest way is to assume lightningd knows and thus use listsendpay
before computing routes.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
ec431276ac renepay: global record of computed routes
Use a single global map of computed routes instead of one for each
payment.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
8b2d45e52e renepay: simpler routetracker
- remove payment pointer from routetracker, fetch payment if necessary
  from payment_hash;
- "have results" condition as a function call to routetracker.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:27:34 -07:00
Lagrang3
f16363b86d renepay: small tweak to decay time
The time of decay "TIMER_FORGET_SEC" was set to 1 hour,
which is very low, it would make the plugin try depleted channels after
just a couple of seconds for very small amounts.
I set it to 1 week ~ 6e5 seconds.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:17:21 -07:00
Lagrang3
5ef5739e27 askrene: reserve: fix assertion
Fixes bad guide for json_scan.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-12 13:17:09 -07:00
michael1011
d32433a553 bkpr: add payment_id parameter to listaccountevents to filter events.
When you have *lots* of events in your bkpr database looking up a
specific event via calling bkpr-listaccountevents and using jq or
grep to filter gets very slow (and wasteful of CPU and disk resources).
This commit adds the paremeter payment_id to the call to filter for a
specific payment id via a where clause in the request to the database of bkpr.

Changelog-Added: Plugins: Add payment_id parameter to bkpr-listaccountevents to filter events.
2024-08-12 10:22:55 -07:00
michael1011
406d6a6e22 bkpr: minor clarification in comment. 2024-08-12 10:22:55 -07:00
Rusty Russell
a243f3c79c plugin/pay: fix crash if failcodename isn't set.
Fixes: https://github.com/ElementsProject/lightning/issues/7200
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-12 18:36:11 +09:30
Rusty Russell
48259afb70 lightningd: always broadcast our own gossip when it changes.
When a peer connects, we always send all our own gossip (even if they
had set the timestamp filters to filter it out).  But we weren't
forcing it out to them when it changed, so this logic only applied to
unstable or frequently-restarting nodes.

So now, we tell all the peers whenever we tell gossipd about our new
gossip.

Fixes: #7276
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Protocol: We now send current peers our changed gossip (even if they set timestamp_filter otherwise), not just on reconnect.
2024-08-12 16:30:29 +09:30
Rusty Russell
b525207e5c lightningd: track whether we're supposed to be throttling gossip.
We're going to need this for the next commit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-12 16:30:29 +09:30
Rusty Russell
4886d228e7 pytest: test that we inform all peers about gossip changes.
In particular, those who've filtered it out.

This currently fails, as expected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-12 16:30:29 +09:30
Rusty Russell
2d129e79ab pytest: enhance test_gossip_pruning
We didn't actually check that we *send* the refreshed gossip, just
that we print the message saying we're going to.

So check that everyone received updated gossip when this happens.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-12 16:30:29 +09:30
Rusty Russell
975dd76086 lightningd: create new return code for enableoffer.
Suggested-by: https://github.com/Lagrang3
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-11 11:27:10 +09:30
Vincenzo Palazzo
1e1edfd073 offer: allow re-enabling a previously disabled offer
Sometimes, for various reasons, a user disables an offer
and then wants to re-enable it. This should be allowed because,
from the CLN point of view, it is just an internal state.

If a user has constraints on the description of the invoice
because they are using services that link some sort of user ID
to an offer, it is important for the user to be able to re-enable the
offer, not create a new one. Creating a new offer would
require a different description.

Link: https://github.com/ElementsProject/lightning/issues/7360
Co-Developed-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-08-11 11:27:10 +09:30
ShahanaFarooqui
47e7127b19 doc: Instructions to use the script for generating examples
Changelog-Added: doc: all examples in the documentation are now generated from running the code, so they are current.
2024-08-09 23:56:45 -07:00
ShahanaFarooqui
f92a4ccea5 doc: Updated json examples in schema files 2024-08-09 23:56:45 -07:00
ShahanaFarooqui
50faa7c122 script: Auto generate rpc examples for documentation
I will commit doc/schemas/lightning-*.json files separately to keep this commit easier to review.

- test-autogenerate-rpc-examples updates all example request & responses in doc/schemas/lightning-*.json files.

- Updated tools/fromschema.py to accommodate the sql JSON example requirement where it does not accept -o in the query but shell does (for queries containing the = sign).

Changelog-None.
2024-08-09 23:56:45 -07:00
ShahanaFarooqui
fe7981bda2 pyln-testing: Increasing bitcoin rpc threads from default 4 to 20
Bitcoind's web server has a default of 4 threads, with queue depth 16 and it fails rather than queue beyond that.

Increasing thread count to 20 for running >10 lightning test nodes simultaneously.
2024-08-09 23:56:45 -07:00
ShahanaFarooqui
1ec508eb54 doc: Fixing schema definition
- `Notes` is not a required field in renepaystatus response
2024-08-09 23:56:45 -07:00
ShahanaFarooqui
9c0f073a44 tests: Removed non-essential hsm copy step 2024-08-09 23:56:45 -07:00
Rusty Russell
62f531a1f2 lightningd: configvar style fixes
1) We can't simply cast away const to manipulate a string, the compiler can assume
   we don't.  The type must be made non-const.
2) cisspace() is nicer to use than isspace() (no cast required!)
3) Simply place a NUL terminator instead of using memmove to set it.
4) Use cast_const to add const to char **, where necessary.
5) Add Changelog line, for CHANGELOG.md

Changelog-Fixed: Config: whitespace at the end of (most) options is now ignored, not complained about.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-10 15:20:59 +09:30
Max Rantil
3e65ef4b12 lightningd: trim whitespaces from end of config parameters
Signed-off-by: Max Rantil <rantil@pm.me>
2024-08-10 15:20:59 +09:30
Rusty Russell
d0c0c4480a plugins: fix more uninitialized vars in bookkeeper.
Did a sweep to find any others, give this from sanitizer:

```
2024-08-09T18:06:45.1729472Z plugins/bkpr/recorder.c:2057:23: runtime error: load of value 190, which is not a valid value for type 'bool'
2024-08-09T18:06:45.1729877Z SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior plugins/bkpr/recorder.c:2057:23 in
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-10 12:21:39 +09:30
Rusty Russell
359f1b8a30 bookkeeper: fix uninitialized variable.
Valgrind found this.  I think two PRs were added in parallel, which is why we
only found it after merge:

```
2024-08-09T01:57:23.7375752Z ==34263== Uninitialised byte(s) found during client check request
2024-08-09T01:57:23.7376275Z ==34263==    at 0x172405: memcheck_ (mem.h:247)
2024-08-09T01:57:23.7376661Z ==34263==    by 0x172585: db_bind_int (bindings.c:49)
2024-08-09T01:57:23.7377086Z ==34263==    by 0x126233: log_chain_event (recorder.c:2057)
2024-08-09T01:57:23.7377544Z ==34263==    by 0x11BF8B: json_utxo_deposit (bookkeeper.c:1735)
2024-08-09T01:57:23.7378207Z ==34263==    by 0x12BED3: ld_command_handle (libplugin.c:1847)
2024-08-09T01:57:23.7378674Z ==34263==    by 0x12C649: ld_read_json_one (libplugin.c:1998)
2024-08-09T01:57:23.7379114Z ==34263==    by 0x12C780: ld_read_json (libplugin.c:2018)
2024-08-09T01:57:23.7379534Z ==34263==    by 0x2990CB: next_plan (io.c:60)
2024-08-09T01:57:23.7379881Z ==34263==    by 0x299D21: do_plan (io.c:422)
2024-08-09T01:57:23.7380230Z ==34263==    by 0x299D88: io_ready (io.c:439)
2024-08-09T01:57:23.7380585Z ==34263==    by 0x29C1BC: io_loop (poll.c:455)
2024-08-09T01:57:23.7380980Z ==34263==    by 0x12D439: plugin_main (libplugin.c:2230)
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-10 12:21:39 +09:30
Lagrang3
db4a26d94a renepay: remove unused declaration
Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-08-09 14:38:17 +09:30
Lagrang3
07d4451a40 renepay: bugfix reading pending sendpays
When renepay starts, one of the first operations it does is to check for
pending sendpays for the same invoice. Those are added up to an internal
database to keep track of. Also the amount they deliver to the
destination is computed so that the current payment rpc call would try
to complete the payment for whatever amount remains to pay.
For an incomplete payment after calling the RPC renepay I found this in
the logs:

2024-05-22T19:44:19.853Z DEBUG   plugin-cln-renepay: There are pending sendpays to this invoice. groupid = 6 delivering = 0msat, last_partid = 10

Where delivering should be the sum of the amounts delivered by pending routes.
2024-08-09 14:38:17 +09:30
Christian Decker
aa45e737dc libplugin: Add parser for channel_hint from JSON 2024-08-09 13:59:07 +09:30
Christian Decker
6a53cf288b libplugin: Add primitive to serialize channel_hint to JSON 2024-08-09 13:59:07 +09:30
Christian Decker
eae378c9d2 common: Add some more JSON primitives
We were missing the `short_channel_id_dir` helpers.
2024-08-09 13:59:07 +09:30
Christian Decker
8e9f71ff85 libplugin: pay now emits channel_hint as we learn about the net
The `pay` plugin, as well as other plugins making use of the tree-pay
executor, will now emit their observations as they see them. The
notifications are sent on the `channel_hint_updated` topic, and any
subscriber will get them.

We also added a `timestamp` to the `struct channel_hint`, as these
observations now outlive the `pay` call, and have to be attenuated /
relaxed as they age, until we can eliminate them completely (when the
restriction is equal to the structural information gathered from the
gossip).

Changelog-Added: pay: Payments now emit `channel_hint_updated` notification to share inferred balances and observations across multiple payments.
2024-08-09 13:59:07 +09:30
niftynei
0e99f2e718 bkpr: add two custom notifications that we listen for
It might be nice to let the bookkeeper keep track of external accounts
as well as the internal onchain wallet? To this end, we add some new
custom notifications, which the bookkeeper will ingest and add to its
ledger.

Suggested-By: @chrisguida

Changelog-Added: PLUGINS: `bookkeeper` now listens for two custom events: `utxo_deposit` and `utxo_spend`. This allows for 3rd party plugins to send onchain coin events to the `bookkeeper`.  See the new plugins/bkpr/README.md for details on how these work!
2024-08-09 10:21:44 +09:30
niftynei
cd4298de84 bugfix: node refuses to re-start after emergency recover
one of the fields in the database isn't read/accessed during stub
reinitialization, so my node crashes.

error:
Never accessed column last_sig in query SELECT  id, peer_id, scid, full_channel_id, channel_config_local, channel_config_remote, state, funder, channel_flags, require_confirm_inputs_local, require_confirm_inputs_remote, minimum_depth, next_index_local, next_index_remote, next_htlc_id, funding_tx_id, funding_tx_outnum, funding_satoshi, our_funding_satoshi, funding_locked_remote, push_msatoshi, msatoshi_local, fundingkey_remote, revocation_basepoint_remote, payment_basepoint_remote, htlc_basepoint_remote, delayed_payment_basepoint_remote, per_commit_remote, old_per_commit_remote, shachain_remote_id, shutdown_scriptpubkey_remote, shutdown_keyidx_local, last_sent_commit_state, last_sent_commit_id, last_tx, last_sig, last_was_revoke, first_blocknum, min_possible_feerate, max_possible_feerate, msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, last_sent_commit, feerate_base, feerate_ppm, remote_upfront_shutdown_script, local_static_remotekey_start, remote_static_remotekey_start, channel_type, shutdown_scriptpubkey_local, closer, state_change_reason, revocation_basepoint_local, payment_basepoint_local, htlc_basepoint_local, delayed_payment_basepoint_local, funding_pubkey_local, shutdown_wrong_txid, shutdown_wrong_outnum, lease_expiry, lease_commit_sig, lease_chan_max_msat, lease_chan_max_ppt, htlc_minimum_msat, htlc_maximum_msat, alias_local, alias_remote, ignore_fee_limits, remote_feerate_base, remote_feerate_ppm, remote_cltv_expiry_delta, remote_htlc_minimum_msat, remote_htlc_maximum_msat, last_stable_connection FROM channels WHERE state != ?;
2024-08-08 17:11:38 -07:00
Christian Decker
8c14c39c7e onchaind: Adjust the sweep target deadline for fee estimation
We used to always target `now() + 300`, which ends up never really
confirming, as the fee estimate bumps into the min-relay-fee
limit. With this commit we set an absolute target of 2 weeks, and a
linear fee rampup, until we are at T-2h, at which point we just stick
with the estimate, and try with this increased feerate to try and get
the sweep confirmed.

This ought to make RBF transactions much more efficient for closing
channels.

Changelog-Fixed onchaind: The sweep deadline for to_us outputs would be reset on each restart of the subdaemon. Now the deadline is absolute in terms of the close height.
2024-08-09 09:08:06 +09:30
niftynei
46dcc6e031 bkpr: properly account for fees and channel closures if splice
We do some fancy accounting for channel closures; since we're tagging
splice txs as closes we need to mark them as splices so we can treat them
as any other 'normal' on chain event.
2024-08-08 12:30:53 -07:00