/** * @param DbInterface $db * @param ChainSegment $segment * @throws \Exception */ private function processSegment(DbInterface $db, ChainSegment $segment) { $id = $segment->getId(); if (isset($this->segmentBlock[$segment])) { throw new \Exception('Already processed this segment'); } $segCount = $segment->getLast()->getHeight() - $segment->getStart() + 1; $hashes = $db->loadHashesForSegment($id); if (count($hashes) !== $segCount) { throw new \Exception('Not enough hashes found for segment'); } $this->hashStorage[$id] = []; foreach ($hashes as $row) { $this->hashStorage[$id][$row['hash']] = $row['height']; $this->heightStorage[$id][$row['height']] = $row['hash']; } if ($segment->getStart() != 0) { $ancestor = $db->loadSegmentAncestor($id, $segment->getStart()); if (!isset($this->segments[$ancestor])) { throw new \RuntimeException('Failed to link segment'); } $this->chainLink[$id] = $ancestor; } $this->segmentBlock[$segment] = $this->db->findSegmentBestBlock($this->getHistory($segment)); }
/** * @param int $segmentId * @return array */ public function loadHashesForSegment($segmentId) { echo __FUNCTION__ . PHP_EOL; return $this->db->loadHashesForSegment($segmentId); }