MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / GetLocator

Method GetLocator

src/chain.cpp:25–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23}
24
25CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
26 int nStep = 1;
27 std::vector<uint256> vHave;
28 vHave.reserve(32);
29
30 if (!pindex)
31 pindex = Tip();
32 while (pindex) {
33 vHave.push_back(pindex->GetBlockHash());
34 // Stop when we have added the genesis block.
35 if (pindex->nHeight == 0)
36 break;
37 // Exponentially larger steps back, plus the genesis block.
38 int nHeight = std::max(pindex->nHeight - nStep, 0);
39 if (Contains(pindex)) {
40 // Use O(1) CChain index if possible.
41 pindex = (*this)[nHeight];
42 } else {
43 // Otherwise, use O(log n) skiplist.
44 pindex = pindex->GetAncestor(nHeight);
45 }
46 if (vHave.size() > 10)
47 nStep *= 2;
48 }
49
50 return CBlockLocator(vHave);
51}
52
53const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
54 if (!pindex)

Callers 7

AppInit2Function · 0.80
requestHeadersFunction · 0.80
FlushStateToDiskFunction · 0.80
SendMessagesFunction · 0.80
operator()Method · 0.80
requestConnectHeadersMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 6

reserveMethod · 0.80
GetAncestorMethod · 0.80
CBlockLocatorClass · 0.50
push_backMethod · 0.45
GetBlockHashMethod · 0.45
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64