Browse Source

test/test_state_coverage: limit HTLCs in flight to 2.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
3e9680659e
  1. 45
      test/test_state_coverage.c

45
test/test_state_coverage.c

@ -43,7 +43,11 @@ struct htlc_spend_watch {
}; };
/* Beyond this we consider cases equal for traverse loop detection. */ /* Beyond this we consider cases equal for traverse loop detection. */
#define MAX_HTLCS 1 #define CAP_HTLCS 1
/* How many HTLCs to negotiate. */
#define MAX_HTLCS 2
/* But we can have many different malleated commit txs. */ /* But we can have many different malleated commit txs. */
#define HTLC_ARRSIZE 20 #define HTLC_ARRSIZE 20
@ -85,7 +89,7 @@ struct state_data {
struct htlc_progress current_htlc; struct htlc_progress current_htlc;
unsigned int num_htlcs_to_them, num_htlcs_to_us; unsigned int num_htlcs_to_them, num_htlcs_to_us;
struct htlc htlcs_to_them[HTLC_ARRSIZE], htlcs_to_us[HTLC_ARRSIZE]; struct htlc htlcs_to_them[MAX_HTLCS], htlcs_to_us[MAX_HTLCS];
unsigned int num_live_htlcs_to_them, num_live_htlcs_to_us; unsigned int num_live_htlcs_to_them, num_live_htlcs_to_us;
struct htlc live_htlcs_to_them[HTLC_ARRSIZE], live_htlcs_to_us[HTLC_ARRSIZE]; struct htlc live_htlcs_to_them[HTLC_ARRSIZE], live_htlcs_to_us[HTLC_ARRSIZE];
@ -131,7 +135,7 @@ static const struct situation *situation_keyof(const struct situation *situation
/* After 2, we stop looping. */ /* After 2, we stop looping. */
static unsigned int cap(unsigned int val) static unsigned int cap(unsigned int val)
{ {
return val > MAX_HTLCS ? MAX_HTLCS : val; return val > CAP_HTLCS ? CAP_HTLCS : val;
} }
static size_t situation_hash(const struct situation *situation) static size_t situation_hash(const struct situation *situation)
@ -749,7 +753,7 @@ struct htlc_watch
enum state_input tothem_spent; enum state_input tothem_spent;
enum state_input tothem_timeout; enum state_input tothem_timeout;
unsigned int num_htlcs_to_us, num_htlcs_to_them; unsigned int num_htlcs_to_us, num_htlcs_to_them;
struct htlc htlcs_to_us[HTLC_ARRSIZE], htlcs_to_them[HTLC_ARRSIZE]; struct htlc htlcs_to_us[MAX_HTLCS], htlcs_to_them[MAX_HTLCS];
}; };
struct htlc_unwatch struct htlc_unwatch
@ -1077,7 +1081,7 @@ static void remove_htlc(struct htlc *to_us, unsigned int *num_to_us,
arr = to_us; arr = to_us;
n = num_to_us; n = num_to_us;
} }
assert(*n < arrsize); assert(*n <= arrsize);
assert(h >= arr && h < arr + *n); assert(h >= arr && h < arr + *n);
off = h - arr; off = h - arr;
@ -1781,20 +1785,7 @@ static struct trail *run_peer(const struct state_data *sdata,
&& sdata->core.current_command == INPUT_NONE) { && sdata->core.current_command == INPUT_NONE) {
unsigned int i; unsigned int i;
/* We can always add a new HTLC, or close. */ /* We can always send a close. */
copy.core.current_command = CMD_SEND_HTLC_UPDATE;
idata->htlc_prog = tal(idata, struct htlc_progress);
idata->htlc_prog->adding = true;
idata->htlc_prog->htlc.to_them = true;
idata->htlc_prog->htlc.id = next_htlc_id();
t = try_input(&copy, copy.core.current_command, idata,
normalpath, errorpath, depth,
hist);
if (t)
return t;
idata->htlc = tal_free(idata->htlc);
copy.core.current_command = CMD_CLOSE; copy.core.current_command = CMD_CLOSE;
t = try_input(&copy, copy.core.current_command, idata, t = try_input(&copy, copy.core.current_command, idata,
normalpath, errorpath, depth, normalpath, errorpath, depth,
@ -1802,6 +1793,22 @@ static struct trail *run_peer(const struct state_data *sdata,
if (t) if (t)
return t; return t;
/* Add a new HTLC if not at max. */
if (copy.num_htlcs_to_them < MAX_HTLCS) {
copy.core.current_command = CMD_SEND_HTLC_UPDATE;
idata->htlc_prog = tal(idata, struct htlc_progress);
idata->htlc_prog->adding = true;
idata->htlc_prog->htlc.to_them = true;
idata->htlc_prog->htlc.id = next_htlc_id();
t = try_input(&copy, copy.core.current_command, idata,
normalpath, errorpath, depth,
hist);
if (t)
return t;
idata->htlc_prog = tal_free(idata->htlc_prog);
}
/* We can complete or routefail an HTLC they offered */ /* We can complete or routefail an HTLC they offered */
for (i = 0; i < sdata->num_htlcs_to_us; i++) { for (i = 0; i < sdata->num_htlcs_to_us; i++) {
idata->htlc_prog = tal(idata, struct htlc_progress); idata->htlc_prog = tal(idata, struct htlc_progress);

Loading…
Cancel
Save