upleb.uk

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

summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorbitflash-maintainer <noreply@bitflash.invalid>2026-09-01 17:14:12 +0000
committerbitflash-maintainer <noreply@bitflash.invalid>2026-09-01 17:14:12 +0000
commitb4f0bc693ef7175702f82bcb2110b627922e8cbd (patch)
tree73435feb1a076dfba94d8143d7d7b7784908c82f /docs
parenta1d867ecbcfc9e218408d0a11863a450243a01f9 (diff)
parent6aa3dade77632f13189d2a3ef29897f29a5f9572 (diff)
Merge upstream v1.2.20 into the fork
Merges upstream tag v1.2.20 (6aa3dade) into our 1.2.19+sec tree. The merge base is bc3de30's descendant 9e39a50 -- upstream's own v1.2.19 -- so this is an ordinary three-way merge, not a replay. Five conflict blocks in four files, all resolved below. No consensus change. CheckBlock, ConnectBlock, DisconnectBlock, ConnectInputs, AcceptBlock, AcceptTransaction, GetNextWorkRequired and GetBlockValue hash identical to v1.2.19; script.cpp and script.h are byte-identical on both sides. main.cpp is +3 lines and main.h +2, all wallet-backend plumbing. rpc.cpp is untouched, so the payout ledger arrives unchanged. Makefile, VERSION. OURS, renumbered. 1.2.20+sec, for the same reason 1.2.19 carried +sec: this tree is not the upstream release of that number and the string names every release artifact. Makefile, AppImage recipe. OURS for the AppDir path, THEIRS for the bundled library. Upstream's hunk reverts the icon paths to a hardcoded /tmp/bitflash.AppDir, which is the local-user pre-placement hazard the fork moved out of /tmp in the first place; taking their side wholesale would have reintroduced it silently, inside a conflict about something else. The AppDir stays $(APPDIR), and libsqlite3.so.0 joins the bundled list, which the new backend genuinely needs. src/Makefile, src/makefile.mingw, HEADERS. BOTH. Ours drops market.h, theirs adds wallet_sqlite.h; the resolution does both. NODE_OBJS auto-merged correctly in both files -- obj/wallet_sqlite.o present, obj/market.o still gone -- and was verified rather than assumed, because that line has trapped this fork before. src/selftest.cpp, known-tests list. BOTH, union. Upstream adds eight wallet-storage tests, we keep payout-ledger. The dispatch chain itself auto-merged and still routes payout-ledger to RunPayoutLedgerSelfTest. Hardening verified intact after merge: the TLS 1.2 floor in nostr.cpp, the /rvrelay pin, opt-in managed Tor, strict sig3-on-onion descriptor verification, and the marketplace removal. Upstream shipped no build logs or __pycache__ this time; the three added files are docs/storage.md and src/wallet_sqlite.{cpp,h}. The SQLite backend this release introduces is NOT enabled here. An existing wallet.dat resolves to Berkeley DB on every branch of the new selection logic, and the conversion wizard is GUI-only and not compiled into the headless node. The review findings that gate ever turning it on -- the non-atomic backend marker, the connection-wide WriteHDMaster transaction, and the encrypt-swap crash window -- are recorded on the tracker, not fixed here.
Diffstat (limited to 'docs')
-rw-r--r--docs/storage.md158
1 files changed, 158 insertions, 0 deletions
diff --git a/docs/storage.md b/docs/storage.md
new file mode 100644
index 0000000..b52a955
--- /dev/null
+++ b/docs/storage.md
@@ -0,0 +1,158 @@
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`.
44Read-only tooling should go through `ScanWalletRecords()` instead of opening a
45Berkeley DB cursor directly. That keeps migration checks, audits, and future
46backends behind one record-stream boundary. Wallet rewrite code should also use
47that boundary when it needs to copy existing records into a newly written
48wallet file.
49
50| Key shape | Value | Secret? | Meaning |
51|---|---|---:|---|
52| `("name", address)` | `string` | No | Address book label. |
53| `("tx", txid)` | `CWalletTx` | No | Wallet transaction state, including spend flags and metadata. |
54| `("key", pubkey)` | `CPrivKey` | Yes | Plain private key record for unencrypted wallets or old backups. |
55| `"defaultkey"` | `vector<unsigned char>` | No | Default public key shown by the wallet. |
56| `"hdmaster"` | `vector<unsigned char>` | Yes | Plain BIP32 master private key material. |
57| `"hdchaincode"` | `vector<unsigned char>` | Yes | Plain BIP32 chain code. |
58| `"hdnext"` | `unsigned int` | No | Legacy deterministic derivation next index. |
59| `"hdschema"` | `int` | No | Deterministic derivation schema (`legacy` or `bip44`). |
60| `"hdcointype"` | `unsigned int` | No | BIP44 coin type. Bitflash is `4346950`. |
61| `"hdreceivenext"` | `unsigned int` | No | BIP44 external receive-chain next index. |
62| `"hdchangenext"` | `unsigned int` | No | BIP44 internal change-chain next index. |
63| `("mkey", id)` | `CWalletMasterKey` | Sensitive | Encrypted wallet master-key metadata. |
64| `("ckey", pubkey)` | `vector<unsigned char>` | Yes | Private key encrypted under the wallet master key. |
65| `"cryptedhdmaster"` | `vector<unsigned char>` | Yes | Encrypted BIP32 master private key material. |
66| `"cryptedhdchaincode"` | `vector<unsigned char>` | Yes | Encrypted BIP32 chain code. |
67| `"walletminversion"` | `int` | No | Minimum wallet format version required to open this wallet safely. |
68| `("pool", index)` | `vector<unsigned char>` | No | Public key reserved in the key pool. The private key lives in `key`/`ckey`. |
69| `("setting", name)` | typed setting value | Usually no | Wallet/UI settings such as mining mode, fees, and backup timestamps. |
70
71### Wallet Migration Rules
72
73A future wallet backend must keep these properties:
74
751. Unknown future wallet formats fail closed with a clear message.
762. Encrypted wallets must encrypt private keys and HD seed material.
773. A locked encrypted wallet may expose public keys and balances, but not
78 private keys or decrypted HD seed material.
794. `-backupwallet` must produce a wallet file that opens in a different datadir
80 without copying `database/`, and must not leave a half-written final backup
81 path if the copy or install step fails.
825. `-recoveryaudit` must distinguish:
83 - no recovery phrase installed;
84 - recovery phrase present;
85 - recovery phrase encrypted and locked, requiring unlock before coverage can
86 be audited.
87
88## SQLite Wallet Store
89
90Since v1.2.20 SQLite is the default wallet backend. It is a byte-preserving
91record store, not a new wallet format -- the same serialized `CDataStream` bytes
92`wallet.dat` uses:
93
94```sql
95CREATE TABLE wallet_records (
96 key BLOB PRIMARY KEY NOT NULL,
97 value BLOB NOT NULL
98);
99PRAGMA user_version=1;
100```
101
102A fresh data directory starts on `wallet.sqlite`. An existing `wallet.dat` keeps
103running on Berkeley DB until it is converted: the GUI offers a one-click
104conversion on first run, and `-walletbackend=sqlite` / `-walletbackend=bdb`
105(recorded in a plain-text `wallet-backend` marker file in the datadir) select a
106backend explicitly. Conversion never modifies `wallet.dat`; it stays as a
107fallback, and the change takes effect on restart.
108
109Every wallet operation runs on either backend: read, write, erase, key-pool and
110HD-seed writes (the two halves of the seed bracketed in one SQLite transaction),
111`-backupwallet` (checkpoint then copy the self-contained file), `-encryptwallet`
112(an atomic rebuild-and-swap in one transaction), and the `-walletstorageaudit` /
113`-walletstoragecheck` diagnostics, which read the active backend's file.
114
115The migration tooling remains available for scripted use. `-walletsqliteexport=FILE`
116streams every raw `wallet.dat` record through `ScanWalletRecords()` into a SQLite
117file in one transaction, refusing to overwrite. `-walletsqliteverify=FILE`
118compares the two streams and prints only counts. `-walletsqliteloadcheck=FILE`
119parses an export with the same record types the loader uses.
120`-walletsqliterestore=FILE` rebuilds a `wallet.dat` from an export in an empty
121data directory. Failed exports and restores remove their incomplete output.
122
123## `blkindex.dat`
124
125`blkindex.dat` is accessed through `CTxDB`.
126
127| Key shape | Value | Rebuildable? | Meaning |
128|---|---|---:|---|
129| `("tx", txid)` | `CTxIndex` | Yes | Transaction disk position and spent-output index state. |
130| `("owner", hash160, CDiskTxPos)` | `int height` | Yes | Legacy owner transaction index cursor range. |
131| `("blockindex", blockhash)` | `CDiskBlockIndex` | Yes | Block index entry. |
132| `"hashBestChain"` | `uint256` | Yes | Current best-chain tip hash. |
133
134`blkindex.dat` can be rebuilt from `blk*.dat` plus consensus validation. A
135future migration may therefore prefer a rebuild path over a byte-preserving
136conversion path.
137
138## Other Legacy Stores
139
140| File | Class | Records | Current risk |
141|---|---|---|---|
142| `reviews.dat` | `CReviewDB` | `("user", hash)`, `("reviews", hash)` | Legacy market/review storage. Not part of wallet safety. |
143| `market.dat` | `CMarketDB` | No explicit typed records in current wrappers. | Legacy market storage shell. |
144
145The old IP address database (`addr.dat`) has been removed. Peer discovery is
146handled by Nostr, `.btf`, rendezvous relays, and direct onion peers.
147
148## Migration Order (shipped in v1.2.20)
149
1501. Storage self-tests were added around Berkeley DB behavior first.
1512. The SQLite backend landed behind an explicit flag, then behind a
152 `wallet-backend` marker and a GUI conversion wizard.
1533. BDB-to-SQLite migration is a one-way copy that leaves `wallet.dat` as a backup.
1544. SQLite became the default for new wallets only after cross-version restore,
155 encryption, backup, and recovery-audit tests passed -- and a live coin-proof
156 of receive, spend, restart, and encrypt on real mainnet funds.
1575. Treat `blkindex.dat` separately; it is safer to rebuild than to migrate under
158 pressure.