Browse Source

wallet: Add a final `CLOSED` state to channels

Instead of deleting the channels we will simple mark them as `CLOSED` from now
on. This is needed for some of the other tables not to end up with dangling
references that would otherwise survive the channel lifetime, e.g., forwards
and transactions.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pull/2938/head
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
1dbdc74bc3
  1. 7
      lightningd/channel_state.h
  2. 5
      lightningd/peer_control.c
  3. 3
      wallet/wallet.c

7
lightningd/channel_state.h

@ -26,8 +26,11 @@ enum channel_state {
FUNDING_SPEND_SEEN, FUNDING_SPEND_SEEN,
/* On chain */ /* 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 */ #endif /* LIGHTNING_LIGHTNINGD_CHANNEL_STATE_H */

5
lightningd/peer_control.c

@ -842,7 +842,10 @@ peer_connected_hook_cb(struct peer_connected_hook_payload *payload,
case ONCHAIN: case ONCHAIN:
case FUNDING_SPEND_SEEN: case FUNDING_SPEND_SEEN:
case CLOSINGD_COMPLETE: 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(); abort();
/* We consider this "active" but we only send an error */ /* We consider this "active" but we only send an error */

3
wallet/wallet.c

@ -850,8 +850,7 @@ bool wallet_channels_load_active(struct wallet *w)
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
/* We load all channels */ /* 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; w->max_channel_dbid = 0;
int count = 0; int count = 0;

Loading…
Cancel
Save