@@ -5,18 +5,16 @@ use ic_config::Config;
5
5
use ic_crypto_sha:: Sha256 ;
6
6
use ic_crypto_tls_interfaces:: TlsHandshake ;
7
7
use ic_http_endpoints_metrics:: MetricsHttpEndpoint ;
8
- use ic_interfaces_registry:: { LocalStoreCertifiedTimeReader , RegistryClient } ;
9
8
use ic_logger:: { info, new_replica_logger_from_config} ;
10
9
use ic_metrics:: MetricsRegistry ;
11
10
use ic_onchain_observability_server:: spawn_onchain_observability_grpc_server_and_register_metrics;
12
- use ic_registry_client_helpers:: subnet:: SubnetRegistry ;
13
11
use ic_replica:: setup;
14
12
use ic_sys:: PAGE_SIZE ;
15
13
use ic_types:: consensus:: CatchUpPackage ;
16
14
use ic_types:: { replica_version:: REPLICA_BINARY_HASH , PrincipalId , ReplicaVersion , SubnetId } ;
17
15
use nix:: unistd:: { setpgid, Pid } ;
18
16
use static_assertions:: assert_eq_size;
19
- use std:: { env, io, path:: PathBuf , str:: FromStr , sync:: Arc , time:: Duration } ;
17
+ use std:: { env, fs , io, path:: PathBuf , str:: FromStr , sync:: Arc , time:: Duration } ;
20
18
use tokio:: signal:: unix:: { signal, SignalKind } ;
21
19
22
20
#[ cfg( target_os = "linux" ) ]
@@ -30,7 +28,6 @@ use jemallocator::Jemalloc;
30
28
#[ cfg( target_os = "linux" ) ]
31
29
static ALLOC : Jemalloc = Jemalloc ;
32
30
33
- use ic_registry_local_store:: LocalStoreImpl ;
34
31
#[ cfg( feature = "profiler" ) ]
35
32
use pprof:: { protos:: Message , ProfilerGuard } ;
36
33
#[ cfg( feature = "profiler" ) ]
@@ -43,15 +40,15 @@ use std::io::Write;
43
40
/// Determine sha256 hash of the current replica binary
44
41
///
45
42
/// Returns tuple (path of the replica binary, hex encoded sha256 of binary)
46
- fn get_replica_binary_hash ( ) -> std :: result :: Result < ( PathBuf , String ) , String > {
43
+ fn get_replica_binary_hash ( ) -> Result < ( PathBuf , String ) , String > {
47
44
let mut hasher = Sha256 :: new ( ) ;
48
45
let replica_binary_path = env:: current_exe ( )
49
46
. map_err ( |e| format ! ( "Failed to determine replica binary path: {:?}" , e) ) ?;
50
47
51
- let mut binary_file = std :: fs:: File :: open ( & replica_binary_path)
48
+ let mut binary_file = fs:: File :: open ( & replica_binary_path)
52
49
. map_err ( |e| format ! ( "Failed to open replica binary to calculate hash: {:?}" , e) ) ?;
53
50
54
- std :: io:: copy ( & mut binary_file, & mut hasher)
51
+ io:: copy ( & mut binary_file, & mut hasher)
55
52
. map_err ( |e| format ! ( "Failed to calculate hash for replica binary: {:?}" , e) ) ?;
56
53
57
54
Ok ( ( replica_binary_path, hex:: encode ( hasher. finish ( ) ) ) )
@@ -60,10 +57,8 @@ fn get_replica_binary_hash() -> std::result::Result<(PathBuf, String), String> {
60
57
fn main ( ) -> io:: Result < ( ) > {
61
58
// We do not support 32 bits architectures and probably never will.
62
59
assert_eq_size ! ( usize , u64 ) ;
63
-
64
60
// Ensure that the hardcoded constant matches the OS page size.
65
61
assert_eq ! ( ic_sys:: sysconf_page_size( ) , PAGE_SIZE ) ;
66
-
67
62
// At this point we need to setup a new process group. This is
68
63
// done to ensure all our children processes belong to the same
69
64
// process group (as policy wise in production we restrict setpgid
@@ -75,7 +70,7 @@ fn main() -> io::Result<()> {
75
70
eprintln ! ( "Failed to setup a new process group for replica." ) ;
76
71
// This is a generic exit error. At this point sandboxing is
77
72
// not turned on so we can do a simple exit with cleanup.
78
- return Err ( std :: io:: Error :: new ( std :: io:: ErrorKind :: Other , err) ) ;
73
+ return Err ( io:: Error :: new ( io:: ErrorKind :: Other , err) ) ;
79
74
}
80
75
81
76
#[ cfg( feature = "profiler" ) ]
@@ -139,6 +134,11 @@ fn main() -> io::Result<()> {
139
134
e. print ( ) . expect ( "Failed to print CLI argument error." ) ;
140
135
}
141
136
137
+ // We abort the whole program with a core dump if a single thread panics.
138
+ // This way we can capture all the context if a critical error
139
+ // happens.
140
+ abort_on_panic ( ) ;
141
+
142
142
let config_source = setup:: get_config_source ( & replica_args) ;
143
143
// Setup temp directory for the configuration.
144
144
let tmpdir = tempfile:: Builder :: new ( )
@@ -148,12 +148,14 @@ fn main() -> io::Result<()> {
148
148
let config = Config :: load_with_tmpdir ( config_source, tmpdir. path ( ) . to_path_buf ( ) ) ;
149
149
150
150
let ( logger, async_log_guard) = new_replica_logger_from_config ( & config. logger ) ;
151
-
152
151
let metrics_registry = MetricsRegistry :: global ( ) ;
153
-
154
152
#[ cfg( target_os = "linux" ) ]
155
153
metrics_registry. register ( jemalloc_metrics:: JemallocMetrics :: new ( ) ) ;
156
154
155
+ let cup = setup:: get_catch_up_package ( & replica_args, & logger)
156
+ . as_ref ( )
157
+ . map ( |c| CatchUpPackage :: try_from ( c) . expect ( "deserializing CUP failed" ) ) ;
158
+
157
159
// Set the replica verison and report as metric
158
160
setup:: set_replica_version ( & replica_args, & logger) ;
159
161
{
@@ -172,17 +174,13 @@ fn main() -> io::Result<()> {
172
174
}
173
175
174
176
let ( registry, crypto) = setup:: setup_crypto_registry (
175
- config. clone ( ) ,
177
+ & config,
176
178
rt_main. handle ( ) . clone ( ) ,
177
- Some ( & metrics_registry) ,
179
+ & metrics_registry,
178
180
logger. clone ( ) ,
179
181
) ;
180
182
181
183
let node_id = crypto. get_node_id ( ) ;
182
- let cup_proto = setup:: get_catch_up_package ( & replica_args, & logger) ;
183
- let cup = cup_proto
184
- . as_ref ( )
185
- . map ( |c| CatchUpPackage :: try_from ( c) . expect ( "deserializing CUP failed" ) ) ;
186
184
187
185
let subnet_id = match & replica_args {
188
186
Ok ( args) => {
@@ -198,23 +196,6 @@ fn main() -> io::Result<()> {
198
196
Err ( _) => setup:: get_subnet_id ( node_id, registry. as_ref ( ) , cup. as_ref ( ) , & logger) ,
199
197
} ;
200
198
201
- let subnet_type = setup:: get_subnet_type (
202
- registry. as_ref ( ) ,
203
- subnet_id,
204
- registry. get_latest_version ( ) ,
205
- & logger,
206
- ) ;
207
-
208
- // Read the root subnet id from registry
209
- let root_subnet_id = registry
210
- . get_root_subnet_id (
211
- cup. as_ref ( )
212
- . map ( |c| c. content . registry_version ( ) )
213
- . unwrap_or_else ( || registry. get_latest_version ( ) ) ,
214
- )
215
- . expect ( "cannot read from registry" )
216
- . expect ( "cannot find root subnet id" ) ;
217
-
218
199
// Set node_id and subnet_id in the logging context
219
200
let mut context = logger. get_context ( ) ;
220
201
context. node_id = format ! ( "{}" , node_id. get( ) ) ;
@@ -228,13 +209,6 @@ fn main() -> io::Result<()> {
228
209
let _ = REPLICA_BINARY_HASH . set ( hash) ;
229
210
}
230
211
231
- // We abort the whole program with a core dump if a single thread panics.
232
- // This way we can capture all the context if a critical error
233
- // happens.
234
- abort_on_panic ( ) ;
235
-
236
- setup:: create_consensus_pool_dir ( & config) ;
237
-
238
212
let crypto = Arc :: new ( crypto) ;
239
213
let _metrics_endpoint = MetricsHttpEndpoint :: new (
240
214
rt_http. handle ( ) . clone ( ) ,
@@ -245,10 +219,6 @@ fn main() -> io::Result<()> {
245
219
& logger. inner_logger . root ,
246
220
) ;
247
221
248
- let registry_certified_time_reader: Arc < dyn LocalStoreCertifiedTimeReader > = Arc :: new (
249
- LocalStoreImpl :: new ( config. registry_client . local_store . clone ( ) ) ,
250
- ) ;
251
-
252
222
info ! ( logger, "Constructing IC stack" ) ;
253
223
let ( _, _, _p2p_thread_joiner, _, _xnet_endpoint) =
254
224
ic_replica:: setup_ic_stack:: construct_ic_stack (
@@ -260,12 +230,9 @@ fn main() -> io::Result<()> {
260
230
config. clone ( ) ,
261
231
node_id,
262
232
subnet_id,
263
- subnet_type,
264
- root_subnet_id,
265
233
registry,
266
234
crypto,
267
235
cup,
268
- registry_certified_time_reader,
269
236
) ?;
270
237
271
238
info ! ( logger, "Constructed IC stack" ) ;
0 commit comments