Research/Bitcoin Dev Archive / lightning-dev list
Minor protocol revisions.
11 messages, Sep 24 to Oct 13, 2015. Started by Rusty Russell.
Rusty Russell (6), Anthony Towns (3), Pierre (2)
Hi all!
I know everyone's been busy, but I wanted to note some lightning.proto changes I just pushed.
1) Close now has an second ACK stage, which means you know the close ack has been received. 2) Minor renumbering (I avoided this while it was still thrashing). 3) HTLC rejection (eg. bad route, insufficient fees) added. 4) HTLC precision increase, ceiling drop.
The last one deserves some discussion; I floated the idea with Taj and Joseph of allowing sub-satoshi HTLC amounts, and they concurred. Amounts get truncated on settlement of course, but they may serve us well in future.
As a secondary effect, 32 bits places a ceiling of 0.04 satoshi (currently about $10USD) on each HTLC. That's more than enough to cover the micropayment uses of lightning, yet if you lose all your money due to a horrible bug in the early days, I can buy you a beer and count us about even[1]. And we can change the protocol later if it becomes overly limiting.
Cheers, Rusty. [1] Please do not construe this as any form of beverage-backed warranty :)
Hi Rusty,
Quoted text (2 lines)
> 1) Close now has an second ACK stage, which means you know the close ack > has been received.
Argh, I already have trouble understanding the rationale behind all the existing closing flows and states :-s Would it be possible to publish an updated version of the svg ? aj, any chance you could do the same with your 'flat' version ?
Quoted text (1 line)
> 3) HTLC rejection (eg. bad route, insufficient fees) added.
How about the 'commit tx too big' case ? will that just be an error ?
Quoted text (6 lines)
> As a secondary effect, 32 bits places [an upper bound of 0.04 BTC] > (currently about $10USD) on each HTLC. That's more than enough to cover > the micropayment uses of lightning, yet if you lose all your money due > to a horrible bug in the early days, I can buy you a beer and count us > about even[1]. And we can change the protocol later if it becomes > overly limiting.
Such a low ceiling bothers me a little bit, because it kind of states that the micropayment use case is the primary target. Is it ? To me, scalability and speed are the most interesting properties of lightning. I would have preferred a higher (1 BTC ?) limit, but I understand this can be changed. Regarding the risk of bugs, you can't loose more than the channel capacity so that's another parameter we can play with I guess.
Cheers,
Pierre
On Thu, Sep 24, 2015 at 03:17:41PM +0930, Rusty Russell wrote:
Quoted text (3 lines)
> 4) HTLC precision increase, ceiling drop. > As a secondary effect, 32 bits places a ceiling of 0.04 satoshi > (currently about $10USD) on each HTLC.
This means keeping the channel balances in 64 bit counters, right?
I was thinking along the following lines:
- bitcoin txns have absolute fees (currently f = 0.1 mBTC) - lightning has percentage fees (call it p) - so breakeven point is a transaction amount A, where A * p = f; ie A = f/p - p should be less than 2%, putting a lower limit on A of 5 mBTC, but 0.04 BTC = 40 mBTC, which is well above that. - if A = 0.04 BTC, p = f/A = 0.25%, putting a lower limit on lightning fees (that's for the entire path, individual hops could be lower)
I probably would have preferred capping out at about 0.1 BTC (~$23), corresponding to lightning fees of 0.1% matching bitcoin fees of 0.1 mBTC, but that's quibbling.
Anyway, if you want to send more than $10 via lightning you just do multiple transactions with different R values [0], the same way you might use two $20 notes to pay someone $40. Even $1000 would just be 100 transactions, which doesn't seem like too big a deal?
Having a small maximum is probably also useful for routing -- if you want to send two $10 notes, send them along different routes to avoid draining any particular channel. That also helps obscure how much is being spent.
A maximum seems pretty helpful for planning how to fund a node too -- if you know no individual transaction will be more than 0.04 BTC, you can setup your fee schedule in 0.04 BTC increments (or greater), and not have to worry about "if i got 30 mBTC I'd raise my fee before the next 30 mBTC came in; but here's 60 mBTC in one hop with just 2x the lower fee! do I accept it or reject it?"
So, hey, turns out I totally endorse this change. +1.
Cheers, aj
[0] or just rely on the different S values the R/S method for avoiding
onion probing would automatically useRusty Russell <rusty at rustcorp.com.au> writes:
Quoted text (1 line)
> As a secondary effect, 32 bits places a ceiling of 0.04 satoshi
Thanks for everyone who pointed out that bitcoin has not jumped in value by a factor of 10^8.
This should indeed be 0.04 BTC :)
Cheers, Rusty.
Pierre <pm+lists at acinq.fr> writes:
Quoted text (8 lines)
> Hi Rusty, > >> 1) Close now has an second ACK stage, which means you know the close ack >> has been received. > Argh, I already have trouble understanding the rationale behind all > the existing closing flows and states :-s Would it be possible to > publish an updated version of the svg ? aj, any chance you could do > the same with your 'flat' version ?
Heh, this one is pretty easy. It's just an ack at the end of the mutual close handshake:
close_channel
close_channel_complete
close_channel_ack (this is new).
Quoted text (2 lines)
>> 3) HTLC rejection (eg. bad route, insufficient fees) added. > How about the 'commit tx too big' case ? will that just be an error ?
A protocol error: you should never propose a HTLC which will cause the commit tx to be malformed.
Quoted text (10 lines)
>> As a secondary effect, 32 bits places [an upper bound of 0.04 BTC] >> (currently about $10USD) on each HTLC. That's more than enough to cover >> the micropayment uses of lightning, yet if you lose all your money due >> to a horrible bug in the early days, I can buy you a beer and count us >> about even[1]. And we can change the protocol later if it becomes >> overly limiting. > Such a low ceiling bothers me a little bit, because it kind of states > that the micropayment use case is the primary target. Is it ? To me, > scalability and speed are the most interesting properties of > lightning.
I think the early adopters are going to be microtransactions. And they're good to have: they build the network, stress-test us, and let us learn without risking too much.
Quoted text (4 lines)
> I would have preferred a higher (1 BTC ?) limit, but I > understand this can be changed. Regarding the risk of bugs, you can't > loose more than the channel capacity so that's another parameter we > can play with I guess.
My reference implementation refuses to create a channel which would overflow this. That was a simple check to implement (we already check that no HTLC would spend more than channel capacity of course).
I use 64 bits internally, to avoid wrap issues anyway.
My general philosophy here is to underpromise, and over-deliver. I can't talk to all the users individually, but if we set *our* expectations at "beer money, not rent money" that will hopefully spread.
I recommend reading one of the "I was Goxxed" reddit threads for some heartbreaking perspective on what happens when innocent people get caught up in hype :(
Cheers, Rusty.
On Thu, Sep 24, 2015 at 12:25:11PM +0200, Pierre wrote:
Quoted text (5 lines)
> > 1) Close now has an second ACK stage, which means you know the close ack > Argh, I already have trouble understanding the rationale behind all > the existing closing flows and states :-s Would it be possible to > publish an updated version of the svg ? aj, any chance you could do > the same with your 'flat' version ?
Yeah. I've updated state.py so the following flow works:
$ test/test_state_coverage --dump-states | tee STATES $ ./state.py > update.dot $ dot -Tsvg update.dot > update.svg
state.py is at https://github.com/ajtowns/lightning/blob/state/state.py
Updated svg is viewable at
http://azure.erisian.com.au/~aj/tmp/lightstate/simplified-states-20150929.svg
Note that some transitions are still missing, notably PKT_UPDATE_DECLINE_HTLC.
(I'm not following why the state coverage testing doesn't do something more like:
states = []
path_to_state = {}
for s in init_states:
path_to_states[s] = [s]
states.append(s)
i = 0
while i < len(states):
tst_state = states[i]
p = path_to_states[tst_state]
for in_pkt in all_packets:
# enter test state
simulation_init(p[0])
for setup_pkt in p[1:]:
simulation_send_pkt(setup_pkt)
# send packet
new_state, response_pkt = simulation_send_pkt(in_pkt)
# document result
dump_transition(tst_state, in_pkt, new_state, response_pkt)
# if new state, add it to list to test
if new_state not in states:
path_to_state[new_state] = p + [in_pkt]
states.append(new_state)
ie, for every state, throw every packet at it and record what happens; assuming that any given state behaves the same no matter how you get into it)
Cheers, aj
Anthony Towns <aj at erisian.com.au> writes:
Quoted text (56 lines)
> On Thu, Sep 24, 2015 at 12:25:11PM +0200, Pierre wrote: >> > 1) Close now has an second ACK stage, which means you know the close ack >> Argh, I already have trouble understanding the rationale behind all >> the existing closing flows and states :-s Would it be possible to >> publish an updated version of the svg ? aj, any chance you could do >> the same with your 'flat' version ? > > Yeah. I've updated state.py so the following flow works: > > $ test/test_state_coverage --dump-states | tee STATES > $ ./state.py > update.dot > $ dot -Tsvg update.dot > update.svg > > state.py is at https://github.com/ajtowns/lightning/blob/state/state.py > > Updated svg is viewable at > > http://azure.erisian.com.au/~aj/tmp/lightstate/simplified-states-20150929.svg > > Note that some transitions are still missing, notably > PKT_UPDATE_DECLINE_HTLC. > > (I'm not following why the state coverage testing doesn't do something > more like: > > states = [] > path_to_state = {} > for s in init_states: > path_to_states[s] = [s] > states.append(s) > > i = 0 > while i < len(states): > tst_state = states[i] > p = path_to_states[tst_state] > > for in_pkt in all_packets: > # enter test state > simulation_init(p[0]) > for setup_pkt in p[1:]: > simulation_send_pkt(setup_pkt) > > # send packet > new_state, response_pkt = simulation_send_pkt(in_pkt) > > # document result > dump_transition(tst_state, in_pkt, new_state, response_pkt) > > # if new state, add it to list to test > if new_state not in states: > path_to_state[new_state] = p + [in_pkt] > states.append(new_state) > > ie, for every state, throw every packet at it and record what happens; > assuming that any given state behaves the same no matter how you get > into it)
Sure, but that's not even close to exhaustive testing (drawing diagrams was just a side-effect for me).
Unfortunately the state doesn't quite encapsulate everything. For example, it captures whether you have HTLCs or not, but not whether you have more than one.
You also want to simulate a pair, and make sure you cover all combinations of states between the two.
You also need to take into account what non-packet events are possible (eg. timeouts, bitcoin watch events).
Finally, you want to inject errors.
Anyway, the final result (requiring about 14.5GB of memory to run, though it should be fairly swap-friendly) has now been pushed.
Cheers, Rusty.
On Wed, Sep 30, 2015 at 11:11:09AM +0930, Rusty Russell wrote:
Quoted text (4 lines)
> > (I'm not following why the state coverage testing doesn't do something > > more like: [...] > Sure, but that's not even close to exhaustive testing (drawing diagrams > was just a side-effect for me).
Absolutely. But... I'm not seeing what the code actually /does/ with the exhaustive testing? There's a lot of asserts; but I'm not sure that's actually testing things "make sense" or just "don't crash". Maybe having some optional output of traces for successful test cases would make it more obvious?
eg, (and I haven't tried pulling the code apart to really understand it or anything) I can't tell if you're testing agreeing on two HTLCs then having the first one time out, versus the second one time out first.
Hmm:
report_trail(&t, "CLOSED with htlc in progress?");
I figured that was expected and normal protocol behaviour? Not ideal, but if you're still communicating at all, if someone decides the channel has to be closed, it's still always better to do a mutual close to avoid the CSV delays and any unnecessarily elevated fees, even with outstanding HTLCs.
That would mean CLOSE should start tracking HTLCs (and spending when timeouts hit or R's become known) just like when a commitment is published; so I guess that's CLOSE_WAIT_HTLCs?
Cheers, aj
Anthony Towns <aj at erisian.com.au> writes:
Quoted text (11 lines)
> On Wed, Sep 30, 2015 at 11:11:09AM +0930, Rusty Russell wrote: >> > (I'm not following why the state coverage testing doesn't do something >> > more like: [...] >> Sure, but that's not even close to exhaustive testing (drawing diagrams >> was just a side-effect for me). > > Absolutely. But... I'm not seeing what the code actually /does/ with the > exhaustive testing? There's a lot of asserts; but I'm not sure that's > actually testing things "make sense" or just "don't crash". Maybe having > some optional output of traces for successful test cases would make it > more obvious?
More comments and more testing would be nice, but at some point I have to stop writing tests :)
Tests are (with varying degrees of thoroughness):
1) State machine never gets into an invalid state. 2) State machine never sends a packet other side doesn't expect. 3) State machine terminates if not on main loop. 4) State machine does not deadlock (both sides waiting, none sending). 5) State machine cleans up.
Quoted text (13 lines)
> eg, (and I haven't tried pulling the code apart to really understand > it or anything) I can't tell if you're testing agreeing on two HTLCs then > having the first one time out, versus the second one time out first. > > Hmm: > > report_trail(&t, "CLOSED with htlc in progress?"); > > I figured that was expected and normal protocol behaviour? Not ideal, > but if you're still communicating at all, if someone decides the channel > has to be closed, it's still always better to do a mutual close to > avoid the CSV delays and any unnecessarily elevated fees, even with > outstanding HTLCs.
STATE_CLOSED here means "completely finished".
But also, we don't support mutual close with outstanding HTLCs. We could, but the protocol is complex enough already.
Cheers, Rusty.
Quoted text (6 lines)
>> Argh, I already have trouble understanding the rationale behind all >> the existing closing flows and states :-s Would it be possible to >> publish an updated version of the svg ? aj, any chance you could do >> the same with your 'flat' version ? > > Yeah. I've updated state.py so the following flow works:
Thanks!
I guess what I'm missing about all those closing states is the reason why we need to handle combinations of the 3 basic cases (current commit, revoked commit or mutual close).
This cannot happen since they all spend the same anchor right ? Why do we care if they are broadcasted and not confirmed ?
Cheers,
Pierre
Pierre <pm+lists at acinq.fr> writes:
Quoted text (15 lines)
>>> Argh, I already have trouble understanding the rationale behind all >>> the existing closing flows and states :-s Would it be possible to >>> publish an updated version of the svg ? aj, any chance you could do >>> the same with your 'flat' version ? >> >> Yeah. I've updated state.py so the following flow works: > > Thanks! > > I guess what I'm missing about all those closing states is the reason > why we need to handle combinations of the 3 basic cases (current > commit, revoked commit or mutual close). > > This cannot happen since they all spend the same anchor right ? Why do > we care if they are broadcasted and not confirmed ?
We need to keep watching until (any one of them) is buried deep enough that we don't care (say 100 deep). Otherwise a revoked transaction + chain reorganization could cheat us of funds.
These details are what makes a robust implementation so difficult :(
Cheers, Rusty.