diff src/db.cpp @ 3647:fdd92a9e5196 draft

Multiple blocks per file Change the block storage layer again, this time with multiple files per block, but tracked by txindex.dat database entries. The file format is exactly the same as the earlier blk00001.dat, but with smaller files (128 MiB for now). The database entries track how many bytes each block file already uses, how many blocks are in it, which range of heights is present and which range of dates.
author Pieter Wuille <pieter.wuille@gmail.com>
date Mon, 13 Aug 2012 19:11:05 +0200
parents 1f8d48b2b3c5
children eb986f1e2e93
line wrap: on
line diff
--- a/src/db.cpp
+++ b/src/db.cpp
@@ -546,6 +546,22 @@
     return Write(make_pair(string("blockindex"), blockindex.GetBlockHash()), blockindex);
 }
 
+bool CTxDB::WriteBlockFileInfo(int nFile, const CBlockFileInfo &info) {
+    return Write(make_pair(string("blockfile"), nFile), info);
+}
+
+bool CTxDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) {
+    return Read(make_pair(string("blockfile"), nFile), info);
+}
+
+bool CTxDB::WriteLastBlockFile(int nFile) {
+    return Write(string("lastblockfile"), nFile);
+}
+
+bool CTxDB::ReadLastBlockFile(int &nFile) {
+    return Read(string("lastblockfile"), nFile);
+}
+
 bool CTxDB::ReadHashBestChain(uint256& hashBestChain)
 {
     return Read(string("hashBestChain"), hashBestChain);
@@ -609,6 +625,12 @@
         pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork();
     }
 
+    // Load block file info
+    ReadLastBlockFile(nLastBlockFile);
+    printf("LoadBlockIndex(): last block file = %i\n", nLastBlockFile);
+    if (ReadBlockFileInfo(nLastBlockFile, infoLastBlockFile))
+        printf("LoadBlockIndex(): last block file: %s\n", infoLastBlockFile.ToString().c_str());
+ 
     // Load hashBestChain pointer to end of best chain
     if (!ReadHashBestChain(hashBestChain))
     {
@@ -788,7 +810,8 @@
             pindexNew->pprev          = InsertBlockIndex(diskindex.hashPrev);
             pindexNew->pnext          = InsertBlockIndex(diskindex.hashNext);
             pindexNew->nHeight        = diskindex.nHeight;
-            pindexNew->nAlternative   = diskindex.nAlternative;
+            pindexNew->pos            = diskindex.pos;
+            pindexNew->nUndoPos       = diskindex.nUndoPos;
             pindexNew->nVersion       = diskindex.nVersion;
             pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
             pindexNew->nTime          = diskindex.nTime;