mm1_node/runtime/
config.rs

1use std::collections::{HashMap, HashSet};
2
3use mm1_address::subnet::NetAddress;
4use tokio::runtime::Runtime;
5
6use crate::runtime::actor_key::ActorKey;
7
8mod actor_config;
9mod rt_config;
10
11pub(crate) use actor_config::EffectiveActorConfig;
12
13#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
14pub struct Mm1Config {
15    #[serde(default = "defaults::subnet_address")]
16    pub(crate) subnet: NetAddress,
17
18    #[serde(default)]
19    actor: actor_config::ActorConfigNode,
20
21    #[serde(default)]
22    runtime: rt_config::RtConfigs,
23}
24
25impl Mm1Config {
26    pub(crate) fn actor_config(&self, actor_key: &ActorKey) -> impl EffectiveActorConfig + '_ {
27        self.actor.select(actor_key)
28    }
29
30    pub(crate) fn build_runtimes(&self) -> std::io::Result<(Runtime, HashMap<String, Runtime>)> {
31        self.runtime.build_runtimes()
32    }
33
34    pub(crate) fn validate(&self) -> Result<(), String> {
35        let runtime_keys: HashSet<_> = self.runtime.runtime_keys().collect();
36        self.actor.ensure_runtime_keys_are_valid(&runtime_keys)?;
37
38        Ok(())
39    }
40}
41
42impl Default for Mm1Config {
43    fn default() -> Self {
44        Self {
45            subnet:  consts::LOCAL_SUBNET,
46            actor:   Default::default(),
47            runtime: Default::default(),
48        }
49    }
50}
51
52pub mod consts {
53    use mm1_address::address::Address;
54    use mm1_address::subnet::{NetAddress, NetMask};
55
56    pub const LOCAL_SUBNET: NetAddress = NetAddress {
57        address: Address::from_u64(0xFFFF0000_00000000),
58        mask:    NetMask::M_16,
59    };
60
61    pub const DEFAULT_ACTOR_NETMASK: NetMask = NetMask::M_56;
62    pub const DEFAULT_ACTOR_INBOX_SIZE: usize = 1024;
63}
64
65mod defaults {
66    use mm1_address::subnet::NetAddress;
67
68    use super::consts;
69    pub(super) const fn subnet_address() -> NetAddress {
70        consts::LOCAL_SUBNET
71    }
72}