Research/Bitcoin Dev Archive / lightning-dev list
Resizing Lightning Channels Off-Chain With Hierarchical Channels
11 messages, Mar 18 to Apr 28, 2023. Started by jlspc.
jlspc (6), Anthony Towns (4), David A. Harding
TL;DR =====
* Dynamic management of Lightning channel capacity is required to support efficient Lightning Network (LN) payments - On-chain resizing introduces delays, adds costs and limits scalability - Fast and cheap resizing may be required to support watchtower-free LN payments for casual users - Channel factories allow off-chain channel resizing, but only by exchanging capacity within a single factory * Hierarchical channels allow flexible, off-chain resizing of channels - They don't require an exchange of capacity within a limited pool of users - They also support watchtower-free casual users without stranding any channel capacity * Hierarchical channels do for channel capacity what the LN does for bitcoin * No change to the underlying Bitcoin protocol is required
Overview ========
The ability to move Lightning channel capacity to where it's most needed is central to the efficient operation of the LN. In fact, it's been stated that the "main (probably only) job of" a dedicated Lightning user "is to efficiently allocate their liquidity" [10].
The use of on-chain transactions to resize channels limits the LN's scalability and increases its fees. In addition, resizing channels on-chain can introduce substantial delays. In fact, delays of multiple months are possible in the case of a casual user who operates in a watchtower-free manner [3], thus stranding capital and potentially preventing such users from operating in a watchtower-free manner in the current environment [10].
Existing proposals for resizing channels off-chain consist of creating a channel factory [1] or CoinPool [7] and exchanging capacity between channels within the same factory or pool. However, only a very small fraction of the LN's channels can be expected to be in a single factory or pool [8], so the ability to match channels that have insufficient capacity with channels that have excess capacity is highly constrained.
This post uses hierarchical Lightning channels to solve two problems.
First, as long as Lightning channels are created within hierarchical channels, it's possible to resize them flexibly, nearly instantly and off-chain. Thus, hierarchical channels do for channel capacity what Lightning does for bitcoin. In fact, this is more than just an analogy, as the channel capacity is actually transferred over the LN.
Second, hierarchical channels can be created by a casual user and a pair of dedicated users such that the casual user can send and receive bitcoin in a watchtower-free manner, while the dedicated users can use all of their channel capacity to route payments even while the casual user is inactive. As a result, casual users can operate in a watchtower-free manner without stranding any capital.
The remainder of this post describes hierarchical channels and how to use them. A more complete description, including figures, is available in a paper [6].
Hierarchical Channels =====================
A *party* is a group of one or more users. A *hierarchical channel* is a 2-party channel that has two main outputs, one per party, plus zero or more HTLC outputs. Each output from a hierarchical channel that pays to a multi-user party funds another (potentially hierarchical) channel. As a result, each output in a hierarchical channel (including an HTLC output once it has been resolved) can be viewed as the root of an off-chain tree of outputs where the leaves are owned by single users.
In order to update a hierarchical channel, funds are offered by one party to the other party in an HTLC. One user within the party offering the HTLC is designated as the *payer* and one user within the party offered the HTLC is designated as the *payee*. All of the funds for the HTLC are provided by the payer, and if the HTLC succeeds, the bulk of the funds go to the payee (but users within the offered party other than the payee can also get routing fees). Before the channel state is updated to include a new HTLC output, all of the users in the channel sign new transactions that spend the new channel state's main outputs, its existing HTLC outputs, and the new HTLC output. The users then sign transactions that implement the new channel state (including the new HTLC output) and revoke the previous channel state. Once the HTLC is resolved, the channel state is updated to include the HTLC's funds in the offered party's main output (if the HTLC succeeded) or in the offering party's main output (if the HTLC failed).
Because the two parties within a hierarchical channel can use an HTLC to exchange bitcoin, they can link their HTLC to HTLCs in other (potentially hierarchical) channels, thus making payments over the LN. In particular, each party in a (potentially hierarchical) channel appears as a node in the LN channel graph and each (potentially hierarchical) channel appears as a pair of unidirectional edges linking the channel's two parties. As in the current LN, a payment consists of a path where the node that's offered an HTLC in one hop offers an HTLC in the next hop (and the user that is the payee in one hop is the payer in the next hop).
Resizing Routing Channels Off-Chain ===================================
Dedicated users who provide routing services to others can use hierarchical channels to resize their Lightning channels off-chain. For example, consider dedicated users A, B, C and D who create a hierarchical channel with parties AB and CD. This hierarchical channel's main outputs fund the (non-hierarchical) channels owned by AB and by CD. Also, assume that party CD has a separate hierarchical channel with (single-user) party E.
If AB wants to reduce the capacity of their (non-hierarchical) channel, they can create a payment through the LN from party AB (with user A being the payer) to party (and user) A consisting of the path AB -> CD -> E -> F -> G -> A. Because this payment is from party AB within the hierarchical channel owned by parties AB and CD, this payment reduces the value of the main output that pays to AB from this hierarchical channel. Furthermore, because the (non-hierarchical) channel owned by A and B is funded by the main output that pays to AB from that hierarchical channel, this payment reduces the size of the channel owned by A and B. Finally, because this payment is paid by A (as the payer within the offering party AB at the payment's first hop) and pays to A (as the payment's destination), user A neither gains nor loses funds (except for paying routing fees to users C, D, E, F and G).
Furthermore, as in any LN payment, each routing node that gains funds in one hop loses an identical (minus fees) amount of funds in the next hop, so their overall balance is unchanged (except for a slight increase due to fees). There's nothing new about this for routing nodes E, F and G, as they act as they do in the current LN. However, it's worth looking in more detail at routing node CD, as the existence of multi-user nodes in the LN is new with hierarchical channels.
Like any routing node, CD gains funds in the hierarchical channel with AB and loses an identical (minus fees) amount of funds in the hierarchical channel with E. Note that C and D also appear as nodes within the LN channel graph, the channel between C and D that's funded by the hierarchical channel with AB appears as a pair of unidirectional edges between C and D, and the channel between C and D that's funded by the hierarchical channel with E appears as a pair of unidirectional edges between C and D. Thus, the sum of the capacities of the two channels between C and D is unchanged, except for a slight increase due to fees.
The effects of this payment from AB to A on a portion of the LN channel graph are shown below. Each party appears as a box and each channel appears as a pair of directed edges between a pair of parties. The channel's capacity is shown between the pair of directed edges, and each party's balance appears either above or below the pair of edges.
200
PHYSICAL CHANNELS +--+ -> +--+
BEFORE AB -> A PAYMENT |C | 500 |D |
OF 100 UNITS PLUS FEES | | <- | |
| | 300 | |
| | | |
800 800 400 200 500 500 | | 700 | |
+--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ | | -> | |
|AB|1300 |CD|1000 |E |1000 |F | 400 |G | 700 |A | 800 |B | | | 800 | |
+--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ +--+ <- +--+
500 200 600 200 200 300 100
308
PHYSICAL CHANNELS +--+ -> +--+
AFTER AB -> A PAYMENT |C | 609 |D |
OF 100 UNITS PLUS FEES | | <- | |
| | 301 | |
| | | |
691 694 296 98 400 391 | | 594 | |
+--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ | | -> | |
|AB|1300 |CD|1000 |E |1000 |F | 400 |G | 700 |A | 691 |B | | | 694 | |
+--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ +--+ <- +--+
609 306 704 302 300 300 100
Logical vs. Physical Channels =============================
Because there are two separate channels between C and D (one funded by the hierarchical channel with AB and the other funded by the hierarchical channel with E), it's natural to express these channels as two separate pairs of edges between C and D (as is shown above). However, a better viewpoint is obtained by logically merging the two physical channels between C and D into a single logical channel containing the sum of the capacities of the two physical channels. In fact, a large payment can be routed between C and D by using parallel HTLCs in the two physical channels connecting them. In addition, when logical (rather than physical) channels are advertised to LN peers, the resulting channel capacities are much more stable, as they don't change (other than increasing due to fees) when the parties owning the channel are used to route a payment.
For example, in the payment shown above the capacity of the channel between A and B is decreased by the amount of the payment from AB to A (plus fees), and the capacity of all other logical channels (including the one between C and D) is unchanged (other than increases due to fees).
LOGICAL CHANNELS BEFORE AB -> A PAYMENT OF 100 UNITS PLUS FEES
800 800 400 200 500 500 900
+--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ +--+ -> +--+
|AB|1300 |CD|1000 |E |1000 |F | 400 |G | 700 |A | 800 |B | |C |1300 |D |
+--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ +--+ <- +--+
500 200 600 200 200 300 400
LOGICAL CHANNELS AFTER AB -> A PAYMENT OF 100 UNITS PLUS FEES
691 694 296 98 400 391 902
+--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ -> +--+ +--+ -> +--+
|AB|1300 |CD|1000 |E |1000 |F | 400 |G | 700 |A | 691 |B | |C |1303 |D |
+--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ <- +--+ +--+ <- +--+
609 306 704 302 300 300 401
Of course, the example given above could be reversed (by making a payment from A to AB) in order to increase the capacity of the channel between A and B off-chain.
Supporting Casual Users Without Stranding Capacity ==================================================
Hierarchical channels can also be used to support watchtower-free casual users without stranding any channel capacity. Consider a watchtower-free casual user A who creates a hierarchical channel with dedicated users B and C, where A is one party and BC is the other party in the channel. Assume A wants to make a payment to G, and that party BC has a separate hierarchical channel with user D, D has a channel with E, E has a channel with F, and F has a channel with G. In this case, A can create a payment through the LN consisting of the path A -> BC -> D -> E -> F -> G.
Of course, this example could be reversed in order to make a payment from G to casual user A.
The key observation is that whenever A is neither sending nor receiving a payment, dedicated users B and C can utilize all of the capacity in the channel between them to route LN payments. Also, note that as long as B and C advertise their two physical channels (namely the one funded by the hierarchical channel shared with A and the one funded by the hierarchical channel shared with D) as a single logical channel, the capacity of the logical channel is unchanged (other than in increase due to fees) when B and C route payments to and from A.
Protocols For Hierarchical Channels ===================================
Several issues have to be addressed in order to create a protocol for hierarchical channels.
First, each main output (or resolved HTLC output) from a hierarchical channel must be able to pay to a tree of transactions that distribute the output's funds to individual users at the leaves. This can be achieved by requiring the users in the hierarchical channel to exchange signatures for the tree of transactions that spend each output of a given Commitment transaction prior to signing that Commitment transaction.
Second, a Lightning channel is currently announced with a channel_announcement message that references the on-chain UTXO funding the channel and the channel's capacity is static. These channel_announcement messages won't work for hierarchical channels that are funded by off-chain UTXOs and have dynamic capacities. Russell's proposal [9] for channel_update_v2 messages is well-suited to hierarchical channels as it merges the concepts of channel announcements and channel updates and it includes the channel's capacity, thus supporting dynamic capacities. In addition, it supports channels that are funded off-chain by allowing on-chain UTXOs to be cited when announcing channels with capacities that are at most a fixed multiple of the on-chain UTXOs' value.
Third, hierarchical channels need to support more than two users per channel. The current Lightning channel protocol only works for 2-user channels, as it penalizes a user that puts an old Commitment transaction on-chain by allowing the other user to obtain all of the channel's funds. Such an approach doesn't work if there are more than two users in the channel, where at least two are dishonest. In such a case, a dishonest user could put an old Commitment transaction on-chain and another dishonest user could "punish" that user by claiming all of the channel funds, including those from the honest users. Even if the dishonest users can't guarantee that they'll take the channel's funds, the expected value obtained by dishonest behavior could exceed the expected value from honest behavior.
In contrast, channel factory protocols are designed to allow more than two users to update factory states off-chain, where each factory state consists of a division of the factory's funds among the factory's users. Therefore, if we define the hierarchical channel's state as consisting of its two main outputs, plus any HTLC outputs, a channel factory protocol can be used to update the channel's state off-chain. In particular, the Invalidation Tree protocol [2], the Tunable-Penalty Factory protocol [5] or the Single-Commitment Factory protocol [5] can be used. Of these, the Tunable-Penalty Factory protocol appears most attractive, as it requires only O(1) time and O(1) on-chain bytes for a unilateral close.
Finally, in addition to maintaining the channel's current set of outputs, each HTLC output must be resolved according to the terms of its associated HTLC. A simple approach, based on the current Lightning protocol, is to allow the HTLC output to be spent by either: * an HTLC-success transaction put on-chain by the payee and providing the HTLC's required preimage, or * an HTLC-timeout transaction put on-chain by any user within the offering party after the HTLC's expiry.
This approach works, but it has two serious performance problems: 1) resolving an HTLC on-chain requires closing the hierarchical channel, and 2) the latency required for putting the HTLC output on-chain can significantly delay the HTLC's expiry.
Fortunately, both of these performance challenges are solved by using separate control transactions to resolve the HTCLs, as is done in the FFO and FFO-WF channel protocols [4]. Specifically, the FFO protocol can be extended to resolve HTLCs in hierarchical channels owned by more than two dedicated users, and the FFO-WF protocol can be extended to resolve HTLCs in hierarchical channels with more than two users, exactly one of whom is a casual user. The details are given in the paper [6].
Conclusions ===========
Sending bitcoin between users can be performed on-chain. However, allocating bitcoin to a Lightning channel allows it to be sent off-chain nearly instantly, with much lower fees, and in a far more scalable manner.
Similarly, Lightning channel capacity can be moved to where it's needed on-chain. However, allocating Lighting channel capacity within a hierarchical channel allows the channel to be resized off-chain nearly instantly, with much lower fees, and in a far more scalable manner.
In addition, hierarchical channels can be used to support watchtower-free casual users without stranding any Lightning channel capacity. As a result, providing watchtower-freedom to casual users appears to be cost-effective.
Given that these results can be achieved without making changes to the underlying Bitcoin protocol, it's hoped that hierarchical channels will eventually be adopted in BOLTs and implemented in order to improve the scalability, efficiency, and usability of the Lightning network.
Regards, John
[1] Burchert, Decker and Wattenhofer, http://dx.doi.org/10.1098/rsos.180089 [2] Decker and Wattenhofer, https://tik-old.ee.ethz.ch/file/716b955c130e6c703fac336ea17b1670/duplex-micropayment-channels.pdf [3] Law, https://github.com/JohnLaw2/ln-watchtower-free [4] Law, https://github.com/JohnLaw2/ln-factory-optimized [5] Law, https://github.com/JohnLaw2/ln-efficient-factories [6] Law, https://github.com/JohnLaw2/ln-hierarchical-channels [7] Naumenko and Riard, https://coinpool.dev/ [8] Riard, https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-April/020370.html [9] Russell, https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/lightning-gossip-alternative#m-8dc7318c [10] Teinturier, https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/watchtower-free-lightning-channels-for-casual-users#m-d7219bfb
Sent with [Proton Mail](https://proton.me/) secure email.
Hi John,
Thank you for another innovative application of your tunable penalties. I see two key benefits being described by your paper[1]:
- **Offchain channel resizes:** in state 0, Alice and Bob share control over an offchain UTXO valued at x satoshis; in state 1, the value of the offchain UTXO is y satoshis.
- **Liquidity multiplexing:** Alice, Bob, Carol, and Dan each rightfully own some portion of a UTXO. Alice and Bob expect to always be available; Carol and Dan may sometimes be unavailable. The proposal allows Carol and Dan to spend/receive in combination with Alice and Bob, but also ensures Alice and Bob can spend back and forth the entirety their portions of the UTXO even if Carol, Dan, or both of them are unavailable.
For the Offchain Channel Resizes, I don't see how your proposal functionally differs from a classic channel factory. In section 3, you show the set {A, B, C, D} with the subset {A,B} where A reduces its balance in {A,B} by transfering it to {C,D} via an HTLC to another of its nodes (A').
Your description uses hierarchical channels (which may have >2 participants per channel). In a classic pair-producing channel factory, each channel only has two participants, e.g. the factory {A, B, C, D} produces the channels,
{A,B}
{A,C}
{A,D}
{B,C}
{B,D}
{C,D}
However, the same thing is possible, A as part of {A,B} can pay through {B,C} out of the factory to A'. After the HTLCs are settled, the offchain channel setup transactions inside the factory can be regenerated with the cooperation of all {A, B, C, D}.
Am I missing something, or is this first key benefit something that was already possible (in theory) with pair-producing channel factories?
For the Liquidity Multiplexing, this does feel like a significant advance. In a pair-producing channel factory, any funds A has in {A, C} or {A, D} can't be spent when C or D are unavailable. In your proposal, {A, B} form one half of {{A,B},C} and {{A,B},D}, allowing {A,B} to redistribute their portion of the funds when C and D are unavailable. That's not an advantage of multiparty channels that I've seen described before, and not something I've been able to think how to functionally reproduce with pair-producing channel factories.
Given that it took me a while to understand the Liquidity Multiplexing, I wanted to double check to see if I had missed something about the Offchain Channel Resizes?
Thanks again,
-Dave
[1] https://github.com/JohnLaw2/ln-hierarchical-channels
On Sat, Mar 18, 2023 at 12:41:00AM +0000, jlspc via Lightning-dev wrote:
Quoted text (1 line)
> TL;DR
Even with Harding's optech write ups, and the optech space, I barely follow all this, so I'm going to try explaining it too as a way of understanding it myself; hopefully maybe that helps someone. Corrections welcome, obviously!
I think understanding all this requires going through each of the four steps.
Step 1: Tunable penalties; https://github.com/JohnLaw2/ln-tunable-penalties https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/lightning-channels-with-tunable-penalties#m-175394aa
This is a clever constructions that lets you do a 2-party lightning channel with existing opcodes where cheating doesn't result in you losing all your funds (or, in fact, any of your in-channel funds). It also retains the ability to do layered commit transactions, that is you can immediately commit to claiming an HTLC or that it's already timed out, even while you're waiting for the to_self_delay to expire to ensure you're not cheating.
The way that it works is by separating the flow of channels funds, from the control flow. So instead of managing the channel via a single utxo, we instead manage it via 3 utxos: F (the channel funds), InA (control flow for a unilateral close by A), InB (control flow for a unilateral close by B).
For each update to a new state "i", which has "k" HTLCs, we create 4 primary txs, and 8k HTLC claims.
StAi which spends InA, and has k+1 outputs. The first output is used for controlling broadcast of the commitment tx, the remaining k are for controlling the resolution of each HTLC.
ComAi is the commitment for the state. It spends the funding output F, and the first output of StAi. In order to spend StAi, it requires a to_self_delay (and signature by A), giving B time to object that i is a revoked state. If B does object, he is able to immediately spend the first output of StAi directly using the revocation information, and these funds form the penalty. It has k+2 outputs, one for the balance of each participant, and one for each HTLC.
For each of the k HTLCs, we construct two success and two timeout transactions: (HAi-j-s, HAi-j-p); (HAi-j-t, HAi-j-r). HAi-j-s and HAi-j-t both spend the jth output of StAi, conditional either on a preimage reveal or a timeout respectively; HAi-j-p and HAi-j-r spend the output of HAi-j-s and HAi-j-t respectively, as well as the output of ComAi. (s=success commitment, t=timeout commitment, p=payment on success, r=refund)
And Bob has similar versions of all of these.
So if Alice is honest, the process is:
* Alice publishes StAi
* Alice publishes HAi-j-{s,t} for any HTLCs she is able to resolve
immediately; as does Bob.
* Alice waits for to_self_delay to complete
* Alice publishes ComAi, and any HAi-j-{r,p} transactions she is able
to, and if desired consolidates her funds.
* As any remaining HTLCs resolve, those are also claimed.
* Bob's InB output is available to do whatever he wants with.
If Alice is dishonest, the process is:
* Alice publishes StAi, and perhaps publishes some HAi-j-{s,t}
transactions.
* Bob spends the first output of StAi unilaterally claiming the
* penalty, meaning ComAi can now never be confirmed.
* Bob publishes StBi', and continues with the honest protocol.
Bob only needs the usual O(log(n)) state in order to be able to reconstruct the key to spend the first output of revoked StAi txs. Because that prevents the corresponding ComAi from ever being published, no revoked HTLC-related state can make it on chain in any way that Bob needs to care about.
If both Alice and Bob are dishonest (Alice tries to cheat, but Bob restored from an old backup and also publishes a revoked state) then both the StAi and StBi' may have their first output claimed by the other party, in which case the channels funds are lost (unless Alice and Bob manage to agree to a cooperative close somehow, even after all the attempts to cheat each other).
While 4+8k transactions per state is a lot, I think you only actually need 2+4k signatures in advance (StAi and HAi-j-{s,t} only need to be signed when they're broadcast). Perhaps using ANYPREVOUT would let you reduce the number of HTLC states?
Step 2: Efficient Factories for Lightning Channels https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2023/efficient-factories-for-lightning-channels#m-f0fe1f08 https://github.com/JohnLaw2/ln-efficient-factories
This generalizes the tunable penalties setup for more than two participants.
The first part of this is a straightforward generalisation, and doesn't cover HTLCs. Where we had 2(2+4k) transactions previously, we presumably would now have P(2+4k) transactions, where P is the number of participants.
The second part of this aims to avoid that factor P. It does this by introducing Trigger and Mold transactions.
To do this, we first establish the number of states that the factory will support; perhaps 2**40. In that case, the trigger transaction will spend the funding tx, and have 40+1 outputs. All of them will require a P-of-P signature to be spend, with the first also requiring a relative timelock of 3*to_self_delay and containing the channel funds, while the rest contain dust-ish amounts.
For any given state i, we represent i as a binary number, and the commitment tx Com_i will spend the outputs corresponding to "0" in the binary number, as well as the first output containing the channel funds.
We will also have St{A..Z}_i transactions, spending In{A..Z} as previously. The sole output of StAi (etc) will be spent either by any other participant via a revoked pubkey, or else by the Mold{A..Z}_i transaction. The Mold{A..Z}_i transaction will also spend the remaining outputs of the Trigger transaction that were not spent by Com_i.
In the honest scenario, this looks like:
* Alice publishes Trigger * Alice publishes StA_i * Alice waits to_self_delay * Alice publishes MoldA_i * Alice waits an additional 2*to_self_delay * Alice publishes Com_i * Alice and everyone else claims their funds
There are various dishonest scenarios available:
* If Alice publishes StA_i before publishing the Trigger, someone else publishes the Trigger.
* If Alice doesn't publish StA_i quickly, Bob publishes StB_i
and continues. If multiple St{A..Z}_i's are published, whoever does
not publish the Mold transaction simply reclaims their funds by the
"revocation" path.
* If Alice publishes an old StA_i, Bob claims the funds using the revoked key, penalising A, and then publishes the correct StB_i, and continues.
* If Alice does not publish MoldA_i, Bob can publish StB_i and MoldB_i.
* Once MoldB_i is confirmed, someone could attempt to broadcast an outdated Com_i' where i' < i. In that case, the outputs corresponding to all the 1's in the binary representation of i are already spent (by MoldB_i), but for any i' < i, the i' necessarily has a 0 somewhere where i had a 1 (otherwise i' >= i), so Com_i' would be double spending an input already spent by MoldB_i.
In this case, you need to track P+1 outputs (F+InA..Z), you need O(P*log(N)) state, and the onchain impact of a unilateral close is ideally 4 transactions (Trigger, StAi, MoldAi, Comi) with size O(log(MaxN)), but maybe be up to 2*P+2 transactions (Trigger, St{A..Z}i, MoldAi, refund{B..Z}i, Comi).
Note that this doesn't consider HTLCs at all.
Step 3: Factory Optimized protocols for Lighting https://github.com/JohnLaw2/ln-factory-optimized https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/factory-optimized-protocols-for-lightning#m-5c0deb6d https://bitcoinops.org/en/newsletters/2022/12/14/#factory-optimized-ln-protocol-proposal
Perhaps this should have been step 2, whoopsie. Anyway, this optimises the construction in step 1 for channels included in factories; mostly to deal with the fact that closing a factory is tedious and can take a while. I'm ignoring the Partial-Factory-Optimized step -- it's barely different to the Tunable Penalty mechanism. The Fully Factory Optimized protocol is more interesting.
The main idea here is this: if a channel in a factory goes defunct while an HTLC is pending, we'd like to be able to guarantee we've resolved the HTLC to our satisfaction while deferring the decision of whether to shutdown the entire factory in order to close the channel, just in case our channel partner eventually comes back, and we can resolve everything properly.
The way we do that is twofold: first, we set things up so that the default resolution of an HTLC is a refund. That immediately does away with half of our HTLC transactions, because now we only need the success/payment paths, not the timeout/refund ones. Second, we require whoever's going to receive the payment to publish their StXi transaction -- that avoids us having to do P*k success/payment paths, now we only need 1*k success/payment paths. Unfortunately, we do introduce a new "kickoff" transaction to make it a three transaction kickoff/success/payment path, rather than just two transactions.
In this case your transactions are:
F - the funding output, only available once the factory is closed
InB - as before
StBi - your state commitment, one output that will be spent by ComBi,
k outputs for each pending HTLC paying to B in state i.
HBi-j-k - the kickoff transaction for HTLC "j" paying to B, spends
the appropriate output of StBi, conditional on revealing the
HTLC preimage and B's signature. Spendable either by B after
to-self-delay, or by A after the HTLC's expiry plus
to-self-delay
HBi-j-s - the success transaction, spendable by B
HBi-j-p - the payment transaction, spends HBi-j-s and the HTLC output
from ComB_i
HAi-j-p - the payment transaction, spends HBi-j-s and the HTLC output
from ComA_i
I think there's an error in the paper here; it says as well as being spendable by H{A,B}i-j-p as above, the HTLC output in ComA_i should be spendable by A after to-self-delay. I believe it should require both to-self-delay (relative timelock) and the HTLC expiry (absolute timelock) before it can be spendable by A.
Anyway, how's that work? If you want to shut the factory down immediately, it looks like:
* Shut the factory down * Broadcast StBi, HBi-j-k * Wait to-self-delay * Broadcast ComBi, HBi-j-s, HBi-j-p * Done!
If you were cheating, then:
* Alice steals StBi's first output if i was on old state, and ComBi cannot be broadcast. Alice publishes the current StAi', ComAi', etc.
* If the HTLC had timed out, Alice claims the output of HBi-j-k before to-self-delay is finished, so that HBi-j-p cannot be broadcast, then claims the output of ComBi once both timeouts are complete.
However, what if you don't want to shut the factory down? In that case:
* Broadcast StBi, HBi-j-k. * Wait for to_self_delay. * Spend HBi-j-k to HBi-j-s. * Wait some more. * The other guy comes online! Let's recover the channel! * Propose spending the first output of StBi and the output of HBi-j-s to a new InB2, but don't sign it. * Update all the off-chain channel data to a new state i+1 that uses InB2 instead of InB, and that acknowledges your claim to the HTLC funds. * Sign and broadcast InB2 * Continue
If the other guy doesn't come online, you close the factory, immediately spend F and the first output of StBi via ComBi, and immediately spend HBi-j-s and the HTLC output of ComBi to claim your funds.
While this is described as an optimisation focussed on improving channels within factories; it seems to me that the reduction in state compared to the "tunable penalties" approach in step 1 makes this a strict improvement in general.
Anyway, combining this step and the previous gives us an idea how to do both factories and HTLCs. I believe that would look like:
Factory funding output -- multisig of A..Z Factory In{A..Z}
Factory Trigger, spends the funding output
Factory St{A..Z}i spends In{A..Z}
Factory Mold{A..Z}i spends St{A..Z}i and various Trigger outputs
Factory Com_i spends the other Trigger outputs; its outputs are the
channels in the factory.
Channel F_x - an output of the Factory Com_i Channel InA, InB Channel StAi, StBi -- spends InA/InB Channel ComAi, ComBi -- spends F_x and the first output of StA/StB Channel H{A,B}i_j_{k,s,p} -- success path funds for active HTLCs
So to update the channel state, the channel participants need:
3*k HTLC transactions (only 1 pre-signed) 2 commitment transactions (both pre-signed) 2 St transactions (neither pre-signed)
Every time the factory updates, every channel state must also update (as the channel funding outputs will change txid).
Every participant needs 1+c "In" confirmed utxos available -- one for the factory itself, and one for each channel they're involved in.
Every participant needs to monitor P+c+1 outputs on chain -- the factory Funding output (which may be spent by the Trigger tx), the P St{A..Z}i outputs, and their counterparty's InX output for each channel they're participating in.
That's getting pretttty complicated, so I'm not confident I've got it all in my head correctly, but I think it still works.
I'm skipping over the watchtower-freedom/casual user section here. cf https://bitcoinops.org/en/newsletters/2022/10/12/#ln-with-long-timeouts-proposal
Step 4: Resizing Lightning Channels Off-Chain / Hierarchial Channels https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2023/resizing-lightning-channels-off-chain-with-hierarchical-channels#m-a7a29696 https://github.com/JohnLaw2/ln-hierarchical-channels https://bitcoinops.org/en/newsletters/2023/03/29/#preventing-stranded-capital-with-multiparty-channels-and-channel-factories
Hey, we made it to this thread!
I'm not entirely sure of the novelty in this proposal; once you have channels in factories, lots of magic is possible, but it's all very complex. I believe the particular proposal here is something like:
- Instead of just having Alice/Bob/Carol/etc as identities in lightning, let them "pair" up, so that AliceBob is considered a node, and CarolDave is also a node.
- So we have a utxo where AliceBob has a channel with CarolDave, and another where CarolDave has a channel with Elizabeth, eg.
- But actually the AliceBob/CarolDave utxo is a factory; and there's an internal channel between Alice and Bob, and another between Carol and Dave
- Now, because we describe AliceBob and CarolDave as a channel, that means funds can move between AliceBob and CarolDave; but that is equivalent to saying the overall capacity of the internal Alice/Bob channel is actually decreasing without any on-chain activity! Neat!
But... that was always the point of channel factories? And the specific structure of four participants split into a single pair of channels doesn't seem particularly compelling? I don't know, I feel like I'm missing something here. Or maybe it's just the first three steps were amazing, so merely interesting seems pedestrian by comparison?
Hmm, looking at Harding's email, I see:
Quoted text (7 lines)
> **Liquidity multiplexing:** Alice, Bob, Carol, and Dan each rightfully > own some portion of a UTXO. Alice and Bob expect to always be > available; Carol and Dan may sometimes be unavailable. The proposal > allows Carol and Dan to spend/receive in combination with Alice and > Bob, but also ensures Alice and Bob can spend back and forth the > entirety their portions of the UTXO even if Carol, Dan, or both of > them are unavailable.
I guess I'm not entirely enthusiastic about that because in that case Alice can only send funds to Carol when Dan (and whoever else is involved in the factory) eventually come online to signoff on the factory state update. That's still useful for (slow) offchain channel reallocations, but it doesn't seem reliable/fast enough for a payment.
For the case where all factory participants are reliably online (perhaps with some exceptions) I guess I could see that making sense? Then you're generally just treating it as a 4-party channel of A/B/C/D with everyone able to easily forward to anyone; but when Alice is offline for system maintenance for an hour every week, it automatically degrades to just having the Carol/Dave channel operational, with no other problems.
fin
Cheers, aj
Hi Dave,
Thank you for your clear and insightful response.
Comments inline below:
Quoted text (34 lines)
>Hi John,
>Thank you for another innovative application of your tunable penalties.
>I see two key benefits being described by your paper[1]:
>- **Offchain channel resizes:** in state 0, Alice and Bob share control
> over an offchain UTXO valued at x satoshis; in state 1, the value of
> the offchain UTXO is y satoshis.
>- **Liquidity multiplexing:** Alice, Bob, Carol, and Dan each rightfully
> own some portion of a UTXO. Alice and Bob expect to always be
> available; Carol and Dan may sometimes be unavailable. The proposal
> allows Carol and Dan to spend/receive in combination with Alice and
> Bob, but also ensures Alice and Bob can spend back and forth the
> entirety their portions of the UTXO even if Carol, Dan, or both of
> them are unavailable.
>For the Offchain Channel Resizes, I don't see how your proposal
>functionally differs from a classic channel factory. In section 3, you
>show the set {A, B, C, D} with the subset {A,B} where A reduces its
>balance in {A,B} by transfering it to {C,D} via an HTLC to another of its
>nodes (A').
>Your description uses hierarchical channels (which may have >2
>participants per channel). In a classic pair-producing channel factory,
>each channel only has two participants, e.g. the factory {A, B, C, D}
>produces the channels,
> {A,B}
> {A,C}
> {A,D}
> {B,C}
> {B,D}
> {C,D}
>However, the same thing is possible, A as part of {A,B} can pay through
>{B,C} out of the factory to A'. After the HTLCs are settled, the
>offchain channel setup transactions inside the factory can be
>regenerated with the cooperation of all {A, B, C, D}.
>Am I missing something, or is this first key benefit something that was
>already possible (in theory) with pair-producing channel factories?When the first key benefit is defined as:
Benefit 1: Ability to resize a channel owned by Alice and Bob offchain from x satoshis to y satoshis
you are correct that this can be achieved with existing techniques using channel factories.
However, when the key benefit is defined differently, it becomes clear that it can be achieved only with hierarchical channels. I'll give two other definitions of the benefit that demonstrate what is new. In these definitions, note that the quantity "delta" could be positive or negative. Also, assume that all capacity owned by the users considered must be in a Lightning channel at all times (in order to avoid stranding liquidity). Finally, for simplicity, ignore routing fees in the following.
Benefit 2: Ability to resize a channel owned by Alice and Bob offchain from x satoshis to y = x - delta satoshis, while resizing a channel owned by Harriet and Isaac from u satoshis to v = u + delta satoshis, where: a) Harriet and Isaac do not know Alice and Bob and never co-sign transactions with Alice and Bob, and b) all other 2-user channels' capacities are unchanged.
Note that Benefit 2 can't be achieved with channel factories, as they would violate requirement a) above. In contrast, Benefit 2 can be achieved with hierarchical channels, as long as all channels are viewed as logical (rather than physical) channels. An example of how this can be achieved is with the payment given in Figure 4 of the paper (p. 8), but stopping the payment one hop earlier as it is received by H and I (Harriet and Isaac). Benefit 2 matters, as it's a lot easier to find a channel that wants to make a capacity change that offsets the capacity change that Alice and Bob want to make if the offsetting channel can be anywhere in the world (but connected via the Lightning Network) as opposed to in a channel factory containing Alice and Bob (as there will only be, say, 10 or 100 users in each such factory). Having to offset a channel capacity change by finding a channel making the opposite change within a channel factory is like having to make LN payments without using HTLCs. It would be possible to make payments within a factory, but in most cases that wouldn't help, as the payer and payee would not happen to be in the same factory.
Benefit 3: Ability to resize a channel owned by Alice and Bob offchain from x satoshis to y = x - delta satoshis, where all other 2-user channels' capacities are unchanged.
Note that Benefit 3 cannot be achieved with channel factories, as any change in the capacity of a channel in a factory must be offset by the opposite change in one or more other channels within the factory (given our requirement that all capacity is always kept within channels in order to avoid stranding liquidity).
In contrast, Benefit 3 is possible with hierarchical channels, as long as they are viewed as logical channels. Examples include the payment shown in Figure 1 of the paper (p. 4). This somewhat surprising result is due to the existence of a 3-user hierarchical channel (namely the one owned by C, D and E in Figure 1) that transitions from HTLCs that swap capacity between pairs of 2-user channels to HTLCs that swap balances between users within a 2-user channel. This benefit is even stronger than the previous one, as no channel that wants to make an offsetting capacity change has to be found at all.
I hope these two explicitly-stated benefits demonstrate that hierarchical channels *do* provide new capabilities that did not exist previously, and that these new capabilities are very important in practice.
Please let me know if any of this doesn't make sense.
Thanks again, John
On Tue, Apr 04, 2023 at 12:00:32AM +1000, Anthony Towns wrote:
Quoted text (10 lines)
> On Sat, Mar 18, 2023 at 12:41:00AM +0000, jlspc via Lightning-dev wrote: > > TL;DR > > Step 1: Tunable penalties; > https://github.com/JohnLaw2/ln-tunable-penalties > https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/lightning-channels-with-tunable-penalties#m-175394aa > > This is a clever constructions that lets you do a 2-party lightning > channel with existing opcodes where cheating doesn't result in you > losing all your funds (or, in fact, any of your in-channel funds).
Ah, a significant difference between this and eltoo is in the game theory of what happens if you lose access to the latest state.
In eltoo, how things would work in that case, is that you would attempt to close the channel to an old state that you do still remember (from a backup), at which point either (a) your counterparty publishes a later state, and you settle with that (possibly with you paying some modest penalty if you're using a Daric-like protocol), or (b) your counterparty does nothing, and you settle at the old state.
With tunable penalties, you are in more of a quandry. If you broadcast an old "St" transaction to attempt to close to an old state, then your counterparty will simply claim those funds and penalise you; however there is nothing forcing them to publish any newer state as well. At that point your counterparty can hold your share of the channel funds hostage indefinitely.
Holding your funds hostage is probably an improvement on simply losing them altogether, of course, so I think this is still a strict improvement on ln-penalty (modulo additional complexity etc).
Cheers, aj
Hi aj,
Thanks for your great write-up!
Comments below:
Quoted text (6 lines)
> Even with Harding's optech write ups, and the optech space, I barely > follow all this, so I'm going to try explaining it too as a way of > understanding it myself; hopefully maybe that helps someone. Corrections > welcome, obviously! > I think understanding all this requires going through each of the four > steps.
[...]
Quoted text (24 lines)
> Step 3: Factory Optimized protocols for Lighting > <a href="https://github.com/JohnLaw2/ln-factory-optimized">https://github.com/JohnLaw2/ln-factory-optimized</a> > <a href="https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/factory-optimized-protocols-for-lightning#m-5c0deb6d">https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/factory-optimized-protocols-for-lightning#m-5c0deb6d</a> > <a href="https://bitcoinops.org/en/newsletters/2022/12/14/#factory-optimized-ln-protocol-proposal">https://bitcoinops.org/en/newsletters/2022/12/14/#factory-optimized-ln-protocol-proposal</a> > In this case your transactions are: > F - the funding output, only available once the factory is closed > InB - as before > StBi - your state commitment, one output that will be spent by ComBi, > k outputs for each pending HTLC paying to B in state i. > HBi-j-k - the kickoff transaction for HTLC "j" paying to B, spends > the appropriate output of StBi, conditional on revealing the > HTLC preimage and B's signature. Spendable either by B after > to-self-delay, or by A after the HTLC's expiry plus > to-self-delay > HBi-j-s - the success transaction, spendable by B > HBi-j-p - the payment transaction, spends HBi-j-s and the HTLC output > from ComB_i > HAi-j-p - the payment transaction, spends HBi-j-s and the HTLC output > from ComA_i > I think there's an error in the paper here; it says as well as being > spendable by H{A,B}i-j-p as above, the HTLC output in ComA_i should be > spendable by A after to-self-delay. I believe it should require both > to-self-delay (relative timelock) and the HTLC expiry (absolute timelock) > before it can be spendable by A.
It's not actually an error in the paper, because the paper includes a "max_cltv_expiry" parameter that prevents the race you're concerned about. However, it's easy to miss that parameter (it's only introduced in an appendix) and I like your idea of using an absolute delay in the HTLC output in ComA_i when it is spent by A. I plan to change the paper to add such an absolute delay (which I believe should be Alice's to-self-delay after the HTLC's expiry) and remove the "max_cltv_expiry" parameter. Thanks for the good idea!
Quoted text (4 lines)
> While this is described as an optimisation focussed on improving channels > within factories; it seems to me that the reduction in state compared to > the "tunable penalties" approach in step 1 makes this a strict improvement > in general.
I agree.
Quoted text (2 lines)
> Every participant needs 1+c "In" confirmed utxos available -- one for > the factory itself, and one for each channel they're involved in.
While 1+c "In" confirmed utxos will work, it's also possible to just have a single confirmed utxo and to create the 1+c desired "In" utxos from it by putting a transaction, or a tree of transactions, on-chain if and when needed. This optimization is described as the "Off-Chain Control Outputs" extension in the original Tunable Penalties paper and in the Factory Optimized Channels paper.
Quoted text (25 lines)
> Step 4: Resizing Lightning Channels Off-Chain / Hierarchial Channels > <a href="https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2023/resizing-lightning-channels-off-chain-with-hierarchical-channels#m-a7a29696">https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2023/resizing-lightning-channels-off-chain-with-hierarchical-channels#m-a7a29696</a> > <a href="https://github.com/JohnLaw2/ln-hierarchical-channels">https://github.com/JohnLaw2/ln-hierarchical-channels</a> > <a href="https://bitcoinops.org/en/newsletters/2023/03/29/#preventing-stranded-capital-with-multiparty-channels-and-channel-factories">https://bitcoinops.org/en/newsletters/2023/03/29/#preventing-stranded-capital-with-multiparty-channels-and-channel-factories</a> > Hey, we made it to this thread! > I'm not entirely sure of the novelty in this proposal; once you have > channels in factories, lots of magic is possible, but it's all very > complex. I believe the particular proposal here is something like: > - Instead of just having Alice/Bob/Carol/etc as identities in > lightning, let them "pair" up, so that AliceBob is considered a node, > and CarolDave is also a node. > - So we have a utxo where AliceBob has a channel with CarolDave, and > another where CarolDave has a channel with Elizabeth, eg. > - But actually the AliceBob/CarolDave utxo is a factory; and there's > an internal channel between Alice and Bob, and another between Carol > and Dave > - Now, because we describe AliceBob and CarolDave as a channel, that > means funds can move between AliceBob and CarolDave; but that is > equivalent to saying the overall capacity of the internal Alice/Bob > channel is actually decreasing without any on-chain activity! Neat! > But... that was always the point of channel factories? And the specific > structure of four participants split into a single pair of channels > doesn't seem particularly compelling? I don't know, I feel like I'm > missing something here. Or maybe it's just the first three steps were > amazing, so merely interesting seems pedestrian by comparison?
Thanks!
Quoted text (1 line)
>From my perspective, this paper makes two contributions (which, to be fair, may only be "interesting" :)
1) it allows dedicated users to resize Lightning channels off-chain by sending channel capacity over the Lightning network, and 2) it allows each casual user to work with a pair of dedicated users in order to let the casual user send and receive payments without forcing the dedicated users to leave any of the channel capacity idle when the casual user is unavailable.
I'll discuss 2) more below.
Regarding 1), I wouldn't say that "that was always the point of channel factories". While it's true that channel factories allow users to resize two-user channels off-chain, they can only do this subject to the following limitations: * whatever channel capacity change is being made is exactly offset by one or more other channel capacity changes in the other direction (assuming all factory capacity is in channels), * the desired change and the offsetting change(s) have to be within a single channel factory, and * every user in the factory has to be available to sign for the factory update.
The first two limitations make one want to create factories with lots of users (in order to have flexibility in finding offsetting channels), while the third limitation makes one want factories with few users (in order to enable obtaining all of the required signatures).
1) eliminates all of these limitations by allowing channel capacity to be routed over the Lightning Network. Previously, I hadn't realized this was possible.
As a result, hierarchical channels with just 3 or 4 users seem to be enough for resizing channels off-chain.
Quoted text (13 lines)
> Hmm, looking at Harding's email, I see: >> **Liquidity multiplexing:** Alice, Bob, Carol, and Dan each rightfully >> own some portion of a UTXO. Alice and Bob expect to always be >> available; Carol and Dan may sometimes be unavailable. The proposal >> allows Carol and Dan to spend/receive in combination with Alice and >> Bob, but also ensures Alice and Bob can spend back and forth the >> entirety their portions of the UTXO even if Carol, Dan, or both of >> them are unavailable. > I guess I'm not entirely enthusiastic about that because in that case > Alice can only send funds to Carol when Dan (and whoever else is involved > in the factory) eventually come online to signoff on the factory state > update. That's still useful for (slow) offchain channel reallocations, > but it doesn't seem reliable/fast enough for a payment.
I too would not be enthusiastic if a casual user could only send and receive funds when some other casual user is available. However, by using three-user channels (two of whom are dedicated), a casual user can send and receive without requiring availability from any other casual user (and without stranding funds).
Regards, John
Comments below:
Quoted text (23 lines)
>> Step 1: Tunable penalties; >> <a href="https://github.com/JohnLaw2/ln-tunable-penalties">https://github.com/JohnLaw2/ln-tunable-penalties</a> >> <a href="https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/lightning-channels-with-tunable-penalties#m-175394aa">https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/lightning-channels-with-tunable-penalties#m-175394aa</a> >> This is a clever constructions that lets you do a 2-party lightning >> channel with existing opcodes where cheating doesn't result in you >> losing all your funds (or, in fact, any of your in-channel funds). > Ah, a significant difference between this and eltoo is in the game > theory of what happens if you lose access to the latest state. > In eltoo, how things would work in that case, is that you would attempt > to close the channel to an old state that you do still remember (from a > backup), at which point either (a) your counterparty publishes a later > state, and you settle with that (possibly with you paying some modest > penalty if you're using a Daric-like protocol), or (b) your counterparty > does nothing, and you settle at the old state. > With tunable penalties, you are in more of a quandry. If you broadcast > an old "St" transaction to attempt to close to an old state, then your > counterparty will simply claim those funds and penalise you; however > there is nothing forcing them to publish any newer state as well. At > that point your counterparty can hold your share of the channel funds > hostage indefinitely. > Holding your funds hostage is probably an improvement on simply losing > them altogether, of course, so I think this is still a strict improvement > on ln-penalty (modulo additional complexity etc).
Yes, that's a good point.
I did describe an extension, called "Unilateral Close after an Old Transaction is Put On-Chain", in the Tunable Penalties paper and in the Factory Optimized Channels paper. The idea is to add a Trigger transaction that spends the output of the Funding transaction. In response to seeing the Trigger transaction, the other party can put their final State transaction and (after a to-self-delay) Commitment transaction on-chain. However, if the other party doesn't do so, then after a 3*to-self-delay, the party that forgot the state can initiate the Decker-Wattenhofer protocol to settle the channel. Of course, the eltoo protocol could be used instead of the Decker-Wattenhofer protocol at this point if APO is available.
Regards, John
On Sat, Apr 08, 2023 at 10:26:45PM +0000, jlspc via Lightning-dev wrote:
Quoted text (1 line)
> From my perspective, this paper makes two contributions (which, to be fair, may only be "interesting" :)
One thing that confuses me about the paper is how to think about routing to a "channel" rather than a node -- ie the payment from "E->FG->A" where "FG" isn't "F" or "G", but "both of them". It feels like there's a whole mass of complications hidden in there from a routing perspective; like how do you link "FG" back with "F" and "G", how do you decide fees, how do you communicate fees/max_htlc/etc. I think it also implies that channel capacity is no longer really something you can gossip very sensibly -- if you have a factory ((A,B),C,D,E) then every payment through AB to C or D or E will decrease AB's channel capacity. You could still gossip the capacity of the overall factory, and sum that to get an overall lightning network capacity, of course. But a lot of the ways of simplifying it also make it harder to do all the nice rebalancing.
Anyway, I've tried a few times now to put some thoughts together on that and come up with nothing that I'm happy with, so figured it might be at least worth posing explicitly as a problem...
Cheers, aj
Quoted text (3 lines)
> One thing that confuses me about the paper is how to think about routing > to a "channel" rather than a node -- ie the payment from "E->FG->A" where > "FG" isn't "F" or "G", but "both of them".
Yes, I found it very difficult to think about, and I kept getting confused between concepts like "user", "node", "channel", and "factory". The thing that works best for me is to create a clear definition of each of these terms, along with the term "party".
I also think it's best to imagine a world in which there are hierarchical channels, but there are no "factories" per se. The distinction is meaningful in the sense that a hierarchical channel requires that there are exactly *two* *fixed* "parties" to which the hierarchical channel pays out, and all changes to the balances paid to those parties are made via HTLCs. In contrast, a "factory" can pay out to an arbitrary number of users or groups of users, and changes to the balances paid to those users or groups of users are made via updating the state of the factory (typically without an HTLC being required).
So, in a world with hierarchical channels, but without factories, we have the following terms:
* User: a person
* Party: a fixed group consisting of one or more users
* Node: a party
- so "party" and "node" are synonyms, with "party" emphasizing the human side of things and "node" emphasizing the graph side of things, such as when discussing the Lightning routing graph
* Physical channel: a layer 2 construct that is funded by an on-chain or an off-chain UTXO, is owned by 2 parties, pays a balance to each of the parties, and updates the parties' balances through HTLCs and a channel protocol
- a physical channel can be non-hierarchical (where each of the 2 parties is a single user) or hierarchical (where at least one party consists of more than 1 user)
- (Footnote: The concept of an "off-chain UTXO" is itself a bit tricky, as it often refers to one of multiple possible transaction outputs, where the transactions or their ancestors conflict, so only one of them can actually be instantiated. For example, a Lightning channel (using the current penalty protocol) can be said to create an off-chain UTXO that pays to one of the users, even though it's not clear which of the users' Commitment transactions will actually be instantiated. In general, an off-chain UTXO is a guaranteed way of getting a certain portion of a specific on-chain UTXO's funds. Let's skip going down this rabbit hole any further and just assume we understand these issues.)
* Logical Channel: a layer 2 construct that consists of all of the physical channels owned by a specific pair of parties
- the size (capacity) of a logical channel is the sum of the sizes of their physical channels
- (Footnote: It's possible, with a significant amount of software development work that I in no way discount, to route a payment through a logical channel where the payment traverses multiple physical channels at the same time. This is done by using separate HTLCs, all sharing the same secret, in each of the physical channels that the payment traverses. I can write more about this if that would be helpful.)
* Lightning Network (LN): a layer 2 network consisting of parties and logical channels between parties
- the LN can be represented as a directed graph, where each party is a node and each logical channel is pair of arcs (one in each direction) between two nodes
- the LN can be used to make payments from one node to another node via a path through the graph
- the purpose of the payment could be to send bitcoin from one user to another (in this case, the payment's source and destination nodes are both 1-user parties)
- the purpose of the payment could be to increase or decrease the size of a logical channel (in this case, the payment's source and/or destination node is a multi-user party)
- (Footnote: Here's another great opportunity for confusion, as the source and/or destination of the payment is a multi-user party, which is defined as more than two users, and yet the purpose of the payment is to resize a logical channel. Obviously, a group of users is different from a logical channel (as shown in the definitions above), so how does making a payment to or from a group of users change the size of a logical channel? The answer is that the logical channel being resized is the one owned by the group of users.)
* Factory: a term that doesn't exist in this world view
Sorry if all of this seems overly pedantic. It's the only way I've been able to keep these concepts straight in my mind. I've also found that drawings help clarify these issues, which is why the paper has 20 drawings, many of which are examples of payments and channel graphs.
Quoted text (4 lines)
> It feels like there's a whole > mass of complications hidden in there from a routing perspective; like how > do you link "FG" back with "F" and "G", how do you decide fees, how do > you communicate fees/max_htlc/etc.
In addition to the assumptions and definitions above, we need to use Rusty Russell's idea for channel_update_v2 messages [1].
Regarding the specific issues you raised:
Q: How do you link "FG" back with "F" and "G"? A: In terms of gossiping and the channel graph, you don't explicitly link "FG" with "F" and "G". "FG", "F" and "G" each have their own identity in the LN's Onion network and each one appears as a separate node in the routing graph, with no explicit linkage between them. Every logical channel in the channel graph is announced with channel_update_v2 messages that provide the channel's current capacity and refer back to an on-chain UTXO. It's possible, but not necessary, that some of the logical channels between "FG" and other nodes, between "F" and other nodes, and between "G" and other nodes, use the same on-chain UTXO for their channel_update_v2 messages.
Q: How do you decide fees? A: All of the users that own a given logical channel negotiate the routing fees that they want to charge. These routing fees are of two types: 1) a fee for devoting capital (by being the "payer" or "payee" as defined in the paper), and 2) a fee for providing signatures without devoting capital. For example, in order to traverse the logical channel ((A,B),(C,D)) (where A, B, C and D are dedicated users, A is the "payer", and C is the "payee"), C will get a payment for devoting capital and D will get a payment for providing signatures. It's reasonable to assume that the sum of these fees will be larger than the fees charged by most non-hierarchical channels, so it's reasonable to assume that the logical channel ((A,B),(C,D)) will be used more often as the first or last hop in a payment (in order to resize (A,B) or (C,D), but not both of them), rather than as an intermediate hop in a payment.
Q: How do you communicate fees/max_htlc/etc.? A: Just like you do today, with the only difference being that a specific user within each node should handle the Onion traffic for that node and (and should forward it to the other users within that node, if it's a multi-user node). This user could be called the "leader" for the node. I didn't describe this detail in the paper, but I could add it if you think it would be helpful.
Quoted text (2 lines)
> I think it also implies that channel > capacity is no longer really something you can gossip very sensibly --
Given the above definitions and assumptions, including the use of channel_update_v2 messages, I think you can gossip channel capacity quite reasonably.
As is shown in the paper, just routing through a logical channel does *not* change its capacity (except for a slight increase due to fees). The only time a channel capacity changes significantly is when it is being resized by being the source or destination of a LN payment. The new capacity will be broadcast in the next weekly channel_update_v2 message. Obviously, there's some potential for an unexpected inability for a channel to route requested payments before the channel_update_v2 message showing a reduced capacity has been received, but nothing actually breaks. Of course, it may be worth sending out a channel_update_v2 message as soon as a channel is resized.
Quoted text (2 lines)
> if you have a factory ((A,B),C,D,E) then every payment through AB to C > or D or E will decrease AB's channel capacity.
First, let's translate this example into one without factories (as that's the world I'm envisioning). Let's assume we have logical channals ((A,B),C), ((A,B),D) and ((A,B),D).
Let's assume that C sends a payment to some other random user/node G that is routed through AB. In this case, the logical channel between A and B does *not* change capacity (except for growing slightly due to fees)! This is shown in Figures 8 and 9 of the paper (with "BC" in those figures playing the role of "AB" described here). That's the beauty of using logical, rather than physical, channels in the channel graph.
It took me a long time to see this and I obviously have not succeeded in explaining it very well. Please let me know if this example isn't clear, in which case I'll try to find a better way of explaining it.
Quoted text (4 lines)
> You could still gossip the > capacity of the overall factory, and sum that to get an overall lightning > network capacity, of course. But a lot of the ways of simplifying it > also make it harder to do all the nice rebalancing.
I think the above approach solves these problems. Please let me know if I've missed something.
Finally, I realize that creating a world without factories doesn't sound like a good solution for scaling Bitcoin. However, I believe hierarchical channels largely solve the problem of resizing channels off-chain. This still leaves the problem of creating channels off-chain, but I don't think we need factories to solve that problem. The key observation is that we don't need to create a factory with *updatable* state in order to create a huge number of channels off-chain. Instead, we just need something that instantiates all of those off-chain channels in a way that guarantees the off-chain UTXOs creating those factories. I think the solution to this simpler problem is Timeout-Trees, but I still need to write that up. In any case, please consider hierarchical channels as being a partial solution to scaling Bitcoin and wait until I can make the case for Timeout-Trees before evaluating whether or not we need factories.
Quoted text (3 lines)
> Anyway, I've tried a few times now to put some thoughts together on that > and come up with nothing that I'm happy with, so figured it might be at > least worth posing explicitly as a problem...
Thanks!
I really appreciate your working through all of these issues.
Regards, John
[1] https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2022/lightning-gossip-alternative#m-8dc7318c
On Tue, Apr 18, 2023 at 07:17:34PM +0000, jlspc wrote:
Quoted text (5 lines)
> > One thing that confuses me about the paper is how to think about routing > > to a "channel" rather than a node -- ie the payment from "E->FG->A" where > > "FG" isn't "F" or "G", but "both of them". > Yes, I found it very difficult to think about, and I kept getting confused between concepts like "user", "node", "channel", and "factory". > The thing that works best for me is to create a clear definition of each of these terms, along with the term "party".
Okay, that makes sense. I think it might work better to treat "node" as synonymous with "user" rather than "party" though -- that way you can say "you create a lightning node by running lightning node software such as lnd/cln/eclair/etc". That means not all vertices in the payment routing network are nodes; but all vertices in the *gossip* network are nodes, so that seems okay.
Just saying "channel" (instead of "logical channel") and "utxo/off-chain utxo" (instead of "physical channel") might also work okay.
Quoted text (1 line)
> I also think it's best to imagine a world in which there are hierarchical channels, but there are no "factories" per se.
Personally, I use "channel factory" to mean "anything that lets a single utxo contain multiple channels between different users, that can be reorganised without going on-chain", so I think once you've got hierarchial channels, you've implicitly got (a variation of) channel factories.
(I'm not sure "channel factories" is really the most evocative way of describing them -- at least when I think of a factory, I think the product should be accessible to everyone; but for channel factories you have to be involved in the factory's original mutlisig to be able to use one of its channels. Maybe better to call them "channel coops", where you're creating a little commune of friends/allies to work together with each other. Could be pronounced like "workers' co-op" or like "chicken coop", either way :)
Quoted text (3 lines)
> * Logical Channel: a layer 2 construct that consists of all of the physical channels owned by a specific pair of parties > - the size (capacity) of a logical channel is the sum of the sizes of their physical channels > - (Footnote: It's possible, with a significant amount of software development work that I in no way discount, to route a payment through a logical channel where the payment traverses multiple physical channels at the same time. This is done by using separate HTLCs, all sharing the same secret, in each of the physical channels that the payment traverses. I can write more about this if that would be helpful.)
I think it might already be interesting to write a BOLT/BLIP for that? Having a single channel backed by multiple on-chain utxos is probably interesting for splicing (adding or spending a utxo while keeping the channel open on the other utxos might be able to be done more simply than splicing in general), and having multiple utxos might let you increase some of your channel limits, eg `max_accepted_htlcs` might be able to be increased to 483*U where U is the number of UTXOs backing the channel.
Quoted text (7 lines)
> > It feels like there's a whole > > mass of complications hidden in there from a routing perspective; like how > > do you link "FG" back with "F" and "G", how do you decide fees, how do > > you communicate fees/max_htlc/etc. > Regarding the specific issues you raised: > Q: How do you link "FG" back with "F" and "G"? > A: In terms of gossiping and the channel graph, you don't
Yeah, I think that simplifies things substantially.
I think the main thing that misled me here was the "CD->E->FG" payment chain -- it doesn't make sense to me why E would want to devote funds that can only be used for rebalancing channels, but not normal payments. Having that be CD->DE->FG seems like it would make much more sense in that model. (Though, obviously, no one except D and E could necessarily tell the difference between those two scenarios in practice, and just because something doesn't make sense, doesn't mean nobody will actually do it)
The other thing was that going from N nodes to C*N channels, then re-considering each of the C*N channels (A->B, etc) as also potentially being nodes and adding an additional K*C*N channels (AB->CD, etc) seemed like it might be quadratic to me. But it's probably not -- C (channels per node) and K (utxos per channel) are probably constant or logarithmic in N, so it's probably okay?
On the other hand, I could see the rebalancing channels not actually being very useful for routing payments (they require 3+ signatures, and may not even be publicly connected to any of the level-1 nodes), so it could make sense to just treat them as two different networks, where regular people doing payments only see the base channels, but high-availability nodes also find out about the rebalancing channels. If so, then the extra nodes/channels in the rebalancing graph only affect people who can afford to dedicate the resources to storing it anyway, so it's probably fine.
Quoted text (2 lines)
> Q: How do you decide fees? > Q: How do you communicate fees/max_htlc/etc.?
Yep, both these bcome trivial.
Quoted text (2 lines)
> > if you have a factory ((A,B),C,D,E) then every payment through AB to C > > or D or E will decrease AB's channel capacity.
I was assuming a payment path using the channels (X->A) and (AB->C) here. But that's not something anyone can pick in this model, unless A announces an (A->AB) path that others can use to link them, and in that case either {A,AB} is a real channel and everything works fine, or it's a fake one that A and B have negotiated because they're both happy if the AB channel changes capacity randomly.
Quoted text (1 line)
> Finally, I realize that creating a world without factories doesn't sound like a good solution for scaling Bitcoin. However, I believe hierarchical channels largely solve the problem of resizing channels off-chain.
I think this is probably a lot harder in practice than in theory? If you have an {A,B} channel holding 3 BTC across two hierarchial channels, {X:1 BTC, AB:1 BTC} and {Y:1 BTC, AB:2 BTC}, and someone wants to route 0.5 BTC through X->AB->Y, then that will look something like:
{X:1, AB:1} {AB:2, Y:1}
{X:0.5, XAB:0.5, AB:1} {AB:2, Y:1}
{X:0.5, XAB:0.5, AB:1} {AB:1.5, ABY:0.5 Y:1}
and either:
{X:1, AB:1} {AB:2, Y:1} (on failure)
or
{X:0.5, AB:1.5} {AB:1.5, Y:1.5} (on success)
But what if you're in the middle of routing 2 BTC over the A,B channel in the meantime? In that case you need some of the AB payments to be conditional on the success path of XAB and the failure path of ABY.
I *think* that's fine, and doesn't involve a combinatorical blowup in the event that you're routing rebalances across multiple off-chain utxos -- you just end up splitting your channel across {X+2*Y} utxos where X is the number of "physical" channels and "Y" is the number of pending rebalances. But it seems like there's a fair chunk of complexity and maybe some extra round trips (eg, moving a pending HTLC from being purely in the AB:2 output to being split across the {XAB:0.5/success and ABY:0.5/timeout} atomically seems tricky?).
(I figure implementing something eltoo-like via 2-user tunable penalty channels and/or ln-symmetry (let alone splicing, taproot funding addresses, and ptlcs) is a sufficient sink for all the available engineering effort any time soon, but talking about hierarchial/factory things well in advance of when they could reasonably be implemented is fun too)
Cheers, aj
Replies inline:
Quoted text (11 lines)
> > > One thing that confuses me about the paper is how to think about routing > > > to a "channel" rather than a node -- ie the payment from "E->FG->A" where > > > "FG" isn't "F" or "G", but "both of them". > > Yes, I found it very difficult to think about, and I kept getting confused between concepts like "user", "node", "channel", and "factory". > > The thing that works best for me is to create a clear definition of each of these terms, along with the term "party". > Okay, that makes sense. I think it might work better to treat "node" as > synonymous with "user" rather than "party" though -- that way you can say > "you create a lightning node by running lightning node software such as > lnd/cln/eclair/etc". That means not all vertices in the payment routing > network are nodes; but all vertices in the *gossip* network are nodes, > so that seems okay.
Yes, it's probably best to refer to a user who runs lightning node software as being a "node".
On the other hand, it sounds really awkward to talk about routing in a directed graph without using the word "node" in some form. Maybe "routing node" for entities in the routing network?
Quoted text (8 lines)
> (I'm not sure "channel factories" is really the most evocative way of > describing them -- at least when I think of a factory, I think the product > should be accessible to everyone; but for channel factories you have to > be involved in the factory's original mutlisig to be able to use one of > its channels. Maybe better to call them "channel coops", where you're > creating a little commune of friends/allies to work together with each > other. Could be pronounced like "workers' co-op" or like "chicken coop", > either way :)
Good point regarding "factories". I like "channel co-op" as an alternative.
Quoted text (10 lines)
> > * Logical Channel: a layer 2 construct that consists of all of the physical channels owned by a specific pair of parties > > - the size (capacity) of a logical channel is the sum of the sizes of their physical channels > > - (Footnote: It's possible, with a significant amount of software development work that I in no way discount, to route a payment through a logical channel where the payment traverses multiple physical channels at the same time. This is done by using separate HTLCs, all sharing the same secret, in each of the physical channels that the payment traverses. I can write more about this if that would be helpful.) > I think it might already be interesting to write a BOLT/BLIP for that? > Having a single channel backed by multiple on-chain utxos is probably > interesting for splicing (adding or spending a utxo while keeping the > channel open on the other utxos might be able to be done more simply than > splicing in general), and having multiple utxos might let you increase > some of your channel limits, eg `max_accepted_htlcs` might be able to > be increased to 483*U where U is the number of UTXOs backing the channel.
Sounds good. I'm glad to write something up, but I'm afraid it may take me a few months.
Quoted text (11 lines)
> > > It feels like there's a whole > > > mass of complications hidden in there from a routing perspective; like how > > > do you link "FG" back with "F" and "G", how do you decide fees, how do > > > you communicate fees/max_htlc/etc. > > Regarding the specific issues you raised: > > Q: How do you link "FG" back with "F" and "G"? > > A: In terms of gossiping and the channel graph, you don't > Yeah, I think that simplifies things substantially. > I think the main thing that misled me here was the "CD->E->FG" payment > chain -- it doesn't make sense to me why E would want to devote funds > that can only be used for rebalancing channels, but not normal payments.
Actually, E's funds in the channels ((C,D),E) and (E,(F,G)) can be used for normal payments. It might not seem attractive to do so, but there may be reasons for doing just that (see below).
Quoted text (4 lines)
> Having that be CD->DE->FG seems like it would make much more sense in that > model. (Though, obviously, no one except D and E could necessarily tell > the difference between those two scenarios in practice, and just because > something doesn't make sense, doesn't mean nobody will actually do it)
I included going from a single-user party to a multi-user party and back to a single-user party, as in E->FG->HI->A in Figure 4 in the paper, just to show the poassibility. I didn't think it would be common, given the extra signatures and fees required. However, I'm now thinking that routing through multi-user parties could be important in practice, even when making normal LN payments between single users. There's a lot more on that idea below.
Quoted text (6 lines)
> The other thing was that going from N nodes to C*N channels, then > re-considering each of the C*N channels (A->B, etc) as also potentially > being nodes and adding an additional K*C*N channels (AB->CD, etc) seemed > like it might be quadratic to me. But it's probably not -- C (channels per > node) and K (utxos per channel) are probably constant or logarithmic in > N, so it's probably okay?
Yep, I'd assume C and K are largely independent of N (and constant or nearly so as the network grows), so that shouldn't be a problem.
Quoted text (9 lines)
> On the other hand, I could see the rebalancing channels not actually > being very useful for routing payments (they require 3+ signatures, > and may not even be publicly connected to any of the level-1 nodes), > so it could make sense to just treat them as two different networks, > where regular people doing payments only see the base channels, but > high-availability nodes also find out about the rebalancing channels. > If so, then the extra nodes/channels in the rebalancing graph only affect > people who can afford to dedicate the resources to storing it anyway, > so it's probably fine.
It would be possible to have a separate rebalancing network consisting of multi-user parties only and a base network consisting of single-user parties only. However, that both complicates and limits the rebalancing functionality.
Let's say A and B want to decrease the size of their channel (A,B) using the separate rebalancing network.
They make a payment on the rebalancing network:
AB->CD->EF->GH->IJ
However, there are two problems with this approach:
1) A and B have to find another channel (I,J) that wants to increase its capacity by exactly the same amount (minus fees) to offset the decrease in (A,B). In general, the rebalancing network can move capacity from one base channel (a.k.a., two-user channel or channel with single-user parties) to another one, but it can't increase or decrease the overall capacity of the channels in the base network.
2) The payment AB->CD->EF->IJ not only rebalances channels, it also sends bitcoin from the payer in (A,B) to the payee in (I,J). This would have to be offset by making a corresponding payment (using the base network) from the payee in (I,J) (e.g., I) to the payer in (A,B) (e.g., A) and that offsetting payment would have to be atomic with the rebalancing payment. It's possible to make this work by using the same secret for the payments in the base network and the rebalancing network, but it certainly adds complexity.
In addition, there are reasons for wanting to include multi-user parties when making regular LN payments (again, see below).
Connecting the level-2 routing nodes with the level-1 routing nodes requires at least some channels that consist of a multi-user party and a single-user party, such as the channel ((C,D),E). Once that's done, the above problems go away and it's possible to increase or decrease the overall capacity of the two-user channels without going on-chain.
Quoted text (23 lines)
> > Finally, I realize that creating a world without factories doesn't sound like a good solution for scaling Bitcoin. However, I believe hierarchical channels largely solve the problem of resizing channels off-chain.
> I think this is probably a lot harder in practice than in theory? If
> you have an {A,B} channel holding 3 BTC across two hierarchial channels,
> {X:1 BTC, AB:1 BTC} and {Y:1 BTC, AB:2 BTC}, and someone wants to route
> 0.5 BTC through X->AB->Y, then that will look something like:
> {X:1, AB:1} {AB:2, Y:1}
> {X:0.5, XAB:0.5, AB:1} {AB:2, Y:1}
> {X:0.5, XAB:0.5, AB:1} {AB:1.5, ABY:0.5 Y:1}
> and either:
> {X:1, AB:1} {AB:2, Y:1} (on failure)
> or
> {X:0.5, AB:1.5} {AB:1.5, Y:1.5} (on success)
> But what if you're in the middle of routing 2 BTC over the A,B channel
> in the meantime? In that case you need some of the AB payments to be
> conditional on the success path of XAB and the failure path of ABY.
> I *think* that's fine, and doesn't involve a combinatorical blowup in
> the event that you're routing rebalances across multiple off-chain utxos
> -- you just end up splitting your channel across {X+2*Y} utxos where X
> is the number of "physical" channels and "Y" is the number of pending
> rebalances. But it seems like there's a fair chunk of complexity and
> maybe some extra round trips (eg, moving a pending HTLC from being
> purely in the AB:2 output to being split across the {XAB:0.5/success and
> ABY:0.5/timeout} atomically seems tricky?).Wow, that's a cool idea!
I hadn't considered having an active HTLC (sending 2 BTC from A to B) that's (partially) funded by a pair of active HTLCs (sending 0.5 BTC from X to Y via the path X->AB->Y). I figured that would be too complex, but I hadn't thought through the details.
In contrast, I had considered having an active HTLC that's funded by a resolved (either successful or failed) HTLC. This seems important, as the resolved HTLC requires 3+ signatures in order to merge it into a new Commitment transaction, so it might not be possible to get all the signatures right away. For example, dedicated users A and B want to be able to use their newly-gained capacity in the channel (C,(A,B)) after making a payment from casual user C without having to wait for C to update the state of (C,(A,B)).
The hierarchical channels paper requires that all the funds in an HTLC be provided by a single user, denoted as the "payer". As a result, the capital in a hierarchical channel can only be used for a single active HTLC at a single level at a time. This requires multiplexing the capital between level-1 channel HTLCs and level-2 channel HTLCs, but I figured that was OK as the level-2 channels would mainly be used for rebalancing, which should be far less frequent than level-1 payments (and the rebalancing could wait until a path was available). Thus, one doesn't have to allow an active HTLC to be funded by a pair of active HTLCs in order to have flexible off-chain rebalancing of channels.
However, as you point out, it should be possible to have an active HTLC be funded by a pair of active HTLCs. The thing that's amazing about this is that the *same capital* is used for routing at two different levels in the hierarchy simultaneously! In other words, in addition to routing normal LN payments through single-user parties, it's possible to simultaneously route independent normal LN payments through multi-user parties by re-using the *same capital*.
Sure, the payments through multi-user parties require more signatures, so that could slow them down or complicate them, but the potential to maybe double the routing fees that can be generated from a given unit of capital (in addition to enabling off-chain rebalancing) sounds pretty compelling if the cost of capital is high.
As you noted, making this work atomically is tricky. Let's consider your example again, using slightly modified notation.
Initially, there's an {A,B} channel holding 3 BTC across two hierarchical channels:
State 0:
{X:1 BTC, {A:0.5 BTC, B:0.5 BTC}}
and
{{A:2 BTC, B:0 BTC}, Y:1 BTC}
First, A initiates a payment of 2 BTC with secret s1 via B in the hierarchical channel with Y:
State 1:
{X:1 BTC, {A:0.5 BTC, B:0.5 BTC}}
and
{{A_or_s1_B:2 BTC}, Y:1 BTC}
Then, while this payment is pending, X sends 0.5 BTC with secret s2 to Y via the following states:
State 2:
{X:0.5 BTC, X_or_s2_{A_or_s1_B:0.5 BTC}, {A:0.5 BTC, B:0.5 BTC}}
and
{{A_or_s1_B:2 BTC}, Y:1 BTC}
State 3:
{X:0.5 BTC, X_or_s2_{A_or_s1_B:0.5 BTC}, {A:0.5 BTC, B:0.5 BTC}}
and
{{A_or_s1_B:1.5 BTC}, {A_or_s1_B:0.5 BTC}_or_s2_Y:0.5 BTC, Y:1 BTC}
Quoted text (1 line)
>From this point, there are 8 possibilities in terms of whether the HTLCs succeed or fail, and in which order they do so.
For example, if s1 is revealed and then the payment with secret s2 times out, we get:
State 4:
{X:0.5 BTC, X_or_s2_{B:0.5 BTC}, {A:0.5 BTC, B:0.5 BTC}}
and
{{B:1.5 BTC}, {B:0.5 BTC}_or_s2_Y:0.5 BTC, Y:1 BTC}
State 5:
{X:0.5 BTC, X:0.5 BTC, {A:0.5 BTC, B:0.5 BTC}}
and
{{B:1.5 BTC}, {B:0.5 BTC}, Y:1 BTC}
State 6:
{X:1.0 BTC, {A:0.5 BTC, B:0.5 BTC}}
and
{{A:0 BTC, B:2.0 BTC}, Y:1 BTC}
Alternatively, if s2 is revealed and then s1 is revealed, we get:
State 4':
{X:0.5 BTC, {A_or_s1_B:0.5 BTC}, {A:0.5 BTC, B:0.5 BTC}}
and
{{A_or_s1_B:1.5 BTC}, Y:0.5 BTC, Y:1 BTC}
State 5':
{X:0.5 BTC, {B:0.5 BTC}, {A:0.5 BTC, B:0.5 BTC}}
and
{{B:1.5 BTC}, Y:0.5 BTC, Y:1 BTC}
State 6':
{X:0.5 BTC, {A:0.5 BTC, B:1 BTC}}
and
{{A:0 BTC, B:1.5 BTC}, Y:1.5 BTC}
The trickiest step is defining State 2. When A and B get the HTCL offered by X with secret s2, A and B figure out what they're going to give up in the hierarchical channel with Y in case the payment from X succeeds. Given that all of A's and B's capital in {{A_or_s1_B:2 BTC}, Y:1 BTC} is in the HTLC with secret s1, they take 0.5 BTC of that HTLC and add it as the payout from secret s2 in the channel with X to obtain State 2. Then, they update the channel with Y to obtain State 3.
This seems to address the atomicity issue. However, there are a couple other details to address in the hierarchical channel protocol.
First, in the adaptation of the FFO protocol to hierarchical channels, the "payee" for an HTLC is the user that must provide the HTLC's secret with an HTLC-kickoff transaction (see Figure 14 in the paper). However, when the HTLC pays to a lower-level HTLC, there is no single "payee" that can be determined. This could be addressed by enabling both users that could be payees to reveal the HTLC's secret with an HTLC-kickoff transaction followed by an HTLC-success transaction (note that this doubles the number of HTLC-payment transactions that are required).
Second, in going from HTLCs to PTLCs, the payee has to create a secret that's subtracted from the secret that's revealed at the payment's next hop. The challenge is how to define a secret that depends on multiple potential payees' secrets. I think it may be possible to solve this by having all potential payees at hop i create their own secret, define the overall secret at hop i as being the sum of the potential payees' secrets (after protecting against key/secret cancellation), and sharing partial signatures between potential payees at hop i such that each potential payee just needs to get hop (i+1)'s secret in order to produce hop (i)'s overall secret, but I haven't worked through the details.
To be clear, the idea of having an active HTLC that's funded by a pair of active HTLCs is your idea, and it's very interesting. We don't need to support this in order to resize channels off-chain, but it does allow a given unit of capital to facilitate two independent payments simultaneously, which is amazing!
Quoted text (6 lines)
> (I figure implementing something eltoo-like via 2-user tunable penalty > channels and/or ln-symmetry (let alone splicing, taproot funding > addresses, and ptlcs) is a sufficient sink for all the available > engineering effort any time soon, but talking about hierarchial/factory > things well in advance of when they could reasonably be implemented is > fun too)
That makes sense.
I'm also hoping that a good understanding of what's possible without changing Bitcoin, plus what's enabled with changes like CTV and/or APO, will help inform any future changes to Bitcoin's consensus rules.
Regards, John