Skip to content

Channel: Fix channel state max and add regression test #8420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions common/test/run-channel_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <ccan/tal/str/str.h>
#include <common/setup.h>
#include <stdio.h>
#include <lightningd/channel_state.h>

/* AUTOGENERATED MOCKS START */
/* Generated stub for amount_asset_is_main */
Expand Down Expand Up @@ -114,6 +115,42 @@ static void assert_names_eq(const char **names, const char *expected)
assert(streq(expected_names[i], names[i]));
}

static enum channel_state calc_channel_state_max(void)
{
enum channel_state largest_state = 0;

assert(DUALOPEND_OPEN_INIT == 1);
for (enum channel_state state = 1;; state++) {
bool known_state;
switch(state) {
case DUALOPEND_OPEN_INIT:
case CHANNELD_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_SIGEXCHANGE:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
case CHANNELD_AWAITING_SPLICE:
case DUALOPEND_OPEN_COMMIT_READY:
largest_state = state;
known_state = true;
break;
default:
known_state = false;
break;
}
if (!known_state)
break;
}

return largest_state;
}

int main(int argc, char *argv[])
{
struct channel_type t;
Expand All @@ -125,6 +162,8 @@ int main(int argc, char *argv[])
assert_names_eq(channel_type_name(tmpctx, channel_type_anchors_zero_fee_htlc(tmpctx)),
"static_remotekey/even anchors/even");

assert(calc_channel_state_max() == CHANNEL_STATE_MAX);

t.features = tal_arr(tmpctx, u8, 0);
set_feature_bit(&t.features, 1000);
assert_names_eq(channel_type_name(tmpctx, &t), "unknown_1000/even");
Expand Down
2 changes: 1 addition & 1 deletion lightningd/channel_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum channel_state {
DUALOPEND_OPEN_COMMIT_READY,

};
#define CHANNEL_STATE_MAX CHANNELD_AWAITING_SPLICE
#define CHANNEL_STATE_MAX DUALOPEND_OPEN_COMMIT_READY

/* These are in the database, so don't renumber them! */
enum state_change {
Expand Down
Loading