def handle_request(self, request, response, connection_id): try: blocks = [] for block in self._proxy.blocks_get(request.block_ids): block_header = BlockHeader() block_header.ParseFromString(block.header) blocks.append( consensus_pb2.ConsensusBlock( block_id=bytes.fromhex(block.header_signature), previous_id=bytes.fromhex( block_header.previous_block_id), signer_id=bytes.fromhex( block_header.signer_public_key), block_num=block_header.block_num, payload=block_header.consensus)) response.blocks.extend(blocks) except UnknownBlock: response.status =\ consensus_pb2.ConsensusBlocksGetResponse.UNKNOWN_BLOCK except Exception: # pylint: disable=broad-except LOGGER.exception("ConsensusBlocksGet") response.status =\ consensus_pb2.ConsensusBlocksGetResponse.SERVICE_ERROR return HandlerStatus.RETURN
def handle_request(self, request, response): try: blocks = [] for block in self._proxy.blocks_get(request.block_ids): LOGGER.debug('ConsensusBlocksGetHandler: block %s',type(block.header)) """ block manager return blocks from store where header is string and we should decode it in case of chain controller it is object """ if not isinstance(block.header,BlockHeader) : block_header = BlockHeader() block_header.ParseFromString(block.header) else: block_header = block.header blocks.append(consensus_pb2.ConsensusBlock( block_id=bytes.fromhex(block.header_signature), previous_id=bytes.fromhex(block_header.previous_block_id), signer_id=bytes.fromhex(block_header.signer_public_key), block_num=block_header.block_num, payload=block_header.consensus)) response.blocks.extend(blocks) except UnknownBlock: LOGGER.debug('ConsensusBlocksGetHandler:proxy UNKNOWN_BLOCK') response.status = consensus_pb2.ConsensusBlocksGetResponse.UNKNOWN_BLOCK except Exception: # pylint: disable=broad-except LOGGER.exception("ConsensusBlocksGet") response.status = consensus_pb2.ConsensusBlocksGetResponse.SERVICE_ERROR
def notify_block_new(self, block): """ A new block was received and passed initial consensus validation in federation mode - send only own cluster's nodes """ summary = hashlib.sha256() for batch in block.batches: summary.update(batch.header_signature.encode()) LOGGER.debug( 'ConsensusNotifier: notify_block_new BLOCK=%s SUMMARY=%s\n', block.header_signature[:8], summary.digest().hex()[:10]) block_header = BlockHeader() block_header.ParseFromString(block.header) self._notify( validator_pb2.Message.CONSENSUS_NOTIFY_BLOCK_NEW, consensus_pb2.ConsensusNotifyBlockNew( block=consensus_pb2.ConsensusBlock( block_id=bytes.fromhex(block.header_signature), previous_id=bytes.fromhex(block_header.previous_block_id), signer_id=bytes.fromhex(block_header.signer_public_key), block_num=block_header.block_num, payload=block_header.consensus, summary=summary.digest())))
def notify_block_new(self, block): """A new block was received and passed initial consensus validation""" summary = hashlib.sha256() for batch in block.batches: summary.update(batch.header_signature.encode()) self._notify( validator_pb2.Message.CONSENSUS_NOTIFY_BLOCK_NEW, consensus_pb2.ConsensusNotifyBlockNew( block=consensus_pb2.ConsensusBlock( block_id=bytes.fromhex(block.identifier), previous_id=bytes.fromhex(block.previous_block_id), signer_id=bytes.fromhex(block.header.signer_public_key), block_num=block.block_num, payload=block.consensus, summary=summary.digest())))
def handle_request(self, request, response): try: response.blocks.extend([ consensus_pb2.ConsensusBlock( block_id=bytes.fromhex(block.identifier), previous_id=bytes.fromhex(block.previous_block_id), signer_id=bytes.fromhex(block.signer_public_key), block_num=block.block_num, payload=block.consensus) for block in self._proxy.blocks_get(request.block_ids) ]) except UnknownBlock: response.status =\ consensus_pb2.ConsensusBlocksGetResponse.UNKNOWN_BLOCK except Exception: # pylint: disable=broad-except LOGGER.exception("ConsensusBlocksGet") response.status =\ consensus_pb2.ConsensusBlocksGetResponse.SERVICE_ERROR
def notify_block_new(self, block): """A new block was received and passed initial consensus validation""" LOGGER.debug('ConsensusNotifier: NOTIFY BLOCK_NEW block=%s', block) summary = hashlib.sha256() for batch in block.batches: summary.update(batch.header_signature.encode()) LOGGER.debug('ConsensusNotifier: NOTIFY BLOCK_NEW summary=%s block=%s', summary, block) block_header = BlockHeader() block_header.ParseFromString(block.header) self._notify( validator_pb2.Message.CONSENSUS_NOTIFY_BLOCK_NEW, consensus_pb2.ConsensusNotifyBlockNew( block=consensus_pb2.ConsensusBlock( block_id=bytes.fromhex(block.header_signature), previous_id=bytes.fromhex(block_header.previous_block_id), signer_id=bytes.fromhex(block_header.signer_public_key), block_num=block_header.block_num, payload=block_header.consensus, summary=summary.digest())))