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:
committed by
Pieter Wuille
parent
b2ba55c42b
commit
e4daecda0b
25
src/main.h
25
src/main.h
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user