Commit Graph

4182 Commits

Author SHA1 Message Date
Christian Decker 3f35f83faa subd: Do not send feerate updates to non-channeld subds
Turns out we were sending feerate updates to daemons that do not
understand it. Don't do that!

Closes #6932

Changelog-Fixed: channeld: We could crash `closingd` by sending it a `channeld` message
2023-12-15 14:29:27 +01:00
Rusty Russell 0b23133ab2 lightningd: don't print out notification msat fields as strings.
Reported-by: Shahana Farooqui
Changelog-Fixed: JSON-RPC: Plugin notification `msat` fields in `invoice_payment` and `invoice_created` hooks now a number, not a string with "msat" suffix.
Changelog-Fixed: JSON-RPC: Plugin hook `payment` `msat` field is now a number, not a string with "msat" suffix.
2023-11-21 08:23:39 +01:00
Dusty Daemon a6a9e5b1e3 splice: Reestablish when commit or sig sends fail
Adds tests for when the connection fails during
1) splice tx_signature
2) splice commitment_signed

Fleshed out the reestablish flow for these two cases and implemented the fixes to make these reestablish flows work.

Part of this work required changing commit process for splices: Now we send a single commit_part for the splice where previously we sent all commits, and accordingly, we no longer revoke in response.

Changelog-Fixed: Implemented splicing restart logic for tx_signature and commitment_signed. Splice commitments are reworked in a manner incompatible with the last version.
2023-11-20 07:35:22 +01:00
Rusty Russell eae0d1da1e lightningd: fix up deprecated `rest-port`, `rest-protocol`, `rest-host` and `rest-certs` option if we would otherwise fail.
Since these worked in v23.08, we can't just rename them.  So if they are
used and unclaimed, we should rename them internally (if they're claimed,
it's probably clightning-rest, and we should *NOT* touch them!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Deprecated: Plugins: `clnrest` parameters `rest-port`, `rest-protocol`, `rest-host` and `rest-certs`: prefix `cln` to them
2023-11-17 10:51:41 +01:00
Ken Sedgwick 9e0b244058 splice: fix WIRE_HSMD_SIGN_SPLICE_TX capability check
Fixes #6866

Changelog-Fixed: The WIRE_HSMD_SIGN_SPLICE_TX HSM capability is now correctly checked.
2023-11-15 18:42:08 +10:30
niftynei f4b4f772f3 dualfund, bump: when bumping a channel make sure it's in ok state
If we disconnect, we lose the open_attempt record. Which is fine, but we
should prevent the user from starting another RBF if the last one isn't
done yet!
2023-11-02 19:32:05 +10:30
niftynei dbcdfd7d66 dualfund, memleak: don't leak the msg on error
We don't let go of the `msg` on error, which triggers a memleak warning!

lightningd-2 2023-10-31T19:54:06.582Z **BROKEN** lightningd: MEMLEAK: 0x55ae3615b498
lightningd-2 2023-10-31T19:54:06.582Z **BROKEN** lightningd:   label=openingd/dualopend_wiregen.c:919:u8[]
lightningd-2 2023-10-31T19:54:06.582Z **BROKEN** lightningd:   alloc:
lightningd-2 2023-10-31T19:54:06.685Z **BROKEN** lightningd:     ccan/ccan/tal/tal.c:477 (tal_alloc_)
lightningd-2 2023-10-31T19:54:06.686Z **BROKEN** lightningd:     ccan/ccan/tal/tal.c:506 (tal_alloc_arr_)
lightningd-2 2023-10-31T19:54:06.686Z **BROKEN** lightningd:     openingd/dualopend_wiregen.c:919 (towire_dualopend_send_tx_sigs)
lightningd-2 2023-10-31T19:54:06.686Z **BROKEN** lightningd:     lightningd/dual_open_control.c:1122 (openchannel2_sign_hook_cb)
lightningd-2 2023-10-31T19:54:06.686Z **BROKEN** lightningd:     lightningd/plugin_hook.c:194 (plugin_hook_call_next)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     lightningd/plugin_hook.c:169 (plugin_hook_callback)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     lightningd/plugin.c:660 (plugin_response_handle)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     lightningd/plugin.c:772 (plugin_read_json_one)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     lightningd/plugin.c:823 (plugin_read_json)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     ccan/ccan/io/io.c:59 (next_plan)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     ccan/ccan/io/io.c:407 (do_plan)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     ccan/ccan/io/io.c:417 (io_ready)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     ccan/ccan/io/poll.c:453 (io_loop)
lightningd-2 2023-10-31T19:54:06.687Z **BROKEN** lightningd:     lightningd/io_loop_with_timers.c:22 (io_loop_with_timers)
lightningd-2 2023-10-31T19:54:06.688Z **BROKEN** lightningd:     lightningd/lightningd.c:1333 (main)
lightningd-2 2023-10-31T19:54:06.688Z **BROKEN** lightningd:     ../sysdeps/nptl/libc_start_call_main.h:58 (__libc_start_call_main)
lightningd-2 2023-10-31T19:54:06.688Z **BROKEN** lightningd:     ../csu/libc-start.c:392 (__libc_start_main_impl)
lightningd-2 2023-10-31T19:54:06.688Z **BROKEN** lightningd:   parents:
2023-11-02 19:32:05 +10:30
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 62de535619 listpeerchannels: only add the scratch_txid if it exists
Changelog-Changed: RPC `listpeerchannels`.`inflights` may sometimes not include `scratch_txid` (mandatory -> optional)
2023-11-02 19:32:05 +10:30
niftynei 30babab1ed dualfund: when dropping to chain, only drop if we have a commitment tx
You can't publish a tx you don't have!
2023-11-02 19:32:05 +10:30
niftynei b9376ac66b dualfund: report on whether or not we've gotten commitments
We need to keep track of if we've gotten the last negotiation's
commitment sigs, for reconnect logic (helps us know what messages to
send in the reconnect case)
2023-11-02 19:32:05 +10:30
niftynei bc40299e9e dualfund: on error, handle different states differently
depending on the state, we might
- forget the channel
- drop it to chain
- reconnect via dualopend
2023-11-02 19:32:05 +10:30
niftynei 0efd10b224 dualfund: if we get an abort, clean up dangling inflights
(ones that are missing last_txs)
2023-11-02 19:32:05 +10:30
niftynei b097389fb5 openchannel_update: check if we've got an inflight record
If an openchannel_update fails (due to disconnect etc) it's possible
that it could 'resolve' itself later due to the auto reconnect logic

If you call an openchannel_update and we've already got an inflight
record saved, go ahead and return the info from the inflight (including
info about whether or not the commitments are secured.)

This makes openchannel_update a bit more 'robust'/idempotent, in that
you can make repeat calls to it after the channel is inflight and get
the info you need back to continue (call openchannel_signed)

Changelog-Changed: RPC: `openchannel_update` will now echo back a result if there's a matching inflight record for this open.
2023-11-02 19:32:05 +10:30
niftynei cfe2b86870 dualfund: remove reliance on open_attempt on commit_received
Since we can now get a COMMITMENT_SIGNED message due to a reconnect,
in addition to the 'inline' open process, it's possible that we might
have cleaned up / lost the open_attempt object.

This is fine, we have (almost) all the data we need to round this off
successfully/send out a notice.

Note that the only exception is the `close_to` data is lost/forgotten in
the case of a restart; this is largely fine.
2023-11-02 19:32:05 +10:30
niftynei c63e65bfcc dualfund: if we don't have commitments, error openchannel_signed
You don't want to be adding sigs to channels we don't have commitment
transactions for..
2023-11-02 19:32:05 +10:30
niftynei ca87afd5bb dualfund: wait til after we've sigs on disk before network check
If the peer's disconnected but the caller sends us valid sigs for the
channel open, we should go ahead and store them to disk before we reject
the call based on the fact that the peer is disconnected.

This way if the peer reconnects later, the channel open will succeed

Changelog-Changed: RPC: `openchannel_signed` will now remember the details of a signed PSBT even if the peer is disconnected.
2023-11-02 19:32:05 +10:30
niftynei 36a8c37fca dualfund: when updating an inflight, check for existing data
If you resend us a commitment tx, and we already have one, we check that
it's correct!
2023-11-02 19:32:05 +10:30
niftynei 4e221e2833 nit: spelling error (int -> in) 2023-11-02 19:32:05 +10:30
niftynei 95c7345515 db, inflights: add method to remove any 'dangling' inflights
When we reconnect, if we get a note from the peer that they dont know
about a pending inflight, we need to be able to clean it up so we can
restart/re-negotiate a new RBF etc.

This adds a cleanup method to remove any inflights for a channel without
a last_tx (commitment tx)
2023-11-02 19:32:05 +10:30
niftynei 20c77419dc dualfund: split 'commit-received' into two parts
Here, we split up what was "commit_received" into two phases:
	- commit-ready, where we're about to send our commitment tx to
	  peer
	- commit-received, when we've gotten the commitment tx from our
          peer

This lets us do the right thing (as far as the spec is concerned) with
returning the correct 'next_funding_txid' on reconnect (later commits).
2023-11-02 19:32:05 +10:30
niftynei 7114a03084 dualfund: add switch for if the incoming channel is "too early"
If we get an error on a channel that doesn't have commitments yet,
we can just delete it.
2023-11-02 19:32:05 +10:30
niftynei 48d2760c56 inflights: split up adding sigs from making a new inflight
We're going to add the commitment transaction data at a different time
than when we init a new inflight. Split them up!
2023-11-02 19:32:05 +10:30
niftynei d69f0aac60 wallet: allow the channel to not have a last_tx
What if the last_tx is empty for the channel?

We're about to let the channels not have last_txs at start.
2023-11-02 19:32:05 +10:30
niftynei ecb8d9d71f dual-fund: add new open-commit-ready state
From the spec:

	Once peers are ready to exchange commitment signatures, they must remember
	the details of the funding transaction to allow resuming the signatures
	exchange if a disconnection happens.

Basically this means we add channels to the database before we've gotten
commitments for them; it's nice that there's now a state for commitments
recevied but we now save the channel prior to that.

This commit makes it possible to track the pre-commit-rcvd but not quite
open-init state.
2023-11-02 19:32:05 +10:30
Rusty Russell f004952442 lightningd: wumbo is now the default, setting has no effect.
"Patrick, I'm sorry I doubted you."

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: Config: `large-channels` is now the default, wumbology for all.
2023-11-02 08:16:51 +01:00
Alex Myers 10bac49dac ld: add commit-fee-offset option, update config schema
Changelog-Added: Added option --commit-fee-offset to potentially reduce feerate update disagreements
2023-11-02 09:49:59 +10:30
Alex Myers 4265699fcd lightningd: add a feerate offset when updating feerates as opener
Adding a fee offset as the channel opener reduces the likelihood of a
disconnect by the peer do to slight variation in feerate calculation
between nodes.

Changelog-Fixed: Some peer disconnects due to update_fee disagreements are avoided.
2023-11-02 09:49:59 +10:30
Rusty Russell 28fd70a3d8 lightningd: rewrite anchor spend to use multiple UTXOs if needed.
Closes: #6747
Changelog-EXPERIMENTAL: Fixed anchor spending to be able to use more than one UTXO.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-11-01 14:11:28 +10:30
Rusty Russell ebf6f2e344 lightningd: use wallet_utxo_boost for zero-fee htlc_tx.
The previous logic looked wrong anyway!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-11-01 14:11:28 +10:30
Rusty Russell e4d7266fff common: add amount_feerate helper.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-11-01 14:11:28 +10:30
Rusty Russell ed034d9deb wallet: specialize get_utxos interfaces.
Turns out we really only want two:
1. wallet_get_all_utxos()
2. wallet_get_unspent_utxos()

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-11-01 14:11:28 +10:30
Rusty Russell af971fd025 wait forwards: add in_htlc_id
Without this, we have no unique identifier for which forward happened.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell f2162bf202 lightningd: add ordering and pagination to listforwards.
Changelog-Added: JSON-RPC: `listforwards` new parameters `index`, `start` and `limit`.
2023-10-28 15:48:26 +10:30
Rusty Russell 1d8af90b56 listforwards: add created_index and updated_index fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `listforwards` fields `created_index` (old: `id`) and `updated_index`.
2023-10-28 15:48:26 +10:30
Rusty Russell de1e459196 forwards: hook into the wait subsystem.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `wait` now works for `forwards` infrastructure.
2023-10-28 15:48:26 +10:30
Rusty Russell e58ae31947 lightningd: hook forwards into the wait system.
This table doesn't have `id`, except as the implicit one in Sqlite3,
so we need to add it for postgres.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell c4f2ada2ff lightningd: split up peer_htlcs a little, create forwards.c
peer_htlcs has become a bit of a dumping ground: move listforwards
etc to its own file.

Also move `struct channel_info` from peer_htlcs.h to channel.h where
it more logically belongs.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell c70a326f1f lightningd: add ordering and pagination to listsendpays.
Changelog-Added: JSON-RPC: `listsendpays` new parameters `index`, `start` and `limit`.
2023-10-28 15:48:26 +10:30
Rusty Russell 00ac1a9475 listsendpays: add created_index and updated_index fields.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `sendpay`, `listsendpays`, `delpay` new fields `created_index` (old: `id`) and `updated_index`.
2023-10-28 15:48:26 +10:30
Rusty Russell 9ec6ac9922 lightningd: don't log that we're trying to pay if we're not.
Looking through logs I was surprise to see:

```
lightningd-1 2023-10-26T03:42:36.824Z INFO    lightningd: Sending 200000000msat over 1 hops to deliver 200000000msat
```

On a re-payment where we simply returned from sendpay immediately!  Move that log to later.
2023-10-28 15:48:26 +10:30
Rusty Russell f65c3cab75 wallet: use standard-style iterators for payments.
We used to have "unsaved" payments: now we don't we can use
our normal "iterator" pattern rather than returning arrays.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell 89cda26164 lightningd: rename struct sendpay_command to waitsendpay_command.
It used to be used for both `sendpay` and `waitsendpay` but now it's
only for the latter, so the name is confusing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell 2689a4ed76 wallet: don't expose wallet_payment constructor, use wallet_add_payment.
Have it construct and return.  No need to expose details about dbid...

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell 52b1ba2992 wallet: remove premature optimization when making payment.
We didn't write to db immediately, but waited until it the actual HTLC got
added (or failed).  That way we didn't have a separate transaction to
write the payment into the db, but the complexity is not worth it: it
makes the next refactors harder, since we can't use the normal
iterator patterns like we do with the rest of the db (as we have to add
the unstored ones).

We might as well also make sendpay return immediately: we used to return
once the HTLC had been confirmed sent, since we entered it in the db
at that point, but we can keep it simple now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell c2d89e4624 sendpays: hook into the wait subsystem.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `wait` now works for `sendpays` infrastructure.
2023-10-28 15:48:26 +10:30
Rusty Russell ccb8d4b687 sendpays: add to wait subsystem.
Adding an index means:

1. Add the new subsystem, and new updated_index field to the db, and
   create xxx_index_deleted/created/updated APIs.
2. Hook up these functions to the points they need to be called.
3. Add index, start and limit fields to the list command.
4. Add created_index and updated_index into the list command.

This does #1.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-28 15:48:26 +10:30
Rusty Russell f8e036b22d channeld: use anchors on peer's commitment(s) if we can't broadcast our own.
This means refactoring out some of the generic anchor info, from the
per-commitment-tx info (we can have at least two, perhaps more with
splicing!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-27 11:19:56 +10:30
Rusty Russell 484deb94fa lightningd: save peer's commitment anchor info into db.
We actually only need to remember the last two, worst case.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-27 11:19:56 +10:30
Rusty Russell e609bc934e channeld: tell lightningd about local anchor for each commitment tx.
It's going to want to remember these, in case it encounters peers'
commitment tx and needs to boost it with CPFP on the anchor.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2023-10-27 11:19:56 +10:30