Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 82a32c0

Browse files
committed
chore: resolve conflicts
1 parent 60213d4 commit 82a32c0

File tree

44 files changed

+789
-408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+789
-408
lines changed

Cargo.lock

Lines changed: 63 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
default-members = ["crates/topos"]
3+
default-members = ["crates/topos", "crates/topos-node"]
44
members = [
55
"crates/*"
66
]

crates/topos-certificate-producer-subnet-client/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ pub type Hash = String;
3636
/// Event collected from the sending subnet
3737
#[derive(Debug, Clone, Serialize, Deserialize)]
3838
pub enum SubnetEvent {
39-
CrossSubnetMessageSent {
40-
target_subnet_id: SubnetId,
41-
source_subnet_id: SubnetId,
42-
nonce: u64,
43-
},
39+
CrossSubnetMessageSent { target_subnet_id: SubnetId },
4440
}
4541

4642
#[derive(Default, Debug, Clone, Serialize, Deserialize)]

crates/topos-certificate-producer-subnet-client/src/subnet_contract.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tracing::info;
1212

1313
abigen!(
1414
IToposCore,
15-
"npm:@topos-protocol/topos-smart-contracts@latest/artifacts/contracts/interfaces/IToposCore.\
15+
"npm:@topos-protocol/topos-smart-contracts@3.2.0/artifacts/contracts/interfaces/IToposCore.\
1616
sol/IToposCore.json"
1717
);
1818

@@ -60,11 +60,9 @@ pub(crate) async fn get_block_events(
6060
);
6161
result.push(SubnetEvent::CrossSubnetMessageSent {
6262
target_subnet_id: f.target_subnet_id.into(),
63-
source_subnet_id: f.source_subnet_id.into(),
64-
nonce: f.nonce.as_u64(),
6563
})
6664
} else {
67-
// Ignored other events until we need them
65+
// Ignored for now other events Upgraded, CertStored
6866
}
6967
}
7068

crates/topos-certificate-producer/src/app_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ impl AppContext {
7070
"Unrecoverable failure in Certificate Producer <-> TCE interaction. Shutting down Certificate Producer."
7171
);
7272
if let Err(e) = self.shutdown().await {
73-
warn!("Error happened during shutdown: {e:?}");
73+
warn!("Failed to shutdown: {e:?}");
7474
}
75-
warn!("Shutdown finished, restarting Certificate Producer...");
75+
info!("Shutdown finished, restarting Certificate Producer...");
7676
return AppContextStatus::Restarting;
7777
},
7878
_ => self.on_tce_proxy_event(tce_evt).await,

crates/topos-certificate-spammer/src/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async fn open_target_node_connection(
8080
Ok(value) => value,
8181
Err(e) => {
8282
error!(
83-
"Unable to create TCE client for node {}, error details: {}",
83+
"Unable to create TCE client for node {}: {}",
8484
&tce_address, e
8585
);
8686
return Err(Error::TCENodeConnection(e));
@@ -90,10 +90,7 @@ async fn open_target_node_connection(
9090
match tce_client.open_stream(Vec::new()).await {
9191
Ok(_) => {}
9292
Err(e) => {
93-
error!(
94-
"Unable to connect to node {}, error details: {}",
95-
&tce_address, e
96-
);
93+
error!("Unable to connect to node {}: {}", &tce_address, e);
9794
return Err(Error::TCENodeConnection(e));
9895
}
9996
}
@@ -150,7 +147,7 @@ async fn close_target_node_connections(
150147
{
151148
info!("Closing connection to target node {}", target_node.address);
152149
if let Err(e) = target_node.shutdown().await {
153-
error!("Error shutting down connection {e}");
150+
error!("Failed to close stream with {}: {e}", target_node.address);
154151
}
155152
}
156153
}
@@ -176,10 +173,7 @@ async fn send_new_certificate(tce_client: &mut TceClient, cert: Certificate) {
176173
.instrument(Span::current())
177174
.await
178175
{
179-
error!(
180-
"failed to pass certificate to tce client, error details: {}",
181-
e
182-
);
176+
error!("Failed to send the Certificate to the TCE client: {}", e);
183177
}
184178
}
185179

crates/topos-config/src/edge/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ impl CommandConfig {
7070

7171
let mut child = command
7272
.stderr(Stdio::piped())
73-
.stdout(Stdio::inherit())
74-
.stdin(Stdio::inherit())
73+
.stdout(Stdio::piped())
74+
.stdin(Stdio::piped())
7575
.spawn()?;
7676

7777
if let Some(pid) = child.id() {

crates/topos-config/src/genesis/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,34 @@ use topos_core::types::ValidatorId;
88
use topos_p2p::{Multiaddr, PeerId};
99
use tracing::info;
1010

11+
use crate::node::NodeConfig;
12+
1113
#[cfg(test)]
1214
pub(crate) mod tests;
1315

1416
/// From the Edge format
1517
pub struct Genesis {
16-
pub path: PathBuf,
1718
pub json: Value,
1819
}
1920

2021
#[derive(Debug, thiserror::Error)]
2122
pub enum Error {
2223
#[error("Failed to parse validators")]
2324
ParseValidators,
25+
2426
#[error("Invalid genesis file on path {0}: {1}")]
2527
InvalidGenesisFile(String, String),
2628
}
2729

2830
impl Genesis {
29-
pub fn new(path: PathBuf) -> Result<Self, Error> {
31+
pub fn new(path: &PathBuf) -> Result<Self, Error> {
3032
info!("Reading subnet genesis file {}", path.display());
31-
let genesis_file = fs::File::open(&path)
33+
let genesis_file = fs::File::open(path)
3234
.map_err(|e| Error::InvalidGenesisFile(path.display().to_string(), e.to_string()))?;
3335

3436
let json: Value = serde_json::from_reader(genesis_file).expect("genesis json parsed");
3537

36-
Ok(Self { path, json })
38+
Ok(Self { json })
3739
}
3840

3941
// TODO: parse directly with serde
@@ -103,3 +105,11 @@ impl Genesis {
103105
)
104106
}
105107
}
108+
109+
impl TryFrom<&NodeConfig> for Genesis {
110+
type Error = Error;
111+
112+
fn try_from(config: &NodeConfig) -> Result<Self, Self::Error> {
113+
Genesis::new(&config.edge_path)
114+
}
115+
}

crates/topos-config/src/genesis/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ macro_rules! test_case {
1414
#[fixture]
1515
#[once]
1616
pub fn genesis() -> Genesis {
17-
Genesis::new(test_case!("genesis-example.json").into())
17+
Genesis::new(&test_case!("genesis-example.json").into())
1818
.expect("Expected valid test genesis file")
1919
}
2020

crates/topos-config/src/node.rs

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use std::path::Path;
1+
use std::path::{Path, PathBuf};
22

33
use figment::{
44
providers::{Format, Toml},
55
Figment,
66
};
77

88
use serde::{Deserialize, Serialize};
9+
use topos_wallet::SecretManager;
10+
use tracing::{debug, error};
911

1012
use crate::{
1113
base::BaseConfig, certificate_producer::CertificateProducerConfig, edge::EdgeConfig,
@@ -26,28 +28,86 @@ pub struct NodeConfig {
2628
pub tce: Option<TceConfig>,
2729
pub certificate_producer: Option<CertificateProducerConfig>,
2830
pub edge: Option<EdgeConfig>,
31+
32+
#[serde(skip)]
33+
pub home_path: PathBuf,
34+
35+
#[serde(skip)]
36+
pub node_path: PathBuf,
37+
38+
#[serde(skip)]
39+
pub edge_path: PathBuf,
2940
}
3041

3142
impl NodeConfig {
32-
pub fn new<S: Serialize>(home: &Path, config: Option<S>) -> Self {
33-
let base = load_config::<BaseConfig, _>(home, config);
43+
/// Try to create a new node config struct from the given home path and node name.
44+
/// It expects a config file to be present in the node's folder.
45+
///
46+
/// This `config.toml` can be generated using: `topos node init` command
47+
pub fn try_from<S: Serialize>(
48+
home_path: &Path,
49+
node_name: &str,
50+
config: Option<S>,
51+
) -> Result<Self, std::io::Error> {
52+
let node_path = home_path.join("node").join(node_name);
53+
let config_path = node_path.join("config.toml");
54+
55+
// TODO: Move this to `topos-node` when migrated
56+
if !Path::new(&config_path).exists() {
57+
error!(
58+
"Please run 'topos node init --name {node_name}' to create a config file first \
59+
for {node_name}."
60+
);
61+
std::process::exit(1);
62+
}
63+
64+
Ok(Self::build_config(node_path, home_path, config))
65+
}
66+
67+
/// Create a new node config struct from the given home path and node name.
68+
///
69+
/// It doesn't check the existence of the config file.
70+
/// It's useful for creating a config file for a new node, relying on the default values.
71+
pub fn create<S: Serialize>(home_path: &Path, node_name: &str, config: Option<S>) -> Self {
72+
let node_path = home_path.join("node").join(node_name);
73+
74+
Self::build_config(node_path, home_path, config)
75+
}
76+
77+
/// Common function to build a node config struct from the given home path and node name.
78+
fn build_config<S: Serialize>(node_path: PathBuf, home_path: &Path, config: Option<S>) -> Self {
79+
let node_folder = node_path.as_path();
80+
let base = load_config::<BaseConfig, _>(node_folder, config);
81+
82+
// Load genesis pointed by the local config
83+
let edge_path = home_path
84+
.join("subnet")
85+
.join(base.subnet.clone())
86+
.join("genesis.json");
3487

3588
let mut config = NodeConfig {
89+
node_path: node_path.to_path_buf(),
90+
edge_path,
91+
home_path: home_path.to_path_buf(),
3692
base: base.clone(),
3793
certificate_producer: base
3894
.need_certificate_producer()
39-
.then(|| load_config::<CertificateProducerConfig, ()>(home, None)),
95+
.then(|| load_config::<CertificateProducerConfig, ()>(node_folder, None)),
4096
tce: base
4197
.need_tce()
42-
.then(|| load_config::<TceConfig, ()>(home, None)),
98+
.then(|| load_config::<TceConfig, ()>(node_folder, None)),
4399
edge: base
44100
.need_edge()
45-
.then(|| load_config::<EdgeConfig, ()>(home, None)),
101+
.then(|| load_config::<EdgeConfig, ()>(node_folder, None)),
46102
};
47103

48104
// Make the TCE DB path relative to the folder
49105
if let Some(config) = config.tce.as_mut() {
50-
config.db_path = home.join(&config.db_path);
106+
config.db_path = node_folder.join(&config.db_path);
107+
debug!(
108+
"Maked TCE DB path relative to the node folder -> {:?}",
109+
config.db_path
110+
);
51111
}
52112

53113
config
@@ -71,3 +131,12 @@ impl Config for NodeConfig {
71131
"default".to_string()
72132
}
73133
}
134+
135+
impl From<&NodeConfig> for SecretManager {
136+
fn from(val: &NodeConfig) -> Self {
137+
match val.base.secrets_config.as_ref() {
138+
Some(secrets_config) => SecretManager::from_aws(secrets_config),
139+
None => SecretManager::from_fs(val.node_path.clone()),
140+
}
141+
}
142+
}

0 commit comments

Comments
 (0)