Exemplo n.º 1
0
def schains_by_node(ctx, save_to):
    """ Command that shows schains for active nodes """
    skale = ctx.obj['skale']

    schains = []
    sizes = []
    for node_id in skale.nodes_data.get_active_node_ids():
        node = skale.nodes_data.get(node_id)

        node_struct = {
            'name': node['name'],
            'ip': ip_from_bytes(node['ip']),
            'basePort': node['port'],
            'publicIP': ip_from_bytes(node['publicIP']),
        }

        schains_for_node = skale.schains_data.get_schains_for_node(node_id)
        schains.append({
            'schains': schains_for_node,
            'amount': len(schains_for_node),
            'node': node_struct
        })
        sizes.append(len(schains_for_node))

    if not os.path.exists(save_to):
        os.makedirs(save_to)

    filepath = os.path.join(save_to, 'schains_data.json')
    with open(filepath, 'w') as outfile:
        json.dump(schains, outfile)

    print('sChains on each node:')
    print(sizes)
Exemplo n.º 2
0
 def _transform_node_info(self, node_info, node_id):
     node_info['ip'] = ip_from_bytes(node_info['ip'])
     node_info['publicIP'] = ip_from_bytes(node_info['publicIP'])
     node_info['status'] = NodeStatuses.CREATED.value
     node_info['id'] = node_id
     node_info['publicKey'] = self.skale.web3.toHex(node_info['publicKey'])
     node_info['owner'] = public_key_to_address(node_info['publicKey'])
     return node_info
Exemplo n.º 3
0
def test_is_node_ip_available(skale):
    node = skale.nodes_data.get_by_name(DEFAULT_NODE_NAME)
    node_ip = Helper.ip_from_bytes(node['ip'])

    unused_ip = '123.123.231.123'
    assert skale.nodes_data.is_node_ip_available(node_ip) is False
    assert skale.nodes_data.is_node_name_available(unused_ip) is True
Exemplo n.º 4
0
def test_get_active_node_ips(skale):
    active_node_ips = skale.nodes_data.get_active_node_ips()

    assert isinstance(active_node_ips, list)

    test_ip = Helper.ip_from_bytes(active_node_ips[0])
    assert Helper.is_valid_ipv4_address(test_ip)
Exemplo n.º 5
0
def test_generate_node_info():
    node_info = CurrentNodeInfo(
        node_name=DEFAULT_NODE_NAME,
        node_id=0,
        base_port=10011,
        bind_ip=ip_from_bytes(TEST_NODE_IP_BYTES),
        ima_mainnet=TEST_URL,
        ima_mp_schain=ZERO_ADDRESS,
        ima_mp_mainnet=ZERO_ADDRESS,
        wallets={},
        rotate_after_block=128
    ).to_config()

    assert isinstance(node_info['bindIP'], str)
    assert isinstance(node_info['nodeID'], int)
    assert isinstance(node_info['nodeName'], str)
    assert isinstance(node_info['basePort'], int)
    assert isinstance(node_info['httpRpcPort'], int)
    assert isinstance(node_info['httpsRpcPort'], int)
    assert isinstance(node_info['wsRpcPort'], int)
    assert isinstance(node_info['wssRpcPort'], int)

    assert isinstance(node_info['imaMainNet'], str)
    assert isinstance(node_info['wallets'], dict)
    assert node_info['imaMessageProxySChain'] == ZERO_ADDRESS
    assert node_info['imaMessageProxyMainNet'] == ZERO_ADDRESS
    assert node_info['rotateAfterBlock'] == 128

    assert len(node_info) == NODE_INFO_LEN
Exemplo n.º 6
0
def get_nodes_for_schain_config(skale, name):
    nodes_info = []
    nodes = get_nodes_for_schain(skale, name)
    for i, node in enumerate(nodes, 1):
        pk = node['publicKey'].hex()

        schains_on_node = skale.schains_data.get_schains_for_node(node['id'])
        base_port = get_schain_base_port_on_node(schains_on_node, name,
                                                 node['port'])

        node_info = SchainNodeInfo(
            node_name=node['name'],
            node_id=node['id'],
            base_port=base_port,
            schain_index=i,
            ip=ip_from_bytes(node['ip']),
            public_key=pk,
            public_ip=ip_from_bytes(node['publicIP']),
            owner=public_key_to_address(pk)).to_config()
        nodes_info.append(node_info)
    return nodes_info
Exemplo n.º 7
0
def show(ctx):
    """ Command to show id name and ip of active nodes """
    skale = ctx.obj['skale']

    nodes_data = []
    for _id in skale.nodes_data.get_active_node_ids():
        data = skale.nodes_data.get(_id)
        name = data.get('name')
        ip = ip_from_bytes(data.get('ip'))
        pub_key = skale.web3.toHex(data['publicKey'])
        port = data.get('port')
        nodes_data.append((_id, name, ip, port, pub_key))
    print(nodes_data)
Exemplo n.º 8
0
def generate_skale_schain_config(skale,
                                 schain_name,
                                 node_id,
                                 base_config=None,
                                 ima_mainnet=None,
                                 ima_mp_schain=None,
                                 ima_mp_mainnet=None,
                                 wallets=None,
                                 rotate_after_block=64):
    node = skale.nodes_data.get(node_id)
    schain = skale.schains_data.get_by_name(schain_name)

    schains_on_node = skale.schains_data.get_schains_for_node(node_id)
    schain_base_port_on_node = get_schain_base_port_on_node(
        schains_on_node, schain_name, node['port'])
    schain_nodes = get_nodes_for_schain_config(skale, schain_name)

    node_info = CurrentNodeInfo(
        node_name=node['name'],
        node_id=node_id,
        base_port=schain_base_port_on_node,
        bind_ip=ip_from_bytes(node['ip']),
        ima_mainnet=ima_mainnet,
        ima_mp_schain=ima_mp_schain,
        ima_mp_mainnet=ima_mp_mainnet,
        wallets=wallets,
        rotate_after_block=rotate_after_block).to_config()
    schain_info = generate_schain_info(schain, schain_nodes)

    if base_config:
        update_base_config(base_config, schain, schain_nodes)
    else:
        base_config = {}
    return generate_schain_config(base_config=base_config,
                                  node_info=node_info,
                                  schain_info=schain_info)
import os
import skale.utils.helper as Helper
from skale.utils.helper import ip_from_bytes
from skale import Skale
from skale.wallets import RPCWallet

from config import ENDPOINT, ABI_FILEPATH

Helper.init_default_logger()

TM_URL = os.environ['TM_URL']
wallet = RPCWallet(TM_URL)
skale = Skale(ENDPOINT, ABI_FILEPATH, wallet)

for _ in range(0, 1000000):
    nodes_ips = skale.nodes_data.get_active_node_ips()
    ips = []
    for ip in nodes_ips:
        ips.append(ip_from_bytes(ip))

    print('====')
    print('IPS', ips)
    print('====')