Skip to content

Commit

Permalink
Merge branch 'kpop/CON-1049/print_registry' into 'master'
Browse files Browse the repository at this point in the history
feat(ic-recovery): [CON-1049] Print the content of the most recent registry after some steps

After making some registry changes proposals, we display the content of the registry, for the user to verify that the registry contains the changes.

```
Jun 27 06:48:42.110 INFO ####################################
Jun 27 06:48:42.110 INFO V     PrepareCanisterMigration     V
Jun 27 06:48:42.110 INFO ####################################
Jun 27 06:48:42.110 INFO /tmp/june-27/1/recovery/binaries/ic-admin --nns-url "https://large03.testnet.dfinity.network/" propose-to-prepare-canister-migration --summary "Add canister migration entry" --source-subnet xqxyq-bcezi-vonf7-hsbgm-3n5jq-hx3qg-r5gpr-7xi4g-7emfo-gadd6-hae --destination-subnet 4heh6-kgou6-qsxov-psrhm-l3pi6-6cc45-c6oyl-pbayl-vayfm-hmxx2-vae --canister-id-ranges 5v3p4-iyaaa-aaaaa-qaaaa-cai:5v3p4-iyaaa-aaaaa-qaaaa-cai --test-neuron-proposer
Jun 27 06:48:42.110 INFO Execute now? [y/n]
y
Jun 27 06:48:49.318 INFO Title: Migrate 1 canister ranges from subnet xqxyq-bcezi-vonf7-hsbgm-3n5jq-hx3qg-r5gpr-7xi4g-7emfo-gadd6-hae to subnet 4heh6-kgou6-qsxov-psrhm-l3pi6-6cc45-c6oyl-pbayl-vayfm-hmxx2-vae

Summary: Add canister migration entry

Payload: PrepareCanisterMigrationPayload {
    canister_id_ranges: [
        CanisterIdRange {
            start: CanisterId(
                5v3p4-iyaaa-aaaaa-qaaaa-cai,
            ),
            end: CanisterId(
                5v3p4-iyaaa-aaaaa-qaaaa-cai,
            ),
        },
    ],
    source_subnet: xqxyq-bcezi-vonf7-hsbgm-3n5jq-hx3qg-r5gpr-7xi4g-7emfo-gadd6-hae,
    destination_subnet: 4heh6-kgou6-qsxov-psrhm-l3pi6-6cc45-c6oyl-pbayl-vayfm-hmxx2-vae,
}
proposal 37

Jun 27 06:48:49.318 INFO

Jun 27 06:48:49.318 INFO #######################################
Jun 27 06:48:49.318 INFO V     HaltSourceSubnetAtCupHeight     V
Jun 27 06:48:49.318 INFO #######################################
Jun 27 06:48:49.330 INFO Canister Migrations at registry version 26: Some(CanisterMigrations({}))
Jun 27 06:48:49.330 INFO Read registry again? [y/n]
y
Jun 27 06:48:53.815 INFO s:/n:/ic_registry_replicator/internal_state Stored registry versions up to: 27
Jun 27 06:48:53.825 INFO Canister Migrations at registry version 27: Some(CanisterMigrations({CanisterIdRange { start: CanisterId(5v3p4-iyaaa-aaaaa-qaaaa-cai), end: CanisterId(5v3p4-iyaaa-aaaaa-qaaaa-cai) }: [xqxyq-bcezi-vonf7-hsbgm-3n5jq-hx3qg-r5gpr-7xi4g-7emfo-gadd6-hae, 4heh6-kgou6-qsxov-psrhm-l3pi6-6cc45-c6oyl-pbayl-vayfm-hmxx2-vae]}))
Jun 27 06:48:53.825 INFO Read registry again? [y/n]
y
Jun 27 06:49:13.079 INFO Canister Migrations at registry version 27: Some(CanisterMigrations({CanisterIdRange { start: CanisterId(5v3p4-iyaaa-aaaaa-qaaaa-cai), end: CanisterId(5v3p4-iyaaa-aaaaa-qaaaa-cai) }: [xqxyq-bcezi-vonf7-hsbgm-3n5jq-hx3qg-r5gpr-7xi4g-7emfo-gadd6-hae, 4heh6-kgou6-qsxov-psrhm-l3pi6-6cc45-c6oyl-pbayl-vayfm-hmxx2-vae]}))
Jun 27 06:49:13.080 INFO Read registry again? [y/n]
n
Jun 27 06:49:14.964 INFO (Optional) Enter public key to add readonly SSH access to subnet:
```

Closes CON-1049 

Closes CON-1049

See merge request dfinity-lab/public/ic!13206
  • Loading branch information
kpop-dfinity committed Jun 28, 2023
2 parents a4f74e5 + f788cda commit c1d8e8f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rs/recovery/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ DEPENDENCIES = [
"//rs/registry/keys",
"//rs/registry/local_store",
"//rs/registry/nns_data_provider",
"//rs/registry/routing_table",
"//rs/registry/subnet_features",
"//rs/replay",
"//rs/state_manager",
Expand Down
1 change: 1 addition & 0 deletions rs/recovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ic-registry-keys = { path = "../registry/keys" }
ic-registry-local-store = { path = "../registry/local_store" }
ic-registry-nns-data-provider = { path = "../registry/nns_data_provider" }
ic-registry-replicator = { path = "../orchestrator/registry_replicator" }
ic-registry-routing-table = { path = "../registry/routing_table" }
ic-registry-subnet-features = { path = "../registry/subnet_features" }
ic-replay = { path = "../replay" }
ic-state-manager = { path = "../state_manager" }
Expand Down
31 changes: 28 additions & 3 deletions rs/recovery/src/registry_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ use crate::{
use ic_base_types::{NodeId, PrincipalId, RegistryVersion, SubnetId};
use ic_crypto_utils_threshold_sig_der::{parse_threshold_sig_key, public_key_to_der};
use ic_interfaces_registry::RegistryClientResult;
use ic_protobuf::registry::{crypto::v1::PublicKey, subnet::v1::SubnetListRecord};
use ic_protobuf::registry::{
crypto::v1::PublicKey,
subnet::v1::{SubnetListRecord, SubnetRecord},
};
use ic_registry_client::client::{RegistryClient, RegistryClientImpl, ThresholdSigPublicKey};
use ic_registry_client_helpers::subnet::SubnetRegistry;
use ic_registry_client_helpers::{routing_table::RoutingTableRegistry, subnet::SubnetRegistry};
use ic_registry_keys::{make_crypto_threshold_signing_pubkey_key, make_subnet_list_record_key};
use ic_registry_local_store::LocalStoreImpl;
use ic_registry_nns_data_provider::registry::RegistryCanister;
use ic_registry_replicator::RegistryReplicator;
use ic_registry_routing_table::{CanisterMigrations, RoutingTable};
use ic_registry_subnet_features::EcdsaConfig;
use prost::Message;
use slog::{error, info, warn, Logger};
Expand All @@ -24,7 +28,7 @@ use std::{
time::Duration,
};

type VersionedRecoveryResult<T> = RecoveryResult<(RegistryVersion, Option<T>)>;
pub type VersionedRecoveryResult<T> = RecoveryResult<(RegistryVersion, Option<T>)>;

#[derive(Clone)]
/// Enum instructing when we should call [RegistryReplicator::poll].
Expand Down Expand Up @@ -111,6 +115,27 @@ impl RegistryHelper {
})
}

/// Returns the [SubnetRecord] of the given subnet.
pub fn get_subnet_record(&self, subnet_id: SubnetId) -> VersionedRecoveryResult<SubnetRecord> {
self.get(|registry_version, registry_client| {
registry_client.get_subnet_record(subnet_id, registry_version)
})
}

/// Returns the list of canister migrations.
pub fn get_canister_migrations(&self) -> VersionedRecoveryResult<CanisterMigrations> {
self.get(|registry_version, registry_client| {
registry_client.get_canister_migrations(registry_version)
})
}

/// Returns the [RoutingTable].
pub fn get_routing_table(&self) -> VersionedRecoveryResult<RoutingTable> {
self.get(|registry_version, registry_client| {
registry_client.get_routing_table(registry_version)
})
}

/// Polls the [RegistryReplicator] for the most recent version of the registry and then
/// gets the latest registry version.
pub fn latest_registry_version(&self) -> RecoveryResult<RegistryVersion> {
Expand Down
65 changes: 61 additions & 4 deletions rs/recovery/subnet_splitting/src/subnet_splitting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ use ic_recovery::{
error::{RecoveryError, RecoveryResult},
recovery_iterator::RecoveryIterator,
recovery_state::{HasRecoveryState, RecoveryState},
registry_helper::RegistryPollingStrategy,
registry_helper::{RegistryPollingStrategy, VersionedRecoveryResult},
steps::{AdminStep, Step, UploadAndRestartStep, WaitForCUPStep},
NeuronArgs, Recovery, RecoveryArgs, CHECKPOINTS, IC_REGISTRY_LOCAL_STORE, IC_STATE_DIR,
};
use ic_registry_routing_table::CanisterIdRange;
use ic_registry_routing_table::{CanisterIdRange, RoutingTable};
use ic_state_manager::manifest::{manifest_from_path, manifest_hash};
use serde::{Deserialize, Serialize};
use slog::{info, warn, Logger};
use slog::{error, info, warn, Logger};
use strum::{EnumMessage, IntoEnumIterator};
use strum_macros::{EnumIter, EnumString};
use url::Url;

use std::{iter::Peekable, net::IpAddr, path::PathBuf};
use std::{collections::HashMap, iter::Peekable, net::IpAddr, path::PathBuf};

const DESTINATION_WORK_DIR: &str = "destination_work_dir";

Expand Down Expand Up @@ -283,6 +283,10 @@ impl RecoveryIterator<StepType, StepTypeIter> for SubnetSplitting {
fn read_step_params(&mut self, step_type: StepType) {
match step_type {
StepType::HaltSourceSubnetAtCupHeight => {
read_registry(&self.logger, "Canister Migrations", || {
self.recovery.registry_helper.get_canister_migrations()
});

let url = match self.recovery.registry_helper.latest_registry_version() {
Ok(registry_version) => {
format!(
Expand Down Expand Up @@ -316,7 +320,36 @@ impl RecoveryIterator<StepType, StepTypeIter> for SubnetSplitting {
}
}

StepType::RerouteCanisterRanges => {
read_registry(&self.logger, "Source Subnet Record", || {
self.recovery
.registry_helper
.get_subnet_record(self.params.source_subnet_id)
})
}

StepType::DownloadStateFromSourceSubnet => {
let get_ranges = |routing_table: RoutingTable| {
HashMap::from([
(
"source subnet canister ranges",
routing_table.ranges(self.params.source_subnet_id),
),
(
"destination subnet canister ranges",
routing_table.ranges(self.params.destination_subnet_id),
),
])
};

read_registry(&self.logger, "Routing Table", || {
self.recovery.registry_helper.get_routing_table().map(
|(registry_version, routing_table)| {
(registry_version, routing_table.map(get_ranges))
},
)
});

if self.params.download_node_source.is_none() {
self.params.download_node_source =
read_optional(&self.logger, "Enter download IP on the Source Subnet:");
Expand Down Expand Up @@ -346,6 +379,10 @@ impl RecoveryIterator<StepType, StepTypeIter> for SubnetSplitting {
}
}

StepType::Cleanup => read_registry(&self.logger, "Canister Migrations", || {
self.recovery.registry_helper.get_canister_migrations()
}),

StepType::UnhaltDestinationSubnet | StepType::CompleteCanisterMigration => {
let url = match self.recovery.registry_helper.latest_registry_version() {
Ok(registry_version) => {
Expand Down Expand Up @@ -508,6 +545,26 @@ impl HasRecoveryState for SubnetSplitting {
}
}

fn read_registry<T: std::fmt::Debug>(
logger: &Logger,
label: &str,
querier: impl Fn() -> VersionedRecoveryResult<T>,
) {
loop {
match querier() {
Ok((registry_version, value)) => info!(
logger,
"{} at registry version {}: {:?}", label, registry_version, value,
),
Err(err) => error!(logger, "Failed getting {}, error: {}", label, err),
}

if !consent_given(logger, "Read registry again?") {
break;
}
}
}

fn print_url_and_ask_for_confirmation(
logger: &Logger,
url: String,
Expand Down

0 comments on commit c1d8e8f

Please sign in to comment.