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

Method findMissingBlocks

src/blockheaderprocessor.cpp:90–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90std::vector<CBlockIndex*> DefaultHeaderProcessor::findMissingBlocks(CBlockIndex* last) {
91 assert(last);
92
93 std::deque<CBlockIndex*> toFetch;
94 CBlockIndex* walk = last;
95
96 const int WALK_LIMIT = 144; // one day
97 int walked = 0;
98
99 // Calculate all the blocks we'd need to switch to last, up to a limit.
100 do {
101
102 if (++walked > WALK_LIMIT) {
103 // We're far behind. No gain in direct fetch.
104 return std::vector<CBlockIndex*>();
105 }
106
107 if (chainActive.Contains(walk))
108 break;
109
110 if (walk->nStatus & BLOCK_HAVE_DATA)
111 continue;
112
113 if (blocksInFlight.isInFlight(walk->GetBlockHash()))
114 continue;
115
116 // We don't have this block, and it's not yet in flight.
117 toFetch.push_back(walk);
118
119 // Avoid out of order fetching, trim off the newest block. Out of order
120 // fetching is conceptually fine, but confuses rpc tests that use comptool.
121 if (toFetch.size() > MAX_BLOCKS_IN_TRANSIT_PER_PEER)
122 toFetch.pop_front();
123
124 } while ((walk = walk->pprev));
125
126 return std::vector<CBlockIndex*>(begin(toFetch), end(toFetch));
127}
128
129bool DefaultHeaderProcessor::hasEqualOrMoreWork(CBlockIndex* last) {
130 return last->IsValid(BLOCK_VALID_TREE)

Callers

nothing calls this directly

Calls 5

ContainsMethod · 0.45
isInFlightMethod · 0.45
GetBlockHashMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected