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

Method GetLocator

src/chain.cpp:23–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 9

ProcessHeadersMessageFunction · 0.80
ProcessMessageFunction · 0.80
ConsiderEvictionMethod · 0.80
SendMessagesMethod · 0.80
FlushStateToDiskFunction · 0.80
CreateWalletFromFileMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
WriteBestBlockMethod · 0.80
InitMethod · 0.80

Calls 7

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

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64