mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
db: Added DB migrations to get the correct sync height
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 <decker.christian@gmail.com>
This commit is contained in:
10
wallet/db.c
10
wallet/db.c
@@ -318,6 +318,16 @@ char *dbmigrations[] = {
|
|||||||
", blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE"
|
", blockheight INTEGER REFERENCES blocks(height) ON DELETE CASCADE"
|
||||||
", PRIMARY KEY(id)"
|
", 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,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user