-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: replace manifest.json with {.dfx/}canister_ids.json #815
Conversation
@ericswanson-dfinity I believe |
src/dfx/src/lib/locations.rs
Outdated
use std::path::PathBuf; | ||
|
||
pub fn canister_did_location(canister_name: &str) -> PathBuf { | ||
PathBuf::from(format!("canisters/{}/{}.did", canister_name, canister_name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to double check: is the did file always under canisters/
or the build output directory specified in dfx.json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were going to remove that output directory (and have everything go under .dfx/somewhere), but until that is done, this should probably point to wherever dfx.json says.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes, but nothing major.
src/dfx/src/lib/error/mod.rs
Outdated
@@ -173,6 +185,25 @@ impl Display for DfxError { | |||
DfxError::NoLocalNetworkProviderFound => { | |||
f.write_str("Expected there to be a local network with a bind address")?; | |||
} | |||
DfxError::CouldNotFindCanisterIdForNetwork(canister, network) => { | |||
f.write_fmt(format_args!( | |||
"Cannot find canister id. Please issue 'dfx canister --network {} create {}'.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we special case network == "local"
if that's the default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, I did first try to only make it include the --network {}
part if network != "local"
, but ran into trouble. I'll try again.
src/dfx/src/lib/canister_info.rs
Outdated
canister_id: RefCell::new(None), | ||
|
||
manifest_path, | ||
canister_id: RefCell::new(canister_id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me we don't need a RefCell
anymore (since we panic if it's not set), correct? If so I'd like to get rid of it. They're usually an anti-pattern. Simply Option
should do the trick.
let identity = get_profile_path().expect("Failed to access profile"); | ||
let agent_url = network_descriptor.providers.first().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be random in this case. Actually, could you add an issue to have ic-agent support having multiple providers in round robin? This would probably be the better place to make this change. If you do that then this code is okay for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/dfx/src/lib/canister_info.rs
Outdated
let canister_type = canister_config | ||
.r#type | ||
.as_ref() | ||
.cloned() | ||
.unwrap_or_else(|| "motoko".to_owned()); | ||
|
||
let canister_id = canister_id_store | ||
.map(|store| store.get_canister_id(name)) | ||
.transpose()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's neat.
src/dfx/src/lib/models/canister.rs
Outdated
|
||
let maybe_canister_id = canister_id_store.find_canister_id(&info.get_name()); | ||
if let Some(canister_id) = maybe_canister_id { | ||
info.set_canister_id(canister_id)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be why it's still a RefCell, but it seems we could pass that to the constructor... or not sure actually.
pub ids: CanisterIds, | ||
} | ||
|
||
impl CanisterIdStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since many functions here has canister_id
, what do you think of simplifying their names as it's redundant and the types already give you that information. So add_canister_id
=> add
, find_canister_id
=> find
. Also, remove canister
where it feels redundant; get_canister_name
=> get_name
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sounds good
…for canister did location
Co-authored-by: Hans <[email protected]>
src/dfx/src/lib/models/canister.rs
Outdated
@@ -258,15 +214,6 @@ impl CanisterPool { | |||
for canister in &self.canisters { | |||
if build_config.build_mode_check { | |||
canister.generate_and_set_canister_id()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hansl When trying to remove the RefCell, I run into this here:
error[E0596]: cannot borrow data in an `Arc` as mutable
--> src/dfx/src/lib/models/canister.rs:218:17
|
218 | canister.generate_and_set_canister_id()?;
| ^^^^^^^^ cannot borrow as mutable
|
= help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::sync::Arc<lib::models::canister::Canister>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it makes canister info immutable. If that's too much trouble we can defer to another PR.
src/dfx/src/lib/models/canister.rs
Outdated
pub struct CanisterManifest { | ||
pub canisters: Map<String, serde_json::value::Value>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct CanManMetadata { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this struct should be deleted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Implements #780
Removed the canister manifest (which had one canister ID per canister, as well as paths to outputs) and replaced it with two files:
.dfx/canister_ids.json
: stores ephemeral canister ids for (typically) local "networks"canister_ids.json
: stores persistent canister ids for (typically) remote networks.The
dfx create
command populates these files, while other commands use the values.Added a
NetworkDescriptor
field toEnvironment
(though really onlyAgentEnvironment
), in order to tell whichcanister_ids.json
file to use.Added to dfx.json
networks
atype
field ("persistent" or "ephemeral")