Research/Bitcoin Dev Archive / lightning-dev list
Acknowledgements in BOLT #2
5 messages, Mar 31 to Apr 4, 2016. Started by Rusty Russell.
Rusty Russell (2), Pierre, Fabrice Drouin, Joseph Poon
Hi all!
Pierre queried the placement of acknowlegements in BOLT #2; I share his concerns, but wanted to document them here too.
The current draft (which I've implemented, and seems to work as of yesterday) has a header with an "acknowledge" field:
(BOLT-encryption): * `acknowledge`: an 8-byte little-endian field indicating the number of non-`authenticate` messages received and processed so far.
This is used so we know what the other side has received when they send an "update_commit" message, and so we know where to restart the conversation after reconnect ("authenticate" message).
The current spec requires that acks never go backwards, meaning in practice an implementation needs to write to disk persistently before *every* new packet sent.
If we move the "ack" back into the update_commit/authenticatate messages (I had this originally), I think we can have the spec say that on reconnect you retransmit from previous received update_revocation. And fee updates should Just Work too. There's also an implied "ack" in the update_revocation message (which has to correspond to the update_commit). One will need to be added to the "authenticate" message, too, which is used for connection re-establishment.
It's not a big code change: it's logically implemented as callbacks when a packet is acked. That just means they'll just fire all at once when we receive a update_commit / update_revocation packet...
I'll now try implementing that, and report back if I've missed anything :)
Cheers, Rusty.
Hello all,
I noticed in the meantime Rusty recently introduced htlc ids in the form of absolute "lnd-like 64 bits unique id" vs the previous relative "order-I-added-them-in" id. I like it better and I think this is closely related to the issue at hand.
Quoted text (3 lines)
> This is used so we know what the other side has received when they send
>an "update_commit" message, and so we know where to restart the
>conversation after reconnect ("authenticate" message).To me those two cases should be handled differently because they do not happen at the same level: - at the protocol level I would only use the htlc id. It is currently already used in add/fulfill/fail, so it would make sense to have it in the update_commit msg as well, instead of relying on the acknowledge field - at the transport level (including the reconnect scenario) I would rely on the acknowledge field to know which messages should be replayed
Yes it is kind of redundant, and probably less optimal, but it does separate clearly the transport from the protocol and testing might be easier.
Also @lnd guys: what's the thing with odd/even htlc ids? Is it just so that we can use the same keyspace for incoming/outgoing htlcs and quickly tell the direction of a given htlc, or is there something else?
Cheers,
Pierre
Hello,
We've thought about it some more and it seems now that htlc ids are indeed not enough and we do have to take the acknowledge field into account in some cases anyway. Consider the following scenario: A sends ADD HTLC X, ADD HTLC Y, ADD HTLC Z B sends FAIL Y A has not yet received this last message and sends SIG Z B receives SIG Z which includes (X,Y,Z) and won't match expected signature (X,Z). B has no way to know whether A did receive the "FAIL Y" message or not without checking the 'acknowledge' field (as mentioned by Rusty), and might decide that SIG Z is not valid and close the channel, when it could just ignore it and keep it open.
Cheers,
Fabrice
On Fri, Apr 01, 2016 at 03:32:15PM +0200, Pierre wrote:
Quoted text (4 lines)
> Also @lnd guys: what's the thing with odd/even htlc ids? Is it just so > that we can use the same keyspace for incoming/outgoing htlcs and > quickly tell the direction of a given htlc, or is there something > else?
Hi Pierre,
I've actually been going back and forth on HTLC IDs lately, and am actually currently working on a cleaner solution -- I think you might like it (provided it works out). The thinking was so that one is able to uniquely identify HTLCs at a later time by having unique ID upon creation (direction should be contextually understood by the positive/negative amount). The ID doesn't really need to be in the final wire protocol, it's more helpful for debugging than anything.
Pierre <pm+lists at acinq.fr> writes:
Quoted text (6 lines)
> Hello all, > > I noticed in the meantime Rusty recently introduced htlc ids in the > form of absolute "lnd-like 64 bits unique id" vs the previous relative > "order-I-added-them-in" id. I like it better and I think this is > closely related to the issue at hand.
Yes. I wanted to avoid it (it's YA index to keep, to map these 64 bit IDs to the HTLC), but we can't: we really need to distinguish two HTLCs with the same R value. This is because if we don't allow that, it's trivial for an attacker to probe us to find out if we've seen an HTLC.
Also, if we switch to keypair-based contracts, it's one less change to make.
Quoted text (10 lines)
>> This is used so we know what the other side has received when they send
>>an "update_commit" message, and so we know where to restart the
>>conversation after reconnect ("authenticate" message).
>
> To me those two cases should be handled differently because they do
> not happen at the same level:
> - at the protocol level I would only use the htlc id. It is currently
> already used in add/fulfill/fail, so it would make sense to have it in
> the update_commit msg as well, instead of relying on the acknowledge
> fieldYou can't use this for (as Fabrice pointed out) because there are multiple HTLCs you may be acknowledging, and you may be acknowledging their removal. Also, you may be acking a fee change. In future this may be changes to the anchor, as well.
So it really is simplest as "number of messages I've processed".
Quoted text (7 lines)
> - at the transport level (including the reconnect scenario) I would > rely on the acknowledge field to know which messages should be > replayed > > Yes it is kind of redundant, and probably less optimal, but it does > separate clearly the transport from the protocol and testing might be > easier.
They're actually closely tied. Every time you send an 'ack' (that's in an update_commit or update_revocation), you *must* have committed state to persistent storage. This matches nicely ie. you want to make sure you remember if you've ever sent a revocation preimage, and you must remember transactions you've signed.
Quoted text (4 lines)
> Also @lnd guys: what's the thing with odd/even htlc ids? Is it just so > that we can use the same keyspace for incoming/outgoing htlcs and > quickly tell the direction of a given htlc, or is there something > else?
I really like this differentiation to catch bugs. The latest spec leaves this open, but my implementation currently uses:
/* Make it different from other node (to catch bugs!), but a * round number for simple eyeballing. */ peer->htlc_id_counter = pseudorand(1ULL << 32) * 1000;
Cheers, Rusty.