Skip to content

Commit

Permalink
feat: listing registry at specific height (#1285)
Browse files Browse the repository at this point in the history
Co-authored-by: Saša Tomić <[email protected]>
  • Loading branch information
NikolaMilosa and sasa-tomic authored Feb 17, 2025
1 parent 2ce5af0 commit 3582dca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
6 changes: 5 additions & 1 deletion rs/cli/src/commands/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ pub struct Registry {
/// Filters in `key=value` format
#[clap(long, short, alias = "filter")]
pub filters: Vec<Filter>,

/// Specify the height for the registry
#[clap(long, visible_aliases = ["registry-height", "version"])]
pub height: Option<u64>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -114,7 +118,7 @@ impl ExecutableCommand for Registry {

impl Registry {
async fn get_registry(&self, ctx: DreContext) -> anyhow::Result<RegistryDump> {
let local_registry = ctx.registry().await;
let local_registry = ctx.registry_with_version(self.height).await;

let elected_guest_os_versions = get_elected_guest_os_versions(&local_registry)?;
let elected_host_os_versions = get_elected_host_os_versions(&local_registry)?;
Expand Down
8 changes: 6 additions & 2 deletions rs/cli/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,19 @@ impl DreContext {
.await
}

pub async fn registry(&self) -> Arc<dyn LazyRegistry> {
pub async fn registry_with_version(&self, version_height: Option<u64>) -> Arc<dyn LazyRegistry> {
if let Some(reg) = self.registry.borrow().as_ref() {
return reg.clone();
}
let registry = self.store.registry(self.network(), self.proposals_agent()).await.unwrap();
let registry = self.store.registry(self.network(), self.proposals_agent(), version_height).await.unwrap();
*self.registry.borrow_mut() = Some(registry.clone());
registry
}

pub async fn registry(&self) -> Arc<dyn LazyRegistry> {
self.registry_with_version(None).await
}

pub fn network(&self) -> &Network {
&self.network
}
Expand Down
8 changes: 7 additions & 1 deletion rs/cli/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ impl Store {
Ok(path)
}

pub async fn registry(&self, network: &Network, proposal_agent: Arc<dyn ProposalAgent>) -> anyhow::Result<Arc<dyn LazyRegistry>> {
pub async fn registry(
&self,
network: &Network,
proposal_agent: Arc<dyn ProposalAgent>,
version_height: Option<u64>,
) -> anyhow::Result<Arc<dyn LazyRegistry>> {
let registry_path = self.local_store_for_network(network)?;

info!("Using local registry path for network {}: {}", network.name, registry_path.display());
Expand All @@ -128,6 +133,7 @@ impl Store {
proposal_agent,
self.guest_labels_cache_path(network)?,
self.health_client(network)?,
version_height,
)))
}

Expand Down
7 changes: 6 additions & 1 deletion rs/ic-management-backend/src/lazy_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ where
proposal_agent: Arc<dyn ProposalAgent>,
guest_labels_cache_path: PathBuf,
health_client: Arc<dyn HealthStatusQuerier>,
version_height: Option<u64>,
}

pub trait LazyRegistryEntry: RegistryValue {
Expand Down Expand Up @@ -265,7 +266,9 @@ impl LazyRegistryFamilyEntries for LazyRegistryImpl {
}

fn get_latest_version(&self) -> RegistryVersion {
self.local_registry.get_latest_version()
self.version_height
.map(RegistryVersion::new)
.unwrap_or_else(|| self.local_registry.get_latest_version())
}
}

Expand All @@ -277,6 +280,7 @@ impl LazyRegistryImpl {
proposal_agent: Arc<dyn ProposalAgent>,
guest_labels_cache_path: PathBuf,
health_client: Arc<dyn HealthStatusQuerier>,
version_height: Option<u64>,
) -> Self {
Self {
local_registry,
Expand All @@ -293,6 +297,7 @@ impl LazyRegistryImpl {
proposal_agent,
guest_labels_cache_path,
health_client,
version_height,
}
}

Expand Down

0 comments on commit 3582dca

Please sign in to comment.