From rusty at rustcorp.com.au Fri Aug 21 01:27:22 2015 From: rusty at rustcorp.com.au (Rusty Russell) Date: Fri, 21 Aug 2015 10:57:22 +0930 Subject: [Lightning-dev] A state machine. In-Reply-To: References: <87si7eiehg.fsf@rustcorp.com.au> Message-ID: <87k2spig79.fsf@rustcorp.com.au> Pierre writes: > Hello all, > > First, bravo for the great work on lightning ! @Rusty I'm the guy who > recently made two dummy PR on your github project, thanks for merging them > ;-) > > I've just got one remark : from OPEN_WAITING state, you seem to be assuming > that the event BITCOIN_ANCHOR_DEPTHOK will always happen before receiving > the other party's PKT_OPEN_COMPLETE ; but that won't necessarily be the > case depending on each party's minDepth, right ? It actually ignores ("defers") that packet until after the transition; I suppressed the loops in the simplified diagram, but the code is: case STATE_OPEN_WAITING_OURANCHOR: if (input_is(input, BITCOIN_ANCHOR_DEPTHOK)) { set_effect(effect, send, pkt_open_complete(effect, sdata)); return STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR; } else if (input_is(input, BITCOIN_ANCHOR_UNSPENT)) { goto anchor_unspent; } else if (input_is(input, PKT_OPEN_COMPLETE)) { /* Ignore until we've hit depth ourselves. */ set_effect(effect, defer, input); return state; ... > Also, can you please confirm that the following is correct in an > Alice->Bob->Carol->Dave scenario if we look at the state of *Bob* ? Bob has two states here; the states are per connection. So there's Bob->Alice and Bob->Carol. > 1) Bob is in NORMAL state > - Bob receives update_add_htlc from Alice > - Bob sends update_accept to Alice > > 2) Bob switches to WAIT_FOR_UPDATE_SIG state > - Bob receives update_signature from Alice > > - (Bob sends update_add_htlc to Carol on another channel) > - (Bob receives update_complete_htlc on another channel) > > 3) Bob switches to NORMAL state So far so good. Now the HTLC is established, so I don't understand these transitions: > - Bob sends update_accept to Alice > > 4) Bob switches to WAIT_FOR_UPDATE_SIG state > - Bob receives update_signature from Alice > > 5) Bob switches to NORMAL state Cheers, Ruysty.