Skip to content

Commit

Permalink
feat: Certify api boundary nodes in the state tree
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuoWangNSL committed Feb 15, 2024
1 parent 85d174e commit d2ac9f7
Show file tree
Hide file tree
Showing 6 changed files with 408 additions and 87 deletions.
4 changes: 3 additions & 1 deletion rs/canonical_state/certification_version/src/lib.rs
Expand Up @@ -37,6 +37,8 @@ pub enum CertificationVersion {
V14 = 14,
/// Added subnet metrics in `subnet` subtree.
V15 = 15,
/// Added `/api_boundary_nodes` subtree with domain, ipv4_address and ipv6_address for each API boundary node.
V16 = 16,
}

#[derive(Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -75,7 +77,7 @@ pub const CURRENT_CERTIFICATION_VERSION: CertificationVersion = CertificationVer
///
/// The replica will panic if requested to certify using a version higher than
/// this.
pub const MAX_SUPPORTED_CERTIFICATION_VERSION: CertificationVersion = CertificationVersion::V15;
pub const MAX_SUPPORTED_CERTIFICATION_VERSION: CertificationVersion = CertificationVersion::V16;

/// Returns a list of all certification versions up to [MAX_SUPPORTED_CERTIFICATION_VERSION].
pub fn all_supported_versions() -> impl std::iter::Iterator<Item = CertificationVersion> {
Expand Down
54 changes: 53 additions & 1 deletion rs/canonical_state/src/lazy_tree_conversion.rs
Expand Up @@ -15,7 +15,8 @@ use ic_registry_routing_table::RoutingTable;
use ic_replicated_state::{
canister_state::CanisterState,
metadata_state::{
IngressHistoryState, StreamMap, SubnetMetrics, SubnetTopology, SystemMetadata,
ApiBoundaryNodeEntry, IngressHistoryState, StreamMap, SubnetMetrics, SubnetTopology,
SystemMetadata,
},
replicated_state::ReplicatedStateMessageRouting,
ExecutionState, ReplicatedState,
Expand Down Expand Up @@ -80,6 +81,25 @@ impl<'a> FiniteMap<'a> {
}
self
}

/// If the optional field is `Some` value, adds a new subtree to this map.
/// Otherwise does nothing.
/// The subtree is constructed by applying `func` to the value extracted from the optional field.
pub fn with_optional_tree<B, T, F>(
mut self,
optional_field: Option<T>,
label: B,
func: F,
) -> Self
where
B: AsRef<[u8]>,
F: Fn(T) -> LazyTree<'a>,
{
if let Some(field) = optional_field {
self.0.insert(Label::from(label), Lazy::Value(func(field)));
}
self
}
}

impl<'a> LazyFork<'a> for FiniteMap<'a> {
Expand Down Expand Up @@ -273,6 +293,16 @@ pub fn replicated_state_as_lazy_tree(state: &ReplicatedState) -> LazyTree<'_> {

fork(
FiniteMap::default()
.with_if(
certification_version >= CertificationVersion::V16,
"api_boundary_nodes",
move || {
api_boundary_nodes_as_tree(
&state.metadata.api_boundary_nodes,
certification_version,
)
},
)
.with("metadata", move || {
system_metadata_as_tree(&state.metadata, certification_version)
})
Expand Down Expand Up @@ -656,6 +686,28 @@ impl<'a> LazyFork<'a> for CanisterFork<'a> {
}
}

fn api_boundary_nodes_as_tree(
api_boundary_nodes: &BTreeMap<NodeId, ApiBoundaryNodeEntry>,
certification_version: CertificationVersion,
) -> LazyTree<'_> {
fork(MapTransformFork {
map: api_boundary_nodes,
certification_version,
mk_tree: |_api_boundary_node_id, api_boundary_node, _certification_version| {
fork(
FiniteMap::default()
.with_tree("domain", string(&api_boundary_node.domain))
.with_optional_tree(
api_boundary_node.ipv4_address.as_ref(),
"ipv4_address",
|ipv4_address| string(ipv4_address),
)
.with_tree("ipv6_address", string(&api_boundary_node.ipv6_address)),
)
},
})
}

fn canisters_as_tree(
canisters: &BTreeMap<CanisterId, CanisterState>,
certification_version: CertificationVersion,
Expand Down

0 comments on commit d2ac9f7

Please sign in to comment.