diff --git a/dfx.nix b/dfx.nix index a42d0ba6c1..1b1206d4d8 100644 --- a/dfx.nix +++ b/dfx.nix @@ -68,6 +68,7 @@ let DFX_ASSETS = pkgs.runCommandNoCC "dfx-assets" {} '' mkdir -p $out cp ${pkgs.dfinity.ic-replica}/bin/replica $out + cp ${pkgs.dfinity.ic-starter}/bin/ic-starter $out cp ${pkgs.motoko.moc-bin}/bin/moc $out cp ${pkgs.motoko.mo-ide}/bin/mo-ide $out cp ${pkgs.motoko.didc}/bin/didc $out diff --git a/nix/sources.json b/nix/sources.json index ef764b5958..557b5f60df 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -32,9 +32,9 @@ "type": "git" }, "dfinity": { - "ref": "v0.5.7", + "ref": "master", "repo": "ssh://git@github.com/dfinity-lab/dfinity", - "rev": "eb653572373754564ac815cd0785c5f7b9674d6d", + "rev": "b479d14729c86279a647fc984b34863d5c40002e", "type": "git" }, "ic-ref": { diff --git a/src/dfx/src/actors/replica.rs b/src/dfx/src/actors/replica.rs index 0229fbc672..517e63de73 100644 --- a/src/dfx/src/actors/replica.rs +++ b/src/dfx/src/actors/replica.rs @@ -38,6 +38,7 @@ pub mod signals { /// The configuration for the replica actor. pub struct Config { + pub ic_starter_path: PathBuf, pub replica_config: ReplicaConfig, pub replica_path: PathBuf, pub logger: Option, @@ -106,25 +107,22 @@ impl Replica { fn start_replica(&mut self, addr: Addr) -> DfxResult { let logger = self.logger.clone(); - // Create a replica config and make it into TOML. + // Create a replica config. let config = &self.config.replica_config; - let config_toml = config.to_toml()?; - debug!( - logger, - "Replica Configuration (TOML):\n-----\n{}-----\n", config_toml - ); let port = config.http_handler.port; let write_port_to = config.http_handler.write_port_to.clone(); let replica_path = self.config.replica_path.to_path_buf(); + let ic_starter_path = self.config.ic_starter_path.to_path_buf(); let (sender, receiver) = unbounded(); let handle = replica_start_thread( logger, - config_toml, + config.clone(), port, write_port_to, + ic_starter_path, replica_path, addr, receiver, @@ -215,9 +213,10 @@ fn wait_for_child_or_receiver( fn replica_start_thread( logger: Logger, - config_toml: String, + config: ReplicaConfig, port: Option, write_port_to: Option, + ic_starter_path: PathBuf, replica_path: PathBuf, addr: Addr, receiver: Receiver<()>, @@ -231,9 +230,13 @@ fn replica_start_thread( waiter.start(); // Start the process, then wait for the file. - let replica_path = replica_path.as_os_str(); - let mut cmd = std::process::Command::new(replica_path); - cmd.args(&["--config", &config_toml]); + let ic_starter_path = ic_starter_path.as_os_str(); + + // form the ic-start command here similar to replica command + let mut cmd = std::process::Command::new(ic_starter_path); + cmd.args(&["--replica-path", replica_path.to_str().unwrap_or_default(), + "--http-port", &port.unwrap_or_default().to_string(), + "--state-dir", config.state_manager.state_root.to_str().unwrap_or_default()]); cmd.stdout(std::process::Stdio::inherit()); cmd.stderr(std::process::Stdio::inherit()); diff --git a/src/dfx/src/commands/replica.rs b/src/dfx/src/commands/replica.rs index b19dd7abea..d207f314e2 100644 --- a/src/dfx/src/commands/replica.rs +++ b/src/dfx/src/commands/replica.rs @@ -112,11 +112,13 @@ fn get_round_gas_limit(config: &ConfigDefaultsReplica, args: &ArgMatches<'_>) -> /// replica at the moment) and the proxy. pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { let replica_pathbuf = env.get_cache().get_binary_command_path("replica")?; + let ic_starter_pathbuf = env.get_cache().get_binary_command_path("ic-starter")?; let system = actix::System::new("dfx-replica"); let config = get_config(env, args)?; actors::replica::Replica::new(actors::replica::Config { + ic_starter_path: ic_starter_pathbuf, replica_config: config, replica_path: replica_pathbuf, logger: Some(env.get_logger().clone()), diff --git a/src/dfx/src/commands/start.rs b/src/dfx/src/commands/start.rs index 97ebc53561..cda5d3054c 100644 --- a/src/dfx/src/commands/start.rs +++ b/src/dfx/src/commands/start.rs @@ -72,6 +72,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { let (frontend_url, address_and_port) = frontend_address(args, &config)?; let client_pathbuf = env.get_cache().get_binary_command_path("replica")?; + let ic_starter_pathbuf = env.get_cache().get_binary_command_path("ic-starter")?; + let temp_dir = env.get_temp_dir(); let state_root = env.get_state_dir(); @@ -88,6 +90,8 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { let client_configuration_dir = temp_dir.join("client-configuration"); fs::create_dir_all(&client_configuration_dir)?; + let state_dir = temp_dir.join("state/replicated_state"); + fs::create_dir_all(&state_dir)?; let client_port_path = client_configuration_dir.join("client-1.port"); // Touch the client port file. This ensures it is empty prior to @@ -121,8 +125,7 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { let rcv_wait_fwatcher = rcv_wait.clone(); b.set_message("Generating IC local replica configuration."); let replica_config = ReplicaConfig::new(state_root) - .with_random_port(&client_port_path) - .to_toml()?; + .with_random_port(&client_port_path); // TODO(eftychis): we need a proper manager type when we start // spawning multiple client processes and registry. @@ -133,6 +136,7 @@ pub fn exec(env: &dyn Environment, args: &ArgMatches<'_>) -> DfxResult { move || { start_client( &client_pathbuf, + &ic_starter_pathbuf, &pid_file_path, is_killed_client, request_stop, @@ -311,17 +315,22 @@ fn check_previous_process_running(dfx_pid_path: &PathBuf) -> DfxResult<()> { /// We panic here to transmit an error to the parent thread. fn start_client( client_pathbuf: &PathBuf, + ic_starter_pathbuf: &PathBuf, pid_file_path: &PathBuf, is_killed_client: Receiver<()>, request_stop: Sender<()>, - config: String, + config: ReplicaConfig, b: ProgressBar, ) -> DfxResult<()> { b.set_message("Generating IC local replica configuration."); - let client = client_pathbuf.as_path().as_os_str(); - let mut cmd = std::process::Command::new(client); - cmd.args(&["--config", config.as_str()]); + let ic_starter = ic_starter_pathbuf.as_path().as_os_str(); + let mut cmd = std::process::Command::new(ic_starter); + // if None is returned, then an empty String will be provided to replica-path + // TODO: figure out the right solution + cmd.args(&["--replica-path", client_pathbuf.to_str().unwrap_or_default(), + "--http-port-file", config.http_handler.write_port_to.unwrap_or_default().to_str().unwrap_or_default(), + "--state-dir", config.state_manager.state_root.to_str().unwrap_or_default()]); cmd.stdout(std::process::Stdio::inherit()); cmd.stderr(std::process::Stdio::inherit()); @@ -332,7 +341,7 @@ fn start_client( .try_send(()) .expect("Replica thread couldn't signal parent to stop"); // We still want to send an error message. - panic!("Couldn't spawn node manager with command {:?}: {}", cmd, e); + panic!("Couldn't spawn ic-starter with command {:?}: {}", cmd, e); }); // Update the pid file. diff --git a/src/dfx/src/lib/error/mod.rs b/src/dfx/src/lib/error/mod.rs index f6449763b3..90b1ef13db 100644 --- a/src/dfx/src/lib/error/mod.rs +++ b/src/dfx/src/lib/error/mod.rs @@ -73,9 +73,6 @@ pub enum DfxError { /// Generic IDL error. CouldNotSerializeIdlFile(candid::Error), - /// Client TOML Serialization error. - CouldNotSerializeClientConfiguration(toml::ser::Error), - /// An error during parsing of a version string. VersionCouldNotBeParsed(semver::SemVerError), diff --git a/src/dfx/src/lib/replica_config.rs b/src/dfx/src/lib/replica_config.rs index 98320d5118..11798bf6bb 100644 --- a/src/dfx/src/lib/replica_config.rs +++ b/src/dfx/src/lib/replica_config.rs @@ -87,13 +87,10 @@ impl ReplicaConfig { self } - pub fn with_random_port(&mut self, write_port_to: &Path) -> &mut Self { + pub fn with_random_port(&mut self, write_port_to: &Path) -> Self { self.http_handler.port = None; self.http_handler.write_port_to = Some(write_port_to.to_path_buf()); - self - } - - pub fn to_toml(&self) -> DfxResult { - toml::to_string(&self).map_err(DfxError::CouldNotSerializeClientConfiguration) + let config = &*self; + config.clone() } }