diff options
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-07-25 16:45:21 +0000 |
---|---|---|
committer | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-07-25 16:45:21 +0000 |
commit | 3b7cd5d89a226426df9c723d1f9ddfe08b7d1def (patch) | |
tree | cb956c8dd87690dcd9e5d554286d39edbb199c32 /db.cpp | |
parent | e8bff10f07b80d820545661cee9337d8664a64cb (diff) |
Gavin Andresen's JSON-RPC HTTP authentication,
faster initial block download
-- version 0.3.3
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@109 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'db.cpp')
-rw-r--r-- | db.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
@@ -130,7 +130,14 @@ void CDB::Close() vTxn.front()->abort();
vTxn.clear();
pdb = NULL;
- dbenv.txn_checkpoint(0, 0, 0);
+
+ // Flush database activity from memory pool to disk log
+ unsigned int nMinutes = 0;
+ if (strFile == "addr.dat")
+ nMinutes = 2;
+ if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)
+ nMinutes = 1;
+ dbenv.txn_checkpoint(0, nMinutes, 0);
CRITICAL_BLOCK(cs_db)
--mapFileUseCount[strFile];
@@ -357,11 +364,12 @@ CBlockIndex* InsertBlockIndex(uint256 hash) bool CTxDB::LoadBlockIndex()
{
- // Get cursor
+ // Get database cursor
Dbc* pcursor = GetCursor();
if (!pcursor)
return false;
+ // Load mapBlockIndex
unsigned int fFlags = DB_SET_RANGE;
loop
{
@@ -398,7 +406,7 @@ bool CTxDB::LoadBlockIndex() pindexNew->nBits = diskindex.nBits;
pindexNew->nNonce = diskindex.nNonce;
- // Watch for genesis block and best block
+ // Watch for genesis block
if (pindexGenesisBlock == NULL && diskindex.GetBlockHash() == hashGenesisBlock)
pindexGenesisBlock = pindexNew;
}
@@ -409,17 +417,33 @@ bool CTxDB::LoadBlockIndex() }
pcursor->close();
+ // Calculate bnChainWork
+ vector<pair<int, CBlockIndex*> > vSortedByHeight;
+ vSortedByHeight.reserve(mapBlockIndex.size());
+ foreach(const PAIRTYPE(uint256, CBlockIndex*)& item, mapBlockIndex)
+ {
+ CBlockIndex* pindex = item.second;
+ vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
+ }
+ sort(vSortedByHeight.begin(), vSortedByHeight.end());
+ foreach(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
+ {
+ CBlockIndex* pindex = item.second;
+ pindex->bnChainWork = (pindex->pprev ? pindex->pprev->bnChainWork : 0) + pindex->GetBlockWork();
+ }
+
+ // Load hashBestChain pointer to end of best chain
if (!ReadHashBestChain(hashBestChain))
{
if (pindexGenesisBlock == NULL)
return true;
- return error("CTxDB::LoadBlockIndex() : hashBestChain not found");
+ return error("CTxDB::LoadBlockIndex() : hashBestChain not loaded");
}
-
if (!mapBlockIndex.count(hashBestChain))
- return error("CTxDB::LoadBlockIndex() : blockindex for hashBestChain not found");
+ return error("CTxDB::LoadBlockIndex() : hashBestChain not found in the block index");
pindexBest = mapBlockIndex[hashBestChain];
nBestHeight = pindexBest->nHeight;
+ bnBestChainWork = pindexBest->bnChainWork;
printf("LoadBlockIndex(): hashBestChain=%s height=%d\n", hashBestChain.ToString().substr(0,16).c_str(), nBestHeight);
return true;
|