Browse Source

db: add column for first block of channel.

This determines how far we go back.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
af0ed9e5cf
  1. 5
      wallet/db.c
  2. 19
      wallet/wallet.c
  3. 9
      wallet/wallet.h

5
wallet/db.c

@ -145,6 +145,11 @@ char *dbmigrations[] = {
" VALUES('next_pay_index', "
" COALESCE((SELECT MAX(pay_index) FROM invoices WHERE state=1), 0) + 1"
" );",
/* Create first_block field; initialize from channel id if any.
* This fails for channels still awaiting lockin, but that only applies to
* pre-release software, so it's forgivable. */
"ALTER TABLE channels ADD first_blocknum INTEGER;",
"UPDATE channels SET first_blocknum=CAST(short_channel_id AS INTEGER) WHERE short_channel_id IS NOT NULL;",
NULL,
};

19
wallet/wallet.c

@ -597,6 +597,25 @@ bool wallet_channels_load_active(struct wallet *w, struct list_head *peers)
return ok;
}
u32 wallet_channels_first_blocknum(struct wallet *w)
{
int err;
u32 first_blocknum;
sqlite3_stmt *stmt =
db_query(__func__, w->db,
"SELECT MIN(first_blocknum) FROM channels WHERE state >= %d AND state != %d;",
OPENINGD, CLOSINGD_COMPLETE);
err = sqlite3_step(stmt);
if (err == SQLITE_ROW && sqlite3_column_type(stmt, 1) != SQLITE_NULL)
first_blocknum = sqlite3_column_int(stmt, 1);
else
first_blocknum = UINT32_MAX;
sqlite3_finalize(stmt);
return first_blocknum;
}
void wallet_channel_config_save(struct wallet *w, struct channel_config *cc)
{
sqlite3_stmt *stmt;

9
wallet/wallet.h

@ -242,6 +242,15 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
*/
bool wallet_channels_load_active(struct wallet *w, struct list_head *peers);
/**
* wallet_channels_first_blocknum - get first block we're interested in.
*
* @w: wallet to load from.
*
* Returns UINT32_MAX if nothing interesting.
*/
u32 wallet_channels_first_blocknum(struct wallet *w);
/**
* wallet_extract_owned_outputs - given a tx, extract all of our outputs
*/

Loading…
Cancel
Save