Merge bitcoin/bitcoin#35227: wallet: check the final BDB page LSN during migration

e2b0984f99 wallet: check BDB last page LSN (Lőrinc)

Pull request description:

  ### Problem

  Legacy wallet migration uses the read-only BDB parser to verify that every page LSN is reset before reading records without BDB log files.

  The BDB `last_page` metadata field stores the last valid page number, but the parser treated it like a page count and scanned only `0..<last_page`:
  e2b0984f99/src/wallet/migrate.cpp (L87)
  This skipped the final page, so a database whose last page still depended on BDB logs could be accepted.

  ### Fix

  Scan LSNs through `last_page` inclusively.

ACKs for top commit:
  achow101:
    ACK e2b0984f99
  w0xlt:
    ACK e2b0984f99
  sedited:
    ACK e2b0984f99

Tree-SHA512: 26fade6cdb4747d299b6e620646aa14751cd91fbb7e40ab6e35c1ca796fb589a2340d66108b812611f2924136a8f12c4f911efe6346fffaf04b2d3d288101cda
This commit is contained in:
merge-script
2026-05-10 12:02:33 +02:00

View File

@@ -567,7 +567,7 @@ void BerkeleyRODatabase::Open()
// 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) {
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;