diff options
author | Ava Chow <github@achow101.com> | 2024-04-15 16:47:14 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-05-16 15:03:13 -0400 |
commit | d9878903fb34939dee8e1462f079acc68110253d (patch) | |
tree | f3473bd229828272e98ab861418288895c0b0906 /src/wallet/migrate.cpp | |
parent | 4d7a3ae78e55f25868979f1bd920857a4aecb825 (diff) | |
download | bitcoin-d9878903fb34939dee8e1462f079acc68110253d.tar.xz |
Error if LSNs are not reset
Diffstat (limited to 'src/wallet/migrate.cpp')
-rw-r--r-- | src/wallet/migrate.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
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); |