diff options
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-08-16 17:05:50 +0000 |
---|---|---|
committer | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-08-16 17:05:50 +0000 |
commit | 15399da9fe29336f119121340146d78973b601a5 (patch) | |
tree | 35a119aa0cd0adea14657b8dbe184b4eef3bdafb /main.cpp | |
parent | 6da916d4acf0c26be81b4547da0e4160d53aacc8 (diff) |
blocks-1,
verify block chain on load, so wouldn't have needed to delete blk*.dat, it would have done a reorg automatically
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@137 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 97 |
1 files changed, 53 insertions, 44 deletions
@@ -1234,6 +1234,57 @@ bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew) }
+bool CBlock::SetBestChain(CTxDB& txdb, CBlockIndex* pindexNew)
+{
+ uint256 hash = GetHash();
+
+ txdb.TxnBegin();
+ if (pindexGenesisBlock == NULL && hash == hashGenesisBlock)
+ {
+ pindexGenesisBlock = pindexNew;
+ txdb.WriteHashBestChain(hash);
+ }
+ else if (hashPrevBlock == hashBestChain)
+ {
+ // Adding to current best branch
+ if (!ConnectBlock(txdb, pindexNew) || !txdb.WriteHashBestChain(hash))
+ {
+ txdb.TxnAbort();
+ Lockdown(pindexNew);
+ return error("SetBestChain() : ConnectBlock failed");
+ }
+ txdb.TxnCommit();
+ pindexNew->pprev->pnext = pindexNew;
+
+ // Delete redundant memory transactions
+ foreach(CTransaction& tx, vtx)
+ tx.RemoveFromMemoryPool();
+ }
+ else
+ {
+ // New best branch
+ if (!Reorganize(txdb, pindexNew))
+ {
+ txdb.TxnAbort();
+ Lockdown(pindexNew);
+ return error("SetBestChain() : Reorganize failed");
+ }
+ }
+ txdb.TxnCommit();
+
+ // New best block
+ hashBestChain = hash;
+ pindexBest = pindexNew;
+ nBestHeight = pindexBest->nHeight;
+ bnBestChainWork = pindexNew->bnChainWork;
+ nTimeBestReceived = GetTime();
+ nTransactionsUpdated++;
+ printf("SetBestChain: new best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
+
+ return true;
+}
+
+
bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos)
{
// Check for duplicate
@@ -1260,50 +1311,8 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) // New best
if (pindexNew->bnChainWork > bnBestChainWork)
- {
- txdb.TxnBegin();
- if (pindexGenesisBlock == NULL && hash == hashGenesisBlock)
- {
- pindexGenesisBlock = pindexNew;
- txdb.WriteHashBestChain(hash);
- }
- else if (hashPrevBlock == hashBestChain)
- {
- // Adding to current best branch
- if (!ConnectBlock(txdb, pindexNew) || !txdb.WriteHashBestChain(hash))
- {
- txdb.TxnAbort();
- Lockdown(pindexNew);
- return error("AddToBlockIndex() : ConnectBlock failed");
- }
- txdb.TxnCommit();
- pindexNew->pprev->pnext = pindexNew;
-
- // Delete redundant memory transactions
- foreach(CTransaction& tx, vtx)
- tx.RemoveFromMemoryPool();
- }
- else
- {
- // New best branch
- if (!Reorganize(txdb, pindexNew))
- {
- txdb.TxnAbort();
- Lockdown(pindexNew);
- return error("AddToBlockIndex() : Reorganize failed");
- }
- }
- txdb.TxnCommit();
-
- // New best block
- hashBestChain = hash;
- pindexBest = pindexNew;
- nBestHeight = pindexBest->nHeight;
- bnBestChainWork = pindexNew->bnChainWork;
- nTimeBestReceived = GetTime();
- nTransactionsUpdated++;
- printf("AddToBlockIndex: new best=%s height=%d work=%s\n", hashBestChain.ToString().substr(0,22).c_str(), nBestHeight, bnBestChainWork.ToString().c_str());
- }
+ if (!SetBestChain(txdb, pindexNew))
+ return false;
txdb.Close();
|