From d4c02f5c0bf175a12a7afb99bcc369a68156eba9 Mon Sep 17 00:00:00 2001 From: Scott Nadal Date: Tue, 14 Aug 2012 15:48:25 +0100 Subject: [PATCH] PPCoin: Fix checkpoint related reorganization issue since ee8c5f5 --- src/checkpoints.cpp | 29 ++++++++++++++++------------- src/main.h | 1 - 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 0160649..7174d10 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -158,12 +158,13 @@ namespace Checkpoints CBlockIndex* pindexCheckpoint = mapBlockIndex[hashPendingCheckpoint]; if (!pindexCheckpoint->IsInMainChain()) { - txdb.TxnBegin(); - if (!Reorganize(txdb, pindexCheckpoint)) + CBlock block; + if (!block.ReadFromDisk(pindexCheckpoint)) + return error("AcceptPendingSyncCheckpoint: ReadFromDisk failed for sync checkpoint %s", hashPendingCheckpoint.ToString().c_str()); + if (!block.SetBestChain(txdb, pindexCheckpoint)) { - txdb.TxnAbort(); hashInvalidCheckpoint = hashPendingCheckpoint; - return error("AcceptPendingSyncCheckpoint: Reorganize failed for sync checkpoint %s", hashPendingCheckpoint.ToString().c_str()); + return error("AcceptPendingSyncCheckpoint: SetBestChain failed for sync checkpoint %s", hashPendingCheckpoint.ToString().c_str()); } } txdb.Close(); @@ -248,13 +249,14 @@ namespace Checkpoints if (mapBlockIndex.count(hash) && !mapBlockIndex[hash]->IsInMainChain()) { // checkpoint block accepted but not yet in main chain - printf("ResetSyncCheckpoint: Reorganize to hardened checkpoint %s\n", hash.ToString().c_str()); + printf("ResetSyncCheckpoint: SetBestChain to hardened checkpoint %s\n", hash.ToString().c_str()); CTxDB txdb; - txdb.TxnBegin(); - if (!Reorganize(txdb, mapBlockIndex[hash])) + CBlock block; + if (!block.ReadFromDisk(mapBlockIndex[hash])) + return error("ResetSyncCheckpoint: ReadFromDisk failed for hardened checkpoint %s", hash.ToString().c_str()); + if (!block.SetBestChain(txdb, mapBlockIndex[hash])) { - txdb.TxnAbort(); - return error("ResetSyncCheckpoint: Reorganize failed for hardened checkpoint %s", hash.ToString().c_str()); + return error("ResetSyncCheckpoint: SetBestChain failed for hardened checkpoint %s", hash.ToString().c_str()); } txdb.Close(); } @@ -402,12 +404,13 @@ bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom) if (!pindexCheckpoint->IsInMainChain()) { // checkpoint chain received but not yet main chain - txdb.TxnBegin(); - if (!Reorganize(txdb, pindexCheckpoint)) + CBlock block; + if (!block.ReadFromDisk(pindexCheckpoint)) + return error("ProcessSyncCheckpoint: ReadFromDisk failed for sync checkpoint %s", hashCheckpoint.ToString().c_str()); + if (!block.SetBestChain(txdb, pindexCheckpoint)) { - txdb.TxnAbort(); Checkpoints::hashInvalidCheckpoint = hashCheckpoint; - return error("ProcessSyncCheckpoint: Reorganize failed for sync checkpoint %s", hashCheckpoint.ToString().c_str()); + return error("ProcessSyncCheckpoint: SetBestChain failed for sync checkpoint %s", hashCheckpoint.ToString().c_str()); } } txdb.Close(); diff --git a/src/main.h b/src/main.h index 2ee7140..d1b5890 100644 --- a/src/main.h +++ b/src/main.h @@ -110,7 +110,6 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime); int GetNumBlocksOfPeers(); bool IsInitialBlockDownload(); std::string GetWarnings(std::string strFor); -bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew); uint256 WantedByOrphan(const CBlock* pblockOrphan); const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake); void BitcoinMiner(CWallet *pwallet, bool fProofOfStake); -- 1.7.1