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.
This commit is contained in:
Pieter Wuille
2012-08-13 19:11:05 +02:00
parent 8adf48dc9b
commit 5382bcf8cd
4 changed files with 265 additions and 102 deletions

View File

@@ -546,6 +546,22 @@ bool CTxDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
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 @@ bool CTxDB::LoadBlockIndex()
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 @@ bool CTxDB::LoadBlockIndexGuts()
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;