Browse Source

short_channel_id: catch parsing errors.

I upgraded my node with --disable-compat, and a heap of channels closed like:

	CHANNELD_NORMAL:We disagree on short_channel_ids: I have 557653x0x1351, you say 557653x2373x1", 

This is because the scids are strings in the databases, and it failed to parse
them properly.

Now we'll not start if that happens.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pylightning-async
Rusty Russell 6 years ago
committed by Christian Decker
parent
commit
d69680934e
  1. 4
      bitcoin/short_channel_id.h
  2. 2
      wallet/db.h
  3. 3
      wallet/wallet.c

4
bitcoin/short_channel_id.h

@ -50,12 +50,12 @@ static inline u16 short_channel_id_outnum(const struct short_channel_id *scid)
void mk_short_channel_id(struct short_channel_id *scid, void mk_short_channel_id(struct short_channel_id *scid,
u32 blocknum, u32 txnum, u16 outnum); u32 blocknum, u32 txnum, u16 outnum);
bool short_channel_id_from_str(const char *str, size_t strlen, bool WARN_UNUSED_RESULT short_channel_id_from_str(const char *str, size_t strlen,
struct short_channel_id *dst); struct short_channel_id *dst);
char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid); char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid);
bool short_channel_id_dir_from_str(const char *str, size_t strlen, bool WARN_UNUSED_RESULT short_channel_id_dir_from_str(const char *str, size_t strlen,
struct short_channel_id_dir *scidd); struct short_channel_id_dir *scidd);
char *short_channel_id_dir_to_str(const tal_t *ctx, char *short_channel_id_dir_to_str(const tal_t *ctx,

2
wallet/db.h

@ -134,7 +134,7 @@ void *sqlite3_column_arr_(const tal_t *ctx, sqlite3_stmt *stmt, int col,
bool sqlite3_bind_short_channel_id(sqlite3_stmt *stmt, int col, bool sqlite3_bind_short_channel_id(sqlite3_stmt *stmt, int col,
const struct short_channel_id *id); const struct short_channel_id *id);
bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col, WARN_UNUSED_RESULT bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col,
struct short_channel_id *dest); struct short_channel_id *dest);
bool sqlite3_bind_short_channel_id_array(sqlite3_stmt *stmt, int col, bool sqlite3_bind_short_channel_id_array(sqlite3_stmt *stmt, int col,
const struct short_channel_id *id); const struct short_channel_id *id);

3
wallet/wallet.c

@ -594,7 +594,8 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
if (sqlite3_column_type(stmt, 2) != SQLITE_NULL) { if (sqlite3_column_type(stmt, 2) != SQLITE_NULL) {
scid = tal(tmpctx, struct short_channel_id); scid = tal(tmpctx, struct short_channel_id);
sqlite3_column_short_channel_id(stmt, 2, scid); if (!sqlite3_column_short_channel_id(stmt, 2, scid))
return NULL;
} else { } else {
scid = NULL; scid = NULL;
} }

Loading…
Cancel
Save