From 236eace071354b2e915b875735540cfb365ac8c7 Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Wed, 20 Nov 2024 10:24:39 +0100 Subject: [PATCH] do not store effective canister id in config --- .../src/config/model/replica_config.rs | 16 ++------- src/dfx/src/actors/mod.rs | 1 - src/dfx/src/actors/pocketic.rs | 35 ------------------- src/dfx/src/commands/start.rs | 2 +- src/dfx/src/lib/environment.rs | 3 -- 5 files changed, 3 insertions(+), 54 deletions(-) diff --git a/src/dfx-core/src/config/model/replica_config.rs b/src/dfx-core/src/config/model/replica_config.rs index 510f0420e3..725272d259 100644 --- a/src/dfx-core/src/config/model/replica_config.rs +++ b/src/dfx-core/src/config/model/replica_config.rs @@ -1,5 +1,4 @@ use crate::config::model::dfinity::{ReplicaLogLevel, ReplicaSubnetType}; -use candid::Principal; use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::default::Default; @@ -193,7 +192,6 @@ pub enum CachedReplicaConfig<'a> { #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct CachedConfig<'a> { pub replica_rev: String, - pub effective_canister_id: Option, #[serde(flatten)] pub config: CachedReplicaConfig<'a>, } @@ -202,30 +200,20 @@ impl<'a> CachedConfig<'a> { pub fn replica(config: &'a ReplicaConfig, replica_rev: String) -> Self { Self { replica_rev, - effective_canister_id: None, config: CachedReplicaConfig::Replica { config: Cow::Borrowed(config), }, } } - pub fn pocketic( - config: &'a ReplicaConfig, - replica_rev: String, - effective_canister_id: Option, - ) -> Self { + pub fn pocketic(config: &'a ReplicaConfig, replica_rev: String) -> Self { Self { replica_rev, - effective_canister_id, config: CachedReplicaConfig::PocketIc { config: Cow::Borrowed(config), }, } } pub fn can_share_state(&self, other: &Self) -> bool { - // effective canister id does not matter for ability to share state - self.replica_rev == other.replica_rev && self.config == other.config - } - pub fn get_effective_canister_id(&self) -> Option { - self.effective_canister_id + self == other } } diff --git a/src/dfx/src/actors/mod.rs b/src/dfx/src/actors/mod.rs index 17c32ae934..0f4da4d34e 100644 --- a/src/dfx/src/actors/mod.rs +++ b/src/dfx/src/actors/mod.rs @@ -212,7 +212,6 @@ pub fn start_pocketic_actor( }; let actor_config = pocketic::Config { pocketic_path, - effective_config_path: local_server_descriptor.effective_config_path(), replica_config, bitcoind_addr: local_server_descriptor.bitcoin.nodes.clone(), bitcoin_integration_config, diff --git a/src/dfx/src/actors/pocketic.rs b/src/dfx/src/actors/pocketic.rs index 693a2f0b2a..130524bc1b 100644 --- a/src/dfx/src/actors/pocketic.rs +++ b/src/dfx/src/actors/pocketic.rs @@ -6,8 +6,6 @@ use crate::actors::shutdown_controller::ShutdownController; use crate::actors::BitcoinIntegrationConfig; use crate::lib::error::{DfxError, DfxResult}; #[cfg(unix)] -use crate::lib::info::replica_rev; -#[cfg(unix)] use crate::lib::integrations::bitcoin::initialize_bitcoin_canister; #[cfg(unix)] use crate::lib::integrations::create_integrations_agent; @@ -16,14 +14,9 @@ use actix::{ ResponseActFuture, Running, WrapFuture, }; use anyhow::anyhow; -#[cfg(unix)] -use candid::Principal; use crossbeam::channel::{unbounded, Receiver, Sender}; #[cfg(unix)] -use dfx_core::config::model::replica_config::CachedConfig; use dfx_core::config::model::replica_config::ReplicaConfig; -#[cfg(unix)] -use dfx_core::json::save_json_file; use slog::{debug, error, info, warn, Logger}; use std::net::SocketAddr; use std::ops::ControlFlow::{self, *}; @@ -49,7 +42,6 @@ pub mod signals { #[derive(Clone)] pub struct Config { pub pocketic_path: PathBuf, - pub effective_config_path: PathBuf, pub replica_config: ReplicaConfig, pub bitcoind_addr: Option>, pub bitcoin_integration_config: Option, @@ -210,7 +202,6 @@ impl PocketIc { }; let pocketic_handle = match initialize_pocketic( port, - &config.effective_config_path, &config.bitcoind_addr, &config.bitcoin_integration_config, &config.replica_config, @@ -350,7 +341,6 @@ impl Handler for PocketIc { #[tokio::main(flavor = "current_thread")] async fn initialize_pocketic( port: u16, - effective_config_path: &Path, bitcoind_addr: &Option>, bitcoin_integration_config: &Option, replica_config: &ReplicaConfig, @@ -377,30 +367,6 @@ async fn initialize_pocketic( ReplicaSubnetType::VerifiedApplication => builder.with_verified_application_subnet(), }; let pocketic_handle = builder.build_async().await; - let topology = pocketic_handle.topology().await; - let subnets = match replica_config.subnet_type { - ReplicaSubnetType::Application => topology.get_app_subnets(), - ReplicaSubnetType::System => topology.get_system_subnets(), - ReplicaSubnetType::VerifiedApplication => topology.get_verified_app_subnets(), - }; - if subnets.len() != 1 { - return Err(anyhow!( - "Internal error: PocketIC topology contains multiple subnets of the same subnet kind." - )); - } - let subnet_id = subnets[0]; - let subnet_config = topology.subnet_configs.get(&subnet_id).ok_or(anyhow!( - "Internal error: subnet id {} not found in PocketIC topology", - subnet_id - ))?; - let effective_canister_id = - Principal::from_slice(&subnet_config.canister_ranges[0].start.canister_id); - let effective_config = CachedConfig::pocketic( - replica_config, - replica_rev().into(), - Some(effective_canister_id), - ); - save_json_file(effective_config_path, &effective_config)?; pocketic_handle.set_time(std::time::SystemTime::now()).await; pocketic_handle.auto_progress().await; @@ -425,7 +391,6 @@ async fn initialize_pocketic( #[cfg(not(unix))] fn initialize_pocketic( _: u16, - _: &Path, _: &Option>, _: &Option, _: &ReplicaConfig, diff --git a/src/dfx/src/commands/start.rs b/src/dfx/src/commands/start.rs index 9ba08000d9..3cc485591f 100644 --- a/src/dfx/src/commands/start.rs +++ b/src/dfx/src/commands/start.rs @@ -329,7 +329,7 @@ pub fn exec( }; let effective_config = if pocketic { - CachedConfig::pocketic(&replica_config, replica_rev().into(), None) + CachedConfig::pocketic(&replica_config, replica_rev().into()) } else { CachedConfig::replica(&replica_config, replica_rev().into()) }; diff --git a/src/dfx/src/lib/environment.rs b/src/dfx/src/lib/environment.rs index 3ccdcda852..805d3d9fbf 100644 --- a/src/dfx/src/lib/environment.rs +++ b/src/dfx/src/lib/environment.rs @@ -313,9 +313,6 @@ impl<'a> AgentEnvironment<'a> { Some(Principal::from_slice( &topology.default_effective_canister_id.canister_id, )) - } else if let Some(d) = &network_descriptor.local_server_descriptor { - d.effective_config()? - .and_then(|c| c.get_effective_canister_id()) } else { None };