|
1 |
| -use anyhow::Result; |
2 |
| -use cliquenet::Address; |
3 |
| -use multisig::x25519; |
4 |
| -use serde::{Deserialize, Serialize}; |
5 |
| -use timeboost_crypto::prelude::{DkgDecKey, DkgEncKey}; |
6 |
| -use tracing::error; |
7 |
| - |
8 | 1 | mod chain;
|
| 2 | +mod committee; |
| 3 | +mod node; |
9 | 4 |
|
10 | 5 | pub use chain::{ChainConfig, ChainConfigBuilder, ParentChain, ParentChainBuilder};
|
11 |
| - |
12 |
| -pub const DECRYPTER_PORT_OFFSET: u16 = 1; |
13 |
| -pub const CERTIFIER_PORT_OFFSET: u16 = 2; |
14 |
| - |
15 |
| -/// Config for each node, containing private keys, public keys, chain_config, network addresses etc |
16 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
17 |
| -pub struct NodeConfig { |
18 |
| - pub net: NodeNetConfig, |
19 |
| - pub keys: NodeKeyConfig, |
20 |
| - pub chain: ChainConfig, |
21 |
| -} |
22 |
| - |
23 |
| -/// Network addresses in [`NodeConfig`] |
24 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
25 |
| -pub struct NodeNetConfig { |
26 |
| - pub public: PublicNet, |
27 |
| - pub internal: InternalNet, |
28 |
| -} |
29 |
| - |
30 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
31 |
| -pub struct PublicNet { |
32 |
| - pub address: Address, |
33 |
| -} |
34 |
| - |
35 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
36 |
| -pub struct InternalNet { |
37 |
| - pub address: Address, |
38 |
| - #[serde(skip_serializing_if = "Option::is_none")] |
39 |
| - pub nitro: Option<Address>, |
40 |
| -} |
41 |
| - |
42 |
| -/// Key materials in [`NodeConfig`] |
43 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
44 |
| -pub struct NodeKeyConfig { |
45 |
| - pub signing: NodeKeypairConfig<multisig::SecretKey, multisig::PublicKey>, |
46 |
| - pub dh: NodeKeypairConfig<x25519::SecretKey, x25519::PublicKey>, |
47 |
| - pub dkg: NodeKeypairConfig<DkgDecKey, DkgEncKey>, |
48 |
| -} |
49 |
| - |
50 |
| -/// A keypair |
51 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
52 |
| -pub struct NodeKeypairConfig<SK, PK> { |
53 |
| - pub secret: SK, |
54 |
| - pub public: PK, |
55 |
| -} |
56 |
| - |
57 |
| -/// Config for the new committee info to be updated to the KeyManager contract. |
58 |
| -/// This file is written during per-node run of `mkconfig` |
59 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
60 |
| -pub struct CommitteeConfig { |
61 |
| - pub effective_timestamp: jiff::Timestamp, |
62 |
| - #[serde(default)] |
63 |
| - pub members: Vec<CommitteeMember>, |
64 |
| -} |
65 |
| - |
66 |
| -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
67 |
| -pub struct CommitteeMember { |
68 |
| - pub signing_key: multisig::PublicKey, |
69 |
| - pub dh_key: x25519::PublicKey, |
70 |
| - pub dkg_enc_key: DkgEncKey, |
71 |
| - pub public_address: Address, |
72 |
| -} |
| 6 | +pub use committee::{CommitteeConfig, CommitteeMember}; |
| 7 | +pub use node::{CERTIFIER_PORT_OFFSET, DECRYPTER_PORT_OFFSET}; |
| 8 | +pub use node::{InternalNet, NodeConfig, NodeKeypair, NodeKeys, NodeNet, PublicNet}; |
73 | 9 |
|
74 | 10 | #[derive(Debug, thiserror::Error)]
|
75 | 11 | #[error("config error: {0}")]
|
76 | 12 | pub struct ConfigError(#[source] Box<dyn std::error::Error + Send + Sync>);
|
77 |
| - |
78 |
| -macro_rules! ConfigImpls { |
79 |
| - ($t:ty) => { |
80 |
| - impl core::str::FromStr for $t { |
81 |
| - type Err = ConfigError; |
82 |
| - |
83 |
| - fn from_str(s: &str) -> Result<Self, Self::Err> { |
84 |
| - toml::from_str(s).map_err(|e| ConfigError(Box::new(e))) |
85 |
| - } |
86 |
| - } |
87 |
| - |
88 |
| - impl core::fmt::Display for $t { |
89 |
| - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
90 |
| - let s = toml::to_string_pretty(self).map_err(|_| core::fmt::Error)?; |
91 |
| - f.write_str(&s) |
92 |
| - } |
93 |
| - } |
94 |
| - |
95 |
| - impl $t { |
96 |
| - pub async fn read<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ConfigError> { |
97 |
| - tokio::fs::read_to_string(path.as_ref()) |
98 |
| - .await |
99 |
| - .map_err(|e| ConfigError(Box::new(e)))? |
100 |
| - .parse() |
101 |
| - } |
102 |
| - } |
103 |
| - }; |
104 |
| -} |
105 |
| - |
106 |
| -ConfigImpls!(NodeConfig); |
107 |
| -ConfigImpls!(CommitteeConfig); |
108 |
| - |
109 |
| -#[cfg(test)] |
110 |
| -mod tests { |
111 |
| - // generated via `just mkconfig 1` |
112 |
| - const CONFIG: &str = r#" |
113 |
| -[net.public] |
114 |
| -address = "127.0.0.1:8001" |
115 |
| -
|
116 |
| -[net.internal] |
117 |
| -address = "127.0.0.1:11001" |
118 |
| -
|
119 |
| -[keys.signing] |
120 |
| -secret = "AS9HxHVwMNyAYsdGntcD56iBbobBn7RPBi32qEBGDSSb" |
121 |
| -public = "23as9Uo6W2AeGronB6nMpcbs8Nxo6CoJ769uePw9sf6Ud" |
122 |
| -
|
123 |
| -[keys.dh] |
124 |
| -secret = "HeTQaTvq1337kSEd5jt4cdF35Touns1WB7xfs24sKxqM" |
125 |
| -public = "3V1LzAgCwubtAb1MT1YgTH2scXg6d2bQEhhsAMeyNo6X" |
126 |
| -
|
127 |
| -[keys.dkg] |
128 |
| -secret = "Cab231aFJTQYmZV7Qw4qa2x49K58fbyTEsM4Tz2CKi1" |
129 |
| -public = "7jdMG9MUWoN4avAc3mbf2tTTGdKSmmGZWTgR3NJ9hJPn6dHj9Vdqspcs3j6zTThfjC" |
130 |
| -
|
131 |
| -[chain] |
132 |
| -namespace = 10101 |
133 |
| -
|
134 |
| -[chain.parent] |
135 |
| -id = 31337 |
136 |
| -rpc_url = "http://127.0.0.1:8545/" |
137 |
| -ibox_contract = "0x4dbd4fc535ac27206064b68ffcf827b0a60bab3f" |
138 |
| -block_tag = "finalized" |
139 |
| -key_manager_contract = "0x2bbf15bc655c4cc157b769cfcb1ea9924b9e1a35" |
140 |
| -"#; |
141 |
| - |
142 |
| - use super::NodeConfig; |
143 |
| - |
144 |
| - #[test] |
145 |
| - fn serialisation_roundtrip() { |
146 |
| - let a: NodeConfig = CONFIG.parse().unwrap(); |
147 |
| - let b: NodeConfig = a.to_string().parse().unwrap(); |
148 |
| - assert_eq!(a, b); |
149 |
| - } |
150 |
| -} |
0 commit comments