diff --git a/src/main/cli.ts b/src/main/cli.ts index e2cd6d1a..8b480892 100644 --- a/src/main/cli.ts +++ b/src/main/cli.ts @@ -3,7 +3,7 @@ import fs from 'fs'; import type { HolochainVersion } from '../types'; import { DEFAULT_HOLOCHAIN_VERSION } from './binaries'; -export interface CliArgs { +export type CliArgs = { profile?: string; holochainPath?: string; adminPort?: number; @@ -11,11 +11,20 @@ export interface CliArgs { appsDataDir?: string; bootstrapUrl?: string; signalingUrl?: string; -} + rustLog?: string; + wasmLog?: string; +}; + +export type ValidatedCliArgs = { + profile: string | undefined; + holochainVersion: HolochainVersion; + bootstrapUrl: string | undefined; + signalingUrl: string | undefined; + rustLog: string | undefined; + wasmLog: string | undefined; +}; -export function validateArgs( - args: CliArgs, -): [string | undefined, HolochainVersion, string | undefined, string | undefined] { +export function validateArgs(args: CliArgs): ValidatedCliArgs { const allowedProfilePattern = /^[0-9a-zA-Z-]+$/; if (args.profile && !allowedProfilePattern.test(args.profile)) { throw new Error( @@ -90,7 +99,14 @@ export function validateArgs( const profile = args.profile ? args.profile : undefined; const bootstrapUrl = args.bootstrapUrl && !args.adminPort ? args.bootstrapUrl : undefined; - const singalingUrl = args.signalingUrl && !args.adminPort ? args.signalingUrl : undefined; + const signalingUrl = args.signalingUrl && !args.adminPort ? args.signalingUrl : undefined; - return [profile, holochainVersion, bootstrapUrl, singalingUrl]; + return { + profile, + holochainVersion, + bootstrapUrl, + signalingUrl, + rustLog: args.rustLog ? args.rustLog : undefined, + wasmLog: args.wasmLog ? args.wasmLog : undefined, + }; } diff --git a/src/main/holochainManager.ts b/src/main/holochainManager.ts index ab07d0a7..ba843f5f 100644 --- a/src/main/holochainManager.ts +++ b/src/main/holochainManager.ts @@ -22,6 +22,15 @@ export type AppPort = number; const DEFAULT_BOOTSTRAP_SERVER = 'https://bootstrap.holo.host'; const DEFAULT_SIGNALING_SERVER = 'wss://signal.holo.host'; +const DEFAULT_RUST_LOG = + 'warn,' + + // this thrashes on startup + 'wasmer_compiler_cranelift=error,' + + // this gives a bunch of warnings about how long db accesses are taking, tmi + 'holochain_sqlite::db::access=error,' + + // this gives a lot of "search_and_discover_peer_connect: no peers found, retrying after delay" messages on INFO + 'kitsune_p2p::spawn::actor::discover=error'; +const DEFAULT_WASM_LOG = 'warn'; export class HolochainManager { processHandle: childProcess.ChildProcessWithoutNullStreams | undefined; @@ -64,6 +73,8 @@ export class HolochainManager { lairUrl: string, bootstrapUrl?: string, signalingUrl?: string, + rustLog?: string, + wasmLog?: string, nonDefaultPartition?: HolochainPartition, // launch with data from a non-default partition ): Promise<[HolochainManager, HolochainDataRoot]> { let holochainDataRoot: HolochainDataRoot; @@ -170,11 +181,10 @@ export class HolochainManager { } const binary = version.type === 'built-in' ? HOLOCHAIN_BINARIES[version.version] : version.path; - console.log('HOLOCHAIN_BINARIES: ', HOLOCHAIN_BINARIES); - console.log('HOLOCHAIN BINARY: ', binary); const conductorHandle = childProcess.spawn(binary, ['-c', configPath, '-p'], { env: { - RUST_LOG: 'info', + RUST_LOG: rustLog ? rustLog : DEFAULT_RUST_LOG, + WASM_LOG: wasmLog ? wasmLog : DEFAULT_WASM_LOG, }, }); conductorHandle.stdin.write(password); @@ -256,7 +266,7 @@ export class HolochainManager { await this.adminWebsocket.enableApp({ installed_app_id: appId }); console.log('Insalled app.'); const installedApps = await this.adminWebsocket.listApps({}); - console.log('Installed apps: ', installedApps); + // console.log('Installed apps: ', installedApps); this.installedApps = installedApps; this.launcherEmitter.emit(APP_INSTALLED, { version: this.version, diff --git a/src/main/index.ts b/src/main/index.ts index 1540e493..8077107d 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -80,15 +80,17 @@ cli .option( '-s, --signaling-url ', 'URL of the signaling server to use. Is ignored if an external holochain binary is being used.', - ); + ) + .option('--rust-log ', 'Set the RUST_LOG to be used.') + .option('--wasm-log ', 'Set the WASM_LOG to be used.'); cli.parse(); console.log('GOT CLI ARGS: ', cli.opts()); -const [PROFILE, HOLOCHAIN_VERSION, BOOTSTRAP_URL, SIGNALING_URL] = validateArgs(cli.opts()); +const VALIDATED_CLI_ARGS = validateArgs(cli.opts()); -console.log('VALIDATED CLI ARGS: ', PROFILE, HOLOCHAIN_VERSION, BOOTSTRAP_URL, SIGNALING_URL); +console.log('VALIDATED CLI ARGS: ', VALIDATED_CLI_ARGS); const appName = app.getName(); @@ -121,7 +123,7 @@ protocol.registerSchemesAsPrivileged([ }, ]); -const LAUNCHER_FILE_SYSTEM = LauncherFileSystem.connect(app, PROFILE); +const LAUNCHER_FILE_SYSTEM = LauncherFileSystem.connect(app, VALIDATED_CLI_ARGS.profile); const LAUNCHER_EMITTER = new LauncherEmitter(); setupLogs(LAUNCHER_EMITTER, LAUNCHER_FILE_SYSTEM); @@ -205,7 +207,7 @@ app.on('quit', () => { async function handleSetupAndLaunch(password: string) { if (!LAUNCHER_WINDOWS) throw new Error('Main window needs to exist before launching.'); - if (HOLOCHAIN_VERSION.type !== 'running-external') { + if (VALIDATED_CLI_ARGS.holochainVersion.type !== 'running-external') { const lairHandleTemp = childProcess.spawnSync(LAIR_BINARY, ['--version']); if (!lairHandleTemp.stdout) { console.error(`Failed to run lair-keystore binary:\n${lairHandleTemp}`); @@ -229,10 +231,11 @@ async function handleLaunch(password: string) { LAUNCHER_EMITTER.emit(LOADING_PROGRESS_UPDATE, 'startingLairKeystore'); let lairUrl: string; - if (HOLOCHAIN_VERSION.type === 'running-external') { - lairUrl = HOLOCHAIN_VERSION.lairUrl; + if (VALIDATED_CLI_ARGS.holochainVersion.type === 'running-external') { + lairUrl = VALIDATED_CLI_ARGS.holochainVersion.lairUrl; const externalZomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrl, password); - CUSTOM_ZOME_CALL_SIGNERS[HOLOCHAIN_VERSION.adminPort] = externalZomeCallSigner; + CUSTOM_ZOME_CALL_SIGNERS[VALIDATED_CLI_ARGS.holochainVersion.adminPort] = + externalZomeCallSigner; } else { const [lairHandle, lairUrl2] = await launchLairKeystore( LAIR_BINARY, @@ -253,22 +256,24 @@ async function handleLaunch(password: string) { if (!LAUNCHER_WINDOWS) throw new Error('Main window needs to exist before launching.'); const nonDefaultPartition: HolochainPartition = - HOLOCHAIN_VERSION.type === 'running-external' - ? { type: 'external', name: 'unknown', path: HOLOCHAIN_VERSION.appsDataDir } - : HOLOCHAIN_VERSION.type === 'custom-path' + VALIDATED_CLI_ARGS.holochainVersion.type === 'running-external' + ? { type: 'external', name: 'unknown', path: VALIDATED_CLI_ARGS.holochainVersion.appsDataDir } + : VALIDATED_CLI_ARGS.holochainVersion.type === 'custom-path' ? { type: 'custom', name: 'unknown' } : { type: 'default' }; - console.log('HOLOCHAIN_VERSION: ', HOLOCHAIN_VERSION); + console.log('VALIDATED_CLI_ARGS.holochainVersion: ', VALIDATED_CLI_ARGS.holochainVersion); const [holochainManager, holochainDataRoot] = await HolochainManager.launch( LAUNCHER_EMITTER, LAUNCHER_FILE_SYSTEM, password, - HOLOCHAIN_VERSION, + VALIDATED_CLI_ARGS.holochainVersion, lairUrl, - BOOTSTRAP_URL, - SIGNALING_URL, + VALIDATED_CLI_ARGS.bootstrapUrl, + VALIDATED_CLI_ARGS.signalingUrl, + VALIDATED_CLI_ARGS.rustLog, + VALIDATED_CLI_ARGS.wasmLog, nonDefaultPartition, ); HOLOCHAIN_DATA_ROOT = holochainDataRoot; @@ -318,7 +323,9 @@ const router = t.router({ installedAppId: appInfo.installed_app_id, agentPubKey: appInfo.agent_pub_key, adminPort: - HOLOCHAIN_VERSION.type === 'running-external' ? HOLOCHAIN_VERSION.adminPort : undefined, + VALIDATED_CLI_ARGS.holochainVersion.type === 'running-external' + ? VALIDATED_CLI_ARGS.holochainVersion.adminPort + : undefined, }; happWindow.on('close', () => { delete WINDOW_INFO_MAP[happWindow.webContents.id]; @@ -350,7 +357,8 @@ const router = t.router({ }), lairSetupRequired: t.procedure.query(() => { const isInitialized = - LAUNCHER_FILE_SYSTEM.keystoreInitialized() || HOLOCHAIN_VERSION.type === 'running-external'; + LAUNCHER_FILE_SYSTEM.keystoreInitialized() || + VALIDATED_CLI_ARGS.holochainVersion.type === 'running-external'; const isInitializedValidated = validateWithZod({ schema: z.boolean(), data: isInitialized,