MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetLocator

Method GetLocator

src/chain.cpp:31–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 8

ProcessHeadersMessageMethod · 0.80
ProcessMessageMethod · 0.80
ConsiderEvictionMethod · 0.80
SendMessagesMethod · 0.80
FlushStateToDiskMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
CommitInternalMethod · 0.80
getTipLocatorMethod · 0.80

Calls 6

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