/** * @param PeerState $state * @param Peer $peer * @param Block $blockMsg */ public function onBlock(PeerState $state, Peer $peer, Block $blockMsg) { $best = $this->node->chain(); $headerIdx = $this->node->headers(); $blockIndex = $this->node->blocks(); $checkSignatures = (bool) $this->config->getItem('config', 'check_signatures', true); $checkSize = (bool) $this->config->getItem('config', 'check_block_size', true); $checkMerkleRoot = (bool) $this->config->getItem('config', 'check_merkle_root', true); try { $index = $blockIndex->accept($blockMsg->getBlock(), $best, $headerIdx, $checkSignatures, $checkSize, $checkMerkleRoot); $this->blockDownload->received($best, $peer, $index->getHash()); } catch (\Exception $e) { $header = $blockMsg->getBlock()->getHeader(); $this->node->emit('event', ['error.onBlock', ['ip' => $peer->getRemoteAddress()->getIp(), 'hash' => $header->getHash()->getHex(), 'error' => $e->getMessage() . PHP_EOL . $e->getTraceAsString()]]); } }
/** * ZmqDebug constructor. * @param NodeInterface $node * @param Context $context */ public function __construct(NodeInterface $node, Context $context) { $this->socket = $context->getSocket(\ZMQ::SOCKET_PUB); $this->socket->bind('tcp://127.0.0.1:5566'); $node->on('event', function ($event, array $params) { $this->log($event, $params); }); $node->headers()->on('tip', [$this, 'logTip']); $node->blocks()->on('block', [$this, 'logBlock']); $node->chains()->on('retarget', [$this, 'logRetarget']); }