def test_initializing_data_dir_with_missing_nodekey(chain_config, data_dir, database_dir): assert not os.path.exists(chain_config.nodekey_path) assert not is_data_dir_initialized(chain_config) initialize_data_dir(chain_config) assert is_data_dir_initialized(chain_config)
def test_initializing_data_dir_from_empty_data_dir(chain_config, data_dir): assert not os.path.exists(chain_config.database_dir) assert not is_data_dir_initialized(chain_config) initialize_data_dir(chain_config) assert is_data_dir_initialized(chain_config)
def test_initializing_data_dir_from_nothing(chain_config): assert not os.path.exists(chain_config.data_dir) assert not is_data_dir_initialized(chain_config) initialize_data_dir(chain_config) assert is_data_dir_initialized(chain_config)
def main() -> None: event_bus = EventBus(ctx) main_endpoint = event_bus.create_endpoint(MAIN_EVENTBUS_ENDPOINT) main_endpoint.connect() plugin_manager = setup_plugins( MainAndIsolatedProcessScope(event_bus, main_endpoint) ) plugin_manager.amend_argparser_config(parser, subparser) args = parser.parse_args() # # Dev testing stuff # if args.start_memory_profile: os.environ["PYTHONTRACEMALLOC"] = '1' if args.rand_db: os.environ["GENERATE_RANDOM_DATABASE"] = 'true' if args.instance is not None: from helios.utils.xdg import get_xdg_helios_root args.port = args.port + args.instance * 2 if args.instance != 0: args.do_rpc_http_server = False subdir = 'instance_' + str(args.instance) absolute_path = get_xdg_helios_root() / subdir absolute_dir = os.path.dirname(os.path.realpath(__file__)) absolute_keystore_path = absolute_dir + '/keystore/' args.keystore_path = absolute_keystore_path + subdir args.keystore_password = '******' os.environ["HELIOS_DATA_DIR"] = str(absolute_path.resolve()) os.environ["INSTANCE_NUMBER"] = str(args.instance) # # # if not args.keystore_password and not hasattr(args, 'func'): password = getpass.getpass(prompt='Keystore Password: '******'default'] = TRACE_LEVEL_NUM log_levels['hvm'] = TRACE_LEVEL_NUM log_levels['hp2p'] = TRACE_LEVEL_NUM log_levels['helios'] = TRACE_LEVEL_NUM log_levels['urllib3'] = TRACE_LEVEL_NUM log_levels['ssdp'] = TRACE_LEVEL_NUM log_levels['Service'] = TRACE_LEVEL_NUM log_levels['Action'] = TRACE_LEVEL_NUM log_levels['Device'] = TRACE_LEVEL_NUM log_levels['helios.extensibility'] = TRACE_LEVEL_NUM else: log_levels['default'] = logging.INFO log_levels['urllib3'] = logging.INFO log_levels['ssdp'] = logging.INFO log_levels['Service'] = logging.INFO log_levels['hvm'] = logging.DEBUG #sets all of hvm log_levels['hvm.db.account.AccountDB'] = logging.DEBUG log_levels['hvm.vm.base.VM.VM'] = logging.DEBUG log_levels['hvm.chain'] = logging.DEBUG #log_levels['hvm.chain.chain.Chain'] = logging.DEBUG log_levels['hvm.db.chain_head.ChainHeadDB'] = logging.DEBUG log_levels['hvm.db.chain_db.ChainDB'] = logging.DEBUG log_levels['hvm.db.consensus'] = logging.DEBUG log_levels['hvm.memoryLogger'] = logging.DEBUG #log_levels['hp2p'] = logging.INFO log_levels['hp2p.peer'] = logging.DEBUG log_levels['hp2p.peer.PeerPool'] = logging.DEBUG log_levels['hp2p.consensus.Consensus'] = logging.DEBUG log_levels['hp2p.SmartContractChainManager'] = logging.DEBUG log_levels['hp2p.kademlia.KademliaProtocol'] = logging.DEBUG log_levels['hp2p.discovery.DiscoveryProtocol'] = logging.INFO log_levels['hp2p.discovery.DiscoveryService'] = logging.INFO log_levels['hp2p.nat.UPnPService'] = logging.CRITICAL log_levels['connectionpool'] = logging.CRITICAL log_levels['hp2p.protocol'] = logging.DEBUG log_levels['hp2p.protocol.Protocol'] = logging.DEBUG #log_levels['helios'] = logging.INFO log_levels['helios.rpc.ipc'] = logging.INFO log_levels['helios.Node'] = logging.INFO log_levels['helios.sync'] = logging.DEBUG log_levels['helios.protocol'] = logging.INFO log_levels['helios.protocol.common'] = logging.DEBUG log_levels['helios.protocol.hls.peer.HLSPeer'] = 5 log_levels['helios.memoryLogger'] = logging.DEBUG log_levels['hp2p.hls'] = logging.INFO log_levels['helios.server.FullServer'] = logging.DEBUG log_levels['Action'] = logging.INFO log_levels['Device'] = logging.INFO log_levels['helios.extensibility'] = logging.INFO setup_log_levels(log_levels = log_levels) try: chain_config = ChainConfig.from_parser_args(args) except AmbigiousFileSystem: parser.error(HELIOS_AMBIGIOUS_FILESYSTEM_INFO) if not is_data_dir_initialized(chain_config): # TODO: this will only work as is for chains with known genesis # parameters. Need to flesh out how genesis parameters for custom # chains are defined and passed around. try: initialize_data_dir(chain_config) except AmbigiousFileSystem: parser.error(HELIOS_AMBIGIOUS_FILESYSTEM_INFO) except MissingPath as e: parser.error( "\n" f"It appears that {e.path} does not exist. " "Helios does not attempt to create directories outside of its root path. " "Either manually create the path or ensure you are using a data directory " "inside the XDG_HELIOS_ROOT path" ) file_logger, log_queue, listener = setup_helios_file_and_queue_logging( stderr_logger, formatter, handler_stream, chain_config, args.file_log_level, ) display_launch_logs(chain_config) # compute the minimum configured log level across all configured loggers. min_configured_log_level = min( stderr_logger.level, file_logger.level, *(args.log_levels or {}).values(), *(log_levels or {}).values() ) extra_kwargs = { 'log_queue': log_queue, 'log_level': min_configured_log_level, 'log_levels': log_levels, 'profile': args.profile, } # Plugins can provide a subcommand with a `func` which does then control # the entire process from here. if hasattr(args, 'func'): args.func(args, chain_config) else: helios_boot( args, chain_config, extra_kwargs, plugin_manager, listener, event_bus, main_endpoint, stderr_logger, )
def chain_config(): _chain_config = ChainConfig(network_id=1, max_peers=1) initialize_data_dir(_chain_config) return _chain_config