Пример #1
0
    async def fetch_headers_starting_at(
            self, start_block: int, cancel_token: CancelToken) -> List[BlockHeader]:
        """Fetches up to self.max_headers_fetch starting at start_block.

        Returns a list containing those headers in ascending order of block number.
        """
        request_id = gen_request_id()
        self.sub_proto.send_get_block_headers(
            start_block, self.max_headers_fetch, request_id, reverse=False)
        reply = await self._wait_for_reply(request_id, cancel_token)
        if not reply['headers']:
            raise EmptyGetBlockHeadersReply(
                "No headers in reply. start_block=={}".format(start_block))
        self.logger.info(
            "fetched headers from %s to %s", reply['headers'][0].block_number,
            reply['headers'][-1].block_number)
        return reply['headers']
Пример #2
0
    async def _fetch_headers_starting_at(
            self, peer: LESPeer, start_block: int) -> List[BlockHeader]:
        """Fetches up to self.max_headers_fetch starting at start_block.

        :return: a list containing those headers in ascending order of block number.

        :raise EmptyGetBlockHeadersReply: if no headers are returned
        """
        request_id = gen_request_id()
        peer.sub_proto.send_get_block_headers(
            start_block, peer.max_headers_fetch, request_id, reverse=False)
        reply = await self._wait_for_reply(request_id)
        if not reply['headers']:
            raise EmptyGetBlockHeadersReply(
                "No headers in reply. start_block=={}".format(start_block))
        self.logger.debug(
            "fetched headers from %s to %s", reply['headers'][0].block_number,
            reply['headers'][-1].block_number)
        return reply['headers']