Commit Graph

16068 Commits

Author SHA1 Message Date
Alex Myers
1e5a577fb2 gossipd: fix typo
Changelog-None
2025-03-03 12:25:26 -06:00
Rusty Russell
1605c13c1a lightningd: fix crash in onchaind replay.
If a tx has already spent one tx we're watching, and it spends another,
we try to add it to the hash table twice, which isn't allowed:

```
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: ../sysdeps/unix/sysv/linux/raise.c:51 (__GI_raise) 0x7fab2e363d51
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: ./stdlib/abort.c:79 (__GI_abort) 0x7fab2e34d536
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: ./assert/assert.c:92 (__assert_fail_base) 0x7fab2e34d40e
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: ./assert/assert.c:101 (__GI___assert_fail) 0x7fab2e35c6d1
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: lightningd/onchain_control.c:48 (replay_tx_hash_add) 0x556928d4e114
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: lightningd/onchain_control.c:365 (replay_watch_tx) 0x556928d4e114
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: lightningd/onchain_control.c:419 (replay_block) 0x556928d4e835
2025-02-28T23:00:32.155Z **BROKEN** lightningd: backtrace: lightningd/bitcoind.c:506 (getrawblockbyheight_callback) 0x556928d1c791
```

Fixes: #8131
Reported-by: Vincenzo Palazzo
Changelog-None: introduced this release, when we banned htable dups.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-02 16:06:34 -06:00
Alex Myers
3f81dc0221 meta: update CHANGELOG for 25.02rc3
Changelog-None
2025-02-27 15:14:41 -06:00
Alex Myers
8f891ce491 doc: update examples without blinded path hop 2025-02-27 13:53:10 -06:00
Rusty Russell
d2f4196179 offers: don't send blinded path to neighbor for *invoices*.
In 6e4ff6a7d2 ("offers: add a blinded path
if we have no advertized address") we were overzealous, and set blinded
paths not just for offers and invoicerequests, but for invoices themselves.

This has revealed various interop issues (which is great, but not good
for our users!) so we should disable that.  It also reduces the reliability
of payments in general.

Changelog-None: fixes previously overzealous addition
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-27 13:53:10 -06:00
daywalker90
05f0100e7d msggen: comply with grpc and rust naming conventions
Changelog-Changed: Some enums, structs, functions in pyln-grpc-proto/cln-grpc/cln-rpc
have been slightly renamed so they follow grpc and rust's naming convention
2025-02-27 11:53:48 -06:00
daywalker90
3e461036b3 msggen: add InjectOnionMessage
Changelog-None
2025-02-27 11:53:48 -06:00
daywalker90
5dab24ff38 msggen: add channel_state_changed notification
Changelog-None
2025-02-27 11:53:48 -06:00
Alex Myers
6368aa953f meta: update changelog for v25.02rc2
Changelog-None
2025-02-26 15:49:21 -06:00
Rusty Russell
2408233b2e pay: use correct CLTV values for blinded paths.
We added twice, which caused spurious failures in real-world cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reported-by: https://github.com/hMsats
Fixes: https://github.com/ElementsProject/lightning/issues/8119
Changelog-Fixed: `xpay` would double the CLTV values in blinded paths, sometimes causing spurious failures.
2025-02-26 14:26:47 -06:00
Rusty Russell
69476dbcab xpay: a test of a similar scenario to a real failure.
Use larger CLTVs and we see the failure from l3, complaining the CLTV is outside
the amount in the payment_constraint field, like:

```
Failing HTLC because of an invalid payload (TLV 10 pos 104): cltv_expiry 609 > payment_constraint 376
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-26 14:26:47 -06:00
Rusty Russell
10f333b041 devtools/bolt12-cli: fix interpretation of blindedpay, amounts.
The old blindedpay fields would have an entry per hop, but that was changed
to a single per-path entry.  The devtools hadn't caught up.

Similarly, it didn't like descriptionless offer fields in invreqs and invoices.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-26 14:26:47 -06:00
Rusty Russell
5e4c1b7839 lightningd: redo closing negotiation even if we consider channel closed.
This corner case started triggering on my machine with latest Bitcoind.

This test sabotages the closing negotiation, and as a result l1
doesn't see l2's CLOSING_SIGNED.  l2 is happy, however, and it is in
CLOSINGD_COMPLETE.  When l1 reconnects, it gets an error, and this causes
it to drop the unilateral tx to chain.

This unilateral tx from l1 replaces or races the mutual close tx from
l2, causing a unilateral close, which breaks our test.

Though this is a corner case, it's much friendlier to allow the
closing negotiation again until we actually see the close onchain.
This fixes the tests here, too.

```
    def test_closing_negotiation_reconnect(node_factory, bitcoind):
        disconnects = ['-WIRE_CLOSING_SIGNED',
                       '+WIRE_CLOSING_SIGNED']
        l1, l2 = node_factory.line_graph(2, opts=[{'disconnect': disconnects,
                                                   'may_reconnect': True},
                                                  {'may_reconnect': True}])
        l1.pay(l2, 200000000)
    
        assert bitcoind.rpc.getmempoolinfo()['size'] == 0
    
        l1.rpc.close(l2.info['id'])
        l1.daemon.wait_for_log(r'State changed from CHANNELD_NORMAL to CHANNELD_SHUTTING_DOWN')
        l2.daemon.wait_for_log(r'State changed from CHANNELD_NORMAL to CHANNELD_SHUTTING_DOWN')
    
        # Now verify that the closing tx is in the mempool.
        bitcoind.generate_block(6, wait_for_mempool=1)
        sync_blockheight(bitcoind, [l1, l2])
        for n in [l1, l2]:
            # Ensure we actually got a mutual close.
>           n.daemon.wait_for_log(r'Resolved FUNDING_TRANSACTION/FUNDING_OUTPUT by MUTUAL_CLOSE')

tests/test_closing.py:275: 
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Fixed: Protocol: We now renegotiate an interrupted close, even if we don't need it, instead of sending an error.
2025-02-26 10:22:03 -06:00
Rusty Russell
a4aa77761c lightningd: create helper routine to make socketpair for a channel.
This is a bit too much boilerplate for these, which mainly do the same
thing.

We add annotaitons to new_peer_fd so the compiler knows that it cannot
return NULL, otherwise with -O3 we get:

```
lightningd/peer_control.c: In function ‘peer_connected_hook_final’:
lightningd/peer_control.c:1388:28: error: ‘error’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1388 |                       take(towire_connectd_peer_send_msg(NULL, &channel->peer->id,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lightningd/peer_control.c:1313:19: note: ‘error’ was declared here
 1313 |         const u8 *error;
      |                   ^~~~~
lightningd/peer_control.c: In function ‘peer_spoke’:
lightningd/peer_control.c:1999:28: error: ‘error’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1999 |                       take(towire_connectd_peer_send_msg(NULL, &peer->id,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:311: lightningd/peer_control.o] Error 1
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-26 10:22:03 -06:00
Alex Myers
4f7df828b4 gossipd, chanbackup: reduce logging levels
The vast majority of incoming channel updates seem to be cut due
to age, which results in noisy logs.  Similarly, the chanbackup
logging verbosity might better match the equivalent actions in
channeld, which are at the debug level.

Fixes: #8058

Changelog-None: introduced in 25.02
2025-02-26 14:15:13 +10:30
Rusty Russell
79b28eb8c2 onchaind: tell lightningd correct nSequence value for local leases.
If the nSequence in the tx it produces is not at least the value we
test in the script, the tx will always fail:

```
error code: -26\nerror message:\nmandatory-script-verify-flag-failed (Locktime requirement not satisfied)
```

If we have a lease, the nSequence is max(lease-time-remaining,
to-self-delay), so have onchaind tell lightningd the correct nSequence.

Fixes: https://github.com/ElementsProject/lightning/issues/7460
Reported-by: https://github.com/pabpas
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: Correctly collect our own (delayed) funds if we have a unilateral close when we are still offering a lease.
2025-02-25 10:10:14 +10:30
Rusty Russell
5078e792e8 onchaind: don't tell lightningd to send OUR_DELAYED_RETURN_TO_WALLET too early (leases).
current height + to_self_delay[LOCAL] is correct normally, but if we
have an outstanding lease it's longer.  Not a big issue, because
lightningd will retry until its spendable, but wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-25 10:10:14 +10:30
Rusty Russell
8c0b2334c1 pytest: add test that to-local output spend actually works during lease time.
What we expect to happen:

1. l3, which unilaterally closed, waits 4032 blocks (minus those mined) before
   trying to send get its "to_local" funds back.
2. This should then succeed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-25 10:10:14 +10:30
Alex Myers
e96af42947 meta: update changelog for 25.02
Changelog-None
2025-02-24 16:06:41 -06:00
Alex Myers
091afee0ee wss-proxy: update dependencies
This should allow the last published version or the
local build (pyln-client v25.02)
2025-02-24 16:06:41 -06:00
Rusty Russell
4fdbd8ba98 lightningd: catch edits of config files *before* we're committed.
Another report, that we crash if it's edited.  We should check that too!

Reported-by: daywalker90
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
5e79cd4608 lightningd: check for writability before allowing setconfig.
If we actually can't write it, we crash (to avoid an inconsistent
state), so sanity check FIRST.

Fixes: https://github.com/ElementsProject/lightning/issues/7964
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
8127fcf825 pytest: don't add bookeeper-db option if bookkeeper is disabled.
There are other ways we can disable it, of course (e.g full path name)
but this is the most obvious.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
989cf17982 setconfig: put vars in separate "config.setconfig" file.
This is neater than appending to some random file: we only do that once
if there's no "include" line to include a ".setconfig" file.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
f4872f96db common: return location of a ".setconfig" file when we load config.
This is where we will put all the dynamic settings.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
da2fb198c4 setconfig: make source for setconfig "setconfig transient".
Previously it would be the value of the previous config setting.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
5a80223f3e setconfig: add transient option.
Changelog-Added: JSON-RPC: `setconfig` now has a `transient` flag which means it won't rewrite your config file.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Rusty Russell
98f15aecf4 lightningd: remove redundant command_check_only()
setconfig_success does this itself at the start, so we don't need it here.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-24 19:38:37 +10:30
Aditya Sharma
2dcbc701e4 tests: Added test_emergencyrecoverpenaltytxn
This test would make sure that the node would publish a penalty txn when channel partner
cheats.
2025-02-22 11:51:54 -06:00
Aditya Sharma
b44ed32408 test_misc.py: Add test_emergencyrecover_old_format_handling
Key Changes:
 - Added encrypted_data which contains emergency.recover in the legacy format
 - Added assert to make sure we watch the funding txn
2025-02-22 11:51:54 -06:00
Aditya Sharma
1a54888e2d Update SCB on every commitment update and handle new format
The chanbackup plugin should update emergency.recover every time we
receive a new commitment secret.

Additionally, chanbackup should be able to serialize both the new
SCB format and the legacy format.

Key Changes:
 - Added a commitment_revocation plugin hook to update emergency.recover whenever a new revocation secret is received.
 - Implemented support for the new emergency.recover format while maintaining compatibility with the legacy format.
2025-02-22 11:51:54 -06:00
Aditya Sharma
ab3ad617ce peer_control: Update shainchain and basepoints
Add the latest shachain when we update the emergency.recover using staticbackup RPC.
2025-02-22 11:51:54 -06:00
Aditya Sharma
41c6e3306f wallet: Add 'wallet_stub_shachain_init' to persist shachain
This function enables direct persistence of shachain data, ensuring all relevant information is saved upon retrieval.

Key Changes:
 - Adds 'wallet_stub_shachain_init' function to store a retrieved shachain in the database.
 - Saves initial metadata ('min_index' and 'num_valid') to the 'shachains' table.
 - Iterates through known shachain secrets, adding each entry to 'shachain_known' with position, index, and hash.
2025-02-22 11:51:54 -06:00
Aditya Sharma
cf2bd9f616 lightningd: Modify stub_chan() to accomodate new fields
These fields enhance 'stub_chan' to make channels which are capable to
create penalty transaction in case the peer broadcasts an old revoked state.

Key Changes:
 - Added new params to stub_chan() to accomodate shachain, basepoints, opener, and remote_to_self_delay
 - Check if any field is NULL inside scb_chan->tlvs and assign them appropriately
2025-02-22 11:51:54 -06:00
Aditya Sharma
fe02d2f1c5 scb_wire: Define new subtype 'modern_scb_chan' with 'scb_tlvs'
We define a new subtype 'modern_scb_chan' and a new tlvtype 'scb_tlvs' which includes
all the relevant information to create a penalty transaction when the peer tries to cheat.

Key Changes:
 - Rename the old format to 'legacy_scb_chan' and define a new type 'modern_scb_chan'
 - Include TLVs to 'modern_scb_chan'
 - Create a new msgtype 'static_chan_backup_with_tlvs'
 - Modify 'struct channel' to include 'struct modern_scb_chan'
 - Add these two types to 'varsize_types' in generate.py
2025-02-22 11:51:54 -06:00
Aditya Sharma
6df6789744 Enable Length-Prefixed TLVs through Generator
This change allows adding a length prefix to a serialized TLV. It will
be particularly useful for serializing all 'scb_chan' entries in
the 'emergency.recover' file.

Key Changes:
 - Removed the need to loop in towire_tlv and fromwire_tlv, so the if conditions have been modified accordingly.
 - During serialization, the length of the TLV is calculated before appending it, and it is stored in a temporary variable.
 - For fromwire_tlv, only a simple length adjustment is required, and no loop is needed here either.
2025-02-22 11:51:54 -06:00
Aditya Sharma
39f63eb27f tools/gen: Enable Subtypes to have TLVStreams
This change will allow subtypes in wiregen files to have tlvstreams.
Shifting tlv structs above subtypes in header_template is done to prevent
forward declaration.

Since generate-wire prepends 'tlv_' in tlvname, we
have to modify fromwire_subtype_field and towire_subtype_field in
impl_template to accommodate this.

Changelog-Added: This PR would turn our peers into watchtower and enable SCB to create penalty txn.
2025-02-22 11:51:54 -06:00
Alex Myers
5b83eff5d9 pytest: update examples generation for listpeerchannels
with fixed our/their_max_htlc_value_in_flight_msat values

suggested by @ShahanaFarooqui
2025-02-21 17:03:36 -06:00
Rusty Russell
a6e476a73b pytest: test sql deprecated field (now we have one!).
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-21 17:03:36 -06:00
Lagrang3
35f899a588 fetch max total htlc value from listpeerchannel
The parameter max_htlc_value_in_flight_msat stablished by peers on
channel opening (BOLT02) can now be retrived from the
gossmods_from_listpeerchannels API.

Adapted the corresponding callback functions in renepay and askrene to
take into account that value as a constraint to the value we can send
through a channel.

Changelog-Add: fetch max_htlc_value_in_flight_msat from gossmods_listpeerchannels API

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2025-02-21 17:03:36 -06:00
Rusty Russell
afb54ff8e8 lightningd: actually deprecate the listpeerchannels field.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-21 17:03:36 -06:00
Lagrang3
fe4d5036c2 add max_htlc_value_in_flight_msat to listpeerchan
Changelog-Added: JSON-RPC: `listpeerchannels` new output fields `their_max_total_htlc_out_msat` and `our_max_total_htlc_out_msat` as the value of `max_htlc_value_in_flight` (as of BOLT02) set by the local and remote nodes on channel creation.

Changelog-Deprecated: JSON-RPC: `listpeerchannels` value `max_total_htlc_in_msat`: use `our_max_total_htlc_out_msat` instead to follow spec naming convention.
2025-02-21 17:03:36 -06:00
Rusty Russell
0df3c5869a plugins/sql: allow deprecated field access if wildcards are used.
Otherwise, deprecating a field causes SELECT * to fail:

```
>       l1.rpc.sql(f"SELECT * FROM peerchannels;")
...
>           raise RpcError(method, payload, resp['error'])
E           pyln.client.lightning.RpcError: RPC call failed: method: sql, payload: ('SELECT * FROM peerchannels;',), error: {'code': -1, 'message': 'query failed with access to peerchannels.max_total_htlc_in_msat is prohibited (Deprecated column table peerchannels.max_total_htlc_in_msat)'}
```

So if they use a wildcard, allow access: though "SELECT *" is fraught,
"COUNT(*)" is perfectly legit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-21 17:03:36 -06:00
ShahanaFarooqui
37828b556a doc: Add enableoffer in makefile
The `enableoffer` JSON schema is present, but it is not included in the `GENERATE_MARKDOWN` list within the Makefile. This resulted into missing `.7` and `.7.md` files, leading to missing manpage and the documentation portal page.

Changelog-None.
2025-02-21 14:12:18 -06:00
daywalker90
121bec5709 pyln-testing: on cln 24.02.2 and earlier use log-level=debug
Changelog-None
2025-02-21 08:35:50 -06:00
daywalker90
119be76136 pyln-testing: set autoconnect-seeker-peers only in supported cln 24.11+
Changelog-None
2025-02-21 08:35:50 -06:00
Rusty Russell
da793e66b9 xpay: rename payment_failed to payment_give_up
Eduardo points out that payment_failed kind of over-promises: it may
actually not fail the payment now (with slow mode).

It's more an indiciation that we're not trying any more payment parts,
so rename it to payment_give_up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-20 20:22:54 -06:00
Rusty Russell
43e59a6774 pytest: test xpay gracefully handles failure after success.
We can create this scenario by having one path force close.  We take
the opportunity to log this, even in non-slow-mode, since it's interesting
(not our bug, but someone just lost money!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-20 20:22:54 -06:00
Rusty Russell
f168cb5949 xpay: add xpay-slow-mode to force waiting for all parts before returning.
This was requested by Michael of Boltz; it's mainly useful if you plan to
try failed payments on a *different* node.  In that case, there's a
theoretical possibility that slow parts of this payment could combine with
that from a different node and overpay.

We don't allow this from the same node, already.

Changelog-Added: xpay: `xpay-slow-mode` makes xpay wait for all parts of a payment to complete before returning success or failure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-20 20:22:54 -06:00
Rusty Russell
db1e26eb67 xpay: refactor payment_succeeded.
1. Don't rely on the current attempt, make caller calculate total.
2. Save preimage inside attempt, for slow mode.
3. Hoist it higher in the file.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-20 20:22:54 -06:00