Skip to content

Commit d987890

Browse files
committed
Error if LSNs are not reset
1 parent 4d7a3ae commit d987890

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/wallet/migrate.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,24 @@ void BerkeleyRODatabase::Open()
561561
throw std::runtime_error("BDB builtin encryption is not supported");
562562
}
563563

564+
// Check all Log Sequence Numbers (LSN) point to file 0 and offset 1 which indicates that the LSNs were
565+
// reset and that the log files are not necessary to get all of the data in the database.
566+
for (uint32_t i = 0; i < outer_meta.last_page; ++i) {
567+
// The LSN is composed of 2 32-bit ints, the first is a file id, the second an offset
568+
// It will always be the first 8 bytes of a page, so we deserialize it directly for every page
569+
uint32_t file;
570+
uint32_t offset;
571+
SeekToPage(db_file, i, page_size);
572+
db_file >> file >> offset;
573+
if (outer_meta.other_endian) {
574+
file = internal_bswap_32(file);
575+
offset = internal_bswap_32(offset);
576+
}
577+
if (file != 0 || offset != 1) {
578+
throw std::runtime_error("LSNs are not reset, this database is not completely flushed. Please reopen then close the database with a version that has BDB support");
579+
}
580+
}
581+
564582
// Read the root page
565583
SeekToPage(db_file, outer_meta.root, page_size);
566584
PageHeader header(outer_meta.root, outer_meta.other_endian);

0 commit comments

Comments
 (0)