mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
state: add _THEYCOMPLETED states to reflect receiving PKT_OPEN_COMPLETE
This is cleaner than deferring the packet receive and asking for it later. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3c1b2ad1c1
commit
3ab4ba1e6f
32
state.c
32
state.c
@ -153,19 +153,24 @@ struct state_effect *state(const tal_t *ctx,
|
||||
}
|
||||
break;
|
||||
case STATE_OPEN_WAITING_OURANCHOR:
|
||||
if (input_is(input, PKT_OPEN_COMPLETE)) {
|
||||
return next_state(ctx, effect,
|
||||
STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED);
|
||||
}
|
||||
/* Fall thru */
|
||||
case STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED:
|
||||
if (input_is(input, BITCOIN_ANCHOR_DEPTHOK)) {
|
||||
add_effect(&effect, send_pkt,
|
||||
pkt_open_complete(ctx, peer));
|
||||
if (state == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED) {
|
||||
add_effect(&effect, cmd_success, CMD_OPEN_WITH_ANCHOR);
|
||||
return next_state(ctx, effect, STATE_NORMAL_HIGHPRIO);
|
||||
}
|
||||
return next_state(ctx, effect,
|
||||
STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR);
|
||||
} else if (input_is(input, BITCOIN_ANCHOR_UNSPENT)) {
|
||||
add_effect(&effect, cmd_fail, NULL);
|
||||
goto anchor_unspent;
|
||||
} else if (input_is(input, PKT_OPEN_COMPLETE)) {
|
||||
/* Ignore until we've hit depth ourselves. */
|
||||
add_effect(&effect, cmd_defer, input);
|
||||
/* No state change. */
|
||||
return effect;
|
||||
} else if (input_is(input, BITCOIN_ANCHOR_THEIRSPEND)) {
|
||||
/* We no longer care about anchor depth. */
|
||||
add_effect(&effect, unwatch,
|
||||
@ -204,6 +209,12 @@ struct state_effect *state(const tal_t *ctx,
|
||||
}
|
||||
break;
|
||||
case STATE_OPEN_WAITING_THEIRANCHOR:
|
||||
if (input_is(input, PKT_OPEN_COMPLETE)) {
|
||||
return next_state(ctx, effect,
|
||||
STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED);
|
||||
}
|
||||
/* Fall thru */
|
||||
case STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED:
|
||||
if (input_is(input, BITCOIN_ANCHOR_TIMEOUT)) {
|
||||
/* Anchor didn't reach blockchain in reasonable time. */
|
||||
add_effect(&effect, send_pkt,
|
||||
@ -212,6 +223,12 @@ struct state_effect *state(const tal_t *ctx,
|
||||
} else if (input_is(input, BITCOIN_ANCHOR_DEPTHOK)) {
|
||||
add_effect(&effect, send_pkt,
|
||||
pkt_open_complete(ctx, peer));
|
||||
if (state == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED) {
|
||||
add_effect(&effect, cmd_success,
|
||||
CMD_OPEN_WITHOUT_ANCHOR);
|
||||
return next_state(ctx, effect,
|
||||
STATE_NORMAL_LOWPRIO);
|
||||
}
|
||||
return next_state(ctx, effect, STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR);
|
||||
} else if (input_is(input, BITCOIN_ANCHOR_UNSPENT)) {
|
||||
add_effect(&effect, cmd_fail, NULL);
|
||||
@ -227,11 +244,6 @@ struct state_effect *state(const tal_t *ctx,
|
||||
BITCOIN_ANCHOR_TIMEOUT));
|
||||
add_effect(&effect, cmd_fail, NULL);
|
||||
goto them_unilateral;
|
||||
} else if (input_is(input, PKT_OPEN_COMPLETE)) {
|
||||
/* Ignore until we've hit depth ourselves. */
|
||||
add_effect(&effect, cmd_defer, input);
|
||||
/* No state change. */
|
||||
return effect;
|
||||
} else if (input_is(input, CMD_CLOSE)) {
|
||||
/* We no longer care about anchor depth. */
|
||||
add_effect(&effect, unwatch,
|
||||
|
@ -23,6 +23,8 @@ enum state {
|
||||
STATE_OPEN_WAIT_FOR_COMMIT_SIG,
|
||||
STATE_OPEN_WAITING_OURANCHOR,
|
||||
STATE_OPEN_WAITING_THEIRANCHOR,
|
||||
STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED,
|
||||
STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED,
|
||||
STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR,
|
||||
STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR,
|
||||
|
||||
|
@ -1858,13 +1858,17 @@ static const char *simplify_state(enum state s)
|
||||
|
||||
static bool waiting_statepair(enum state a, enum state b)
|
||||
{
|
||||
if (a > b)
|
||||
return waiting_statepair(b, a);
|
||||
|
||||
/* We don't need inputs if we're waiting for anchors. */
|
||||
if (a == STATE_OPEN_WAITING_OURANCHOR)
|
||||
if (a == STATE_OPEN_WAITING_OURANCHOR
|
||||
|| a == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED
|
||||
|| a == STATE_OPEN_WAITING_THEIRANCHOR
|
||||
|| a == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED)
|
||||
return true;
|
||||
if (b == STATE_OPEN_WAITING_THEIRANCHOR)
|
||||
|
||||
if (b == STATE_OPEN_WAITING_OURANCHOR
|
||||
|| b == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED
|
||||
|| b == STATE_OPEN_WAITING_THEIRANCHOR
|
||||
|| b == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED)
|
||||
return true;
|
||||
|
||||
/* We don't need inputs at start of main loop. */
|
||||
@ -1872,6 +1876,10 @@ static bool waiting_statepair(enum state a, enum state b)
|
||||
&& b == STATE_NORMAL_HIGHPRIO)
|
||||
return true;
|
||||
|
||||
if (a == STATE_NORMAL_HIGHPRIO
|
||||
&& b == STATE_NORMAL_LOWPRIO)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2493,13 +2501,15 @@ int main(int argc, char *argv[])
|
||||
if (i == STATE_OPEN_WAIT_FOR_OPEN_NOANCHOR
|
||||
|| i == STATE_OPEN_WAIT_FOR_ANCHOR
|
||||
|| i == STATE_OPEN_WAITING_THEIRANCHOR
|
||||
|| i == STATE_OPEN_WAITING_THEIRANCHOR_THEYCOMPLETED
|
||||
|| i == STATE_OPEN_WAIT_FOR_COMPLETE_THEIRANCHOR
|
||||
|| i == STATE_ERR_ANCHOR_TIMEOUT)
|
||||
a_expect = false;
|
||||
if (i == STATE_OPEN_WAIT_FOR_OPEN_WITHANCHOR
|
||||
|| i == STATE_OPEN_WAIT_FOR_COMMIT_SIG
|
||||
|| i == STATE_OPEN_WAIT_FOR_COMPLETE_OURANCHOR
|
||||
|| i == STATE_OPEN_WAITING_OURANCHOR)
|
||||
|| i == STATE_OPEN_WAITING_OURANCHOR
|
||||
|| i == STATE_OPEN_WAITING_OURANCHOR_THEYCOMPLETED)
|
||||
b_expect = false;
|
||||
if (i == STATE_ERR_INTERNAL)
|
||||
a_expect = b_expect = false;
|
||||
|
Loading…
Reference in New Issue
Block a user