Research/Bitcoin Dev Archive / lightning-dev list
Dual Funding Proposal
9 messages, Nov 28 to Dec 4, 2018. Started by lisa neigut.
Rusty Russell (4), lisa neigut (3), ZmnSCPxj (2)
Hello fellow Lightning devs!
What follows is a draft for the new dual funding flow. Note that the `option_will_fund_for_food` specification has been omitted for this draft.
===== Proposal
Create a new channel open protocol set (v2), with three new message types: `funding_puts2`, `commitment_signed2`, and `funding_signed2`, plus two for negotiating RBF, `init_rbf` and `accept_rbf`.
Quick overview of the message exchange for v2:
+-------+ +-------+
| |--(1)--- open_channel2 ---->| |
| |<-(2)-- accept_channel2 ----| |
| | | |
| |--(3)-- funding_puts2 ----->| |
| |<-(4)-- funding_puts2 ----- | |
| | | |
--->| |--(5)-- commitment_signed2 -->| |
| | |<-(6)-- commitment_signed2 ---| |
| | A | | B |
| | |--(7)--- funding_signed2 ---->| |
| | |<-(8)--- funding_signed2 -----| |
| | | | |
| | |--(a)--- init_rbf ----------->| |
----| |<-(b)--- accept_rbf ----------| |
| | | |
| |--(9)--- funding_locked2 ---->| |
| |<-(10)---funding_locked2 -----| |
+-------+ +-------+
where node A is the ‘initiator’ and node B is the ‘dual-funder’
== Negotiating the use of dual_funding (open_channel2) flow Willingness to use v2 is flagged in init via `option_dual_fund`.
`init`
local channel feature flag, `option_dual_fund`
== Channel establishment with dual_funding
____`open_channel2`:
[32:chain_hash]
… // unchanged
[1:channel_flags]
[?: options_tlv]
options_tlv:
1.
Type: 1 `option_upfront_shutdown_script` 1.
[2:len]
2.
Value: `shutdown_scriptpubkey`
If nodes have negotiated `option_dual_fund`
The sending node:
-
MAY begin channel establishment using `open_channel2`
Otherwise the receiving node:
-
MUST return an error.
____ `accept_channel2`:
[32:temporary_channel_id]
… // unchanged
[33:first_per_commitment_point]
[?: options_tlv]
options_tlv:
1.
Type: 1 `option_upfront_shutdown_script`
[2:len]
Value: `shutdown_scriptpubkey`
____`funding_puts2`
This message exchanges the input and output information necessary to compose the funding transaction.
[32:temporary_channel_id]
[`2`:`num_inputs`]
[`num_inputs*input_info`]
[`2`:`num_outputs`]
[`num_outputs`*ouput_info`]
1. subtype: `input_info`
2. data:
* [`8`:`satoshis`]
* [`32`:`prevtxid`]
* [`4`:`prevtxoutnum`]
* [`2`:`scriptlen`]
* [`scriptlen`:`script`]
* [`2`:`max_extra_witness_len`]
* [`2`:`wscriptlen`]
* [`wscriptlen`:`wscript`]
1. subtype: `output_info`
2. data:
* [`8`:`satoshis`]
* [`2`:`scriptlen`]
* [`scriptlen`:`script`]
Requirements:
The sending node:
-
MUST ensure each `input_info` refers to an existing UTXO -
MUST ensure the `output_info`.`script` is a standard script -
MUST NOT spend any UTXOs specified in funding_puts2 until/unless the channel establishment has failed
If is the initiator (A): - MUST NOT send an empty message (`num_inputs` + `num_outputs` = 0)
If is the dual-funder (B):
-
consider the `put_limit` the total number of `num_inputs` plus `num_outputs` from `funding_puts2`, with minimum 2. -
MUST NOT send a number of `input_data` and/or `output_data` which exceeds the `put_limit` -
MAY send an empty message
The receiving node:
If is the initiator (A):
-
MUST fail the channel if the `num_inputs` plus `num_outputs` is greater than the `put_limit`
If has not yet sent a `fund_puts2` for this channel establishment
- SHOULD send their `fund_puts2` message
Otherwise
-
SHOULD send `commitment_signed2`
Rationale:
Each node must have a complete set of the transaction inputs/outputs, to derive the funding transaction hash.
There is a dual_funding protocol that only requires one side to send their witness data and inputs. This is more efficient, however it results in asymmetry between the nodes, where one is revealing their UTXOs before the funding transaction is committed.. We mitigate this asymmetry by asking the initiator (A) to send their set of inputs before the dual-funder (B) does.
NB: This is reusing the input/output structures from the Splicing proposal, but with a more generalized name.
____`commitment_signed2`
This message exchanges the counterparty’s signature for the first commitment transaction, so it can broadcast the funding transaction knowing that funds can be redeemed.
[32: `channel_id`]
[`64`: commitment_signature`]
Requirements:
The sending node:
-
MUST derive the `channel_id` from the funding transaction’s id -
MUST set signature to the valid signature, using its funding_pubkey for the initial commitment transaction, as defined in BOLT #3
If it has not received a `funding_puts2`
-
MUST NOT send their `commitment_signature`
The receiving node:
-
MUST verify the commitment signature is valid for the funding transaction -> commitment transaction that it has derived independently
If this signature is invalid it
-
MUST fail the channel
If it has not sent a `commitment_signed2` message
-
MUST send their `commitment_signed2` message
If this is in a flow initiated from `init_rbf`,:
-
MUST save the temporary_channel_id until the channel funding transaction has been locked (this is the channel id of the currently broadcast transaction)
Rationale:
In the previous channel establishment protocol, we were able to compress the commitment signature exchange into `funding_created`/`funding_signed`. With dual funding, we need interaction to build the funding transaction -- commitment sig exchange is now a separate step.
___`funding_signed2`
This message exchanges the witness data for the inputs that were originally sent in the `funding_puts2` message.
[`32`:`channel_id`]
[`2`:`num_witnesses`]
[`num_witnesses*witness_stack`]
Requirements:
The sending node:
- MUST remember the details of this funding transaction
- MUST NOT send a `witness_stack` whose length exceeds the corresponding `max_extra_witness_len`
If they have NOT received a valid `commitment_signed2` message
-
MUST not send their `funding_signed2` message
The receiving node:
-
SHOULD check that the number of witnesses sent matches the number of inputs
If a `witness_stack` length exceeds the corresponding `max_extra_witness_len`:
-
MAY error.
If is the `initiator` (A):
-
SHOULD apply `witness` to the funding transaction and broadcast the result.
Rationale:
Exchanging witness data allows either side to broadcast the funding transaction. It also maintains the information symmetry between the nodes.
___`funding_locked2`
// same as v1
Requirements:
A dual-funding node (B):
-
SHOULD broadcast their funding transaction if it does not see the transaction broadcast after a reasonable timeout.
== RBF for Channel Establishment v2
_____`init_rbf`
This message is sent by the initiator, after the funding transaction has been broadcast but before the `funding_locked2` has been exchanged.
[32: `channel_id`]
[8: funding_satoshis]
[8:dust_limit_satoshis]
[8:channel_reserve_satoshis]
[4: feerate_per_kw]
[`2`:`num_inputs`]
[`num_inputs*input_info`]
[`2`:`num_outputs`]
[`num_outputs`*ouput_info`]
Requirements
The sending node:
-
MUST be the initiator (A) -
MAY update the amount, fee rate, dust limit, or channel reserve for the channel
The receiving node:
-
MAY reject (error) the RBF request if: -
the fee rate, dust, or channel reserve is unreasonable
-
MUST reject (error) the RBF request if: -
the `fee_rate` is less than the rate that was originally proposed
-
the `funding_satoshis` amount is less than the previous negotiated
`push_mast`
-
It considers the `feerate_per_kw` too small for timely processing or
unreasonable
-
the `dust_limit_satoshis` is greater than the
`channel_reserve_satoshis`
-
the initiator’s amount for the initial commitment transaction is not
sufficient for full fee payment
-
the `inputs`.`satoshis` does not sum to the `funding_satoshis`
-
the `funding_satoshis` is insufficient to create the transaction at
the new `fee_rate`
-
there is no overlap in the proposed inputs and the original input set
included in the currently published funding transaction
-
they have already received or sent a `funding_locked2` message
-
If there are no errors or unreasonable demands: -
SHOULD send an `accept_rbf`
Rationale:
Once an `init_rbf` has been accepted by the dual-funding node, the message flow returns to `commitment_signed2` and proceeds as above, with the exception that the `temporary_channel_id` remains as the `channel_id` for the currently published but unmined transaction.
The channel id that becomes fixed for this node will be determined by the `funding_locked2` message.
___`accept_rbf`
This message accepts an RBF request, and renegotiates a dual-funder’s funds, dust limit, and channel reserve, and sends the dual-funder’s updated puts.
[32: `channel_id`]
[8: funding_satoshis]
[8:ndust_limit_satoshis]
[8:channel_reserve_satoshis]
[`2`:`num_inputs`]
[`num_inputs*input_info`]
[`2`:`num_outputs`]
[`num_outputs`*ouput_info`]
Requirements:
The sending node:
-
MAY update the amount, dust limit, or channel reserve for the channel
The receiving node:
-
MAY reject (error) the RBF request if: -
the dust or channel reserve is unreasonable
-
MUST reject (error) the RBF request if: -
the `funding_satoshis` amount is less than the previous negotiated
`push_mast`
-
the `dust_limit_satoshis` is greater than the
`channel_reserve_satoshis`
-
the total fees incurred by the `input_info`s and `output_info`s at
the new `fee_rate` is more than their `funding_satoshis`
otherwise:
-
SHOULD send a `commitment_signed2` message
Good morning Lisa,
Minor comments only, have not studied in detail:
Quoted text (19 lines)
> ____ `accept_channel2`: > > [32:temporary_channel_id] > > … // unchanged > > [33:first_per_commitment_point] > > [?: options_tlv] > > options_tlv: > > - > > Type: 1 `option_upfront_shutdown_script` > > [2:len] > > Value: `shutdown_scriptpubkey`
I believe an even type is more appropriate, since the other side MUST enforce that sthudown only goes to the specified script?
Quoted text (33 lines)
> ____`funding_puts2` > > This message exchanges the input and output information necessary to compose the funding transaction. > > [32:temporary_channel_id] > > [`2`:`num_inputs`] > > [`num_inputs*input_info`] > > [`2`:`num_outputs`] > > [`num_outputs`*ouput_info`] > > 1. subtype: `input_info` > > 2. data: > > * [`8`:`satoshis`] > > * [`32`:`prevtxid`] > > * [`4`:`prevtxoutnum`] > > * [`2`:`scriptlen`] > > * [`scriptlen`:`script`] > > * [`2`:`max_extra_witness_len`] > > * [`2`:`wscriptlen`] > > * [`wscriptlen`:`wscript`]
`script` here is the `scriptPubKey`? This is needed for `hashPrevouts` in BIP143 I believe.
What is the `wscript`? Is this the `scriptCode` in BIP143?
Are non-SegWit inputs disallowed?
Quoted text (25 lines)
> 1. subtype: `output_info` > > 2. data: > > * [`8`:`satoshis`] > > * [`2`:`scriptlen`] > > * [`scriptlen`:`script`] > > Requirements: > > The sending node: > > - > > MUST ensure each `input_info` refers to an existing UTXO > > - > > MUST ensure the `output_info`.`script` is a standard script > > - > > MUST NOT spend any UTXOs specified in funding_puts2 until/unless the channel establishment has failed
If a violation of this is detected, what MUST we do?
Regards, ZmnSCPxj
On Tue, Nov 27, 2018 at 11:26 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
Quoted text (31 lines)
> Good morning Lisa, > > Minor comments only, have not studied in detail: > > > > ____ `accept_channel2`: > > [32:temporary_channel_id] > > … // unchanged > > [33:first_per_commitment_point] > > [?: options_tlv] > > options_tlv: > > 1. > > Type: 1 `option_upfront_shutdown_script` > > [2:len] > > Value: `shutdown_scriptpubkey` > > > I believe an even type is more appropriate, since the other side MUST > enforce that sthudown only goes to the specified script? > >
Good point. This definitely should be an even type number as you suggest. My initial thought was that being inside an `options_tlv` would preclude the need to maintain the even/oddness designation, but I think this is a mistake.
____`funding_puts2`
Quoted text (42 lines)
> > This message exchanges the input and output information necessary to > compose the funding transaction. > > [32:temporary_channel_id] > > [`2`:`num_inputs`] > > [`num_inputs*input_info`] > > [`2`:`num_outputs`] > > [`num_outputs`*ouput_info`] > > 1. subtype: `input_info` > > 2. data: > > * [`8`:`satoshis`] > > * [`32`:`prevtxid`] > > * [`4`:`prevtxoutnum`] > > * [`2`:`scriptlen`] > > * [`scriptlen`:`script`] > > * [`2`:`max_extra_witness_len`] > > * [`2`:`wscriptlen`] > > * [`wscriptlen`:`wscript`] > > > `script` here is the `scriptPubKey`? This is needed for `hashPrevouts` in > BIP143 I believe. > > What is the `wscript`? Is this the `scriptCode` in BIP143? > > Are non-SegWit inputs disallowed? >
This borrows heavily from Rusty's splicing proposal; whatever was specified there should be assumed to also be specified here for inputs. Rationale being there should be no difference between the input requirements for a splice versus a dual fund.
Quoted text (30 lines)
> > > 1. subtype: `output_info` > > 2. data: > > * [`8`:`satoshis`] > > * [`2`:`scriptlen`] > > * [`scriptlen`:`script`] > > Requirements: > > The sending node: > > - > > MUST ensure each `input_info` refers to an existing UTXO > - > > MUST ensure the `output_info`.`script` is a standard script > - > > MUST NOT spend any UTXOs specified in funding_puts2 until/unless the > channel establishment has failed > > > If a violation of this is detected, what MUST we do? >
I'm not sure what you mean here, it's not exactly enforceable other than from an implementation perspective. If the funding transaction is invalid because of an input (ie a double spend), the funding transaction won't be confirmed. This should be discovered when the node attempts to broadcast the funding transaction, and can be handled (ie treated as a channel failure) there.
Quoted text (3 lines)
> Regards, > ZmnSCPxj >
lisa neigut <niftynei at gmail.com> writes:
Quoted text (4 lines)
> Hello fellow Lightning devs! > > What follows is a draft for the new dual funding flow. Note that the > `option_will_fund_for_food` specification has been omitted for this draft.
Hi!
Wow, my mailer really mangled this! I've liberally demangled below as I quote.
The proposal is great, but intense, so I've bikeshedded the language. My only objection is that I'd love to simplify RBF.
Quoted text (29 lines)
> ===== Proposal > > Create a new channel open protocol set (v2), with three new message types: > `funding_puts2`, `commitment_signed2`, and `funding_signed2`, plus two for > negotiating RBF, `init_rbf` and `accept_rbf`. > > > Quick overview of the message exchange for v2: > > +----+ +----+ > | |--(1)--- open_channel2 ---->| | > | |<-(2)-- accept_channel2 ----| | > | | | | > | |--(3)-- funding_puts2 ----->| | > | |<-(4)-- funding_puts2 ----- | | > | | | | > | |--(5)-- commitment_signed2 -->| | > | |<-(6)-- commitment_signed2 ---| | > | A | | B | > | |--(7)--- funding_signed2 ---->| | > | |<-(8)--- funding_signed2 -----| | > | | | | > | |--(a)--- init_rbf ----------->| | > | |<-(b)--- accept_rbf ----------| | > | | | | > | |--(9)--- funding_locked2 ---->| | > | |<-(10)---funding_locked2 -----| | > +----+ +----+ > where node A is the ‘initiator’ and node B is the ‘dual-funder’
We currently use the terms funder and fundee, which are now inaccurate ofc. Perhaps 'opener' and 'accepter' are not great english, but they map to the messages well?
Quoted text (12 lines)
> Willingness to use v2 is flagged in init via `option_dual_fund`. > `init` > > local channel feature flag, `option_dual_fund` > > == Channel establishment with dual_funding > > ____`open_channel2`: > [32:chain_hash] > … // unchanged > [1:channel_flags] > [?: options_tlv]
Always prefix variable fields by length, even this one. Otherwise we can never extend, and you never know...
[2:tlv_len] [tlv_len:opening_tlv]
I think we can remove `funding_satoshis` here; we'll know when they add their inputs, so it's redundant.
Another subtle point is the feerate_per_kw field; in the old scheme it applied to the first commitment tx, but here it applies to both the first commitment tx and the funding tx itself (unless option_simplified_commitment, though roasbeef has suggested further splitting that option, in which case we'll want another fee field here).
Quoted text (1 line)
> options_tlv:
Let's call this `opening_tlv` since there are other TLVs coming?
Quoted text (12 lines)
> 1. > Type: 1 `option_upfront_shutdown_script` > 1. > > [2:len] > 2. > > Value: `shutdown_scriptpubkey` > If nodes have negotiated `option_dual_fund` > The sending node: > - > MAY begin channel establishment using `open_channel2`
- MUST NOT send `open_channel`.
Quoted text (3 lines)
> Otherwise the receiving node: > - > MUST return an error.
This is a requirement for receiving `open_channel` IIUC?
ie.
The receiving node MUST fail the channel if: ... - `option_dual_fund` has been negotiated.
Quoted text (7 lines)
> ____ `accept_channel2`: > > [32:temporary_channel_id] > … // unchanged > [33:first_per_commitment_point] > [?: options_tlv] >
If we call this `opening_tlv` we can just reuse the definition from before.
Quoted text (1 line)
> ____`funding_puts2`
We can probably drop the 2 here and call it, um.. `funding_compose`? (Thanks thesaurus.com). I get where you're going with 'puts, but it took me a while :)
Quoted text (8 lines)
> This message exchanges the input and output information necessary to > compose the funding transaction. > > [32:temporary_channel_id] > [`2`:`num_inputs`] > [`num_inputs*input_info`] > [`2`:`num_outputs`] > [`num_outputs`*ouput_info`]
typo: output_info
Quoted text (35 lines)
> 1. subtype: `input_info` > 2. data: > * [`8`:`satoshis`] > * [`32`:`prevtxid`] > * [`4`:`prevtxoutnum`] > * [`2`:`scriptlen`] > * [`scriptlen`:`script`] > * [`2`:`max_extra_witness_len`] > * [`2`:`wscriptlen`] > * [`wscriptlen`:`wscript`] > > 1. subtype: `output_info` > 2. data: > * [`8`:`satoshis`] > * [`2`:`scriptlen`] > * [`scriptlen`:`script`] > > Requirements: > > The sending node: > > - MUST ensure each `input_info` refers to an existing UTXO > - MUST ensure the `output_info`.`script` is a standard script > - MUST NOT spend any UTXOs specified in funding_puts2 until/unless the > channel establishment has failed > If is the initiator (A): > - MUST NOT send an empty message (`num_inputs` + `num_outputs` = 0) > > If is the dual-funder (B): > - > consider the `put_limit` the total number of `num_inputs` plus > `num_outputs` from `funding_puts2`, with minimum 2. > - > MUST NOT send a number of `input_data` and/or `output_data` which > exceeds the `put_limit`
Side note: I wonder if we should relax this limit when we talk about `option_will_fund_for_food`?
Quoted text (2 lines)
> - > MAY send an empty message
Be explicit? MAY offer zero `num_inputs` and `num_outputs`. That's not quite an empty message...
Quoted text (7 lines)
> The receiving node: > > If is the initiator (A): > > - > MUST fail the channel if the `num_inputs` plus `num_outputs` is greater > than the `put_limit`
How about MAY? It's a protection thing, but less to change when we option_will_fund_for_food. Unless we set the `put_limit` to min (4) or something in that case?
Oh, it needs to check max_extra_witness_len is reasonable too, since that will affect the fees. Each signature adds 74, and pubkey adds 34, so I think MUST BE less than 500 is perfectly reasonable (for both reader and writer).
Quoted text (5 lines)
> If has not yet sent a `fund_puts2` for this channel establishment > - SHOULD send their `fund_puts2` message > > Otherwise > - SHOULD send `commitment_signed2`
Perhaps add '- MUST use the sent and received `input_info` and `output_info` to create the funding transaction, using `max_extra_witness_len` for each `input_info` and `feerate_per_kw` from `open_channel2`.'
Side note: we need to define max_extra_witness_len as the total marshalled length of the extra witness data which will be supplied (ie. sizeof(varint) + sizeof(data) for each one).
Quoted text (16 lines)
> Rationale: > > Each node must have a complete set of the transaction inputs/outputs, to > derive the funding transaction hash. > > There is a dual_funding protocol that only requires one side to send their > witness data and inputs. This is more efficient, however it results in > asymmetry between the nodes, where one is revealing their UTXOs before the > funding transaction is committed.. We mitigate this asymmetry by asking the > initiator (A) to send their set of inputs before the dual-funder (B) does. > > NB: This is reusing the input/output structures from the Splicing proposal, > but with a more generalized name. > > > ____`commitment_signed2`
I just realized that `commitment_signed` is the name of the message we use during HTLC / fee updates. But since the message is identical to this one in both form and purpose, I think we can reuse it here.
Quoted text (14 lines)
> This message exchanges the counterparty’s signature for the first > commitment transaction, so it can broadcast the funding transaction knowing > that funds can be redeemed. > > [32: `channel_id`] > [`64`: commitment_signature`] > > Requirements: > > The sending node: > > - MUST derive the `channel_id` from the funding transaction’s id > - MUST set signature to the valid signature, using its funding_pubkey for > the initial commitment transaction, as defined in BOLT #3
This is good.
Quoted text (6 lines)
> > If it has not received a `funding_puts2` > > - > > MUST NOT send their `commitment_signature`
This is implied by the requirement that they generate the funding transaction. For better or worse, we don't usually spell out requirements not to send things out of order.
Quoted text (16 lines)
> The receiving node: > > - MUST verify the commitment signature is valid for the funding > transaction -> commitment transaction that it has derived independently > > If this signature is invalid it > > - MUST fail the channel > > > If it has not sent a `commitment_signed2` message > > - MUST send their `commitment_signed2` message > > If this is in a flow initiated from `init_rbf`: > -
Perhaps be explicit here: 'If this commitment_signed2 was in response to an `init_rbf` message:'?
Quoted text (3 lines)
> MUST save the temporary_channel_id until the channel funding transaction > has been locked (this is the channel id of the currently broadcast > transaction)
Confused by this, see commentry down later.
Quoted text (19 lines)
> Rationale: > > In the previous channel establishment protocol, we were able to compress > the commitment signature exchange into `funding_created`/`funding_signed`. > With dual funding, we need interaction to build the funding transaction -- > commitment sig exchange is now a separate step. > ___`funding_signed2` > > This message exchanges the witness data for the inputs that were originally > sent in the `funding_puts2` message. > > [`32`:`channel_id`] > [`2`:`num_witnesses`] > [`num_witnesses*witness_stack`] > > Requirements: > > The sending node: > - MUST remember the details of this funding transaction
- MUST send one `witness_stack` for each `output_info`
it sent in `funding_puts2`.
Quoted text (5 lines)
> - MUST NOT send a `witness_stack` whose length exceeds the corresponding > `max_extra_witness_len` > > If they have NOT received a valid `commitment_signed2` message > - MUST not send their `funding_signed2` message
Redundant, but so vital I agree it needs to be stated.
Quoted text (4 lines)
> The receiving node: > > - SHOULD check that the number of witnesses sent matches the number of > inputs
"SHOULD check" is a spec anti-pattern :)
if `num_witnesses` does not equal `num_inputs` received in
`funding_puts2`:
- MUST fail the channel.
Quoted text (6 lines)
> If a `witness_stack` length exceeds the corresponding > `max_extra_witness_len`: > > - > > MAY error.
MUST?
Quoted text (6 lines)
> If is the `initiator` (A): > > - > > SHOULD apply `witness` to the funding transaction and broadcast the > result.
Since this is symmetrical, you can drop "if it is the `initiator`"?
Quoted text (17 lines)
> Rationale: > > Exchanging witness data allows either side to broadcast the funding > transaction. It also maintains the information symmetry between the nodes. > > ___`funding_locked2` > > // same as v1 > > Requirements: > > A dual-funding node (B): > > - > > SHOULD broadcast their funding transaction if it does not see the > transaction broadcast after a reasonable timeout.
Let's just reuse `funding_locked` maybe?
Not sure why this should wait for broadcast?
Quoted text (16 lines)
> == RBF for Channel Establishment v2 > > _____`init_rbf` > > This message is sent by the initiator, after the funding transaction has > been broadcast but before the `funding_locked2` has been exchanged. > > [32: `channel_id`] > [8: funding_satoshis] > [8:dust_limit_satoshis] > [8:channel_reserve_satoshis] > [4: feerate_per_kw] > [`2`:`num_inputs`] > [`num_inputs*input_info`] > [`2`:`num_outputs`] > [`num_outputs`*ouput_info`]
Typo again :)
Quoted text (6 lines)
> Requirements > > The sending node: > - MUST be the initiator (A) > - MAY update the amount, fee rate, dust limit, or channel reserve for the > channel
- MAY send init_rbf if it considers the most recent funding tx unlikely to be confirmed in reasonable time. - MUST set `feerate_per_kw` larger than the most recent funding tx.
Do we really want to negotiate everything again? It seems like the funder should be able to maybe add *new* inputs and outputs (though TBH I think that's going to be unusual enough that we could omit it), but doing a wholesale replacement means we have to be careful that the all RBFs end up having at least one input in common. Yech.
Quoted text (39 lines)
> The receiving node: > > - MAY reject (error) the RBF request if: > - > > the fee rate, dust, or channel reserve is unreasonable > - > > MUST reject (error) the RBF request if: > - > > the `fee_rate` is less than the rate that was originally proposed > - > > the `funding_satoshis` amount is less than the previous negotiated > `push_mast` > - > > It considers the `feerate_per_kw` too small for timely processing or > unreasonable > - > > the `dust_limit_satoshis` is greater than the > `channel_reserve_satoshis` > - > > the initiator’s amount for the initial commitment transaction is not > sufficient for full fee payment > - > > the `inputs`.`satoshis` does not sum to the `funding_satoshis` > - > > the `funding_satoshis` is insufficient to create the transaction at > the new `fee_rate` > - > > there is no overlap in the proposed inputs and the original input set > included in the currently published funding transaction
More subtly, there must be a common subset of inputs between every two funding txs.
Quoted text (17 lines)
> - > > they have already received or sent a `funding_locked2` message > - > > If there are no errors or unreasonable demands: > - > > SHOULD send an `accept_rbf` > > > Rationale: > > Once an `init_rbf` has been accepted by the dual-funding node, the message > flow returns to `commitment_signed2` and proceeds as above, with the > exception that the `temporary_channel_id` remains as the `channel_id` for > the currently published but unmined transaction.
By this stage, we are no longer using temporary_channel_id though.
But it's an excellent point I had missed. The channel_id changes on each renegotiation. We could either switch channel_id *after* each accept_rbf, or keep the original channel_id until funding_locked2 (in which case it should have a "final_channel_id" field, to make sure we're talking about the same funding tx).
Since we have to handle the "oops, old one got in!" it might be weird to see `funding_locked2` with an old txid. Perhaps we stick with the original channel_id until then, and flip *after* funding_locked2 is sent and received.
And yeah, no `update_fee`, `announcement_signatures` until that funding_locked2 exchange is complete, so we don't get those with an unsettled channel_id.
Quoted text (8 lines)
> The channel id that becomes fixed for this node will be determined by the > `funding_locked2` message. > > ___`accept_rbf` > > This message accepts an RBF request, and renegotiates a dual-funder’s > funds, dust limit, and channel reserve, and sends the dual-funder’s updated > puts.
I would make this an empty message, simply an ack. And note that the channel_id after this is that of the RBFed tx.
The question then becomes what do we do about reconnection. I suggest:
opener: if we haven't sent funding_signed, consider it cancelled. If we've received funding_signed, it's obviously locked in. If we sent and didn't received, re-xmit.
accepter: must remember rbf if we sent commitment_signed2. If we received funding_signed it's locked in. If we receive an init_rbf, drop the one we remembered. If we receive funding_signed, continue.
We still need to address the funding_tx construction; BIP69-style seems like an unnecessary information leak here. A 128-bit seed in open_channel2 could be added, with sorting by SHA(seed | <marshal of input> | <marshal of witness>) and SHA(seed | <marshal of output>)?
Phew! Rusty.
lisa neigut <niftynei at gmail.com> writes:
Quoted text (15 lines)
>> * [`2`:`scriptlen`] >> >> * [`scriptlen`:`script`] >> >> * [`2`:`max_extra_witness_len`] >> >> * [`2`:`wscriptlen`] >> >> * [`wscriptlen`:`wscript`] >> >> >> `script` here is the `scriptPubKey`? This is needed for `hashPrevouts` in >> BIP143 I believe. >> >> What is the `wscript`? Is this the `scriptCode` in BIP143?
I was thinking the BIP141 witnessScript; this mixes weirdly with P2WPKH though where the witnessScript does not really exist. So I guess an empty witnessScript means P2WPKH.
Quoted text (1 line)
>> Are non-SegWit inputs disallowed?
No, since we'd have a malleability problem :(
Cheers, Rusty.
Quoted text (3 lines)
> 128-bit seed in > open_channel2 could be added, with sorting by SHA(seed | <marshal of > input> | <marshal of witness>) and SHA(seed | <marshal of output>)?
`open_channel2` contains a good amount of entropy --- temporary channel ID, various basepoints. Would not hashing `open_channel2` to get this `seed` be sufficient?
Regards, ZmnSCPxj
Quoted text (7 lines)
> > Phew! > Rusty. > > Lightning-dev mailing list > Lightning-dev at lists.linuxfoundation.org > https://www.learnbitcoin.com/archive/lists/lightning-dev
ZmnSCPxj <ZmnSCPxj at protonmail.com> writes:
Quoted text (6 lines)
>> 128-bit seed in >> open_channel2 could be added, with sorting by SHA(seed | <marshal of >> input> | <marshal of witness>) and SHA(seed | <marshal of output>)? > > `open_channel2` contains a good amount of entropy --- temporary channel ID, various basepoints. > Would not hashing `open_channel2` to get this `seed` be sufficient?
Good point. Something we already have to remember would be ideal, so any of the basepoints would work, and is not exposed onchain.
seed = revocation_basepoint of open_channel2?
Cheers, Rusty.
Quoted text (9 lines)
> > > > +----+ +----+ > > where node A is the ‘initiator’ and node B is the ‘dual-funder’ > > We currently use the terms funder and fundee, which are now > inaccurate ofc. Perhaps 'opener' and 'accepter' are not great english, > but they map to the messages well? >
'opener' and 'accepter' do map to the messages. I've adopted it for the rest of this response, to see how it fits in context.
"Another subtle point is the feerate_per_kw field; in the old scheme it applied to the first commitment tx, but here it applies to both the first commitment tx and the funding tx itself"
You're right. Initially I didn't think the `accepter` would care since they're not paying them, but you need it to be able to construct the funding transaction. I'll add a second field, it seems important to keep them separated esp since the timing consideration for the fees is different (now vs the future).
Quoted text (18 lines)
> The sending node: > > - > > MAY begin channel establishment using `open_channel2` > > - MUST NOT send `open_channel`. > > > Otherwise the receiving node: > > - > > MUST return an error. > > This is a requirement for receiving `open_channel` IIUC? > > ie. > > The receiving node MUST fail the channel if: > ... > - `option_dual_fund` has been negotiated. >
Does v2 of channel open necessarily deprecate the original between two upgraded nodes?
This seems more sane than having both as an option...will update.
Quoted text (6 lines)
> > > ____`funding_puts2` > > We can probably drop the 2 here and call it, um.. `funding_compose`? > (Thanks thesaurus.com). I get where you're going with 'puts, but it > took me a while :)
Initially only the duplicated messages had the 2-suffix, but ended up adding it to all of them to denote that they belonged to the v2 of channel open... I can see how that's confusing though.
+1 for `funding_compose`, it's definitely more easily understood. :-D
...
Quoted text (6 lines)
> > MUST NOT send a number of `input_data` and/or `output_data` which > > exceeds the `put_limit` > > Side note: I wonder if we should relax this limit when we talk about > `option_will_fund_for_food`? >
Yes! Thanks for pointing this out.
Quoted text (7 lines)
> > > - > > MAY send an empty message > > Be explicit? MAY offer zero `num_inputs` and `num_outputs`. That's not > quite an empty message... >
I defined it a few lines above, but that's not super easy to see from this. Will fix.
Quoted text (14 lines)
> > > The receiving node: > > > > If is the initiator (A): > > > > - > > MUST fail the channel if the `num_inputs` plus `num_outputs` is > greater > > than the `put_limit` > > How about MAY? It's a protection thing, but less to change when we > option_will_fund_for_food. Unless we set the `put_limit` to min (4) or > something in that case? >
+1 for MAY, considering that the opener will be paying the fees. The limit for what's reasonable to pay is fairly subjective, i.e. perhaps the opener doesn't care how many inputs/outputs the acceptor adds.
Quoted text (6 lines)
> > Oh, it needs to check max_extra_witness_len is reasonable too, since > that will affect the fees. Each signature adds 74, and pubkey adds 34, > so I think MUST BE less than 500 is perfectly reasonable (for both > reader and writer). >
Ack
Quoted text (17 lines)
> > ___`funding_locked2` > > > > // same as v1 > > > > Requirements: > > > > A dual-funding node (B): > > > > - > > > > SHOULD broadcast their funding transaction if it does not see the > > transaction broadcast after a reasonable timeout. > > Let's just reuse `funding_locked` maybe? > > Not sure why this should wait for broadcast? >
I was overthinking this*. Can't think of a reason for both sides not to broadcast; will amend.
* confused it with conflicting transaction broadcast behavior
Quoted text (31 lines)
> > == RBF for Channel Establishment v2 > > > > _____`init_rbf` > > > > This message is sent by the initiator, after the funding transaction has > > been broadcast but before the `funding_locked2` has been exchanged. > > > > [32: `channel_id`] > > [8: funding_satoshis] > > [8:dust_limit_satoshis] > > [8:channel_reserve_satoshis] > > [4: feerate_per_kw] > > [`2`:`num_inputs`] > > [`num_inputs*input_info`] > > [`2`:`num_outputs`] > > [`num_outputs`*ouput_info`] > > Typo again :) > > > Requirements > > > > The sending node: > > - MUST be the initiator (A) > > - MAY update the amount, fee rate, dust limit, or channel reserve for > the > > channel > > - MAY send init_rbf if it considers the most recent funding tx unlikely > to be confirmed in reasonable time. > - MUST set `feerate_per_kw` larger than the most recent funding tx. >
Another good reason to break out `funding_txn_feerate_per_kw` from `commitment_txn_feerate_per_kw` in `open_channel2`
Quoted text (7 lines)
> > Do we really want to negotiate everything again? It seems like the > funder should be able to maybe add *new* inputs and outputs (though TBH > I think that's going to be unusual enough that we could omit it), but > doing a wholesale replacement means we have to be careful that the all > RBFs end up having at least one input in common. Yech. >
Only allowing the opener to add new inputs/outputs drives down the scope of a RBF a good deal. I like it. Adding new inputs seems like a common sense bare minimum, especially if we assume wildly unpredictable fee rates.
Quoted text (23 lines)
> > > > Rationale: > > > > Once an `init_rbf` has been accepted by the dual-funding node, the > message > > flow returns to `commitment_signed2` and proceeds as above, with the > > exception that the `temporary_channel_id` remains as the `channel_id` for > > the currently published but unmined transaction. > > By this stage, we are no longer using temporary_channel_id though. > > But it's an excellent point I had missed. The channel_id changes on > each renegotiation. We could either switch channel_id *after* > each accept_rbf, or keep the original channel_id until funding_locked2 (in > which case it should have a "final_channel_id" field, to make sure we're > talking about the same funding tx). > > Since we have to handle the "oops, old one got in!" it might be weird to > see `funding_locked2` with an old txid. Perhaps we stick with the > original channel_id until then, and flip *after* funding_locked2 is sent > and received. > >
Would it be more sane to continue to include the temporary channel id, in addition to the 'current' (i.e. most recently negotiated funding txn) channel id, until the funding_locked2 is sent (adds a `temporary_channel_id` field for `commitment_signed2`, ` funding_signed2` and `funding_locked2`, in addition to `channel_id`)? That way, all opening messages would have a stable id across an RBF re-negotiation, `temp_channel_id`. Sticking with the first broadcast funding transaction hash feels a bit misleading in the case of a second round of `commitment_signed2` and `funding_signed2`.
Quoted text (35 lines)
> And yeah, no `update_fee`, `announcement_signatures` until that > funding_locked2 exchange is complete, so we don't get those with an > unsettled channel_id. > > > The channel id that becomes fixed for this node will be determined by the > > `funding_locked2` message. > > > > ___`accept_rbf` > > > > This message accepts an RBF request, and renegotiates a dual-funder’s > > funds, dust limit, and channel reserve, and sends the dual-funder’s > updated > > puts. > > I would make this an empty message, simply an ack. And note that > the channel_id after this is that of the RBFed tx. > > The question then becomes what do we do about reconnection. I suggest: > > opener: if we haven't sent funding_signed, consider it cancelled. If > we've received funding_signed, it's obviously locked in. If we sent > and didn't received, re-xmit. > > accepter: must remember rbf if we sent commitment_signed2. If we > received funding_signed it's locked in. If we receive an init_rbf, > drop the one we remembered. If we receive funding_signed, continue. > > We still need to address the funding_tx construction; BIP69-style seems > like an unnecessary information leak here. A 128-bit seed in > open_channel2 could be added, with sorting by SHA(seed | <marshal of > input> | <marshal of witness>) and SHA(seed | <marshal of output>)? > > Phew! > Rusty. >
lisa neigut <niftynei at gmail.com> writes:
Quoted text (9 lines)
>> The receiving node MUST fail the channel if: >> ... >> - `option_dual_fund` has been negotiated. >> > > Does v2 of channel open necessarily deprecate the original between two > upgraded nodes? > > This seems more sane than having both as an option...will update.
Yes. This is a nod to the future in which we drop the old open_channel mechanics altogether.
Quoted text (4 lines)
>> Oh, it needs to check max_extra_witness_len is reasonable too, since >> that will affect the fees. Each signature adds 74, and pubkey adds 34, >> so I think MUST BE less than 500 is perfectly reasonable (for both >> reader and writer).
OK, I've reconsidered the format slightly; we should just send `max_witness_len` and not send *any* witness at this stage. Send the entire witness in `funding_signed2`.
This now means we need room for the script itself, so perhaps relax this value to 1000?
Quoted text (7 lines)
>> - MAY send init_rbf if it considers the most recent funding tx unlikely >> to be confirmed in reasonable time. >> - MUST set `feerate_per_kw` larger than the most recent funding tx. >> > > Another good reason to break out `funding_txn_feerate_per_kw` from > `commitment_txn_feerate_per_kw` in `open_channel2`
Agreed; BTW I kinda wish bitcoin uses 'txn' instead of 'tx' to abbreviate transaction since I used to read 'tx' as 'transmit'. But I've been brainwashed now so it doesn't matter any more...
Quoted text (11 lines)
>> Do we really want to negotiate everything again? It seems like the >> funder should be able to maybe add *new* inputs and outputs (though TBH >> I think that's going to be unusual enough that we could omit it), but >> doing a wholesale replacement means we have to be careful that the all >> RBFs end up having at least one input in common. Yech. >> > > Only allowing the opener to add new inputs/outputs drives down the scope of > a RBF a good deal. I like it. > Adding new inputs seems like a common sense bare minimum, especially if we > assume wildly unpredictable fee rates.
You need be able to specify new outputs with new inputs (change); except of course you want to be able to simply so you probably need to specify *new* inputs, and *all* your outputs (since the other side doesn't care about what outputs you use, you might even eliminate some for all I care).
This seems asymmetrical, but I love protocols which are hard to mis-implement.
Quoted text (23 lines)
>> But it's an excellent point I had missed. The channel_id changes on >> each renegotiation. We could either switch channel_id *after* >> each accept_rbf, or keep the original channel_id until funding_locked2 (in >> which case it should have a "final_channel_id" field, to make sure we're >> talking about the same funding tx). >> >> Since we have to handle the "oops, old one got in!" it might be weird to >> see `funding_locked2` with an old txid. Perhaps we stick with the >> original channel_id until then, and flip *after* funding_locked2 is sent >> and received. >> >> > Would it be more sane to continue to include the temporary channel id, > in addition to the 'current' (i.e. most recently negotiated funding txn) > channel id, > until the funding_locked2 is sent (adds a `temporary_channel_id` field for > `commitment_signed2`, ` funding_signed2` and `funding_locked2`, in addition > to `channel_id`)? > That way, all opening messages would have a stable id across an RBF > re-negotiation, `temp_channel_id`. > Sticking with the first broadcast funding transaction hash feels > a bit misleading in the case of a second round of `commitment_signed2` and > `funding_signed2`.
I hate temporary_channel_id, because (as specced) it's an untrusted
value. See Matt's complaints about it:
https://github.com/lightningnetwork/lightning-rfc/pull/496
That was bearable though, because it only lasted 3 messages (open, accept, funding_created).
Strawman idea: for dual funded channels, `channel_id` is based not on the txid, but the SHA256(open_channel2.revocation_basepoint | accept_channel2.revocation_basepoint). That must be unique, and we can use this same value to sort the tx, FWIW.
We'd still use the `temporary_channel_id` for open_channel2 and the accept_channel2 reply (to match them), but we don't ever need to change again.
Cheers, Rusty.