Example #1
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Pull.
    network_id = factory.create_network_id(args.network)
    network = cache.infra.get_network(network_id)
    if network is None:
        raise ValueError("Unregistered network.")

    # Set key pair.
    pvk, pbk = crypto.get_key_pair_from_pvk_pem_file(
        args.pem_path,
        crypto.KeyAlgorithm.ED25519,
        crypto.KeyEncoding.HEX,
    )

    # Set faucet.
    network.faucet = factory.create_account(
        network=network.name,
        typeof=AccountType.NETWORK_FAUCET,
        index=0,
        key_algo=crypto.KeyAlgorithm.ED25519,
        private_key=pvk,
        public_key=pbk,
    )

    # Push.
    cache.infra.set_network(network)

    # Inform.
    utils.log(f"Network {args.network} faucet key was successfully registered")
Example #2
0
def get_network_node(src: typing.Union[ExecutionContext, NodeIdentifier],
                     node_index=None) -> typing.Tuple[Network, Node]:
    """Returns the network and node to which deploy(s) will be dispatched.

    :param src: Source from which targets will be derived.

    :returns: 2 member tuple -> (network, node).
    
    """
    if isinstance(src, ExecutionContext):
        network_id = factory.create_network_id(src.network)
        network = cache.infra.get_network(network_id)
        if node_index is not None:
            node_id = factory.create_node_id(network_id, node_index)
            node = cache.infra.get_node(node_id)
        elif src.node_index != 0:
            node_id = factory.create_node_id(network_id, src.node_index)
            node = cache.infra.get_node(node_id)
        else:
            node = cache.infra.get_node_by_network(network)

    elif isinstance(src, NodeIdentifier):
        network = cache.infra.get_network(src.network_id)
        node = cache.infra.get_node(src)

    else:
        raise ValueError("Cannot derive network & node from source")

    return network, node
Example #3
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")
Example #4
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Unpack.
    network_id = factory.create_network_id(args.network)
    node_id = factory.create_node_id(network_id, int(args.node))

    # Pull.
    node = cache.infra.get_node(node_id)
    if node is None:
        raise ValueError("Unregistered node.")

    # Update.
    node.status = NodeStatus[args.status.upper()]

    # Push.
    cache.infra.set_node(node)

    # Notify.
    utils.log(
        f"Node {args.network}:{args.node} status was updated --> {node.status}"
    )
Example #5
0
def start_generator(meta: typing.Any):
    """Entry point.

    :param meta: Generator meta-data.

    """
    # Parse cli args.
    args = meta.ARGS.parse_args()

    # Import worker to setup upstream services / actors.
    _import_actors()

    # Import dramatiq actor used to ping message to broker.
    from stests.core.orchestration.run import do_run

    # Unpack args.
    network_id = factory.create_network_id(args.network_name)
    node_id = factory.create_node_id(network_id, args.node_index)

    # Start generator(s).
    ctx_list = _get_context_list(meta, args, network_id, node_id)
    for ctx in ctx_list:
        do_run.send(ctx)

    # Notify.
    if len(ctx_list) == 1:
        log_event(EventType.WFLOW_GENERATOR_LAUNCHED,
                  f"{ctx.run_type} :: run {ctx.run_index}", ctx)
    else:
        log_event(
            EventType.WFLOW_GENERATORS_LAUNCHED,
            f"{ctx.run_type} :: runs {ctx_list[0].run_index} -> {ctx_list[-1].run_index}",
            ctx)
Example #6
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Pull data.
    network_id = factory.create_network_id(args.network)
    data = cache.orchestration.get_info_list(network_id, args.run_type)
    data = [i for i in data if i.aspect == ExecutionAspect.RUN]
    if not data:
        utils.log("No run information found.")
        return

    # Filter by status.
    if args.status not in (None, "*"):
        for status in ExecutionStatus:
            if status.name.lower().startswith(args.status.lower()):
                data = [i for i in data if i.status == status]
                break

    # Associate info with execution context.
    ctx_list = cache.orchestration.get_context_list(network_id, args.run_type)
    for i in data:
        i.ctx = _get_ctx(i, ctx_list)

    # Associate info with deploy count.
    keys, counts = cache.orchestration.get_deploy_count_list(
        network_id, args.run_type)
    counts = dict(zip(keys, counts))
    for i in data:
        i.deploy_count = _get_deploy_count(i, counts)

    # Sort data.
    data = sorted(data, key=lambda i: f"{i.run_type}.{i.label_index}")

    # Set cols/rows.
    cols = [i for i, _ in COLS]
    rows = map(lambda i: _get_row(i, counts), data)

    # Set table.
    t = utils.get_table(cols, rows)

    # Set table alignments.
    for key, aligmnent in COLS:
        t.column_alignments[key] = aligmnent

    # Render.
    print(t)
    print(
        "----------------------------------------------------------------------------------------------------------------------------"
    )
    print(f"{network_id.name} - total runs = {len(data)}.")
    print(
        "----------------------------------------------------------------------------------------------------------------------------"
    )
Example #7
0
def do_start_monitoring():
    """Starts monitoring of registered networks.
    
    """
    for network in cache.infra.get_networks():
        network_id = factory.create_network_id(network.name)
        for node in cache.infra.get_nodes_for_monitoring(network, _MAX_NODES):
            do_monitor_node.send(
                factory.create_node_id(network_id, node.index), )
            time.sleep(float(1))
Example #8
0
def get_network(args) -> Network:
    """Maps input args to a target network node.
    
    """
    network_id = factory.create_network_id(args.network)
    network = cache.infra.get_network(network_id)
    if network is None:
        raise ValueError("Unregistered network.")

    return network
Example #9
0
 def __init__(self, info: NodeEventInfo):
     self.block = None
     self.block_hash = info.block_hash
     self.deploy = None
     self.deploy_hash = None
     self.info = info
     self.network_id = factory.create_network_id(info.network)
     self.network = cache.infra.get_network(self.network_id)
     self.node_id = factory.create_node_id(self.network_id, info.node_index)
     self.node = cache.infra.get_node(self.node_id)
     self.on_chain_block = None
     self.on_chain_deploy = None
Example #10
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}")
Example #11
0
def get_network_nodeset(args) -> typing.Tuple[Network, typing.List[Node]]:
    """Maps input args to a target network node.
    
    """
    network_id = factory.create_network_id(args.network)
    network = cache.infra.get_network(network_id)
    if network is None:
        raise ValueError("Unregistered network.")

    nodeset = cache.infra.get_nodes_for_dispatch(network)
    if nodeset is None or len(nodeset) == 0:
        raise ValueError("Unregistered nodeset.")

    return network, sorted(nodeset, key=lambda i: i.index)
Example #12
0
def get_network_node(args) -> typing.Tuple[Network, Node]:
    """Maps input args to a target network node.
    
    """
    network_id = factory.create_network_id(args.network)
    network = cache.infra.get_network(network_id)
    if network is None:
        raise ValueError("Unregistered network.")

    node_id = factory.create_node_id(network_id, int(args.node))
    node = cache.infra.get_node(node_id)
    if node is None:
        raise ValueError("Unregistered node.")

    return network, node
Example #13
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}")
Example #14
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Pull data.
    network_id = factory.create_network_id(args.network)
    data = cache.state.get_deploys(network_id, args.run_type, args.run_index)
    if not data:
        utils.log("No run deploys found.")
        return

    # Sort data.
    data = sorted(data, key=lambda i: i.dispatch_timestamp)

    # Render views.
    _render_table(args, network_id, data)
    _render_finalization_stats(data)
Example #15
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Set run data.
    network_id = factory.create_network_id(args.network)
    data = cache.orchestration.get_info_list(network_id, args.run_type,
                                             args.run_index)
    if not data:
        utils.log("No run information found.")
        return

    # Set sorted data.
    data = sorted(data, key=lambda i: i.label_index)

    # Set deploy counts.
    keys, counts = cache.orchestration.get_deploy_count_list(
        network_id, args.run_type, args.run_index)
    keys = [i.split(":") for i in keys]
    keys = [f"{i[3]}.{i[5]}" if i[5] != "-" else i[3] for i in keys]
    counts = dict(zip(keys, counts))

    # Set table.
    t = utils.get_table(
        [i for i, _ in COLS],
        map(lambda i: _get_row(i, counts), data),
    )
    for key, aligmnent in COLS:
        t.column_alignments[key] = aligmnent

    # Render.
    print(t)
    print(
        "--------------------------------------------------------------------------------------------------------------------"
    )
    print(f"{network_id.name} - {args.run_type}  - Run {args.run_index}")
    print(
        "--------------------------------------------------------------------------------------------------------------------"
    )
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Pull.
    network_id = factory.create_network_id(args.network)
    network = cache.infra.get_network(network_id)
    if network is None:
        raise ValueError("Unregistered network.")

    # Update.
    network.status = NetworkStatus[args.status.upper()]

    # Push.
    cache.infra.set_network(network)

    # Notify.
    utils.log(
        f"Network {args.network} status was updated --> {network.status}")
Example #17
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Unpack.
    network_id = factory.create_network_id(args.network)
    node_id = factory.create_node_id(network_id, int(args.node))

    # Pull.
    node = cache.infra.get_node(node_id)
    if node is None:
        raise ValueError("Unregistered node.")

    # Set key pair.
    pvk, pbk = crypto.get_key_pair_from_pvk_pem_file(
        args.pem_path,
        algo=crypto.KeyAlgorithm.ED25519,
        encoding=crypto.KeyEncoding.HEX)

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

    # Push.
    cache.infra.set_node(node)

    # Inform.
    utils.log(
        f"Node {args.network}:{args.node} bonding key was successfully registered"
    )
Example #18
0
def main(args):
    """Entry point.
    
    :param args: Parsed CLI arguments.

    """
    # Pull data.
    network_id=factory.create_network_id(args.network)
    if cache.infra.get_network(network_id) is None:
        utils.log_warning(f"Network {args.network} is unregistered.")
        return
    data = cache.infra.get_named_keys(network_id)
    if not data:
        utils.log_warning(f"Network {args.network} has no registered contracts.")
        return

    # Sort data.
    data = sorted(data, key=lambda i: f"{i.contract_type}.{i.name}")

    # Set table cols/rows.
    cols = [i for i, _ in COLS]
    rows = map(lambda i: [
        network_id.name,
        i.contract_type,
        i.name,      
        i.hash,      
    ], data)

    # Set table.
    t = utils.get_table(cols, rows)

    # Set table alignments.
    for key, aligmnent in COLS:
        t.column_alignments[key] = aligmnent    

    # Render.
    print(t)
Example #19
0
def main(args):
    """Entry point.

    :param args: Parsed CLI arguments.

    """
    # Pull data.
    network_id = factory.create_network_id(args.network)
    network = cache.infra.get_network(network_id)
    if network is None:
        utils.log_warning(f"Network {args.network} is unregistered.")
        return
    data = cache.infra.get_nodes(network_id)
    if not data:
        utils.log_warning(f"Network {args.network} has no nodes.")
        return

    # Set cols/rows.
    cols = [i for i, _ in COLS]
    rows = map(
        lambda i: [
            i.label_index,
            f"{i.host}:{i.port_rpc}",
            i.typeof.name,
        ], sorted(data, key=lambda i: i.index))

    # Set table.
    t = utils.get_table(cols, rows)

    # Set table alignments.
    for key, aligmnent in COLS:
        t.column_alignments[key] = aligmnent

    # Render.
    print(t)
    print(f"{network_id.name} node count = {len(data)}")
Example #20
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}")
Example #21
0
def create_network_id() -> types.infra.NetworkIdentifier:
    return factory.create_network_id("lrt1")