def get_all_other_nodes() -> Tuple[List[str], List[str]]:
    """
    Get number of discovery nodes
    At each node, get the service info which includes the endpoint
    Return all a tuple of node endpoints except that of this node and all wallets
    (endpoints, wallets)
    """
    eth_web3 = web3_provider.get_eth_web3()

    eth_registry_address = eth_web3.toChecksumAddress(
        shared_config["eth_contracts"]["registry"]
    )
    eth_registry_instance = eth_web3.eth.contract(
        address=eth_registry_address, abi=eth_abi_values["Registry"]["abi"]
    )
    sp_factory_address = eth_registry_instance.functions.getContract(
        SP_FACTORY_REGISTRY_KEY
    ).call()
    sp_factory_inst = eth_web3.eth.contract(
        address=sp_factory_address, abi=eth_abi_values["ServiceProviderFactory"]["abi"]
    )
    num_discovery_nodes = sp_factory_inst.functions.getTotalServiceTypeProviders(
        DISCOVERY_NODE_SERVICE_TYPE
    ).call()
    logger.info(f"number of discovery nodes: {num_discovery_nodes}")

    ids_list = list(range(1, num_discovery_nodes + 1))
    all_other_nodes = []
    all_other_wallets = []

    # fetch all discovery nodes info in parallel
    with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
        discovery_node_futures = {
            executor.submit(fetch_discovery_node_info, i, sp_factory_inst): i
            for i in ids_list
        }
        for future in concurrent.futures.as_completed(discovery_node_futures):
            node_op = discovery_node_futures[future]
            try:
                node_info = future.result()
                wallet = node_info[3]
                if wallet != shared_config["delegate"]["owner_wallet"]:
                    endpoint = node_info[1]
                    all_other_wallets.append(wallet)
                    if is_fqdn(endpoint):
                        all_other_nodes.append(endpoint)
            except Exception as e:
                logger.error(
                    f"index_metrics.py | ERROR in discovery_node_futures {node_op} generated {e}"
                )

    logger.info(
        f"this node's delegate owner wallet: {shared_config['delegate']['owner_wallet']}"
    )
    logger.info(f"all the other nodes: {all_other_nodes}")
    return all_other_nodes, all_other_wallets
Exemplo n.º 2
0
def get_all_other_nodes():
    """
    Get number of discovery nodes
    At each node, get the service info which includes the endpoint
    Return all node endpoints except that of this node
    """
    shared_config = aggregate_metrics.shared_config
    eth_web3 = aggregate_metrics.eth_web3
    eth_registry_address = aggregate_metrics.eth_web3.toChecksumAddress(
        shared_config["eth_contracts"]["registry"]
    )
    eth_registry_instance = eth_web3.eth.contract(
        address=eth_registry_address, abi=eth_abi_values["Registry"]["abi"]
    )
    sp_factory_address = eth_registry_instance.functions.getContract(
        sp_factory_registry_key
    ).call()
    sp_factory_inst = eth_web3.eth.contract(
        address=sp_factory_address, abi=eth_abi_values["ServiceProviderFactory"]["abi"]
    )
    num_discovery_nodes = sp_factory_inst.functions.getTotalServiceTypeProviders(discovery_node_service_type).call()
    logger.info(f"number of discovery nodes: {num_discovery_nodes}")

    ids_list = list(range(1, num_discovery_nodes + 1))
    all_other_nodes = []

    # fetch all discovery nodes info in parallel
    with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
        discovery_node_futures = {executor.submit(fetch_discovery_node_info, i, sp_factory_inst): i for i in ids_list}
        for future in concurrent.futures.as_completed(discovery_node_futures):
            node_op = discovery_node_futures[future]
            try:
                node_info = future.result()
                if node_info[3] != shared_config["delegate"]["owner_wallet"]:
                    endpoint = node_info[1]
                    if is_fqdn(endpoint):
                        all_other_nodes.append(endpoint)
            except Exception as e:
                logger.error(
                    f"index_metrics.py | ERROR in discovery_node_futures {node_op} generated {e}"
                )

    logger.info(f"this node's delegate owner wallet: {shared_config['delegate']['owner_wallet']}")
    logger.info(f"all the other nodes: {all_other_nodes}")
    return all_other_nodes
Exemplo n.º 3
0
def fetch_all_registered_content_nodes(
    eth_web3, shared_config, redis, eth_abi_values
) -> set:
    eth_registry_address = eth_web3.toChecksumAddress(
        shared_config["eth_contracts"]["registry"]
    )
    eth_registry_instance = eth_web3.eth.contract(
        address=eth_registry_address, abi=eth_abi_values["Registry"]["abi"]
    )
    sp_factory_address = eth_registry_instance.functions.getContract(
        sp_factory_registry_key
    ).call()
    sp_factory_inst = eth_web3.eth.contract(
        address=sp_factory_address, abi=eth_abi_values["ServiceProviderFactory"]["abi"]
    )
    total_cn_type_providers = sp_factory_inst.functions.getTotalServiceTypeProviders(
        content_node_service_type
    ).call()
    ids_list = list(range(1, total_cn_type_providers + 1))
    eth_cn_endpoints_set = set()
    # Given the total number of nodes in the network we can now fetch node info in parallel
    with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
        fetch_cnode_futures = {
            executor.submit(fetch_cnode_info, i, sp_factory_inst, redis): i
            for i in ids_list
        }
        for future in concurrent.futures.as_completed(fetch_cnode_futures):
            single_cnode_fetch_op = fetch_cnode_futures[future]
            try:
                cn_endpoint_info = future.result()
                # Validate the endpoint on chain
                # As endpoints get deregistered, this peering system must not slow down with failed connections
                #   or unanticipated load
                eth_sp_endpoint = cn_endpoint_info[1]
                valid_endpoint = is_fqdn(eth_sp_endpoint)
                # Only valid FQDN strings are worth validating
                if valid_endpoint:
                    eth_cn_endpoints_set.add(eth_sp_endpoint)
            except Exception as exc:
                logger.error(
                    f"eth_contract_helpers.py | ERROR in fetch_cnode_futures {single_cnode_fetch_op} generated {exc}"
                )
    return eth_cn_endpoints_set
def test_is_fqdn_url():
    assert is_fqdn("https://validurl1.domain.com") == True
    assert is_fqdn("http://validurl2.subdomain.domain.com") == True
    assert is_fqdn("http://cn2_creator-node_1:4001") == True
    assert is_fqdn("http://www.example.$com\and%26here.html") == False