mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
test/test_state_coverage: Check for deadlock.
We should always have a packet in flight unless we're in the two waiting-for-anchor-to-mature states, or at the top of the main loop. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
642c3e36e3
commit
066bf1f4e5
@ -354,6 +354,11 @@ Pkt *accept_pkt_close_complete(struct state_effect *effect, const struct state_d
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Pkt *accept_pkt_simultaneous_close(struct state_effect *effect, const struct state_data *sdata, const Pkt *pkt)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Pkt *accept_pkt_close_ack(struct state_effect *effect, const struct state_data *sdata, const Pkt *pkt)
|
||||
{
|
||||
return NULL;
|
||||
@ -820,6 +825,31 @@ 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)
|
||||
return true;
|
||||
if (b == STATE_OPEN_WAITING_THEIRANCHOR)
|
||||
return true;
|
||||
|
||||
/* We don't need inputs at start of main loop. */
|
||||
if (a == STATE_NORMAL_LOWPRIO
|
||||
&& b == STATE_NORMAL_HIGHPRIO)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool has_packets(const struct state_data *sdata)
|
||||
{
|
||||
return sdata->deferred_pkt != INPUT_NONE
|
||||
|| sdata->num_outputs != 0;
|
||||
}
|
||||
|
||||
static struct trail *try_input(const struct state_data *sdata,
|
||||
enum state_input i,
|
||||
bool normalpath, bool errorpath,
|
||||
@ -899,6 +929,14 @@ static struct trail *try_input(const struct state_data *sdata,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're listening, someone should be talking (usually).
|
||||
*/
|
||||
if (copy.pkt_inputs && !has_packets(©) && !has_packets(&peer)
|
||||
&& !waiting_statepair(copy.state, peer.state)) {
|
||||
return new_trail(i, sdata, newstate, effect, "Deadlock");
|
||||
}
|
||||
|
||||
/* Finished? */
|
||||
if (newstate == STATE_CLOSED) {
|
||||
if (copy.pkt_inputs)
|
||||
|
Loading…
Reference in New Issue
Block a user