diff --git a/lightningd/channel_state.h b/lightningd/channel_state.h index 60036e36f..f1bcd1bc3 100644 --- a/lightningd/channel_state.h +++ b/lightningd/channel_state.h @@ -26,8 +26,11 @@ enum channel_state { FUNDING_SPEND_SEEN, /* On chain */ - ONCHAIN + ONCHAIN, + + /* Final state after we have fully settled on-chain */ + CLOSED }; -#define CHANNEL_STATE_MAX ONCHAIN +#define CHANNEL_STATE_MAX CLOSED #endif /* LIGHTNING_LIGHTNINGD_CHANNEL_STATE_H */ diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 012ed8634..1239d8d5a 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -842,7 +842,10 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload, case ONCHAIN: case FUNDING_SPEND_SEEN: case CLOSINGD_COMPLETE: - /* Channel is supposed to be active! */ + /* Channel is supposed to be active!*/ + abort(); + case CLOSED: + /* Channel should not have been loaded */ abort(); /* We consider this "active" but we only send an error */ diff --git a/wallet/wallet.c b/wallet/wallet.c index bbc040d8e..cd783bf78 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -850,8 +850,7 @@ bool wallet_channels_load_active(struct wallet *w) sqlite3_stmt *stmt; /* We load all channels */ - stmt = db_select(w->db, "%s FROM channels;", channel_fields); - + stmt = db_select(w->db, "%s FROM channels WHERE state < %d;", channel_fields, CLOSED); w->max_channel_dbid = 0; int count = 0;