upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/storage.md
diff options
context:
space:
mode:
authorNsable-sh <nsable-sh@noreply.git.bitflash.network>2026-08-13 17:21:01 -0300
committerNsable-sh <nsable-sh@noreply.git.bitflash.network>2026-08-13 17:59:25 -0300
commit4660b7ba94b071e8e7cc69c06e04b5ff64f12dd4 (patch)
tree46a1d2482876099b8ff24601ea385d27ac3a8ea6 /docs/storage.md
parent6f9e07186d06f772c93832f0dcbd4f9432b44579 (diff)
docs: inventory Berkeley DB storage
Diffstat (limited to 'docs/storage.md')
-rw-r--r--docs/storage.md115
1 files changed, 115 insertions, 0 deletions
diff --git a/docs/storage.md b/docs/storage.md
new file mode 100644
index 0000000..4dd35bd
--- /dev/null
+++ b/docs/storage.md
@@ -0,0 +1,115 @@
1# Bitflash Storage Inventory
2
3This document records the Berkeley DB surface that still exists in Bitflash.
4It is a migration map, not a promise that all stores should move at once.
5
6The immediate priority is `wallet.dat`: it holds spend authority and recovery
7metadata. `blkindex.dat` can be rebuilt from block files, so it is important for
8startup correctness but less dangerous than wallet storage.
9
10## Berkeley DB Environment
11
12All `CDB` stores use one Berkeley DB environment rooted at:
13
14```text
15<datadir>/database/
16```
17
18The environment creates log files such as:
19
20```text
21database/log.0000000001
22```
23
24Those logs are part of the legacy BDB risk model. They are not user-facing
25wallet files, but they can contain historical records while the environment is
26live. Wallet encryption already rewrites `wallet.dat` and purges BDB environment
27logs after the encrypted file is installed.
28
29## Common Records
30
31Every `CDB` file can carry:
32
33| Key | Value | Purpose |
34|---|---|---|
35| `"version"` | `int` | Database format version written when a DB is opened in create mode. |
36
37Keys and values are serialized with the existing `CDataStream` format. A future
38SQLite migration must preserve byte-for-byte value semantics until a higher
39level schema migration is intentionally introduced.
40
41## `wallet.dat`
42
43`wallet.dat` is accessed through `CWalletDB`.
44
45| Key shape | Value | Secret? | Meaning |
46|---|---|---:|---|
47| `("name", address)` | `string` | No | Address book label. |
48| `("tx", txid)` | `CWalletTx` | No | Wallet transaction state, including spend flags and metadata. |
49| `("key", pubkey)` | `CPrivKey` | Yes | Plain private key record for unencrypted wallets or old backups. |
50| `"defaultkey"` | `vector<unsigned char>` | No | Default public key shown by the wallet. |
51| `"hdmaster"` | `vector<unsigned char>` | Yes | Plain BIP32 master private key material. |
52| `"hdchaincode"` | `vector<unsigned char>` | Yes | Plain BIP32 chain code. |
53| `"hdnext"` | `unsigned int` | No | Legacy deterministic derivation next index. |
54| `"hdschema"` | `int` | No | Deterministic derivation schema (`legacy` or `bip44`). |
55| `"hdcointype"` | `unsigned int` | No | BIP44 coin type. Bitflash is `4346950`. |
56| `"hdreceivenext"` | `unsigned int` | No | BIP44 external receive-chain next index. |
57| `"hdchangenext"` | `unsigned int` | No | BIP44 internal change-chain next index. |
58| `("mkey", id)` | `CWalletMasterKey` | Sensitive | Encrypted wallet master-key metadata. |
59| `("ckey", pubkey)` | `vector<unsigned char>` | Yes | Private key encrypted under the wallet master key. |
60| `"cryptedhdmaster"` | `vector<unsigned char>` | Yes | Encrypted BIP32 master private key material. |
61| `"cryptedhdchaincode"` | `vector<unsigned char>` | Yes | Encrypted BIP32 chain code. |
62| `"walletminversion"` | `int` | No | Minimum wallet format version required to open this wallet safely. |
63| `("pool", index)` | `vector<unsigned char>` | No | Public key reserved in the key pool. The private key lives in `key`/`ckey`. |
64| `("setting", name)` | typed setting value | Usually no | Wallet/UI settings such as mining mode, fees, and backup timestamps. |
65
66### Wallet Migration Rules
67
68A future wallet backend must keep these properties:
69
701. Unknown future wallet formats fail closed with a clear message.
712. Encrypted wallets must encrypt private keys and HD seed material.
723. A locked encrypted wallet may expose public keys and balances, but not
73 private keys or decrypted HD seed material.
744. `-backupwallet` must produce a wallet file that opens in a different datadir
75 without copying `database/`.
765. `-recoveryaudit` must distinguish:
77 - no recovery phrase installed;
78 - recovery phrase present;
79 - recovery phrase encrypted and locked, requiring unlock before coverage can
80 be audited.
81
82## `blkindex.dat`
83
84`blkindex.dat` is accessed through `CTxDB`.
85
86| Key shape | Value | Rebuildable? | Meaning |
87|---|---|---:|---|
88| `("tx", txid)` | `CTxIndex` | Yes | Transaction disk position and spent-output index state. |
89| `("owner", hash160, CDiskTxPos)` | `int height` | Yes | Legacy owner transaction index cursor range. |
90| `("blockindex", blockhash)` | `CDiskBlockIndex` | Yes | Block index entry. |
91| `"hashBestChain"` | `uint256` | Yes | Current best-chain tip hash. |
92
93`blkindex.dat` can be rebuilt from `blk*.dat` plus consensus validation. A
94future migration may therefore prefer a rebuild path over a byte-preserving
95conversion path.
96
97## Other Legacy Stores
98
99| File | Class | Records | Current risk |
100|---|---|---|---|
101| `reviews.dat` | `CReviewDB` | `("user", hash)`, `("reviews", hash)` | Legacy market/review storage. Not part of wallet safety. |
102| `market.dat` | `CMarketDB` | No explicit typed records in current wrappers. | Legacy market storage shell. |
103
104The old IP address database (`addr.dat`) has been removed. Peer discovery is
105handled by Nostr, `.btf`, rendezvous relays, and direct onion peers.
106
107## Recommended Migration Order
108
1091. Keep adding storage self-tests around current BDB behavior.
1102. Add an experimental wallet backend behind an explicit flag.
1113. Implement BDB-to-new-wallet migration as a one-way copy with a backup.
1124. Make the new wallet backend default only after cross-version restore,
113 encryption, backup, and recovery-audit tests pass.
1145. Treat `blkindex.dat` separately; it is safer to rebuild than to migrate under
115 pressure.