1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Reactor used to initialize a node.

use casper_node_macros::reactor;

use crate::{protocol::Message, reactor::validator, types::NodeId, utils::WithDir};

reactor!(Initializer {
  type Config = WithDir<validator::Config>;

  components: {
    chainspec = has_effects infallible ChainspecLoader(cfg
           .value()
           .node
           .chainspec_config_path
           .clone()
           .load(cfg.dir())
           .expect("TODO: return proper error when chainspec cannot be loaded"), effect_builder);
    storage = Storage(&cfg.map_ref(|cfg| cfg.storage.clone()));
    contract_runtime = ContractRuntime(cfg.map_ref(|cfg| cfg.storage.clone()),
&cfg.value().contract_runtime, registry);   }

  events: {}

  requests: {
    StorageRequest -> storage;
    ContractRuntimeRequest -> contract_runtime;

    // No network traffic during initialization, just discard.
    // TODO: Allow for "hard" discard, resulting in a crash?
    NetworkRequest<NodeId, Message> -> !;
  }

  announcements: {
    // We neither send nor process announcements.
  }
});

// TODO: Metrics
// TODO: is_stopped

impl Initializer {
    /// Returns whether the initialization process completed successfully or not.
    pub fn stopped_successfully(&self) -> bool {
        self.chainspec.stopped_successfully()
    }
}