@@ -8,12 +8,13 @@ use std::{
88use ic_base_types:: { NodeId , PrincipalId , SubnetId } ;
99use ic_protobuf:: registry:: {
1010 api_boundary_node:: v1:: ApiBoundaryNodeRecord , crypto:: v1:: ChainKeyEnabledSubnetList ,
11- hostos_version:: v1:: HostosVersionRecord , node:: v1:: NodeRecord , subnet:: v1:: SubnetListRecord ,
11+ hostos_version:: v1:: HostosVersionRecord , node:: v1:: NodeRecord ,
12+ replica_version:: v1:: ReplicaVersionRecord , subnet:: v1:: SubnetListRecord ,
1213} ;
1314use ic_registry_keys:: {
14- CHAIN_KEY_ENABLED_SUBNET_LIST_KEY_PREFIX , HOSTOS_VERSION_KEY_PREFIX , NODE_RECORD_KEY_PREFIX ,
15- get_api_boundary_node_record_node_id , get_node_record_node_id , make_node_record_key ,
16- make_subnet_list_record_key,
15+ CHAIN_KEY_ENABLED_SUBNET_LIST_KEY_PREFIX , HOSTOS_VERSION_KEY_PREFIX ,
16+ REPLICA_VERSION_KEY_PREFIX , get_api_boundary_node_record_node_id , get_node_record_node_id ,
17+ make_node_record_key , make_subnet_list_record_key,
1718} ;
1819use prost:: Message ;
1920use url:: Url ;
@@ -46,17 +47,36 @@ impl error::Error for InvariantCheckError {
4647}
4748
4849/// Returns all node records in the snapshot.
49- pub ( crate ) fn get_all_node_records ( snapshot : & RegistrySnapshot ) -> Vec < NodeRecord > {
50- let mut nodes: Vec < NodeRecord > = Vec :: new ( ) ;
50+ pub ( crate ) fn get_all_node_records ( snapshot : & RegistrySnapshot ) -> Vec < ( NodeId , NodeRecord ) > {
51+ let mut nodes = Vec :: new ( ) ;
5152 for ( k, v) in snapshot {
52- if k . starts_with ( NODE_RECORD_KEY_PREFIX . as_bytes ( ) ) {
53+ if let Some ( id ) = get_node_record_node_id ( str :: from_utf8 ( k ) . unwrap ( ) ) {
5354 let record = NodeRecord :: decode ( v. as_slice ( ) ) . unwrap ( ) ;
54- nodes. push ( record) ;
55+ nodes. push ( ( NodeId :: from ( id ) , record) ) ;
5556 }
5657 }
58+
5759 nodes
5860}
5961
62+ /// Returns all replica version records in the snapshot.
63+ pub ( crate ) fn get_all_replica_version_records (
64+ snapshot : & RegistrySnapshot ,
65+ ) -> Vec < ( String , ReplicaVersionRecord ) > {
66+ let mut replica_versions = Vec :: new ( ) ;
67+ for ( k, v) in snapshot {
68+ if let Some ( key) = str:: from_utf8 ( k)
69+ . unwrap ( )
70+ . strip_prefix ( REPLICA_VERSION_KEY_PREFIX )
71+ {
72+ let record = ReplicaVersionRecord :: decode ( v. as_slice ( ) ) . unwrap ( ) ;
73+ replica_versions. push ( ( key. to_owned ( ) , record) ) ;
74+ }
75+ }
76+
77+ replica_versions
78+ }
79+
6080pub ( crate ) fn get_value_from_snapshot < T : Message + Default > (
6181 snapshot : & RegistrySnapshot ,
6282 key : String ,
@@ -96,41 +116,13 @@ pub(crate) fn get_all_hostos_version_records(
96116 snapshot : & RegistrySnapshot ,
97117) -> Vec < HostosVersionRecord > {
98118 let mut result = Vec :: new ( ) ;
99- for key in snapshot. keys ( ) {
100- let hostos_version_key = String :: from_utf8 ( key. clone ( ) ) . unwrap ( ) ;
101- if hostos_version_key. starts_with ( HOSTOS_VERSION_KEY_PREFIX ) {
102- let hostos_version_record = match snapshot. get ( key) {
103- Some ( hostos_version_record_bytes) => {
104- HostosVersionRecord :: decode ( hostos_version_record_bytes. as_slice ( ) ) . unwrap ( )
105- }
106- None => panic ! ( "Cannot fetch HostosVersionRecord for an existing key" ) ,
107- } ;
119+ for ( k, v) in snapshot {
120+ if k. starts_with ( HOSTOS_VERSION_KEY_PREFIX . as_bytes ( ) ) {
121+ let hostos_version_record = HostosVersionRecord :: decode ( v. as_slice ( ) ) . unwrap ( ) ;
108122 result. push ( hostos_version_record) ;
109123 }
110124 }
111- result
112- }
113125
114- /// Returns all node records from the snapshot.
115- pub ( crate ) fn get_node_records_from_snapshot (
116- snapshot : & RegistrySnapshot ,
117- ) -> BTreeMap < NodeId , NodeRecord > {
118- let mut result = BTreeMap :: < NodeId , NodeRecord > :: new ( ) ;
119- for key in snapshot. keys ( ) {
120- if let Some ( principal_id) =
121- get_node_record_node_id ( String :: from_utf8 ( key. clone ( ) ) . unwrap ( ) . as_str ( ) )
122- {
123- // This is indeed a node record
124- let node_record = match snapshot. get ( key) {
125- Some ( node_record_bytes) => {
126- NodeRecord :: decode ( node_record_bytes. as_slice ( ) ) . unwrap ( )
127- }
128- None => panic ! ( "Cannot fetch node record for an existing key" ) ,
129- } ;
130- let node_id = NodeId :: from ( principal_id) ;
131- result. insert ( node_id, node_record) ;
132- }
133- }
134126 result
135127}
136128
0 commit comments