Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion rs/pocket_ic_server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,26 @@ MAINNET_NNS_CANISTER_ENV = {
]
]

# The latest registry version to bump the hard-coded registry version can be determined using:
# `bazel run //rs/registry/admin:ic-admin -- get-registry-version`
genrule(
name = "mainnet_routing_table",
testonly = True,
srcs = [],
outs = ["mainnet_routing_table.json"],
cmd = "$(location //rs/registry/admin:ic-admin) get-routing-table --json --registry-version 55267 > $@",
tags = ["requires-network"],
tools = ["//rs/registry/admin:ic-admin"],
)

[
rust_binary(
name = "pocket-ic-server" + name_suffix,
testonly = True,
srcs = ["src/main.rs"],
compile_data = ["src/mainnet_routing_table.json"], # generated by running `ic-admin get-routing-table --json`
compile_data = [":mainnet_routing_table"],
proc_macro_deps = MACRO_DEPENDENCIES,
rustc_env = {"MAINNET_ROUTING_TABLE": "$(location :mainnet_routing_table)"},
# TODO: restrict the visibility
visibility = ["//visibility:public"],
deps = LIB_DEPENDENCIES + [
Expand Down
6 changes: 6 additions & 0 deletions rs/pocket_ic_server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added
- New CLI option `--mainnet-registry-version` to specify the mainnet registry version to use for fetching the mainnet routing table
using the existing CLI option `--fetch-mainnet-routing-table`. Defaults to the latest registry version.



## 11.0.0 - 2025-12-05

### Added
Expand Down
18 changes: 18 additions & 0 deletions rs/pocket_ic_server/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,22 @@ struct Dashboard<'a> {{
);
}
}

// The environment variable `MAINNET_ROUTING_TABLE` pointing to a file (storing the mainnet routing table) is needed
// for the PocketIC server to compile. There are two flows to support:
// - code validation using `cargo`: we create a dummy file and point `MAINNET_ROUTING_TABLE` to that file for code validation to succeed;
// - building the PocketIC server using `bazel`: `bazel` always sets `MAINNET_ROUTING_TABLE` to an actual file storing the mainnet routing table
// (built separately) and thus we don't override `MAINNET_ROUTING_TABLE` if already set.
let mainnet_routing_table_var_name = "MAINNET_ROUTING_TABLE".to_string();
if std::env::var(&mainnet_routing_table_var_name).is_err() {
let mainnet_routing_table_file_name = "mainnet_routing_table.json";
let mainnet_routing_table_file_path =
PathBuf::from(std::env::var("OUT_DIR").unwrap()).join(mainnet_routing_table_file_name);
File::create(&mainnet_routing_table_file_path).unwrap();
println!(
"cargo:rustc-env={}={}",
mainnet_routing_table_var_name,
mainnet_routing_table_file_path.display()
);
}
}
11 changes: 8 additions & 3 deletions rs/pocket_ic_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use ic_crypto_iccsa::{public_key_bytes_from_der, types::SignatureBytes, verify};
use ic_crypto_sha2::Sha256;
use ic_crypto_utils_threshold_sig_der::parse_threshold_sig_key_from_der;
use ic_registry_routing_table::{CanisterIdRange, RoutingTable};
use ic_types::SubnetId;
use ic_types::{RegistryVersion, SubnetId};
use libc::{RLIMIT_NOFILE, getrlimit, rlimit, setrlimit};
use pocket_ic::common::rest::{BinaryBlob, BlobCompression, BlobId, RawVerifyCanisterSigArg};
use pocket_ic_server::BlobStore;
Expand Down Expand Up @@ -61,7 +61,7 @@ const DEFAULT_LOG_LEVELS: &str = "pocket_ic_server=info,tower_http=info,axum::re
const LOG_DIR_PATH_ENV_NAME: &str = "POCKET_IC_LOG_DIR";
const LOG_DIR_LEVELS_ENV_NAME: &str = "POCKET_IC_LOG_DIR_LEVELS";

static MAINNET_ROUTING_TABLE: &[u8] = include_bytes!("mainnet_routing_table.json");
static MAINNET_ROUTING_TABLE: &[u8] = include_bytes!(env!("MAINNET_ROUTING_TABLE"));

#[derive(Parser)]
#[clap(name = "pocket-ic-server")]
Expand Down Expand Up @@ -89,6 +89,10 @@ struct Args {
/// and write it to the file path specified as `--mainnet-routing-table`.
#[clap(long, default_value_t = false, requires = "mainnet_routing_table")]
fetch_mainnet_routing_table: bool,
/// The mainnet registry version to use for fetching the mainnet routing table.
/// Defaults to the latest registry version.
#[clap(long, requires = "fetch_mainnet_routing_table")]
mainnet_registry_version: Option<u64>,
}

/// Get the path of the current running binary.
Expand Down Expand Up @@ -220,7 +224,8 @@ async fn start(runtime: Arc<Runtime>) {
));
let mainnet_routing_table_json = if args.fetch_mainnet_routing_table {
let nns_url = Url::parse("https://icp0.io").unwrap();
let (routing_table, _) = get_routing_table(vec![nns_url]);
let registry_version = args.mainnet_registry_version.map(RegistryVersion::from);
let (routing_table, _) = get_routing_table(vec![nns_url], registry_version);
let routing_table_json = serde_json::to_string_pretty(&routing_table).unwrap();
// `#[clap(long, default_value_t = false, requires = "mainnet_routing_table")]`
// ensures that the mainnet routing table file path is specified.
Expand Down
Loading
Loading