<oembed><type>rich</type><version>1.0</version><title>Rusty Russell [ARCHIVE] wrote</title><author_name>Rusty Russell [ARCHIVE] (npub1zw…hkhpx)</author_name><author_url>https://yabu.me/npub1zw7cc8z78v6s3grujfvcv3ckpvg6kr0w7nz9yzvwyglyg0qu5sjsqhkhpx</author_url><provider_name>njump</provider_name><provider_url>https://yabu.me</provider_url><html>📅 Original date posted:2018-10-10&#xA;📝 Original message:&#xA;Hi all!&#xA;&#xA;        We&#39;ve had increasing numbers of c-lightning users get upset they&#xA;can&#39;t open multiple channels, so I guess we&#39;re most motivated to allow&#xA;splicing of existing channels.  Hence this rough proposal.&#xA;&#xA;For simplicity, I&#39;ve chosen to only allow a single splice at a time.&#xA;It&#39;s still complex :(&#xA;&#xA;Feedback welcome!&#xA;--&#xA;Splice Negotiation:&#xA;&#xA;1. type: 40 (`splice_add_input`) (`option_splice`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`8`: `satoshis`]&#xA;   * [`32`: `prevtxid`]&#xA;   * [`4`: `prevtxoutnum`]&#xA;   * [`2`: `scriptlen`]&#xA;   * [`scriptlen`: `scriptpubkey`]&#xA;&#xA;1. type: 41 (`splice_add_output`) (`option_splice`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`8`: `satoshis`]&#xA;   * [`2`: `scriptlen`]&#xA;   * [`scriptlen`: `outscript`]&#xA;&#xA;1. type: 42 (`splice_all_added`) (`option_splice`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`4`:`feerate_per_kw`]&#xA;   * [`4`:`minimum_depth`]&#xA;&#xA;Each side sends 0 or more `splice_add_input` and 0 or more&#xA;`splice_add_output` followed by `spice_all_added` to complete the splice&#xA;proposal.  This is done either to initiate a splice, or to respond to a&#xA;`splice_*` from the other party.&#xA;&#xA;`splice_add_input` is checked for the following:&#xA;- must not be during a current splice&#xA;- scriptpubkey is empty, or of form &#39;HASH160 &lt;20-byte-script-hash&gt; EQUAL&#39;&#xA;- `satoshis` doesn&#39;t wrap on addition.&#xA;- MAY check that it matches outpoint specified (sig will simply be&#xA;  invalid if so), and that outpoint is segwit.&#xA;&#xA;`splice_add_output` is checked for the following:&#xA;- must not be during a current splice&#xA;- `satoshis` is less than or equal to amount owing to proposer, minus&#xA;  current reserve, and greater than or equal to `dust_limit_satoshis` we&#xA;  sent in our open_channel/accept_channel ,sg.&#xA;- script is one of the approved forms as it is for `shutdown`.&#xA;&#xA;FIXME: Do we disallow splice-out if they specified&#xA;       option_upfront_shutdown_script?&#xA;&#xA;`splice_all_added` is checked for the following:&#xA;- average of `feerate_per_kw` by both sides (round down) is sufficient.&#xA;- average of `feerate_per_kw` by both sides not grossly excessive, if we&#39;re&#xA;  paying some of the fees (see below!)&#xA;- both sides can afford the fees from their post-splice funds (see&#xA;  Verification Changes below)&#xA;- maximum of the two `minimum_depth` is not grossly excessive.&#xA;- There is at least one splice_add_input or splice_add_output.&#xA;&#xA;Splice negotiation, like closing negotiation, does not have persistent&#xA;state.  Reconnecting forgets previous negotiation.&#xA;&#xA;&#xA;Splice Signing&#xA;--------------&#xA;&#xA;Once `splice_all_added` is both sent and received, we need to create and&#xA;sign both the splice tx itself, and the first commitment transaction&#xA;which spends it (but not in that order!).&#xA;&#xA;1. One input spends the current funding tx output.&#xA;2. There is one additional input for each splice_add_input.&#xA;3. One output creates the new funding tx.&#xA;4. There is one additional output for each splice_add_output.&#xA;5. The entire transaction is sorted into BIP69 order.&#xA;6. The feerate is the sum of the two `feerate_per_kw` divided by 2,&#xA;   rounded down.&#xA;&#xA;1. type: 43 (`splice_commitment_signature`) (`option_splice`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`64`:`commitment_signature`]&#xA;   * [`2`:`num_htlcs`]&#xA;   * [`num_htlcs*64`:`htlc_signature`]&#xA;&#xA;1. type: 44 (`splice_signature`) (`option_splice`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`64`:`splice_signature`]&#xA;&#xA;1. type: 45 (`splice_witness`) (`option_splice`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`2`: `num_witness_elements`&#xA;   * [`2`:`len`]&#xA;   * [`len`:`witnesses`]&#xA;&#xA;`witnesses` itself is serialized as `num_witness_elements` of:&#xA;* `2`:`len`&#xA;* `len`: `witness_element`&#xA;&#xA;Each side sends `splice_commitment_signature` and waits to receive and&#xA;verify the other side&#39;s `splice_commitment_signature` before sending&#xA;`splice_signature` and `splice_witness` for each `splice_add_input` it&#xA;proposed, in BIP69 input order.&#xA;&#xA;Once a node has sent `splice_commitment_signature` it should remember&#xA;the splice proposal across reconnects.  Once it has both sent&#xA;`splice_signature`, the splice is locked in.&#xA;&#xA;&#xA;Splice Announcement&#xA;-------------------&#xA;&#xA;We have to tell the network about the new channel, otherwise there will&#xA;be a distruption when it sees the old funding transaction spent.  This&#xA;is inevitable for older nodes who won&#39;t understand splicing anyway.&#xA;&#xA;We can&#39;t send out a `channel_announcement` or `channel_update` for the&#xA;new channel until after the new funding transaction has 6 confirmations,&#xA;so we append to the existing `channel_update` for the original channel,&#xA;using a new `message_flags` field:&#xA;&#xA;| Bit Position  | Name                      | Field                            |&#xA;| ------------- | ------------------------- | -------------------------------- |&#xA;| 0             | `option_channel_htlc_max` | `htlc_maximum_msat`              |&#xA;| 1             | `option_channel_moving`   | `moving_txid                     |&#xA;&#xA;The `channel_update` gains the following field:&#xA;    * [`32`: moving_txid`] (option_channel_moving)&#xA;&#xA;If a current `channel_update` for a closing channel contains&#xA;`option_channel_moving` a node SHOULD ignore the channel close for at&#xA;least 100 blocks iff spent by `moving_txid`.&#xA;&#xA;A node SHOULD immediately forward a `channel_update` it sees containing&#xA;`option_channel_moving` if neither previous `channel_update` for the&#xA;channel contains `option_channel_moving`.&#xA;&#xA;Each side of the splice can send these unilaterally, and SHOULD allow a&#xA;few minutes for propagation (remember, average propagation from old&#xA;nodes is still 30 seconds) prior to broadcast of the splice transaction.&#xA;&#xA;&#xA;Message Changes During Splicing&#xA;-------------------------------&#xA;Once you&#39;ve sent `splice_commitment_signature` each commitment&#xA;transaction is duplicated: one spends the old funding transaction, one&#xA;spends the splice transaction:&#xA;&#xA;1. type: 39 (`closing_signed`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`8`:`fee_satoshis`]&#xA;   * [`64`:`signature`]&#xA;   * [`64`:`splice_signature`] (`option_splice`)&#xA;&#xA;1. type: 132 (`commitment_signed`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`64`:`signature`]&#xA;   * [`2`:`num_htlcs`]&#xA;   * [`num_htlcs*64`:`htlc_signature`]&#xA;   * [`num_htlcs*64`:`htlc_splice_signature`] (`option_splice`)&#xA;&#xA;If a reconnection occurs between between sending and receiving&#xA;`splice_commitment_signature`) the peer&#39;s status is uncertain (similarly&#xA;for closing).  This we have a new field in `channel_reestablish` to flag&#xA;that we consider ourselves to be splicing:&#xA;&#xA;1. type: 136 (`channel_reestablish`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;   * [`8`:`next_local_commitment_number`]&#xA;   * [`8`:`next_remote_revocation_number`]&#xA;   * [`32`:`your_last_per_commitment_secret`] (`option_data_loss_protect`)&#xA;   * [`33`:`my_current_per_commitment_point`] (`option_data_loss_protect`)&#xA;   * [`32`:`splice_txid`] (`option_splice`)&#xA;&#xA;The splice_txid field indicates that this side considers itself to be&#xA;splicing.&#xA;&#xA;The sender:&#xA;- if it has sent `splice_commitment_signature` and not sent the corresponding&#xA;  `splice_closed`, MUST set `splice_txid` to the txid of the splice tx.&#xA;   - Otherwise MUST NOT.&#xA;&#xA;The recipient:&#xA;- if it has sent `splice_commitment_signature` and not sent the corresponding&#xA;  `splice_closed`:&#xA;  - if `splice_txid` does not exist or does not match the current splice:&#xA;    - SHOULD fail the channel&#xA;  - otherwise:&#xA;    - MUST retransmit `splice_signature`&#xA;- otherwise:&#xA;  - if `splice_txid` field exists and is not all zeroes:&#xA;    - MUST send `splice_closed`&#xA;&#xA;&#xA;Validation Changes During Splicing&#xA;----------------------------------&#xA;We track &#34;post-splice&#34; values as well as current values during&#xA;splicing.&#xA;&#xA;The post-splice reserve is 1% of post-splice capcacity (rounded down).&#xA;&#xA;The fees for the splicing transaction itself are divided into parts by&#xA;the number of `splice_add_input` plus `splice_add_output`, rounded up.&#xA;Each side pays as many parts as it proposed `splice_add_input` plus&#xA;`splice_add_output`.&#xA;&#xA;(So if Alice proposes two and Bob proposes one, and the total fee is 1000&#xA;satoshi, each part is 334 satoshi: Alice pays 668 and Bob pays 334.)&#xA;&#xA;Each side&#39;s post-splice funds are debited their `splice_add_output`&#xA;amounts, and credited their `splice_add_input` amounts, a debited the&#xA;splice tx fees.  If any debiting occurs, the funds must be above the&#xA;post-splice reserve (ie. you can have below reserve, but you can&#39;t spend&#xA;if you&#39;re below reserve).&#xA;&#xA;All update_add_htlc must be valid for the *both* the current and&#xA;post-splice balances.&#xA;&#xA;Completing Splicing&#xA;-------------------&#xA;Once you&#39;ve seen both side&#39;s `minimum_depth` confirmations of the splice&#xA;transaction (ie. the maximum of the two `minimum_depth` values), you can&#xA;complete the splice by sending:&#xA;&#xA;1. type: 46 (`splice_closed`) (`option_splice`)&#xA;2. data:&#xA;   * [`32`:`channel_id`]&#xA;&#xA;Once you&#39;ve sent and received `splice_closed` you can send&#xA;`announcement_signatures` for the new channel as per normal rules (ie. 6&#xA;confirmations, `announce_channel` bit set).&#xA;&#xA;In addition, you can forget everything about the old channel (including&#xA;old HTLCs and revocation requirements).</html></oembed>