/** * @param int $height * @return BufferInterface */ public function getHashFromHeight($height) { if ($height > $this->position) { throw new \RuntimeException('GuidedChainCache: index at this height (' . $height . ') not known'); } return $this->view->getHashFromHeight($height); }
/** * @param ChainViewInterface $headerChain * @param BufferInterface $startHash * @throws \RuntimeException * @throws \Exception * @return Inventory[] */ private function relativeNextInventory(ChainViewInterface $headerChain, BufferInterface $startHash) { if (!$headerChain->containsHash($startHash)) { throw new \RuntimeException('Hash not found in this chain'); } $startHeight = $headerChain->getHeightFromHash($startHash) + 1; $stopHeight = min($startHeight + self::DOWNLOAD_AMOUNT, $headerChain->getIndex()->getHeight()); $nInFlight = count($this->inFlight); $request = []; for ($i = $startHeight; $i < $stopHeight && $nInFlight < self::MAX_IN_FLIGHT; $i++) { $request[] = Inventory::block($headerChain->getHashFromHeight($i)); $nInFlight++; } return $request; }
/** * @param int $height * @return BlockIndexInterface */ public function fetchAncestor($height) { return $this->fetchIndex($this->view->getHashFromHeight($height)); }