Skip to content
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(PocketIC): VerifiedApplication subnets #963

Merged
merged 10 commits into from
Aug 20, 2024
4 changes: 4 additions & 0 deletions packages/pocket-ic/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added
- Support for verified application subnets: the library function `PocketIcBuilder::with_verified_application_subnet` adds a verified application subnet to the PocketIC instance;
the library function `PocketIc::get_verified_app_subnets` lists all verified application subnets of the PocketIC instance.



## 4.0.0 - 2024-07-22
Expand Down
16 changes: 16 additions & 0 deletions packages/pocket-ic/src/common/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ pub enum SubnetKind {
NNS,
SNS,
System,
VerifiedApplication,
}

/// This represents which named subnets the user wants to create, and how
Expand All @@ -387,12 +388,14 @@ pub struct SubnetConfigSet {
pub bitcoin: bool,
pub system: usize,
pub application: usize,
pub verified_application: usize,
}

impl SubnetConfigSet {
pub fn validate(&self) -> Result<(), String> {
if self.system > 0
|| self.application > 0
|| self.verified_application > 0
|| self.nns
|| self.sns
|| self.ii
Expand All @@ -415,6 +418,7 @@ impl From<SubnetConfigSet> for ExtendedSubnetConfigSet {
bitcoin,
system,
application,
verified_application,
}: SubnetConfigSet,
) -> Self {
ExtendedSubnetConfigSet {
Expand Down Expand Up @@ -445,6 +449,7 @@ impl From<SubnetConfigSet> for ExtendedSubnetConfigSet {
},
system: vec![SubnetSpec::default(); system],
application: vec![SubnetSpec::default(); application],
verified_application: vec![SubnetSpec::default(); verified_application],
}
}
}
Expand All @@ -465,6 +470,7 @@ pub struct ExtendedSubnetConfigSet {
pub bitcoin: Option<SubnetSpec>,
pub system: Vec<SubnetSpec>,
pub application: Vec<SubnetSpec>,
pub verified_application: Vec<SubnetSpec>,
}

/// Specifies various configurations for a subnet.
Expand Down Expand Up @@ -622,6 +628,7 @@ impl ExtendedSubnetConfigSet {
pub fn validate(&self) -> Result<(), String> {
if !self.system.is_empty()
|| !self.application.is_empty()
|| !self.verified_application.is_empty()
|| self.nns.is_some()
|| self.sns.is_some()
|| self.ii.is_some()
Expand Down Expand Up @@ -651,6 +658,11 @@ impl ExtendedSubnetConfigSet {
.into_iter()
.map(|conf| conf.with_dts_flag(dts_flag))
.collect();
self.verified_application = self
.verified_application
.into_iter()
.map(|conf| conf.with_dts_flag(dts_flag))
.collect();
self
}
}
Expand Down Expand Up @@ -682,6 +694,10 @@ impl Topology {
self.find_subnets(SubnetKind::Application, None)
}

pub fn get_verified_app_subnets(&self) -> Vec<SubnetId> {
self.find_subnets(SubnetKind::VerifiedApplication, None)
}

pub fn get_benchmarking_app_subnets(&self) -> Vec<SubnetId> {
self.find_subnets(
SubnetKind::Application,
Expand Down
6 changes: 6 additions & 0 deletions packages/pocket-ic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ impl PocketIcBuilder {
self
}

/// Add an empty verified application subnet
pub fn with_verified_application_subnet(mut self) -> Self {
self.config.verified_application.push(SubnetSpec::default());
self
}

pub fn with_benchmarking_application_subnet(mut self) -> Self {
self.config
.application
Expand Down
2 changes: 2 additions & 0 deletions rs/pocket_ic_server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New GET endpoint `/http_gateway` listing all HTTP gateways and their details.
- Support for query statistics in the management canister.
- The argument of the endpoint `/instances/<instance_id>/auto_progress` becomes a struct with an optional field `artificial_delay_ms` specifying the minimum delay between consecutive rounds in auto progress mode.
- Support for verified application subnets: the record types `SubnetConfigSet` and `ExtendedSubnetConfigSet` contain a new field `verified_application` specifying verified application subnets;
the enumeration type `SubnetKind` has a new variant `VerifiedApplication`.

### Changed
- The argument `listen_at` of the endpoint `/http_gateway` has been renamed to `port`.
Expand Down
20 changes: 18 additions & 2 deletions rs/pocket_ic_server/src/pocket_ic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,16 @@ impl PocketIc {
spec.get_dts_flag(),
)
});
sys.chain(app)
let verified_app = subnet_configs.verified_application.iter().map(|spec| {
(
SubnetKind::VerifiedApplication,
spec.get_state_path(),
spec.get_subnet_id(),
spec.get_instruction_config(),
spec.get_dts_flag(),
)
});
sys.chain(app).chain(verified_app)
};

let mut subnet_config_info: Vec<SubnetConfigInfo> = vec![];
Expand Down Expand Up @@ -566,6 +575,11 @@ impl PocketIc {
if let Some(subnet) = random_app_subnet {
return subnet;
}
let random_verified_app_subnet =
self.get_random_subnet_of_type(rest::SubnetKind::VerifiedApplication);
if let Some(subnet) = random_verified_app_subnet {
return subnet;
}
let random_system_subnet = self.get_random_subnet_of_type(rest::SubnetKind::System);
if let Some(subnet) = random_system_subnet {
return subnet;
Expand Down Expand Up @@ -672,13 +686,15 @@ fn conv_type(inp: rest::SubnetKind) -> SubnetType {
match inp {
Application | Fiduciary | SNS => SubnetType::Application,
Bitcoin | II | NNS | System => SubnetType::System,
VerifiedApplication => SubnetType::VerifiedApplication,
}
}

fn subnet_size(subnet: SubnetKind) -> u64 {
use rest::SubnetKind::*;
match subnet {
Application => 13,
VerifiedApplication => 13,
Fiduciary => 28,
SNS => 34,
Bitcoin => 13,
Expand All @@ -698,7 +714,7 @@ fn from_range(range: &CanisterIdRange) -> rest::CanisterIdRange {
fn subnet_kind_canister_range(subnet_kind: SubnetKind) -> Option<Vec<CanisterIdRange>> {
use rest::SubnetKind::*;
match subnet_kind {
Application | System => None,
Application | VerifiedApplication | System => None,
NNS => Some(vec![
gen_range("rwlgt-iiaaa-aaaaa-aaaaa-cai", "renrk-eyaaa-aaaaa-aaada-cai"),
gen_range("qoctq-giaaa-aaaaa-aaaea-cai", "n5n4y-3aaaa-aaaaa-p777q-cai"),
Expand Down
3 changes: 2 additions & 1 deletion rs/pocket_ic_server/src/state_api/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,8 @@ fn contains_unimplemented(config: ExtendedSubnetConfigSet) -> bool {
.into_iter()
.flatten()
.chain(config.system)
.chain(config.application),
.chain(config.application)
.chain(config.verified_application),
|spec: pocket_ic::common::rest::SubnetSpec| {
spec.get_subnet_id().is_some() || !spec.is_supported()
},
Expand Down
Loading