Research/Bitcoin Dev Archive / lightning-dev list
Protocol for multiple in-flight updates.
13 messages, Feb 1 to 9, 2016. Started by Rusty Russell.
Rusty Russell (9), Joseph Poon (4)
Hi Joseph and ml,
Wondering if you can describe your HTLC negotiation protocol? Laolu said on IRC you're working on it.
I've been trying to adapt my code to do this, and ended up with something quite different AFAICT from your HTLC ids.
Because you need to supply the revocation hash to get a signature from the other side, this implies an ordering in commitments.
The c-lightning protocol exchange looks like:
Send: [add/fulfill/fail/timeout, with new revocation hash]
Receive: [acceptance, with new revocation hash] or [decline if add]
Send: [commitment, with signature of new commit tx, and old
revocation preimage]
Receive: [commitment reply, with signature of new commit tx, and old
revocation preimage]
The obvious way to batch this is to have variants of the first two which don't have a new revocation hash: you could follow your initial proposal with an arbitrary number of additional changes to build up the new commit tx, and the commitment is to all the accepted updates.
How similar is this to yours?
Thanks! Rusty. PS. I swear I send this before, but I couldn't find it...
OK, I've thought about this some more, and here's my strawman protocol.
Importantly, if we pipeline requests, we need something more sophisticated than "discard if not your turn" for overlaps. Including the other side's commitment and retransmitting seems to work.
Each side keeps two sets of "proposals"; mine and yours. There are two kinds of proposals, "add to my htlcs" and "remove from your htlcs".
- As part of finalizing a commit tx, we always tell the other side
what the next revocation hash will be.
- This simplifies the protocol, as you need the other side's
revocation hash to produce a signature.
- To add an HTLC, send the proposal.
- If they decline, fail the HTLC.
- If they accept, add to my proposals.
- To close an HTLC, send fulfill/timeout/fail:
- They cannot decline this.
- Add to my proposals.
- If we receive an add proposal:
- If we don't want it, send decline.
- If it's OK, send ack, add the their proposals.
- If we receive a fulfill/timeout/fail:
- Add to their proposals.
- If we have no outstanding add requests, we can send commit msg
- Send update_commit: signature of current state including our proposals.
- If we receive commit_accept with signature and their old revocation preimage.
- Commit our proposals
- Send update_commit_complete with our old revocation preimage.
- If we receive an update_commit message (conflict!)
- If signature matches current state + their proposals
- They didn't get our update_commit.
- Commit their proposals to current state, re-send update_commit
with that current state + our proposals.
- Otherwise signature matches current state + their proposals + our proposals
- Commit their proposals and our proposals to current state.
- Send update_commit_accept: signature and revocation preimage.
- Expect update_commit_complete or update_commit_accept.
- If we receive an update_commit message (and we've not sent one!)
- Commit "their changes" to current state.
- Send update_commit_accept: signature and revocation preimage.
- Expect update_commit_complete.
Packets involved:
update_add_htlc: [new htlc details]
update_decline_htlc: [reason]
update_accept_htlc
update_fulfill_htlc: [r value]
update_timeout_htlc: [htlc rhash]
update_fail_htlc: [htlc rhash]
update_commit: [sig]
update_commit_accept: [sig] [old commit preimage] [next commit hash]
update_commit_complete: [old commit preimage] [next commit hash]
Cheers, Rusty. PS. Yes, it's complex. Better way welcome...
Hi Rusty,
For synchronous across-the-wire commit steps, 3 steps is a good idea and more secure than 2 steps for the commit transaction.
However, the nice thing about keeping everything asynchronous is it simplifies orchestration and no locking across-the-wire. We have a preliminary explanation on the git repo in the README.md file.
Joseph Poon <joseph at lightning.network> writes:
Quoted text (4 lines)
> Hi Rusty, > > For synchronous across-the-wire commit steps, 3 steps is a good idea and > more secure than 2 steps for the commit transaction.
I guess it depends how we count steps. Each party needs to receive the signature for the N+1 commit tx before handing over the Nth revocation preimage, but that's the only irreducible constraint isn't it?
It's probably simpler to do a three way handshake on every stage, but I didn't see that in your protocol?
Quoted text (3 lines)
> However, the nice thing about keeping everything asynchronous is it > simplifies orchestration and no locking across-the-wire. We have a > preliminary explanation on the git repo in the README.md file.
Yes, but it was a bit dense. Or I am :)
If I receive "add request" "add request" "signed commit", how do I know what that signatures covers? Both new htlcs? Are you required to wait for my accept/reject message replies before commiting? Or does the commit message include a counter?
I guess "asynchronous" is a bit nebulous: out-of-order or in-order? I couldn't see a good reason for out-of-order. Whereas letting both sides offer updates in parallel makes good sense for throughput...
Thanks! Rusty.
On Wed, Feb 03, 2016 at 11:02:50AM +1030, Rusty Russell wrote:
Quoted text (3 lines)
> I guess it depends how we count steps. Each party needs to receive the > signature for the N+1 commit tx before handing over the Nth revocation > preimage, but that's the only irreducible constraint isn't it?
Correct, that is a necessity for a secure implementation.
Quoted text (2 lines)
> It's probably simpler to do a three way handshake on every stage, but I > didn't see that in your protocol?
Unlike a 3-step synchronous commitment, it doesn't wait for the other party to send their sigantures/revocations and can happen simultaneously.
Bob's broadcastable Commitment: Alice sends a Signature to Bob. Bob sends the Revocation of the previous Commitment to Alice.
Alice's broadcastable Commitment: Bob sends a Signature to Alice. Alice sends to Revocation of the previous Commitment to Bob.
It's that simple. If the HTLC is reflected in both and the previous commitment(s) is/are revoked, then it's complete.
Quoted text (2 lines)
> If I receive "add request" "add request" "signed commit", how do I know > what that signatures covers?
The protocol is still being optimized (deprecating the even/odd structure, etc.), but the structure is both parties have a list of HTLC modifications which they want to update. When the modification is acknowledged by the other party, the HTLC modifcation request is staged into the next Commitment signature. The inclusion of modifications are enumerated by including both parties' higest HTLC ID (two of them) in each Commitment signature message.
Quoted text (2 lines)
> Are you required to wait for my accept/reject message replies before > commiting? Or does the commit message include a counter?
Any which is accepted by the other party is included. Two IDs, one for each party, is included. Two are necessary to allow for timing issues with HTLC Add responses in-flight not being fully synced up.
Quoted text (3 lines)
> I guess "asynchronous" is a bit nebulous: out-of-order or in-order? I > couldn't see a good reason for out-of-order. Whereas letting both > sides offer updates in parallel makes good sense for throughput...
In-order. I should have an update in the coming days for lnstate if that helps (various protocol updates, e.g. fixing exchanging of revocation hashes, etc.)
Joseph Poon <joseph at lightning.network> writes:
Quoted text (8 lines)
> Bob's broadcastable Commitment: Alice sends a Signature to Bob. Bob > sends the Revocation of the previous Commitment to Alice. > > Alice's broadcastable Commitment: Bob sends a Signature to Alice. Alice > sends to Revocation of the previous Commitment to Bob. > > It's that simple. If the HTLC is reflected in both and the previous > commitment(s) is/are revoked, then it's complete.
Ah, I think I finally understand! I was artificially linking the two sides' commit transactions, but there's really no reason to. As you say, once you've included an HTLC in both sides in any form, it's locked in.
Quoted text (10 lines)
>> If I receive "add request" "add request" "signed commit", how do I know >> what that signatures covers? > > The protocol is still being optimized (deprecating the even/odd > structure, etc.), but the structure is both parties have a list of HTLC > modifications which they want to update. When the modification is > acknowledged by the other party, the HTLC modifcation request is staged > into the next Commitment signature. The inclusion of modifications are > enumerated by including both parties' higest HTLC ID (two of them) in > each Commitment signature message.
Right, so "this signature covers you up to X me up to Y". That resolves the in-flight issue.
But isn't that more a request ID rather than an HTLC ID? Since requests can include removing HTLCs as well? And doesn't that simply degrade to a counter?
Quoted text (6 lines)
>> Are you required to wait for my accept/reject message replies before >> commiting? Or does the commit message include a counter? > > Any which is accepted by the other party is included. Two IDs, one for > each party, is included. Two are necessary to allow for timing issues > with HTLC Add responses in-flight not being fully synced up.
Right.
Quoted text (7 lines)
>> I guess "asynchronous" is a bit nebulous: out-of-order or in-order? I >> couldn't see a good reason for out-of-order. Whereas letting both >> sides offer updates in parallel makes good sense for throughput... > > In-order. I should have an update in the coming days for lnstate if that > helps (various protocol updates, e.g. fixing exchanging of revocation > hashes, etc.)
Thanks, I feel smarter now! :)
Cheers, Rusty.
On Wed, Feb 03, 2016 at 03:05:33PM +1030, Rusty Russell wrote:
Quoted text (6 lines)
> Right, so "this signature covers you up to X me up to Y". That resolves > the in-flight issue. > > But isn't that more a request ID rather than an HTLC ID? Since requests > can include removing HTLCs as well? And doesn't that simply degrade to > a counter?
Yeah, it's more like a request "staging" ID. The "counter" aspect requires two counters (one for each originator of the request). Two IDs sent in the commitment message allow for simultaneous action on accept/reject/etc, whereas only one would require a lock on accepting/rejecting modifications.
Minor note which has the potential to be overlooked: It's a hard requirement that all messages sent are in order, and if the replyer skips the requester's Add Requests when replying, the skipped are assumed to be request rejections (or an outright channel closeout) since it should never happen -- this is to enforce accept/reject order, as we need to know which modifications are included in the signature/transaction and not have that change after-the-fact.
Joseph Poon <joseph at lightning.network> writes:
Quoted text (21 lines)
> On Wed, Feb 03, 2016 at 03:05:33PM +1030, Rusty Russell wrote: >> Right, so "this signature covers you up to X me up to Y". That resolves >> the in-flight issue. >> >> But isn't that more a request ID rather than an HTLC ID? Since requests >> can include removing HTLCs as well? And doesn't that simply degrade to >> a counter? > > Yeah, it's more like a request "staging" ID. The "counter" aspect > requires two counters (one for each originator of the request). Two IDs > sent in the commitment message allow for simultaneous action on > accept/reject/etc, whereas only one would require a lock on > accepting/rejecting modifications. > > Minor note which has the potential to be overlooked: It's a hard > requirement that all messages sent are in order, and if the replyer > skips the requester's Add Requests when replying, the skipped are > assumed to be request rejections (or an outright channel closeout) since > it should never happen -- this is to enforce accept/reject order, as we > need to know which modifications are included in the > signature/transaction and not have that change after-the-fact.
I would simply disallow skipping as a protocol violation.
I think this approach also leads neatly to an gentler close protocol: sending close would simply imply the initiator would send no more adds, and reject all received. It could take a while to clean out all the remaining HTLCs for mutual close (assuming we still don't support close with htlcs), but at least the other side knows what we're doing and can open new channels to replace capacity if it wants to.
I'm going to try to document your protocol in another mail, let's see how close I get this time!
Thanks, Rusty.
Joseph Poon <joseph at lightning.network> writes:
Quoted text (13 lines)
> On Wed, Feb 03, 2016 at 03:05:33PM +1030, Rusty Russell wrote: >> Right, so "this signature covers you up to X me up to Y". That resolves >> the in-flight issue. >> >> But isn't that more a request ID rather than an HTLC ID? Since requests >> can include removing HTLCs as well? And doesn't that simply degrade to >> a counter? > > Yeah, it's more like a request "staging" ID. The "counter" aspect > requires two counters (one for each originator of the request). Two IDs > sent in the commitment message allow for simultaneous action on > accept/reject/etc, whereas only one would require a lock on > accepting/rejecting modifications.
Indeed.
I wrote up the protocol as I gleaned it from your explanations, and it was many words. But I couldn't quite figure out the commitment steps, so maybe I'm missing something.
Does your scheme prevent cut-through HTLCs? A sends B an "add request" and B wants to send the corresponding "add request" to C immediately to minimize latency.
If B does this, it has the HTLCa in ADD_STAGED with A, and HTLCb in ADD_STAGED and C. C sends B a commit sig which covers the new HTLCb, but B doesn't want to be locked into HTLCb in case A vanishes before HTLCa is committed...
Thanks! Rusty. PS. Reading Go is suprisingly nice :)
OK, so this is based on my understanding of what Joseph's protocol will look like when done, from here and perusing the lnd source. See proposals if this is all simply revision; it's mainly to document my understanding.
Each HTLC has one of these states:
ADD_PRESTAGE ADD_STAGED ADD_SIGNING_AND_REVOKING ADD_COMPLETE ADD_REJECTED
TIMEOUT_PRESTAGE TIMEOUT_STAGED TIMEOUT_SIGNING_AND_REVOKING TIMEOUT_COMPLETE
SETTLE_PRESTAGE SETTLE_STAGED SETTLE_SIGNING_AND_REVOKING SETTLE_COMPLETE
Each side starts with a commit tx with 0 HTLCs. HTLCs are numbered using a counter, but these numbers explicitly sent on the wire. Proposed changes are processed in order.
Adding An HTLC
--------------
A: HTLC = ADD_PRESTAGE. Send "add request { htlc details }".
B: Receive "add request".
(If reject, reply and forget HTLC, we'll ignore this)
If accept, HTLC = ADD_STAGED (since both sides know it), send "accept"
A: Receive "accept". HTLC = ADD_STAGED.
Removing An HTLC ---------------- There's timeout and there's settle; the only difference is settle requires the R value.
A: HTLC must be in ADD_COMPLETE state. HTLC = SETTLE/TIMEOUT_PRESTAGE.
Send "settle/timeout request { htlc id [r value] }".
B: Receive "request". Check r value for settle, time for timeout.
HTLC = SETTLE/TIMEOUT_STAGED (since both sides know it), send "accept"
A: Receive "accept". HTLC = ADD_STAGED.
Committing ---------- Both sides can do this. I can't figure out how the HTLC states work here, since we might have sent the signature, but not received theirs. Should there be a separate SIG_SENT and SIG_RECEIVED states?
A: Move HTLCs all *_STAGED htlcs to *_SIGNING_AND_REVOKING, then
generate their commit tx using all the ADD_COMPLETE and
ADD_SIGNING_AND_REVOKING htlcs. Sign it, and send
"commit { staged-htlcs; sig }"
B: Receive commit, generate our commit tx using all the ADD_COMPLETE,
and any TIMEOUT_PRESTAGE or SETTLE_PRESTAGE which are not listed
in staged-htlcs. Check their signature is valid for this.
[FIXME: Does B update states here?]
Send "commit revocation { old-revocation-preimage }" for
the previous commit tx.
A: Receive commit revocation, move all the HTLCs we moved in
step 1 above from *_SIGNING_AND_REVOKING to *_COMPLETE.
(If we never create two commits in-flight at once, this is simply
every *_SIGNING_AND_REVOKING htlc).
Proposals =========
There's no reason to "accept" anything except an add request. Thus the states SETTLE_PRESTAGE and TIMEOUT_PRESTAGE are redundant.
There are also other failures (ie. upstream node rejected). This suggests a FAIL messages, perhaps with a reason message (which might be encrypted back to the payer).
C-lightning only allows closes be sent from the HTLC recipient. I thought that would be simpler but it doesn't make any real difference (it only applies to TIMEOUT; FAIL and SETTLE have to come from recipient anyway). I would defined TIMEOUT to be the responsibility of the HTLC proposer.
In order to reduce latency, we want to be able to start staging an HTLC on the outgoing channel before it's committed on the incoming one. But this means an HTLC recipient can't commit to the HTLC until the HTLC sender does.
This has a few implications:
1) We need a new "unstage request" to unstage if the incoming HTLC fails
to complete in reasonable time. This requires no accept response.
2) We don't need to commit to adds and removes in order wrt each other;
a commit message always commits to:
- All HTLCs proposed and commited by the other side, and
- All removes staged by the other side up to some counter, and
- All HTLCs proposed by this side up to some counter, and
- All removes sent by this side.
3) This implies we should count htlcs and remove requests separately;
the htlc count could also serve as an HTLC ID which makes timeout/fail/abort
messages shorter than using R hashes.
Oh, and it should be illegal to send a noop commit (ie. one which doesn't change the commit tx).
That's enough email for now! Rusty.
Hi all!
Eliminating all acknowledgements makes for a much simpler protocol.
Each side sends one or more updates (ADD/SETTLE/TIMEOUT/FAIL/UNADD), followed by a COMMIT (with sig). Reply COMPLETE with the old revocation preimage. Each side tracks two commit txs: its own and the other side's. When you COMMIT you're locking in your updates to my commit, and staging them for your commit, enforcing the requirement that you commit to your updates first.
Details
-------
ADD:
Insert this new HTLC from proposer to recipient.
SETTLE:
Recipient collects proposers's committed HTLC with R value.
TIMEOUT:
Proposer removes committed HTLC it added.
FAIL:
Recipient removes committed HTLC it received.
UNADD:
Proposer removes uncommitted HTLC it added.
COMMIT:
Contains a signature for receiver's commit tx, with all the
updates included. Recipient commits updates to its own commit tx,
and stages those same updates to the other side's commit tx, then
sends COMPLETE for its own old commit tx.
COMPLETE:
Completes removal of old commit tx. Recipient commits updates
to other side's commit tx, stages those same updates for its own
commit tx.
So the shortest possible complete exchange looks like:
A B
ADD->
COMMIT->
<-COMPLETE
<-COMMIT
COMPLETE->
Optimizations ------------- If we want to fail faster, we can add a non-binding ADD_FAIL message, rather than waiting for a COMMIT. This would be a hint that we will FAIL an HTLC as soon as it is committed; recipient may UNADD if it receives it in time.
Fee Negotiation --------------- lnd has a fee field in their commit msg, c-lightning uses a fixed fee negotiation at channel establishment and a FIXME. The logical place for fee negotiation is in the COMMIT message, with a requested fee rate and a range of acceptable values. Instead of COMPLETE a node may REJECT, with a fee range; the COMPLETE may then be reattempted.
Similar fee negotiation would be required for mutual close (this isn't as urgent and so would use a normal fee).
Cheers, Rusty.
On Tue, Feb 09, 2016 at 06:47:07AM +1030, Rusty Russell wrote:
Quoted text (2 lines)
> Eliminating all acknowledgements makes for a much simpler > protocol.
For adding HTLCs, this may be an option, but there are some tradeoffs. The downside of doing this is that it's uncertain whether the other party has received the message. Essentially, the moment the packets are sent over the wire, it should be assumed the other party can broadcast (TCP SACKs cannot be relied upon, of course). To remove the HTLC securely, it requires removing the HTLC, committing, and then the other party revokes the prior commitment. If the ratio of success/failure is high enough it can be worth it. This may have some disadvantages with intermittently connected nodes, as requiring confirmation has a significantly smaller time window for non-responsive payments. I'm optimizing against payment failure on the ADD side, as failure may require a re-route in the opposite direction to do a full cancel with a non-responsive node in multi-hop payments (as an add request/accept structure has lower time windows for going offline). However, I agree if both nodes are well connected, then this is more optimal if latency is the primary concern.
Joseph Poon <joseph at lightning.network> writes:
Quoted text (9 lines)
> On Tue, Feb 09, 2016 at 06:47:07AM +1030, Rusty Russell wrote: >> Eliminating all acknowledgements makes for a much simpler >> protocol. > > For adding HTLCs, this may be an option, but there are some tradeoffs. > The downside of doing this is that it's uncertain whether the other > party has received the message. Essentially, the moment the packets are > sent over the wire, it should be assumed the other party can broadcast > (TCP SACKs cannot be relied upon, of course).
Only once you've sent the signature; they ack the signature with the old revocation preimage. It's a single-RTT window.
Quoted text (6 lines)
> To remove the HTLC securely, it requires removing the HTLC, > committing, and then the other party revokes the prior commitment. If > the ratio of success/failure is high enough it can be worth it. > This may have some disadvantages with > intermittently connected nodes, as requiring confirmation has a > significantly smaller time window for non-responsive payments.
I don't think anything can save a node which goes offline in the middle of an exchange. Not sure this makes it worse?
Quoted text (5 lines)
> I'm > optimizing against payment failure on the ADD side, as failure may > require a re-route in the opposite direction to do a full cancel with a > non-responsive node in multi-hop payments (as an add request/accept > structure has lower time windows for going offline).
I'm not convinced the re-route scheme will be used in practice. We're probably going to need to distinguish (for fee reasons) payments expected to resolve quickly, and those expected to take a long time. Re-routing in the opposite direction is worst case: it ties up funds for a long time with no actual likely redemption, thus would require a large up-front fee.
I think in practice, if a node goes down with possibly-live HTLCs, those HTLCs get delayed. The node loses channels, too, so it's not free for them either.
Quoted text (3 lines)
> However, I agree if > both nodes are well connected, then this is more optimal if latency is > the primary concern.
This offers 3x inter-node latency, which is optimal AFAICT (I know I talked about cut-through, but while possible for route discovery it turns out not to help total end-to-end commit latency).
As I said before, I was unsure on your commitment scheme, so maybe I'm missing a trick?
Thanks! Rusty.