Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option_will_fund: liquidity ads #878

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,4 @@ ints
replaceability
disincentivize
UTXOs
blockheight
164 changes: 163 additions & 1 deletion 02-peer-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,10 @@ This message initiates the v2 channel establishment workflow.
2. data:
* [`...*byte`:`type`]
1. type: 2 (`require_confirmed_inputs`)
1. type: 3 (`request_funds`)
niftynei marked this conversation as resolved.
Show resolved Hide resolved
2. data:
* [`u64`:`requested_sats`]
* [`u32`:`blockheight`]

Rationale and Requirements are the same as for [`open_channel`](#the-open_channel-message),
with the following additions.
Expand All @@ -1185,11 +1189,19 @@ The sending node:
- MUST set `funding_feerate_perkw` to the feerate for this transaction
- If it requires the receiving node to only use confirmed inputs:
- MUST set `require_confirmed_inputs`
- if is accepting a `option_will_fund` offer from the peer's
`node_announcement`:
- MUST set `requested_sats` to the amount of sats they are requesting
the peer contribute to the channel in their `funding_satoshi`
- MUST set `blockheight` to the blockheight to be used
to calculate the commitment transaction accepter's CLTV encumbrance

The receiving node:
- MAY fail the negotiation if:
- the `locktime` is unacceptable
- the `funding_feerate_perkw` is unacceptable
- if the `option_will_fund` tlv is present and:
- the `blockheight` is considered too far in the past or future
- MUST fail the negotiation if:
- `require_confirmed_inputs` is set but it cannot provide confirmed inputs

Expand Down Expand Up @@ -1223,7 +1235,11 @@ as a convenience for implementations.

The sending node may require the other participant to only use confirmed inputs.
This ensures that the sending node doesn't end up paying the fees of a low
feerate unconfirmed ancestor of one of the other participant's inputs.

If the receiving node has advertised `option_will_fund`, opener
may `request_funds` from the peer. They provide an amount requested
and a `blockheight` which is the starting point for the funding lease
of 4032 blocks.

### The `accept_channel2` Message

Expand Down Expand Up @@ -1258,6 +1274,18 @@ acceptance of the new channel.
2. data:
* [`...*byte`:`type`]
1. type: 2 (`require_confirmed_inputs`)
1. type: 3 (`will_fund`)
2. data:
* [`signature`:`signature`]
* [`lease_rates`:`lease_rates`]

1. subtype: `lease_rates`
2. data:
* [`u16`:`funding_weight`]
* [`u16`:`lease_fee_basis`]
* [`u16`:`channel_fee_max_basis`]
* [`u32`:`lease_fee_base_sat`]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep channel base fees in a way where we can omit it thanks to truncated ints:

Suggested change
* [`u32`:`lease_fee_base_sat`]
* [`u32`:`lease_fee_base_sat`]
* [`tu32`:`channel_fee_base_msat_max`]

* [`tu32`:`channel_fee_max_base_msat`]

Rationale and Requirements are the same as listed above,
for [`accept_channel`](#the-accept_channel-message) with the following
Expand All @@ -1270,10 +1298,47 @@ The accepting node:
- MAY respond with a `funding_satoshis` value of zero.
- If it requires the opening node to only use confirmed inputs:
- MUST set `require_confirmed_inputs`
- if the `option_will_fund` tlv was sent in `open_channel2`:
- if they decline to contribute funds or to be paid for their
contributions:
- SHOULD omit the `will_fund` tlv
- if they decide to accept the offer:
- MUST include a `will_fund` tlv
- MUST set `funding_satoshis` to a value greater than 0msat
- MAY send `funding_satoshis` less than `requested_sats`
- MUST set `lease_fee_base_sat` to the base fee
(in satoshi) it will charge for the `funding_satoshis`
- MUST set `lease_fee_basis` to the amount
(in thousandths of satoshi) it will charge per `funding_satoshi`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was basis points, thus ten thousandths of satoshi? Same for channel_fee_basis_max below. The formula used in the examples below uses 1/10_000.

- MUST set `funding_weight` to the weight they will charge
the peer for.

- MUST set `channel_fee_base_max_msat` to the max base fee
(in millisatoshi) it will charge for any HTLC on this channel
during the funding period.
- MUST set `channel_fee_max_basis` to the max amount
(in thousandths of a satoshi) it will charge per transferred
satoshi during the funding period.
- MUST set `signature` to the ECDSA signature of
SHA256("option_will_fund" || `funding_pubkey`|| `blockheight` ||
`channel_fee_base_max_msat` || `channel_fee_max_basis`)
using the node_id key.

The receiving node:
- SHOULD fail the negotiation if:
- they sent `request_funds` tlv and:
- the `funding_satoshi` is less than required
- the `lease_fee_basis` is too high
- the `lease_fee_base_sat` is too high
- the `funding_weight` is too high
t-bast marked this conversation as resolved.
Show resolved Hide resolved
- the `channel_fee_max_basis` is too high
- the `channel_fee_max_base_msat` is too high
- the `signature` is invalid
- SHOULD accept the negotiation if:
- the `funding_satoshi` is excess of `requested_sats`
- MUST fail the negotiation if:
- `require_confirmed_inputs` is set but it cannot provide confirmed inputs
- `will_fund` tlv was recieved and they DID NOT send a `request_funds` tlv

#### Rationale

Expand All @@ -1286,6 +1351,44 @@ Instead, the channel reserve is fixed at 1% of the total channel balance
rounded down to the nearest whole satoshi or the `dust_limit_satoshis`,
whichever is greater.

If the opener requested a `option_will_fund` peer to contribute funds to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option_will_fund doesn't exist, this doesn't need a feature bit since it instead relies on a TLV in node_announcement.

this channel, via the inclusion of a `will_fund` tlv in their
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this channel, via the inclusion of a `will_fund` tlv in their
this channel, via the inclusion of a `request_funds` tlv in their

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The will_fund is present also down in this file, worried that @niftynei want to express anything else with this field?

Or it is just a typo?

`open_channel2`, the peer may or may not choose to accept the offer.

If the accepter node has run out of available funds, they should
either fail the negotiation or reply with a `funding_satoshi` set
to 0msat and no `will_fund` TLV, allowing the peer to fail the negotiation.

`funding_weight` is the weight it will cost the node to
contribute the offered funds to the channel. This is added to the
total lease fee at a rate of `funding_weight` times the
`funding_feerate_perkw` established in `open_channel2`.

The total lease fee is added to the accepter node's output in the
commitment transaction. It is equal to the `lease_fee_base_sat` +
min(`accept_channel2`.`funding_satoshis`,`open_channel2`.`requested_sats`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it says lease_fee_basis is charged only for requested_sats even if extra funding_satoshis are provided.

However, the requirements above state that lease_fee_basis is charged for the full funding_satoshis amount.

Please clarify.

* `lease_fee_basis` / 10_000 + `funding_feerate_perkw` *
`funding_weight` / 1000, rounded down to the nearest satoshi. See [Appendix A: The lease fee](#appendix-a-the-lease-fee).

`signature` signs the leasing node's `funding_pubkey`, the
lease expiration block (opener's `blockheight` + 4032), and the returned
`channel_fee` parameters. This provides the opener
with proof in the case the accepter does not maintain the stated
`channel_fee` rates during the channel's funding lease.

The lessor is the `accepter`, who contributes funds to the channel for a fee.
The lessee is the `opener`, who requests for funds and pays the lessor a fee
for the funds they contribute to the channel. A lease is defined as being for
4032 blocks; a `lease_end` is defined as the `open_channel2`.`blockheight`
+ 4032. If the initiating node sent `request_funds` and the
accepting node replied with `will_fund` this channel is considered 'leased'.
Comment on lines +1383 to +1384
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except the opener can still decide it doesn't like the terms provided in will_fund (e.g., if the terms have changed from what was advertised) and abort.

Intuitively, I'd consider the channel 'leased' once tx_signatures or channel_ready have been exchanged.


During the duration of the lease, the lessee may limit
the rate funds are routed through the channel as this provides the lessor
the opportunity to move the funds elsewhere (and renders the
lease lock fairly useless). A sensible policy here depends on the
motivation of the lessee in acquiring the lease.

### Funding Composition

Funding composition for channel establishment v2 makes use of the
Expand Down Expand Up @@ -2312,6 +2415,12 @@ be trimmed at the updated feerate, this could overflow the configured
`max_dust_htlc_exposure_msat`. Whether to close the channel preemptively
or not is left as a matter of node policy.

The lessor's lease is only shortened when a new `blockheight` is committed,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph is obsolete, it only made sense when using CSVs?

otherwise it's always 4032 blocks in the future. If the peer doesn't
update the blockheight, at some point it has to start the closing process
to retrieve its funds. 1008 blocks seems a reasonable (but not compulsory!)
answer here.

## Message Retransmission

Because communication transports are unreliable, and may need to be
Expand Down Expand Up @@ -2578,6 +2687,59 @@ interactive transaction construction, or safely abort that transaction
if it was not signed by one of the peers, who has thus already removed
it from its state.

## Appendix A: The lease fee (`option_will_fund`)

The lease fee is added to the accepter's balance in a channel, in addition
to the `funding_satoshi` that they are contributing. The channel initiator
must contribute enough funds to cover `open_channel2`.`funding_satoshis`,
the lease fee, and their tx weight * `funding_feerate_perkw` / 1000.

The lease fee is calculated as:

`lease_fee_base_sat` +
min(`accept_channel2`.`funding_satoshis`, `open_channel2`.`requested_sats`) * `lease_fee_basis` / 10_000 +
`funding_weight` * `funding_feerate_perkw` / 1000

E.g.
An node requests 1_000_000sats at a feerate of 2500perkw. They
are contributing 500_000sats. Their weight contribution to the
funding transaction will be 720.

The accepter adds 1,100,000sats and charges a base funding fee of
233sats with a lease fee basis of 22. Their funding weight is 444.
The lease fee is as follows:

233 + min(1_000_000,1_100_000) * 22 / 10_000 + 444 * 2500 / 1000

The total lease fee for this open is 3543sats.

The outputs to the peers in the commitment transaction will be

to-opener: 500_000sats
to-accepter: 1_103_543sats

The miner fee for the opener will be 720 * 2500 / 1000 or 1800sats.

Minimum funds that the opener must contribute to the channel open
transaction:

open_channel2.funding_satoshis: 500_000sats
lease fee: 3_543sats
miner fee: 1_800sats

total required contribution: 505_343sats

Minimum funds that the accepter must contribute to the channel open
transaction:

accept_channel2.funding_satoshis: 1_100_000sats
miner fee[1]: 1_110sats

total required contribution: 1_101_110sats


[1] assumes `444` is their total weight for this transaction.

# Authors

[ FIXME: Insert Author List ]
Expand Down
Loading