def main(eth_rpc, ):
    # setup logging
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        datefmt='%m-%d %H:%M:%S',
    )

    logging.getLogger('web3').setLevel(logging.INFO)
    logging.getLogger('urllib3.connectionpool').setLevel(logging.INFO)

    log.info("Starting Raiden Metrics Server")

    try:
        log.info(f'Starting Web3 client for node at {eth_rpc}')
        web3 = Web3(HTTPProvider(eth_rpc))
    except ConnectionError:
        log.error(
            'Can not connect to the Ethereum client. Please check that it is running and that '
            'your settings are correct.')
        sys.exit()

    with no_ssl_verification():
        service = None
        try:
            service = MetricsService(
                web3=web3,
                contract_manager=CONTRACT_MANAGER,
                registry_address=REGISTRY_ADDRESS,
                sync_start_block=3_800_000,
            )

            gevent.spawn(write_topology_task, service)

            api = NetworkInfoAPI(service)
            api.run(port=DEFAULT_PORT)
            print(
                f'Running metrics endpoint at http://localhost:{DEFAULT_PORT}/info'
            )

            print('Raiden Status Page backend running...')
            service.run()

        except (KeyboardInterrupt, SystemExit):
            print('Exiting...')
        finally:
            if service:
                log.info('Stopping Raiden Metrics Backend')
                service.stop()

    return 0
Пример #2
0
    if os.path.isdir(app_dir) is False:
        os.makedirs(app_dir)
    transport = MatrixTransport(
        matrix_homeserver,
        matrix_username,
        matrix_password,
        monitoring_channel
    )
    web3 = Web3(HTTPProvider(eth_rpc))
    blockchain = BlockchainMonitor(web3)
    db = StateDB(state_db)

    monitor = MonitoringService(
        private_key,
        state_db=db,
        transport=transport,
        blockchain=blockchain
    )

    api = ServiceApi(monitor, blockchain)
    api.run(rest_host, rest_port)

    monitor.run()


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('urllib3.connectionpool').setLevel(logging.WARN)
    with no_ssl_verification():
        main()
Пример #3
0
def main(
    eth_rpc,
    monitoring_channel,
    matrix_homeserver,
    matrix_username,
    matrix_password,
    token_network_addresses,
):
    """Console script for pathfinder."""

    # setup logging
    logging.basicConfig(level=logging.INFO)
    # logging.getLogger('urllib3.connectionpool').setLevel(logging.DEBUG)

    log.info("Starting Raiden Pathfinding Service")

    token_network_addresses = check_supplied_token_network_addresses(token_network_addresses)
    if token_network_addresses:
        log.info('Following {} networks.')
    else:
        log.info('Following all networks.')

    with no_ssl_verification():
        service = None
        try:
            log.info('Starting Matrix Transport...')
            transport = MatrixTransport(
                matrix_homeserver,
                matrix_username,
                matrix_password,
                monitoring_channel
            )

            log.info('Starting Web3 client...')
            web3 = Web3(HTTPProvider(eth_rpc))

            module_dir = os.path.dirname(pathfinder.__file__)
            contracts_path = os.path.join(module_dir, 'contract', 'contracts_12032018.json')
            contract_manager = ContractManager(contracts_path)

            log.info('Starting TokenNetwork Listener...')
            token_network_listener = BlockchainListener(
                web3,
                contract_manager,
                'TokenNetwork',
            )

            log.info('Starting Pathfinding Service...')
            if token_network_addresses:
                service = PathfindingService(
                    web3,
                    contract_manager,
                    transport,
                    token_network_listener,
                    follow_networks=token_network_addresses)
            else:
                log.info('Starting TokenNetworkRegistry Listener...')
                token_network_registry_listener = BlockchainListener(
                    web3,
                    contract_manager,
                    'TokenNetworkRegistry',
                )

                service = PathfindingService(
                    web3,
                    contract_manager,
                    transport,
                    token_network_listener,
                    token_network_registry_listener=token_network_registry_listener)

            service.run()
        except (KeyboardInterrupt, SystemExit):
            print('Exiting...')
        finally:
            if service:
                log.info('Stopping Pathfinding Service...')
                service.stop()

    return 0
Пример #4
0
def main(
    eth_rpc,
    monitoring_channel,
    matrix_homeserver,
    matrix_username,
    matrix_password,
    token_network_addresses,
):
    """Console script for pathfinder."""

    # setup logging
    logging.basicConfig(level=logging.INFO)
    # logging.getLogger('urllib3.connectionpool').setLevel(logging.DEBUG)

    log.info("Starting Raiden Pathfinding Service")

    try:
        log.info(f'Starting Web3 client for node at {eth_rpc}')
        web3 = Web3(HTTPProvider(eth_rpc))

        token_network_addresses = check_supplied_token_network_addresses(
            token_network_addresses, web3)
        if token_network_addresses:
            log.info(f'Following {len(token_network_addresses)} network(s):')
        else:
            log.info('Following all networks.')
    except ConnectionError as error:
        log.error(
            'Can not connect to the Ethereum client. Please check that it is running and that '
            'your settings are correct.')
        sys.exit()

    with no_ssl_verification():
        service = None
        try:
            log.info('Starting Matrix Transport...')
            transport = MatrixTransport(matrix_homeserver, matrix_username,
                                        matrix_password, monitoring_channel)

            log.info('Starting TokenNetwork Listener...')
            token_network_listener = BlockchainListener(
                web3,
                CONTRACT_MANAGER,
                'TokenNetwork',
            )

            log.info('Starting Pathfinding Service...')
            if token_network_addresses:
                service = PathfindingService(
                    CONTRACT_MANAGER,
                    transport,
                    token_network_listener,
                    chain_id=int(web3.net.version),
                    follow_networks=token_network_addresses)
            else:
                log.info('Starting TokenNetworkRegistry Listener...')
                token_network_registry_listener = BlockchainListener(
                    web3,
                    CONTRACT_MANAGER,
                    'TokenNetworkRegistry',
                )

                service = PathfindingService(CONTRACT_MANAGER,
                                             transport,
                                             token_network_listener,
                                             chain_id=int(web3.net.version),
                                             token_network_registry_listener=
                                             token_network_registry_listener)

            service.run()
        except (KeyboardInterrupt, SystemExit):
            print('Exiting...')
        finally:
            if service:
                log.info('Stopping Pathfinding Service...')
                service.stop()

    return 0
Пример #5
0
def main(
    eth_rpc,
    registry_address,
    start_block,
    port,
    confirmations,
):
    # setup logging
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
        datefmt='%m-%d %H:%M:%S',
    )

    logging.getLogger('web3').setLevel(logging.INFO)
    logging.getLogger('urllib3.connectionpool').setLevel(logging.ERROR)

    log.info("Starting Raiden Metrics Server")
    try:
        log.info(f'Starting Web3 client for node at {eth_rpc}')
        web3 = Web3(HTTPProvider(eth_rpc))
        web3.middleware_stack.inject(geth_poa_middleware, layer=0)
    except ConnectionError:
        log.error(
            'Can not connect to the Ethereum client. Please check that it is running and that '
            'your settings are correct.')
        sys.exit()

    with no_ssl_verification():
        valid_params_given = is_checksum_address(
            registry_address) and start_block >= 0
        if not valid_params_given:
            try:
                chain_id = int(web3.net.version)
                # use limits for mainnet, pre limits for testnets
                is_mainnet = chain_id == 1
                version = None if is_mainnet else 'pre_limits'
                contract_data = get_contracts_deployed(int(web3.net.version),
                                                       version)
                token_network_registry_info = contract_data['contracts'][
                    CONTRACT_TOKEN_NETWORK_REGISTRY]  # noqa
                registry_address = token_network_registry_info['address']
                start_block = max(
                    0, token_network_registry_info['block_number'] - 100)
            except ValueError:
                log.error(
                    'Provided registry address or start block are not valid and '
                    'no deployed contracts were found')
                sys.exit(1)

        try:
            service = MetricsService(
                web3=web3,
                contract_manager=ContractManager(contracts_precompiled_path()),
                registry_address=registry_address,
                sync_start_block=start_block,
                required_confirmations=confirmations,
            )

            # re-enable once deployment works
            # gevent.spawn(write_topology_task, service)

            api = NetworkInfoAPI(service)
            api.run(port=port)
            print(f'Running metrics endpoint at http://localhost:{port}/json')

            print('Raiden Status Page backend running...')
            service.run()

        except (KeyboardInterrupt, SystemExit):
            print('Exiting...')
        finally:
            if service:
                log.info('Stopping Raiden Metrics Backend')
                service.stop()

    return 0
Пример #6
0
def main(
    eth_rpc,
    token_registry_address,
    endpoint_registry_address,
    start_block,
    confirmations,
    # latest,
):
    """Main command"""
    # setup logging
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s %(levelname)s %(message)s",
        datefmt="%Y%m%d %H:%M:%S",
    )
    log = logging.getLogger(__name__)
    logging.getLogger("web3").setLevel(logging.INFO)
    logging.getLogger("urllib3.connectionpool").setLevel(logging.ERROR)

    log.info("Starting Raiden Metrics Server")
    try:
        log.info(f"Starting Web3 client for node at {eth_rpc}")
        web3 = Web3(HTTPProvider(eth_rpc))
        web3.middleware_stack.inject(geth_poa_middleware, layer=0)
    except ConnectionError:
        log.error(
            "Can not connect to the Ethereum client. Please check that it is running and that "
            "your settings are correct."
        )
        sys.exit()

    # chain = Net(web3)
    # log.info(f"Net version = {chain.version}")
    # # use limits for mainnet, pre limits for testnets
    # is_mainnet = chain.version == 1
    # version = None if is_mainnet else "pre_limits"

    with no_ssl_verification():
        valid_params_given = (
            is_checksum_address(token_registry_address) and start_block >= 0
        )

        if not valid_params_given: # or latest is True
            try:
                contract_data = get_contracts_deployed(chain_id=4, version="pre_limits")
                token_network_registry_info = contract_data["contracts"][
                    CONTRACT_TOKEN_NETWORK_REGISTRY
                ]
                endpoint_registry_info = contract_data["contracts"][
                    CONTRACT_ENDPOINT_REGISTRY
                ]

                token_registry_address = token_network_registry_info["address"]
                endpoint_registry_address = endpoint_registry_info["address"]

                start_block = (
                    min(
                        token_network_registry_info["block_number"],
                        endpoint_registry_info["block_number"],
                    )
                    - 20
                )

            except ValueError as ex:
                log.error(ex)
                log.error(
                    "Provided registry address or start block are not valid and "
                    "no deployed contracts were found"
                )
                sys.exit(1)

        token_service = MetricsService(
            web3=web3,
            contract_manager=ContractManager(
                contracts_precompiled_path(version="pre_limits")
            ),
            token_registry_address=token_registry_address,
            endpoint_registry_address=endpoint_registry_address,
            sync_start_block=start_block,
            required_confirmations=confirmations,
        )

        token_service.run()

    sys.exit(0)