Пример #1
0
 /**
  * @param BufferInterface $hash
  * @return BlockIndexInterface
  */
 public function fetchIndex(BufferInterface $hash)
 {
     if (!$this->view->containsHash($hash)) {
         throw new \RuntimeException('Index by this hash not known');
     }
     return $this->db->fetchIndex($hash);
 }
Пример #2
0
 /**
  * @param ChainViewInterface $view
  * @param BufferInterface $hash
  */
 public function updateBlockAvailability(ChainViewInterface $view, BufferInterface $hash)
 {
     if ($view->containsHash($hash)) {
         $this->save(self::INDEXBESTKNOWNBLOCK, $hash);
     } else {
         $this->save(self::HASHLASTUNKNOWNBLOCK, $hash);
     }
 }
Пример #3
0
 /**
  * @param BufferInterface $hash
  * @return bool
  */
 public function containsHash(BufferInterface $hash)
 {
     if (!$this->view->containsHash($hash)) {
         return false;
     }
     $lookupHeight = $this->view->getHeightFromHash($hash);
     if ($lookupHeight > $this->position) {
         return false;
     }
     return true;
 }
Пример #4
0
 /**
  * @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;
 }
Пример #5
0
 /**
  * @param ChainViewInterface $headerChain
  * @param GuidedChainView $blockChain
  * @param Peer $peer
  * @param array $items
  */
 public function advertised(ChainViewInterface $headerChain, GuidedChainView $blockChain, Peer $peer, array $items)
 {
     $fetch = [];
     $lastUnknown = null;
     foreach ($items as $inv) {
         $hash = $inv->getHash();
         if ($headerChain->containsHash($hash)) {
             if (!$blockChain->containsHash($hash)) {
                 $fetch[] = $inv;
             }
         } else {
             $lastUnknown = $hash;
         }
     }
     if (null !== $lastUnknown) {
         $peer->getheaders($headerChain->getHeadersLocator($lastUnknown));
         $this->peerState->fetch($peer)->updateBlockAvailability($headerChain, $lastUnknown);
     }
 }