diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-13 17:21:01 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-13 17:59:25 -0300 |
| commit | 4660b7ba94b071e8e7cc69c06e04b5ff64f12dd4 (patch) | |
| tree | 46a1d2482876099b8ff24601ea385d27ac3a8ea6 | |
| parent | 6f9e07186d06f772c93832f0dcbd4f9432b44579 (diff) | |
docs: inventory Berkeley DB storage
| -rw-r--r-- | docs/storage.md | 115 |
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 | |||
| 3 | This document records the Berkeley DB surface that still exists in Bitflash. | ||
| 4 | It is a migration map, not a promise that all stores should move at once. | ||
| 5 | |||
| 6 | The immediate priority is `wallet.dat`: it holds spend authority and recovery | ||
| 7 | metadata. `blkindex.dat` can be rebuilt from block files, so it is important for | ||
| 8 | startup correctness but less dangerous than wallet storage. | ||
| 9 | |||
| 10 | ## Berkeley DB Environment | ||
| 11 | |||
| 12 | All `CDB` stores use one Berkeley DB environment rooted at: | ||
| 13 | |||
| 14 | ```text | ||
| 15 | <datadir>/database/ | ||
| 16 | ``` | ||
| 17 | |||
| 18 | The environment creates log files such as: | ||
| 19 | |||
| 20 | ```text | ||
| 21 | database/log.0000000001 | ||
| 22 | ``` | ||
| 23 | |||
| 24 | Those logs are part of the legacy BDB risk model. They are not user-facing | ||
| 25 | wallet files, but they can contain historical records while the environment is | ||
| 26 | live. Wallet encryption already rewrites `wallet.dat` and purges BDB environment | ||
| 27 | logs after the encrypted file is installed. | ||
| 28 | |||
| 29 | ## Common Records | ||
| 30 | |||
| 31 | Every `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 | |||
| 37 | Keys and values are serialized with the existing `CDataStream` format. A future | ||
| 38 | SQLite migration must preserve byte-for-byte value semantics until a higher | ||
| 39 | level 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 | |||
| 68 | A future wallet backend must keep these properties: | ||
| 69 | |||
| 70 | 1. Unknown future wallet formats fail closed with a clear message. | ||
| 71 | 2. Encrypted wallets must encrypt private keys and HD seed material. | ||
| 72 | 3. A locked encrypted wallet may expose public keys and balances, but not | ||
| 73 | private keys or decrypted HD seed material. | ||
| 74 | 4. `-backupwallet` must produce a wallet file that opens in a different datadir | ||
| 75 | without copying `database/`. | ||
| 76 | 5. `-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 | ||
| 94 | future migration may therefore prefer a rebuild path over a byte-preserving | ||
| 95 | conversion 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 | |||
| 104 | The old IP address database (`addr.dat`) has been removed. Peer discovery is | ||
| 105 | handled by Nostr, `.btf`, rendezvous relays, and direct onion peers. | ||
| 106 | |||
| 107 | ## Recommended Migration Order | ||
| 108 | |||
| 109 | 1. Keep adding storage self-tests around current BDB behavior. | ||
| 110 | 2. Add an experimental wallet backend behind an explicit flag. | ||
| 111 | 3. Implement BDB-to-new-wallet migration as a one-way copy with a backup. | ||
| 112 | 4. Make the new wallet backend default only after cross-version restore, | ||
| 113 | encryption, backup, and recovery-audit tests pass. | ||
| 114 | 5. Treat `blkindex.dat` separately; it is safer to rebuild than to migrate under | ||
| 115 | pressure. | ||