def node_from_node_config(node_config: NodeConfig): # Test connection and match-up chain name log_and_print('Trying to retrieve data from the API of {}'.format( node_config.node_name)) try: actual_chain = polkadot_api_data_wrapper.get_system_chain( node_config.node_ws_url) log_and_print('Success.') if actual_chain != node_config.chain_name: log_and_print( 'WARNING: actual chain name of {} is \"{}\" not \"{}\". PANIC ' 'will continue using the supplied chain name \"{}\".'.format( node_config.node_name, actual_chain, node_config.chain_name, node_config.chain_name)) except Exception as e: logger_general.error(e) raise InitialisationException( 'Failed to retrieve data from the API of {}'.format( node_config.node_name)) # Get node type node_type = NodeType.VALIDATOR_FULL_NODE \ if node_config.node_is_validator \ else NodeType.NON_VALIDATOR_FULL_NODE # Check if validator stash account address exists by querying some data # which requires the validator's address. If address does not exist, an # exception is thrown. if node_config.node_is_validator: try: polkadot_api_data_wrapper.get_eras_stakers( node_config.node_ws_url, node_config.stash_account_address) except InvalidStashAccountAddressException as e: logger_general.error(e.message) raise InitialisationException(e.message) except Exception as e: logger_general.error(e) raise InitialisationException( 'Failed validating stash account address {}'.format( node_config.stash_account_address)) # Initialise node and load any state node = Node(node_config.node_name, node_config.node_ws_url, node_type, node_config.stash_account_address, node_config.chain_name, REDIS, node_config.is_archive_node, internal_conf=InternalConf) node.load_state(logger_general) # Return node return node
def node_from_node_config(node_config: NodeConfig): # Test connection and match-up chain name log_and_print('Trying to retrieve data from the API of {}'.format( node_config.node_name)) # Try to ping the API to see if configuration is correct try: pong_response = oasis_api_data_wrapper.ping_api( node_config.node_api_url) if pong_response != "pong": log_and_print('WARNING: API of node {} is not reachable.'.format( node_config.node_name)) log_and_print('Success. API is configured correctly') except Exception as e: logger_general.error(e) raise InitialisationException( 'Failed to retrieve data from the API of {}'.format( node_config.node_name)) # Test connection and match-up chain name log_and_print('Trying to retrieve node name {} from API'.format( node_config.node_name)) # Check if the node name exists by Pinging the node # If it doesn't then it is miss configured. try: pong_response = oasis_api_data_wrapper.ping_node( node_config.node_api_url, node_config.node_name) if pong_response != "pong": log_and_print( 'WARNING: Node {} is not configured properly, PANIC node' \ 'name should match that set in the API Server.'.format( node_config.node_name)) log_and_print('Success. node name is configured correctly') except Exception as e: logger_general.error(e) raise InitialisationException( 'Failed to retrieve data from the API of {}'.format( node_config.node_name)) # Get node type node_type = NodeType.VALIDATOR_FULL_NODE \ if node_config.node_is_validator \ else NodeType.NON_VALIDATOR_FULL_NODE # Check if the node public key exists by calling the API to retrieve the # node successfully. # Test connection and match-up chain name if node_config.node_is_validator: log_and_print('Trying to retrieve Node Public Key {} from'.format( node_config.node_name)) try: node_details = oasis_api_data_wrapper.get_node( node_config.node_api_url, node_config.node_name, node_config.node_public_key) entity_public_key = node_details['entity_id'] staking_address = oasis_api_data_wrapper.get_staking_address( node_config.node_api_url, entity_public_key) except Exception as e: logger_general.error(e) raise InitialisationException( 'Failed validating node public key {}'.format( node_config.node_public_key)) else: entity_public_key = EMPTY_URL staking_address = EMPTY_URL # Prometheus configuration should be checked on start up if Peers monitoring # is enabled. try: peers_response = oasis_api_data_wrapper.get_prometheus_gauge( node_config.node_api_url, node_config.node_name, \ "tendermint_p2p_peers") if isinstance(peers_response, int): log_and_print( 'WARNING: Node {} does not have prometheus enabled. Please ' \ 'enable Prometheus to monitor data such as no of Peers'.format( node_config.node_name)) log_and_print('Success. Prometheus is configured correctly') except Exception as e: logger_general.error(e) raise InitialisationException( 'Failed to retrieve Prometheus Data from API of {}'.format( node_config.node_name)) # Node Exporter should be an optional tool for System Monitoring if node_config.node_exporter_url != "": try: metric_to_test = ['process_cpu_seconds_total'] prometheus_data = get_oasis_prometheus( \ node_config.node_exporter_url, metric_to_test, logger_general) process_cpu_seconds_total = ( \ prometheus_data['process_cpu_seconds_total']) node_exporter_url = node_config.node_exporter_url log_and_print('Success. Node Exporter is configured correctly') except Exception as e: log_and_print(e) logger_general.error(e) raise InitialisationException( 'Failed to retrieve Node Exporter Data from URL of {}'.format( node_config.node_name)) else: node_exporter_url = EMPTY_URL # Test connection and match-up chain name log_and_print('Trying to convert the Node {} Key into a Consensus ' \ 'Public Key and a Tendermint Address key '.format( node_config.node_name)) # Retrieve the Consensus Public Key and the Tendermint Address if node_config.node_is_validator: try: consensus_public_key = oasis_api_data_wrapper. \ get_registry_node(node_config.node_api_url, \ node_config.node_name, \ node_config.node_public_key) tendermint_address_key = oasis_api_data_wrapper. \ get_tendermint_address(node_config.node_api_url, \ str(consensus_public_key['consensus'][ 'id'])) log_and_print('Successfully converted node public key into ' \ 'Consensus Public Key and Tendermint Address') except Exception as e: logger_general.error(e) raise InitialisationException( 'Failed to convert a node public key for the node {}'.format( node_config.node_name)) else: consensus_public_key = EMPTY_URL tendermint_address_key = EMPTY_URL chain_id = node_config.chain_name # Initialise node and load any state node = Node(node_config.node_name, node_config.node_api_url, node_exporter_url, node_type, node_config.node_public_key, chain_id, REDIS, node_config.is_archive_node, consensus_public_key, tendermint_address_key, staking_address, entity_public_key, internal_conf=InternalConf) node.load_state(logger_general) # Return node return node