Skip to content

Commit

Permalink
tests: Handle BDB dynamic pagesize
Browse files Browse the repository at this point in the history
BDB may choose to use a pagesize other than 4096. As such, the parser
should use the pagesize given by the BDB file.
  • Loading branch information
achow101 committed Nov 5, 2024
1 parent b934954 commit 74ff846
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions test/functional/test_framework/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
Utilities for working directly with the wallet's BDB database file
This is specific to the configuration of BDB used in this project:
- pagesize: 4096 bytes
- Outer database contains single subdatabase named 'main'
- btree
- btree leaf pages
Expand All @@ -27,7 +26,7 @@
import struct

# Important constants
PAGESIZE = 4096
MIN_PAGESIZE = 512
OUTER_META_PAGE = 0
INNER_META_PAGE = 2

Expand Down Expand Up @@ -132,10 +131,14 @@ def dump_bdb_kv(filename):
# Read in the BDB file and start deserializing it
pages = []
with open(filename, 'rb') as f:
data = f.read(PAGESIZE)
# Read the outer meta page for the page size. It will always be at least 512 bytes.
metadata = dump_meta_page(f.read(MIN_PAGESIZE))
f.seek(0)

data = f.read(metadata["pagesize"])
while len(data) > 0:
pages.append(data)
data = f.read(PAGESIZE)
data = f.read(metadata["pagesize"])

# Sanity check the meta pages
dump_meta_page(pages[OUTER_META_PAGE])
Expand Down

0 comments on commit 74ff846

Please sign in to comment.