Esempio n. 1
0
def main(args):
    """Entry point.

    :param args: Parsed CLI arguments.

    """
    # Unpack.
    host = args.hostname
    index = int(args.node)
    network = args.network
    port_rest = int(args.port_rest)
    port_rpc = int(args.port_rpc)
    port_event = int(args.port_event)
    typeof = NodeType[args.typeof.upper()]

    # Instantiate.
    node = factory.create_node(group=NodeGroup.UNKNOWN,
                               host=host,
                               index=index,
                               network_id=factory.create_network_id(network),
                               port_rest=port_rest,
                               port_rpc=port_rpc,
                               port_event=port_event,
                               typeof=typeof)

    # Push.
    cache.infra.set_node(node)

    # Notify.
    utils.log(f"Node {args.network}:{args.node} was successfully registered")
Esempio n. 2
0
def create_node() -> types.infra.Node:
    return factory.create_node(
        host="localhost",
        index=1,
        network_id=create_network_id(),
        port_rest=50101,
        port_rpc=40101,
        port_event=60101,
        typeof=random.choice(list(types.infra.NodeType)),
        status=random.choice(list(types.infra.NodeStatus)),
    )
Esempio n. 3
0
def _register_node(
    network: Network,
    index: int,
    info: typing.Tuple[str, int, pathlib.Path]
    ):
    """Register a network node.

    """
    # Destructure node info.
    host, weight, path_sk_pem = info

    # Set default ports.
    port_rpc = 7777
    port_rest = 8888
    port_sse = 9999

    # Set node.
    node = factory.create_node(
        group=NodeGroup.UNKNOWN,
        host=host,
        index=index,
        network_id=factory.create_network_id(network.name_raw),
        port_rest=port_rest,
        port_rpc=port_rpc,
        port_event=port_sse,
        typeof=NodeType.VALIDATOR,
        weight=weight,
    )

    # Set bonding key pair.
    private_key, public_key = crypto.get_key_pair_from_pvk_pem_file(
        path_sk_pem,
        algo=crypto.KeyAlgorithm.ED25519,
        encoding=crypto.KeyEncoding.HEX,
        )

    # Set bonding account.
    node.account = factory.create_account(
        network=network.name,
        typeof=AccountType.VALIDATOR_BOND,
        index=index,
        key_algo=crypto.KeyAlgorithm.ED25519,
        private_key=private_key,
        public_key=public_key,
    )

    # Push.
    cache.infra.set_node(node)

    # Inform.
    utils.log(f"registered {network.name_raw} - {node.address_rpc} : {node.typeof.name}")
Esempio n. 4
0
def _register_node(network: Network, accounts: dict, index: int,
                   info: typing.Tuple[str, dict, pathlib.Path]):
    """Register a network node.

    """
    host, cfg, path_to_pvk, is_boostrap = info

    # Set bonding key pair.
    private_key, public_key = crypto.get_key_pair_from_pvk_pem_file(
        path_to_pvk, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX)

    # Set staking weight.
    _, _, _, stake_weight = _get_account(accounts, public_key,
                                         crypto.DEFAULT_KEY_ALGO)

    # Set group.
    group = NodeGroup.BOOTSTRAP if is_boostrap else NodeGroup.GENESIS

    # Set node.
    node = factory.create_node(
        group=group,
        host=host,
        index=index,
        network_id=factory.create_network_id(network.name_raw),
        port_rest=8888,
        port_rpc=7777,
        port_event=9999,
        typeof=NodeType.VALIDATOR,
        use_to_dispatch=True,
        use_to_monitor=random.choice(range(4)) == 0,
        use_to_query=True,
        weight=stake_weight,
    )

    # Set bonding account.
    node.account = factory.create_account(
        network=network.name,
        typeof=AccountType.VALIDATOR_BOND,
        index=index,
        key_algo=crypto.KeyAlgorithm.ED25519,
        private_key=private_key,
        public_key=public_key,
    )

    # Push.
    cache.infra.set_node(node)
    utils.log(f"Registered {node.label}")
Esempio n. 5
0
def _register_node(network: Network, accounts: dict,
                   info: typing.Tuple[int, dict, pathlib.Path]):
    """Register a network node.

    """
    # Destructure node info.
    index, cfg, path_pvk_pem = info

    # Set bonding key pair.
    private_key, public_key = crypto.get_key_pair_from_pvk_pem_file(
        path_pvk_pem, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX)

    # Set entry in accounts.toml.
    account_info = _get_account(accounts, public_key, crypto.DEFAULT_KEY_ALGO)
    if account_info is None:
        return

    # Set staking weight.
    _, _, _, stake_weight = account_info

    # Set node addrress.
    node_address_event = cfg['event_stream_server']['address']
    node_address_rest = cfg['rest_server']['address']
    node_address_rpc = cfg['rpc_server']['address']

    # Set node host.
    node_host_event = node_address_event.split(":")[0]
    node_host_rest = node_address_rest.split(":")[0]
    node_host_rpc = node_address_rpc.split(":")[0]
    assert node_host_event == node_host_rest == node_host_rpc, "hostname mismatch"
    node_host = node_host_event

    # Set node ports - derived.
    node_port_event = _get_node_port("event", network.index, index)
    node_port_rpc = _get_node_port("rpc", network.index, index)
    node_port_rest = _get_node_port("rest", network.index, index)

    # Set node group.
    if index <= network.count_of_bootstrap_nodes:
        group = NodeGroup.BOOTSTRAP
    elif index <= network.count_of_genesis_nodes:
        group = NodeGroup.GENESIS
    else:
        group = NodeGroup.OTHER

    # Set function flags - initially only interact with genesis nodes.
    use_to_dispatch = group in (NodeGroup.BOOTSTRAP, NodeGroup.GENESIS)
    use_to_monitor = group in (NodeGroup.BOOTSTRAP, NodeGroup.GENESIS)
    use_to_query = group in (NodeGroup.BOOTSTRAP, NodeGroup.GENESIS)

    # Set node.
    node = factory.create_node(
        group=group,
        host=node_host,
        index=index,
        network_id=factory.create_network_id(network.name_raw),
        port_rest=node_port_rest,
        port_rpc=node_port_rpc,
        port_event=node_port_event,
        typeof=NodeType.VALIDATOR,
        use_to_dispatch=use_to_dispatch,
        use_to_monitor=use_to_monitor,
        use_to_query=use_to_query,
        weight=stake_weight,
    )

    # Set bonding account.
    node.account = factory.create_account(
        network=network.name,
        typeof=AccountType.VALIDATOR_BOND,
        index=index,
        key_algo=crypto.KeyAlgorithm.ED25519,
        private_key=private_key,
        public_key=public_key,
    )

    # Push.
    cache.infra.set_node(node)

    # Inform.
    utils.log(f"Registered {node.label}")