Skip to content

Commit

Permalink
db: Added DB migrations to get the correct sync height
Browse files Browse the repository at this point in the history
The no-rescan change requires us to rescan one last time from the first_blocknum
of our channels (if we have any). The migrations just drop blocks that are
higher, then insert a dummy with the first_blocknum, and then clean up after
us. If we don't have any channels we don't go back at all.

Signed-off-by: Christian Decker <[email protected]>
  • Loading branch information
cdecker committed Apr 25, 2018
1 parent ac9e558 commit 89ff46f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,16 @@ char *dbmigrations[] = {
", blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE"
", PRIMARY KEY(id)"
");",
/* -- Set the correct rescan height for PR #1398 -- */
/* Delete blocks that are higher than our initial scan point, this is a
* no-op if we don't have a channel. */
"DELETE FROM blocks WHERE height > (SELECT MIN(first_blocknum) FROM channels);",
/* Now make sure we have the lower bound block with the first_blocknum
* height. This may introduce a block with NULL height if we didn't have any
* blocks, remove that in the next. */
"INSERT OR IGNORE INTO blocks (height) VALUES ((SELECT MIN(first_blocknum) FROM channels));",
"DELETE FROM blocks WHERE height IS NULL;",
/* -- End of PR #1398 -- */
NULL,
};

Expand Down

0 comments on commit 89ff46f

Please sign in to comment.