From 4bb99fbce1b57eef730491a98d442679a1e6bd7f Mon Sep 17 00:00:00 2001 From: Sunny King Date: Sat, 23 Jun 2012 14:57:11 +0100 Subject: [PATCH] PPCoin: Ask for orphan root directly for pending synchronized checkpoint --- src/checkpoints.cpp | 5 +++++ src/main.cpp | 9 ++++----- src/main.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 1384082..78a0be7 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -328,7 +328,12 @@ bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom) printf("ProcessSyncCheckpoint: pending for sync-checkpoint %s\n", hashCheckpoint.ToString().c_str()); // Ask this guy to fill in what we're missing if (pfrom) + { pfrom->PushGetBlocks(pindexBest, hashCheckpoint); + // ask directly as well in case rejected earlier by duplicate + // proof-of-stake because getblocks may not get it this time + pfrom->AskFor(CInv(MSG_BLOCK, mapOrphanBlocks.count(hashCheckpoint)? GetOrphanRoot(mapOrphanBlocks[hashCheckpoint]) : hashCheckpoint)); + } return false; } diff --git a/src/main.cpp b/src/main.cpp index a50b5ab..e5234c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -660,7 +660,7 @@ bool CBlock::ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions) return true; } -uint256 static GetOrphanRoot(const CBlock* pblock) +uint256 GetOrphanRoot(const CBlock* pblock) { // Work back to the first block in the orphan chain while (mapOrphanBlocks.count(pblock->hashPrevBlock)) @@ -1676,10 +1676,9 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) if (pfrom) { pfrom->PushGetBlocks(pindexBest, GetOrphanRoot(pblock2)); - // ppcoin: getblocks may not obtain the parent block rejected earlier - // by duplicate-stake check so we must ask for it again directly - if (!mapOrphanBlocks.count(pblock->hashPrevBlock)) - pfrom->AskFor(CInv(MSG_BLOCK, pblock->hashPrevBlock)); + // ppcoin: getblocks may not obtain the ancestor block rejected + // earlier by duplicate-stake check so we ask for it again directly + pfrom->AskFor(CInv(MSG_BLOCK, GetOrphanRoot(pblock2))); } return true; } diff --git a/src/main.h b/src/main.h index feed1e2..9e4a1a8 100644 --- a/src/main.h +++ b/src/main.h @@ -67,6 +67,7 @@ extern int64 nHPSTimerStart; extern int64 nTimeBestReceived; extern CCriticalSection cs_setpwalletRegistered; extern std::set setpwalletRegistered; +extern std::map mapOrphanBlocks; // Settings extern int fGenerateBitcoins; @@ -108,7 +109,7 @@ int GetNumBlocksOfPeers(); bool IsInitialBlockDownload(); std::string GetWarnings(std::string strFor); bool Reorganize(CTxDB& txdb, CBlockIndex* pindexNew); - +uint256 GetOrphanRoot(const CBlock* pblock); -- 1.7.1