fn start_server_initialization(
    state_reader: Arc<dyn StateReader<State = ReplicatedState>>,
    subnet_id: SubnetId,
    nns_subnet_id: SubnetId,
    log: ReplicaLogger,
    delegation_from_nns: Arc<RwLock<Option<CertificateDelegation>>>,
    health_status: Arc<RwLock<ReplicaHealthStatus>>,
) {
    tokio::task::spawn_blocking(move || {
        info!(log, "Initializing HTTP server...");
        let mut check_count: i32 = 0;
        // Sleep one second between retries, only log every 10th round.
        info!(log, "Waiting for certified state...");
        *health_status.write().unwrap() = ReplicaHealthStatus::WaitingForCertifiedState;
        while common::get_latest_certified_state(state_reader.as_ref()).is_none() {
            check_count += 1;
            if check_count % 10 == 0 {
                info!(log, "Certified state is not yet available...");
            }
            std::thread::sleep(Duration::from_secs(1));
        }
        info!(log, "Certified state is now available.");
        // Fetch the delegation from the NNS for this subnet to be
        // able to issue certificates.
        *health_status.write().unwrap() = ReplicaHealthStatus::WaitingForRootDelegation;
        match load_root_delegation(state_reader.as_ref(), subnet_id, nns_subnet_id, &log) {
            Err(err) => {
                error!(log, "Could not load nns delegation: {}", err);
            }
            Ok(loaded_delegation) => {
                *delegation_from_nns.write().unwrap() = loaded_delegation;
                *health_status.write().unwrap() = ReplicaHealthStatus::Healthy;
                // IMPORTANT: The system-tests relies on this log message to understand when it
                // can start interacting with the replica. In the future, we plan to
                // have a dedicated instrumentation channel to communicate between the
                // replica and the testing framework, but for now, this is the best we can do.
                info!(log, "Ready for interaction.");
            }
        }
    });
}
// Crates a detached tokio blocking task that initializes the server (reading
// required state, etc).
Crates a detached tokio blocking task that initializes the server (reading
required state, etc).
Crates a detached tokio blocking task that initializes the server ( reading required state etc ) .
fn start_server_initialization(
    state_reader: Arc<dyn StateReader<State = ReplicatedState>>,
    subnet_id: SubnetId,
    nns_subnet_id: SubnetId,
    log: ReplicaLogger,
    delegation_from_nns: Arc<RwLock<Option<CertificateDelegation>>>,
    health_status: Arc<RwLock<ReplicaHealthStatus>>,
) {
    tokio::task::spawn_blocking(move || {
        info!(log, "Initializing HTTP server...");
        let mut check_count: i32 = 0;
        // Sleep one second between retries, only log every 10th round.
        info!(log, "Waiting for certified state...");
        *health_status.write().unwrap() = ReplicaHealthStatus::WaitingForCertifiedState;
        while common::get_latest_certified_state(state_reader.as_ref()).is_none() {
            check_count += 1;
            if check_count % 10 == 0 {
                info!(log, "Certified state is not yet available...");
            }
            std::thread::sleep(Duration::from_secs(1));
        }
        info!(log, "Certified state is now available.");
        // Fetch the delegation from the NNS for this subnet to be
        // able to issue certificates.
        *health_status.write().unwrap() = ReplicaHealthStatus::WaitingForRootDelegation;
        match load_root_delegation(state_reader.as_ref(), subnet_id, nns_subnet_id, &log) {
            Err(err) => {
                error!(log, "Could not load nns delegation: {}", err);
            }
            Ok(loaded_delegation) => {
                *delegation_from_nns.write().unwrap() = loaded_delegation;
                *health_status.write().unwrap() = ReplicaHealthStatus::Healthy;
                // IMPORTANT: The system-tests relies on this log message to understand when it
                // can start interacting with the replica. In the future, we plan to
                // have a dedicated instrumentation channel to communicate between the
                // replica and the testing framework, but for now, this is the best we can do.
                info!(log, "Ready for interaction.");
            }
        }
    });
}
fn start_server_initialization ( state_reader : Arc < dyn StateReader < State = ReplicatedState > > , subnet_id : SubnetId , nns_subnet_id : SubnetId , log : ReplicaLogger , delegation_from_nns : Arc < RwLock < Option < CertificateDelegation > > > , health_status : Arc < RwLock < ReplicaHealthStatus > > , ) { tokio :: task :: spawn_blocking ( move | | { info ! ( log " " ) ; let mut check_count : i32 = 0 ; // Sleep one second between retries, only log every 10th round. info ! ( log " " ) ; * health_status . write ( ) . unwrap ( ) = ReplicaHealthStatus :: WaitingForCertifiedState ; while common :: get_latest_certified_state ( state_reader . as_ref ( ) ) . is_none ( ) { check_count += 1 ; if check_count % 10 == 0 { info ! ( log " " ) ; } std :: thread :: sleep ( Duration :: from_secs ( 1 ) ) ; } info ! ( log " " ) ; // Fetch the delegation from the NNS for this subnet to be // able to issue certificates. * health_status . write ( ) . unwrap ( ) = ReplicaHealthStatus :: WaitingForRootDelegation ; match load_root_delegation ( state_reader . as_ref ( ) , subnet_id , nns_subnet_id , & log ) { Err ( err ) => { error ! ( log " " err ) ; } Ok ( loaded_delegation ) => { * delegation_from_nns . write ( ) . unwrap ( ) = loaded_delegation ; * health_status . write ( ) . unwrap ( ) = ReplicaHealthStatus :: Healthy ; // IMPORTANT: The system-tests relies on this log message to understand when it // can start interacting with the replica. In the future, we plan to // have a dedicated instrumentation channel to communicate between the // replica and the testing framework, but for now, this is the best we can do. info ! ( log " " ) ; } } } ) ; }
Crates a detached tokio blocking task that initializes the server (reading
required state, etc).
Crates a detached tokio blocking task that initializes the server ( reading required state etc ) .
state_reader
Arc<dyn StateReader<State = ReplicatedState>>
subnet_id
SubnetId
nns_subnet_id
SubnetId
log
ReplicaLogger
delegation_from_nns
Arc<RwLock<Option<CertificateDelegation>>>
health_status
Arc<RwLock<ReplicaHealthStatus>>
state_reader
Arc<dyn StateReader<State = ReplicatedState>>
subnet_id
SubnetId
nns_subnet_id
SubnetId
log
ReplicaLogger
delegation_from_nns
Arc<RwLock<Option<CertificateDelegation>>>
health_status
Arc<RwLock<ReplicaHealthStatus>>