def msg_get_block_bodies(self, msg: GetBlockBodiesEthProtocolMessage): processed = self.node.block_processing_service.try_process_get_block_bodies_request( msg) if not processed: self.node.log_requested_remote_blocks(msg.get_block_hashes()) self.msg_proxy_request(msg, self.connection)
def request_block_body(self, block_hashes: List[Sha256Hash]): block_request_message = GetBlockBodiesEthProtocolMessage( None, block_hashes=[bytes(blk.binary) for blk in block_hashes] ) self.node.send_msg_to_node(block_request_message) self._block_bodies_requests.append(block_hashes)
def try_process_get_block_bodies_request( self, msg: GetBlockBodiesEthProtocolMessage) -> bool: block_hashes = msg.get_block_hashes() logger.trace("Checking for bodies in local block cache...") return self._node.block_queuing_service.try_send_bodies_to_node( block_hashes)
def test_try_process_get_block_bodies_request_not_found(self): success = self.block_processing_service.try_process_get_block_bodies_request( GetBlockBodiesEthProtocolMessage( None, [self.block_hashes[0].binary, bytes(helpers.generate_hash())])) self.assertFalse(success) self.node.broadcast.assert_not_called()
def test_try_process_get_block_bodies_request(self): success = self.block_processing_service.try_process_get_block_bodies_request( GetBlockBodiesEthProtocolMessage( None, [block_hash.binary for block_hash in self.block_hashes[:2]])) self.assertTrue(success) self.node.send_msg_to_node.assert_called_once_with( BlockBodiesEthProtocolMessage(None, self.block_bodies[:2]))
def try_process_get_block_bodies_request( self, msg: GetBlockBodiesEthProtocolMessage, block_queuing_service: Optional[EthBlockQueuingService]) -> bool: if block_queuing_service is None: return False block_hashes = msg.get_block_hashes() logger.trace("Checking for bodies in local block cache...") return block_queuing_service.try_send_bodies_to_node(block_hashes)
def msg_get_block_bodies(self, msg: GetBlockBodiesEthProtocolMessage): block_queuing_service = cast( EthBlockQueuingService, self.node.block_queuing_service_manager.get_block_queuing_service( self.connection)) processed = self.node.block_processing_service.try_process_get_block_bodies_request( msg, block_queuing_service) if not processed: self.node.log_requested_remote_blocks(msg.get_block_hashes()) self.msg_proxy_request(msg, self.connection)
def msg_get_block_bodies(self, msg: GetBlockBodiesEthProtocolMessage) -> None: block_hashes = msg.get_block_hashes() logger.debug( "Received unexpected get block bodies message from remote " "blockchain node for {} blocks: {}. Replying with empty block bodies.", len(block_hashes), ", ".join([ convert.bytes_to_hex(block_hash.binary) for block_hash in block_hashes[:10] ])) empty_block_bodies_msg = BlockBodiesEthProtocolMessage(None, []) self.connection.enqueue_msg(empty_block_bodies_msg)
def test_try_process_get_block_bodies_request(self): success = self.block_processing_service.try_process_get_block_bodies_request( GetBlockBodiesEthProtocolMessage( None, [block_hash.binary for block_hash in self.block_hashes[:2]])) self.assertTrue(success) self.node.broadcast.assert_called_once_with( BlockBodiesEthProtocolMessage( None, self.block_bodies[:2], ), connection_types=[ConnectionType.BLOCKCHAIN_NODE])
def request_block_body(self, block_hashes: List[Sha256Hash]): block_request_message = GetBlockBodiesEthProtocolMessage( None, block_hashes=[bytes(blk.binary) for blk in block_hashes]) self.connection.enqueue_msg(block_request_message) self._block_bodies_requests.append(block_hashes)