1
0
Fork 0
mirror of https://github.com/lightning/bolts.git synced 2025-03-13 19:37:31 +01:00
Commit graph

299 commits

Author SHA1 Message Date
t-bast
7a4053de28
fixup! Make splice_locked atomic on reestablish 2025-02-28 11:10:55 +01:00
t-bast
c79dca9696
Clarify announcement requirements
We make the requirements for `announcement_signatures` more clear. It
is important that both nodes are able to generate the corresponding
`channel_announcement` to allow them to create a new `channel_update`
using the `short_channel_id` of the confirmed splice.

We insist on exchanging `splice_locked` before generating signatures
to ensure compatibility with taproot channels, where nonces will be
exchanged in `splice_locked` messages. This means that we need to
retransmit `splice_locked` on reconnection if `announcement_signatures`
hasn't been fully exchanged.

Importantly, after announcing a splice, nodes must still allow payments
that use the previous `short_channel_id`, because remote nodes may not
have processed the `channel_announcement` and `channel_update`s yet.
2025-02-18 16:18:06 +01:00
t-bast
5912705ed4
Make splice_locked atomic on reestablish
If one side sent `splice_locked` and the other side is ready to send
its own `splice_locked` while they are disconnected, this creates a
race condition on reestablish because `splice_locked` is retransmitted
after `channel_reestablish`, and other channel updates can be inserted
by the other node before receiving `splice_locked`. This will be an
issue for taproot channels, because nonces will be missing.
This race condition is described in more details in #1223.

We fix this race condition by adding TLVs to `channel_reestablish`
that provide information about the latest locked transaction. This
additional information also makes it easier to detect when we need
to retransmit our previous `splice_locked`.
2025-02-18 16:10:09 +01:00
t-bast
43b5785da5
Channel Splicing (feature 62/63)
Splicing allows spending the current funding transaction to replace it
with a new one that changes the capacity of the channel, allowing both
peers to add or remove funds to/from their channel balance.

Splicing takes place while a channel is quiescent, to ensure that both
peers have the same view of the current commitments.

We don't want channels to be unusable while waiting for transactions to
confirm, so channel operation returns to normal once the splice tx has
been signed and we're waiting for it to confirm. The channel can then
be used for payments, as long as those payments are valid for every
pending splice transactions. Splice transactions can be RBF-ed to speed
up confirmation.

Once one of the pending splice transactions confirms and reaches
acceptable depth, peers exchange `splice_locked` to discard the other
pending splice transactions and the previous funding transaction. The
confirmed splice transaction becomes the channel funding transaction.

Nodes then advertize this spliced channel to the network, so that nodes
keep routing payments through it without any downtime.
2025-02-12 11:18:36 +01:00
t-bast
ccfa38ed4f Explicitly mention which output to set to 0 2025-02-12 09:46:08 +01:00
t-bast
90662b1323 Clarify a few requirements
As suggested by @yyforyongyu.
2025-02-12 09:46:08 +01:00
t-bast
7b635f0f2d Clarify OP_RETURN requirements
As suggested by @roasbeef.
2025-02-12 09:46:08 +01:00
t-bast
7eff1485a5 Simplify state machine by removing shutdown exchange
As pointed out by @TheBlueMatt, we can greatly simplify the protocol
by removing the `shutdown` exchange entirely. The only piece of data
nodes must remember is the last script their peer sent. This can be
found in the last received `closing_complete`, or in `shutdown` if
`closing_complete` was never received. This doesn't even need to be
persisted, because on reconnection nodes will exchange `shutdown`
again with the last script they want to use for their output.

By doing that, the protocol becomes a trivial request/response protocol
where nodes send `closing_complete` and expect `closing_sig` back. This
creates a race condition when both nodes update their script at the same
time, but this will be extremely rare so we can simply resolve it by
reconnecting.

This protocol is compatible with taproot channels, with the following
additions:

- when sending `shutdown`, nodes will include two random nonces:
  - `closer_nonce` that will be used in their `closing_complete`
  - `closee_nonce` that will be used in their `closing_sig`
- when sending `closing_complete`, nodes will include a new random nonce
  for their next `closing_complete` (`next_closer_nonce`)
- when sending `closing_sig`, nodes will include a new random nonce for
  their next `closing_sig` (`next_closee_nonce`)

This ensures that nodes always have a pair of random nonces for their
next signing round.
2025-02-12 09:46:08 +01:00
t-bast
7f8520079e Fix @tnull's comments
Clarify strict `shutdown` exchange requirements and fix typos.
2025-02-12 09:46:08 +01:00
t-bast
37fa862a82 Add strict shutdown exchange for taproot channels
It was previously unclear whether a node could send `shutdown` and
`closing_complete` immediately after that whenever RBF-ing their
previous closing transaction. While this worked for non-taproot
channels, it doesn't allow a clean exchange of fresh musig2 nonces
for taproot channels. We now require that whenever a node wants to
start a new signing round, `shutdown` must be sent *and* received
before sending `closing_complete`.
2025-02-12 09:46:08 +01:00
t-bast
8efb63eb61 Address pending PR comments
- add more detailed protocol flow diagram
- rename sigs TLVs as suggested by @morehouse
- mention `upfront_shutdown_script` as suggested by @Crypt-iQ
- fix typos
- reformat
2025-02-12 09:46:08 +01:00
t-bast
039f8ce99a Allow setting nLockTime, not nSequence
We always set `nSequence` to `0xFFFFFFFD`, but each node can choose the
`nLockTime` they want to use for the transactions for which they are
paying the fees.
2025-02-12 09:46:08 +01:00
t-bast
3d9f0b8fad Set output amount to 0 when using OP_RETURN
Bitcoin Core version 25+ will not broadcast transactions containing
`OP_RETURN` outputs if their amount is greater than 0, because this
amount would then be unspendable. We thus require that the output
amount is set to 0 when using `OP_RETURN`.
2025-02-12 09:46:08 +01:00
Rusty Russell
9981a0a9f2 BOLT 2: specify nSequence explicitly.
We don't care, as long as it's RBF-able.  This will be nicer for
Taproot when mutual closes are otherwise indistinguishable from normal
spends.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
e8eced6795 Feedback from Bastien
- Make it clear why the OP_RETURN restrictions have two forms.
- Cross-reference existing dust threshold
- Lots of typo fixes
- Don't set closer_and_closee if we're larger/equal, and closee is dust.
- Remove Rationale on delete zero-output tx hack.
2025-02-12 09:46:08 +01:00
Rusty Russell
b2ef4b48ea BOLT 2: allow standard OP_RETURN as an output type.
This gets around "but both our outputs are dust!" problems, as
recommended by Anthony Towns.

I hope I interpreted the standardness rules correctly (technically,
you can have multiple pushes in an OP_RETURN as long as the total is
under 83 bytes, but let's keep it simple).

Add an explicit note that "OP_RETURN" is never considered "uneconomic".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
8490ccc5d1 BOLT 2: Rewrite to use TLV, and only allow the lesser-amount to drop output.
If both are dust, you should lowball fees.  The next patch adds OP_RETURN
as a valid shutdown scriptpubkey though if you really want to do this.

This also addresses the case where people send a new `shutdown` with a *different* scriptpubkey.  This could previously cause a race where you receive a bad signature (because it hasn't received the updated shutdown), so we ignore these cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
167a7354fb Require non-dust output for closer.
You have to give them something which will propagate.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
a1ae46ddc3 BOLT 2: fix battling requirements for shutdown
The shutdown section says:

```
  - MUST NOT send multiple `shutdown` messages.
```

But the reconnection section says:

```
  - upon reconnection:
    - if it has sent a previous `shutdown`:
      - MUST retransmit `shutdown`.
```

So clearly, remove the former.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
dc376ca241 BOLT 2, 3, 9: option_simple_close.
Pay your own fees, so the peer will sign without caring.  Even if it doesn't relay.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
t-bast
3fffab3b88 Clean-up nits
This commit doesn't change the logic at all, it simply:

- removes `realm` from onion test vector
- cleans-up markdown formatting and indents
- fixes typos and missing parenthesis
- consistently uses `_` instead of `-` for field names
- fixes math formatting (including changes from #1169 and #1158)
2024-07-17 10:40:35 +09:30
Rusty Russell
5e9ea22272 BOLT 2, 4: rename blinding to path_key.
Sure, it's used to derive a secret for blinding, but it's also used to derive the key
for encrypted_recipient_data.  It's not used as a blinding factor *directly*.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-07-17 10:40:35 +09:30
Rusty Russell
bc1ce064d2 BOLT 2, BOLT 4: refer to the onion decryption section in update_add_htlc/onion message requirements.
This ties it together, saying what to use as associated data, blinding, and what to do on failure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-07-17 10:40:35 +09:30
Rusty Russell
c562d91ace BOLT 2: add requirement for disconnect if quiescence takes too long with HTLCs pending.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-06-18 07:08:11 +09:30
Keagan McClelland
99d67c6c73 require quiescence sessions to be single-use 2024-06-18 07:08:11 +09:30
Rusty Russell
5dd9d9cd5f BOLT 2: quiescence protocol.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>




Header from folded patch 'bolt_2__set_an_initiator_in_quiescence.patch':

BOLT #2: Set an initiator in quiescence.

This is especially useful for protocols such as splicing; for
simplified commitment transactions, there is already an implied
initiator at each point, so having the negotiation at splicing
time would be redundant.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>



Header from folded patch 'option_quiesce__feature_to_support_stfu_method.patch':

option_quiesce: feature to support stfu method.

In practice, sftu is useless unless you have something (e.g. channel_upgrade)
which uses it, but adding a feature is best practice IMHO.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-06-18 07:08:11 +09:30
t-bast
3e9b5728cc
Clean-up: follow-up on removing spec features
This is a follow-up to https://github.com/lightning/bolts/pull/1092
that fixes the following issues:

- fix a few typos
- remove non-zero-fee anchors test cases
- remove `remote_pubkey` rotation
2024-05-21 10:58:55 +02:00
Rusty Russell
e042c615ef BOLT 9: assume var_onion_optin.
Advertized as supported by all but 6 nodes (and those can no longer
route payments since people only send the modern onion these days)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-05-20 15:06:27 -05:00
Rusty Russell
d745028f65 BOLT 9: Remove option_anchor_outputs, in favor of option_anchors_zero_fee_htlc_tx.
It's supported only by pre-23.05 core-lightning nodes built with
EXPERIMENTAL_FEATURES.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-05-20 15:06:27 -05:00
Rusty Russell
91f4bd2383 BOLT 9: option_data_loss_protect and option_static_remotekey are now assumed.
These still have names and numbers, since they appear in `channel_type`.  They are somewhat tangled with each other, so let's tie them together as assumed.

option_data_loss_protect is advertized by all by 11 nodes(*), and option_static_remotekey all but 16 nodes.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
[* there are 449 three-year old LND nodes which advertize `2200` as their features, which have already been trimmed from most gossip for not having htlc_maximum_msat in their channel_updates]
2024-05-20 15:06:27 -05:00
Erik De Smedt
08ce2f6f83
Fix broken link in BOLT-2 (#1148) 2024-03-14 11:48:03 +01:00
niftynei
0bdaa8b9f6 dual-fund: add require_confirmed_inputs to RBF messages
Make `require_confirmed_inputs` explicit for RBF regnegotiation.

Requested-By: @t-bast
2024-02-13 11:55:23 -06:00
niftynei
6018a4d43b dual-fund, verbiage: clarify situation for closing a underfunded channel
Moved up some rationale from the Rationale section and added a
bit of clarification to when you'd want to close/cancel an open.

Reported-By: @morehouse
2024-02-13 11:55:23 -06:00
niftynei
bd1460d8cf dual-fund, wording: move sighash_all into existing verbiage
Suggested-By: @morehouse
2024-02-13 11:55:23 -06:00
niftynei
d9c571d25d dual-fund, nit: change wording on common input heuristic
Suggested-By: @devrandom
2024-02-13 11:55:23 -06:00
niftynei
f0c9ff732f tx-signatures: address comments regarding underpyament of fees
Reported-By: @morehouse
2024-02-13 11:55:23 -06:00
niftynei
076f21d65e nit: verbiage + wording
Suggested-By: @morehouse
2024-02-13 11:55:23 -06:00
niftynei
fa879e325c tx-complete: clarify that the total input/total output incl funding
Found-by: @morehouse
2024-02-13 11:55:23 -06:00
niftynei
11dea59504 tx-abort: port over meaning of the data field from warning
`tx_abort`'s structure comes from the `warning`/`error` messages,
but we failed to port over the rationale/rules for the `data` field.

Suggested-By: @morehouse
2024-02-13 11:55:23 -06:00
Dustin Dettmer
71e67e6d46 Bolt 2: Make interactive-tx explicitly use SIGHASH_ALL
This was previously assumed but adding it to the spec makes it explicit, should we ever want to change it in the future.

Suggested-By: @morehouse
2024-02-13 11:55:23 -06:00
niftynei
c51ef43fee interactive-tx: highlight MUST of serial_id sorting
Suggested-By: @dunxen
2024-02-13 11:55:23 -06:00
Duncan Dean
2ddddbd7c2 Use bitcoin wire encoding for witnesses 2024-02-13 11:55:23 -06:00
t-bast
c7af874f3d Store state when sending commitment_signed
If we only store state when sending `tx_signatures`, there are cases where
we cannot reconcile states if a disconnection occurs during the signing
steps: one side will have sent `tx_signatures` and thus must wait for the
transaction to be spent or double-spent, while the other side has already
forgotten that channel because they haven't sent `tx_signatures`.

This is fixed by storing state when sending `commitment_signed`, and
adding a `next_funding_txid` field to `channel_reestablish` to ask our
peer to retransmit signatures that we haven't received.
2024-02-13 11:55:23 -06:00
t-bast
1e48543ff1 Add section about liquidity griefing
This issue is non-trivial and worth mentioning, otherwise implementations
may forget to handle this which would result in an easy way of attacking
node's on-chain liquidity, creating a large opportunity cost.
2024-02-13 11:55:23 -06:00
t-bast
03a0eab139 Add require_confirmed_inputs TLV
This lets any side of the protocol require the other side to use confirmed
inputs, to avoid paying the fees of a low feerate unconfirmed ancestor.
2024-02-13 11:55:23 -06:00
niftynei
0bc22790ea v2 opens: proposal to get rid of the minimum estimated fee
Prior versions of the v2 dual-funding protocol assumed a 'minimum fee'
payment for any witness stack of any input, as a way to simplify fee
checks.

The suggested min feerate didn't make sense for taproot spend paths etc;
instead we remove this check entirely.
2024-02-13 11:55:23 -06:00
niftynei
cf9a5fcfe5 peer-protocol: send first+second commit point in openchanv2 + accept
Repeat the second commit point in the initial openchannel2 +
acceptchannel2 messages.

Suggested-By: @pm47
2024-02-13 11:55:23 -06:00
t-bast
811e55cd9e Use signed amounts in RBF messages
While dual funding only needs unsigned funding amounts, other protocols
that leverage interactive-tx may use signed funding amounts, for example
to take funds out of an existing channel (splice-out).

It is thus more future-proof to use signed amounts in `tx_init_rbf` and
`tx_ack_rbf`.
2024-02-13 11:55:23 -06:00
t-bast
180e4764ce Clarify RBF funding requirements 2024-02-13 11:55:23 -06:00
niftynei
3f1d142471 v2 opens: add a tx_abort message
Requested-by: @t-bast
2024-02-13 11:55:23 -06:00