Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dfx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
25 changes: 14 additions & 11 deletions src/dfx/src/actors/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Logger>,
Expand Down Expand Up @@ -106,25 +107,22 @@ impl Replica {
fn start_replica(&mut self, addr: Addr<Self>) -> 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,
Expand Down Expand Up @@ -215,9 +213,10 @@ fn wait_for_child_or_receiver(

fn replica_start_thread(
logger: Logger,
config_toml: String,
config: ReplicaConfig,
port: Option<u16>,
write_port_to: Option<PathBuf>,
ic_starter_path: PathBuf,
replica_path: PathBuf,
addr: Addr<Replica>,
receiver: Receiver<()>,
Expand All @@ -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());

Expand Down
2 changes: 2 additions & 0 deletions src/dfx/src/commands/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
23 changes: 16 additions & 7 deletions src/dfx/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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());

Expand All @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions src/dfx/src/lib/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down
9 changes: 3 additions & 6 deletions src/dfx/src/lib/replica_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
toml::to_string(&self).map_err(DfxError::CouldNotSerializeClientConfiguration)
let config = &*self;
config.clone()
}
}