| 283 | } // anon namespace |
| 284 | |
| 285 | CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator) |
| 286 | { |
| 287 | AssertLockHeld(cs_main); |
| 288 | |
| 289 | // Find the latest block common to locator and chain - we expect that |
| 290 | // locator.vHave is sorted descending by height. |
| 291 | for (const uint256& hash : locator.vHave) { |
| 292 | CBlockIndex* pindex = LookupBlockIndex(hash); |
| 293 | if (pindex) { |
| 294 | if (chain.Contains(pindex)) |
| 295 | return pindex; |
| 296 | if (pindex->GetAncestor(chain.Height()) == chain.Tip()) { |
| 297 | return chain.Tip(); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | return chain.Genesis(); |
| 302 | } |
| 303 | |
| 304 | std::unique_ptr<CCoinsViewDB> pcoinsdbview; |
| 305 | std::unique_ptr<CCoinsViewCache> pcoinsTip; |
no test coverage detected