Skip to content

Commit

Permalink
refactor(clone-cell)!: return cell info for clone operations (#1763)
Browse files Browse the repository at this point in the history
* clone cell calls return cell info

* add clone cell refactor to changelog

* rename cell type to snake_case during serialization

* mention cell info serde in changelog

* remove unimplemented app request signal_subscription

* add docs for cell info

* remove unused import

* refactor to return Cell instead of CellInfo for clone calls

* update changelog

* update app info test

* remove redundant clone

* break out Cell into ProvisionedCell and ClonedCell

* fix intra-doc links

* Keep clone cells disabled on restart (#1775)

* Write failing test for disabling clones

* Fix problem where disabled clones are started at conductor restart

* Fixes for macos (#1777)

* chore: update holonix version

* chore(nix):fix dev shell for macos

* chore(kitsune_p2p/types): update sysinfo to fix build

* chore(nix): update holonix version

* chore(nix): remove crate2nix override

* chore(nix): revert disabling crate2nix for macos

* chore(nix): update holonix

* dummy commit to trigger CI

* chore(nix): use crate2nix from nixpkgs

* docs(readme): remove chat + forum and add Discord link (#1778)

* Add Discord link to Readme

Removed the link to chat.holochain.net and in its place added the discord server link to the readme

* Update README.md

* countersigning top level docs (#1768)

* countersigning top level docs

* Update crates/hdk/src/lib.rs

Co-authored-by: Jost Schulte <jost.schulte@protonmail.com>

* Update crates/hdk/src/lib.rs

Co-authored-by: Jost Schulte <jost.schulte@protonmail.com>

Co-authored-by: Jost Schulte <jost.schulte@protonmail.com>

* fix(app-install): reject duplicate identical cells (#1773)

* add failing test for two identical apps install

* add failing test for duplicate app installation

* check there's no identical running cell when installng an app

* update changelog

* search through all cells for identical cell

* add specific error for duplicate cells

* clippy: combine find & is_some() to any

* document call_info in hdk (#1765)

* Apply suggestions from code review

Co-authored-by: Jost Schulte <jost.schulte@protonmail.com>

* remove docs saying links are to entries (#1767)

Co-authored-by: DavHau <hsngrmpf+github@gmail.com>
Co-authored-by: Abraham Njama <62102332+abe-njama@users.noreply.github.com>
Co-authored-by: David Meister <thedavidmeister@gmail.com>
Co-authored-by: Jost Schulte <jost.schulte@protonmail.com>

Co-authored-by: Michael Dougherty <maackle.d@gmail.com>
Co-authored-by: DavHau <hsngrmpf+github@gmail.com>
Co-authored-by: Abraham Njama <62102332+abe-njama@users.noreply.github.com>
Co-authored-by: David Meister <thedavidmeister@gmail.com>
  • Loading branch information
5 people committed Jan 19, 2023
1 parent 4a66026 commit 0737cf3
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 158 deletions.
2 changes: 2 additions & 0 deletions crates/holochain/CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

- Fix: Disabled clone cells are no longer started when conductor restarts. [\#1775](https://github.com/holochain/holochain/pull/1775)

## 0.1.0-beta-rc.3

- Fix: calling `emit_signal` from the `post_commit` callback caused a panic, this is now fixed [\#1749](https://github.com/holochain/holochain/pull/1749)
Expand Down
Expand Up @@ -86,12 +86,12 @@ impl AppInterfaceApi for RealAppInterfaceApi {
}
}
AppRequest::CreateCloneCell(payload) => {
let installed_clone_cell = self
let clone_cell = self
.conductor_handle
.clone()
.create_clone_cell(*payload)
.await?;
Ok(AppResponse::CloneCellCreated(installed_clone_cell))
Ok(AppResponse::CloneCellCreated(clone_cell))
}
AppRequest::DisableCloneCell(payload) => {
self.conductor_handle
Expand All @@ -112,7 +112,6 @@ impl AppInterfaceApi for RealAppInterfaceApi {
let info = self.conductor_handle.network_info(&payload.dnas).await?;
Ok(AppResponse::NetworkInfo(info))
}
AppRequest::SignalSubscription(_) => Ok(AppResponse::Unimplemented(request)),
}
}
}
Expand Down
86 changes: 61 additions & 25 deletions crates/holochain/src/conductor/conductor.rs
Expand Up @@ -81,6 +81,7 @@ use holo_hash::DnaHash;
use holochain_conductor_api::conductor::KeystoreConfig;
use holochain_conductor_api::AppInfo;
use holochain_conductor_api::AppStatusFilter;
use holochain_conductor_api::ClonedCell;
use holochain_conductor_api::FullIntegrationStateDump;
use holochain_conductor_api::FullStateDump;
use holochain_conductor_api::IntegrationStateDump;
Expand Down Expand Up @@ -643,6 +644,8 @@ mod dna_impls {
.filter_map(|cell_id| cells.remove(cell_id).map(|c| (cell_id, c)))
.collect()
});
self.running_cells.share_ref(|cells| dbg!(cells.len()));

for (cell_id, item) in to_cleanup {
if let Err(err) = item.cell.cleanup().await {
tracing::error!("Error cleaning up Cell: {:?}\nCellId: {}", err, cell_id);
Expand Down Expand Up @@ -1291,6 +1294,9 @@ mod cell_impls {

/// Methods related to clone cell management
mod clone_cell_impls {
use holochain_conductor_api::ClonedCell;
use itertools::Itertools;

use super::*;

impl Conductor {
Expand All @@ -1302,7 +1308,7 @@ mod clone_cell_impls {
pub async fn create_clone_cell(
self: Arc<Self>,
payload: CreateCloneCellPayload,
) -> ConductorResult<InstalledCell> {
) -> ConductorResult<ClonedCell> {
let CreateCloneCellPayload {
app_id,
role_name,
Expand All @@ -1318,16 +1324,23 @@ mod clone_cell_impls {
}
let state = self.get_state().await?;
let app = state.get_app(&app_id)?;

app.provisioned_cells()
.find(|(app_role_name, _)| **app_role_name == role_name)
.ok_or_else(|| {
ConductorError::CloneCellError(
"no base cell found for provided role id".to_string(),
)
let role_names = app
.provisioned_cells()
.map(|(role_name, _)| format!("'{}'", role_name))
.join(", ");

ConductorError::CloneCellError(format!(
"no base cell found for provided role id. Available role names are: ({})",
role_names
))
})?;

// add cell to app
let installed_clone_cell = self
let clone_cell = self
.add_clone_cell_to_app(
app_id.clone(),
role_name.clone(),
Expand All @@ -1337,11 +1350,11 @@ mod clone_cell_impls {
.await?;

// run genesis on cloned cell
let cells = vec![(installed_clone_cell.as_id().clone(), membrane_proof)];
let cells = vec![(clone_cell.cell_id.clone(), membrane_proof)];
crate::conductor::conductor::genesis_cells(self.clone(), cells).await?;
self.create_and_add_initialized_cells_for_running_apps(Some(&app_id))
.await?;
Ok(installed_clone_cell)
Ok(clone_cell)
}

/// Disable a clone cell.
Expand Down Expand Up @@ -1373,15 +1386,30 @@ mod clone_cell_impls {
pub async fn enable_clone_cell(
self: Arc<Self>,
payload: &EnableCloneCellPayload,
) -> ConductorResult<InstalledCell> {
) -> ConductorResult<ClonedCell> {
let conductor = self.clone();
let (_, enabled_cell) = self
.update_state_prime({
let app_id = payload.app_id.to_owned();
let clone_cell_id = payload.clone_cell_id.to_owned();
move |mut state| {
let app = state.get_app_mut(&app_id)?;
let clone_id = app.get_disabled_clone_id(&clone_cell_id)?;
let enabled_cell = app.enable_clone_cell(&clone_id)?;
let (cell_id, _) = app.enable_clone_cell(&clone_id)?.into_inner();
let app_role = app.role(&clone_id.as_base_role_name())?;
let original_dna_hash = app_role.dna_hash().clone();
let ribosome = conductor.get_ribosome(cell_id.dna_hash())?;
let dna = ribosome.dna_file.dna();
let dna_modifiers = dna.modifiers.clone();
let name = dna.name.clone();
let enabled_cell = ClonedCell {
cell_id,
clone_id,
original_dna_hash,
dna_modifiers,
name,
enabled: true,
};
Ok((state, enabled_cell))
}
})
Expand Down Expand Up @@ -2173,7 +2201,7 @@ impl Conductor {
Some(app_id) => {
let app = state.get_app(app_id)?;
if app.status().is_running() {
app.all_cells().into_iter().cloned().collect()
app.all_enabled_cells().into_iter().cloned().collect()
} else {
HashSet::new()
}
Expand All @@ -2185,7 +2213,7 @@ impl Conductor {
.installed_apps()
.iter()
.filter(|(_, app)| app.status().is_running())
.flat_map(|(_id, app)| app.all_cells().collect::<Vec<&CellId>>())
.flat_map(|(_id, app)| app.all_enabled_cells().collect::<Vec<&CellId>>())
.cloned()
.collect()
}
Expand Down Expand Up @@ -2288,7 +2316,7 @@ impl Conductor {
role_name: RoleName,
dna_modifiers: DnaModifiersOpt,
name: Option<String>,
) -> ConductorResult<InstalledCell> {
) -> ConductorResult<ClonedCell> {
let ribosome_store = &self.ribosome_store;
// retrieve base cell DNA hash from conductor
let (_, base_cell_dna_hash) = self
Expand All @@ -2297,24 +2325,23 @@ impl Conductor {
let role_name = role_name.clone();
move |mut state| {
let app = state.get_app_mut(&app_id)?;
let app_role_assignment = app
.roles()
.get(&role_name)
.ok_or_else(|| AppError::RoleNameMissing(role_name.to_owned()))?;
if app_role_assignment.is_clone_limit_reached() {
let app_role = app.role(&role_name)?;
if app_role.is_clone_limit_reached() {
return Err(ConductorError::AppError(AppError::CloneLimitExceeded(
app_role_assignment.clone_limit(),
app_role_assignment.clone(),
app_role.clone_limit(),
app_role.clone(),
)));
}
let parent_dna_hash = app_role_assignment.dna_hash().clone();
Ok((state, parent_dna_hash))
let original_dna_hash = app_role.dna_hash().clone();
Ok((state, original_dna_hash))
}
})
.await?;
let original_dna_hash = base_cell_dna_hash.clone();

// clone cell from base cell DNA
let clone_dna = ribosome_store.share_ref(|ds| {
let mut dna_file = ds
let clone_dna = ribosome_store.share_ref(|rs| {
let mut dna_file = rs
.get_dna_file(&base_cell_dna_hash)
.ok_or(DnaError::DnaMissing(base_cell_dna_hash))?
.update_modifiers(dna_modifiers);
Expand All @@ -2323,16 +2350,25 @@ impl Conductor {
}
Ok::<_, DnaError>(dna_file)
})?;
let name = clone_dna.dna().name.clone();
let dna_modifiers = clone_dna.dna().modifiers.clone();
let clone_dna_hash = clone_dna.dna_hash().to_owned();

// add clone cell to app and instantiate resulting clone cell
let (_, installed_clone_cell) = self
.update_state_prime(move |mut state| {
let app = state.get_app_mut(&app_id)?;
let agent_key = app.role(&role_name)?.agent_key().to_owned();
let cell_id = CellId::new(clone_dna_hash, agent_key);
let clone_id = app.add_clone(&role_name, &cell_id)?;
let installed_clone_cell =
InstalledCell::new(cell_id, clone_id.as_app_role_name().clone());
let installed_clone_cell = ClonedCell {
cell_id,
clone_id,
original_dna_hash,
dna_modifiers,
name,
enabled: true,
};
Ok((state, installed_clone_cell))
})
.await?;
Expand Down

0 comments on commit 0737cf3

Please sign in to comment.