Skip to content

Commit

Permalink
do not store effective canister id in config
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk committed Nov 20, 2024
1 parent 569c9c0 commit 236eace
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 54 deletions.
16 changes: 2 additions & 14 deletions src/dfx-core/src/config/model/replica_config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Principal>,
#[serde(flatten)]
pub config: CachedReplicaConfig<'a>,
}
Expand All @@ -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<Principal>,
) -> 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<Principal> {
self.effective_canister_id
self == other
}
}
1 change: 0 additions & 1 deletion src/dfx/src/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 0 additions & 35 deletions src/dfx/src/actors/pocketic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, *};
Expand All @@ -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<Vec<SocketAddr>>,
pub bitcoin_integration_config: Option<BitcoinIntegrationConfig>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -350,7 +341,6 @@ impl Handler<Shutdown> for PocketIc {
#[tokio::main(flavor = "current_thread")]
async fn initialize_pocketic(
port: u16,
effective_config_path: &Path,
bitcoind_addr: &Option<Vec<SocketAddr>>,
bitcoin_integration_config: &Option<BitcoinIntegrationConfig>,
replica_config: &ReplicaConfig,
Expand All @@ -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;
Expand All @@ -425,7 +391,6 @@ async fn initialize_pocketic(
#[cfg(not(unix))]
fn initialize_pocketic(
_: u16,
_: &Path,
_: &Option<Vec<SocketAddr>>,
_: &Option<BitcoinIntegrationConfig>,
_: &ReplicaConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
};
Expand Down
3 changes: 0 additions & 3 deletions src/dfx/src/lib/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 236eace

Please sign in to comment.