From d9878903fb34939dee8e1462f079acc68110253d Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Mon, 15 Apr 2024 16:47:14 -0400 Subject: Error if LSNs are not reset --- src/wallet/migrate.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/wallet') diff --git a/src/wallet/migrate.cpp b/src/wallet/migrate.cpp index 895cee9e14..09254a76ad 100644 --- a/src/wallet/migrate.cpp +++ b/src/wallet/migrate.cpp @@ -561,6 +561,24 @@ void BerkeleyRODatabase::Open() throw std::runtime_error("BDB builtin encryption is not supported"); } + // Check all Log Sequence Numbers (LSN) point to file 0 and offset 1 which indicates that the LSNs were + // reset and that the log files are not necessary to get all of the data in the database. + for (uint32_t i = 0; i < outer_meta.last_page; ++i) { + // The LSN is composed of 2 32-bit ints, the first is a file id, the second an offset + // It will always be the first 8 bytes of a page, so we deserialize it directly for every page + uint32_t file; + uint32_t offset; + SeekToPage(db_file, i, page_size); + db_file >> file >> offset; + if (outer_meta.other_endian) { + file = internal_bswap_32(file); + offset = internal_bswap_32(offset); + } + if (file != 0 || offset != 1) { + 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"); + } + } + // Read the root page SeekToPage(db_file, outer_meta.root, page_size); PageHeader header(outer_meta.root, outer_meta.other_endian); -- cgit v1.2.3