Reimplement CBlockLocator's chain-related logic in CChain.

This removes a few unused CBlockLocator methods, and moves the
construction and fork-finding logic to CChain (which can do these
more efficiently, as it has a height-indexable chain available).
It also makes CBlockLocator independent from the validation code.
This commit is contained in:
Pieter Wuille
2013-10-12 15:18:08 +02:00
committed by Pieter Wuille
parent b2ba55c42b
commit e4daecda0b
5 changed files with 63 additions and 117 deletions

View File

@@ -22,6 +22,7 @@ class CBlock;
class CBlockIndex;
class CKeyItem;
class CReserveKey;
class CBlockLocator;
class CAddress;
class CInv;
@@ -1033,6 +1034,12 @@ public:
/** Set/initialize a chain with a given tip. Returns the forking point. */
CBlockIndex *SetTip(CBlockIndex *pindex);
/** Return a CBlockLocator that refers to a block in this chain (by default the tip). */
CBlockLocator GetLocator(const CBlockIndex *pindex = NULL) const;
/** Find the last common block between this chain and a locator. */
CBlockIndex *FindFork(const CBlockLocator &locator) const;
};
/** The currently-connected chain of blocks. */
@@ -1051,13 +1058,6 @@ protected:
public:
CBlockLocator() {}
explicit CBlockLocator(const CBlockIndex* pindex)
{
Set(pindex);
}
explicit CBlockLocator(uint256 hashBlock);
CBlockLocator(const std::vector<uint256>& vHaveIn)
{
vHave = vHaveIn;
@@ -1080,16 +1080,7 @@ public:
return vHave.empty();
}
/** Given a block initialises the locator to that point in the chain. */
void Set(const CBlockIndex* pindex);
/** Returns the distance in blocks this locator is from our chain head. */
int GetDistanceBack();
/** Returns the first best-chain block the locator contains. */
CBlockIndex* GetBlockIndex();
/** Returns the hash of the first best chain block the locator contains. */
uint256 GetBlockHash();
/** Returns the height of the first best chain block the locator has. */
int GetHeight();
friend class CChain;
};