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

Method GetLocator

src/chain/chain.cpp:60–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60CBlockLocator CChain::GetLocator(const CBlockIndex *pIndex) const {
61 int32_t nStep = 1;
62 vector<uint256> vHave;
63 vHave.reserve(32);
64
65 if (!pIndex)
66 pIndex = Tip();
67 while (pIndex) {
68 vHave.push_back(pIndex->GetBlockHash());
69 // Stop when we have added the genesis block.
70 if (pIndex->height == 0)
71 break;
72 // Exponentially larger steps back, plus the genesis block.
73 int32_t height = max(pIndex->height - nStep, 0);
74 // Jump back quickly to the same height as the chain.
75 if (pIndex->height > height)
76 pIndex = pIndex->GetAncestor(height);
77 // In case pIndex is not in this chain, iterate pIndex->pprev to find blocks.
78 while (!Contains(pIndex))
79 pIndex = pIndex->pprev;
80
81 // If pIndex is in this chain, use direct height-based access.
82 if (pIndex->height > height)
83 pIndex = (*this)[height];
84
85 if (vHave.size() > 10)
86 nStep *= 2;
87 }
88
89 return CBlockLocator(vHave);
90}
91
92CBlockIndex* CChain::FindFork(map<uint256, CBlockIndex *> &mapBlockIndex, const CBlockLocator &locator) const {
93 // Find the first block the caller has in the main chain

Callers 4

ShutdownFunction · 0.80
UpdateTipFunction · 0.80
PushGetBlocksFunction · 0.80
PushGetBlocksOnConditionFunction · 0.80

Calls 6

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

Tested by

no test coverage detected