Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save config after loading from orchestrator #904

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sequencer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub struct NetworkParams {
pub async fn init_node(
network_params: NetworkParams,
metrics: &dyn Metrics,
persistence: impl SequencerPersistence,
persistence: &mut impl SequencerPersistence,
) -> anyhow::Result<(SystemContextHandle<SeqTypes, Node<network::Web>>, u64)> {
// Orchestrator client
let validator_args = ValidatorArgs {
Expand All @@ -285,6 +285,7 @@ pub async fn init_node(
tracing::info!("loading network config from orchestrator");
let config = orchestrator_client.get_config(public_ip.to_string()).await;
tracing::info!("loaded config, we are node {}", config.node_index);
persistence.save_config(&config).await?;
tracing::info!("waiting for orchestrated start");
orchestrator_client
.wait_for_all_nodes_ready(config.node_index)
Expand Down
12 changes: 8 additions & 4 deletions sequencer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,21 @@ where
if let Some(status) = modules.status {
opt = opt.status(status);
}
let storage = storage_opt.create().await?;
let mut storage = storage_opt.create().await?;
let SequencerNode { handle, .. } = opt
.serve(move |metrics| {
async move { init_node(network_params, &*metrics, storage).await.unwrap() }
.boxed()
async move {
init_node(network_params, &*metrics, &mut storage)
.await
.unwrap()
}
.boxed()
})
.await?;
handle
}
None => {
init_node(network_params, &NoMetrics, storage_opt.create().await?)
init_node(network_params, &NoMetrics, &mut storage_opt.create().await?)
.await?
.0
}
Expand Down
13 changes: 8 additions & 5 deletions sequencer/src/persistence/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ impl Persistence {
#[async_trait]
impl SequencerPersistence for Persistence {
async fn load_config(&self) -> anyhow::Result<Option<NetworkConfig>> {
if !self.config_path().is_file() {
let path = self.config_path();
if !path.is_file() {
tracing::info!("config not found at {}", path.display());
return Ok(None);
}
Ok(Some(NetworkConfig::from_file(
self.config_path().display().to_string(),
)?))
tracing::info!("loading config from {}", path.display());
Ok(Some(NetworkConfig::from_file(path.display().to_string())?))
}

async fn save_config(&mut self, cfg: &NetworkConfig) -> anyhow::Result<()> {
Ok(cfg.to_file(self.config_path().display().to_string())?)
let path = self.config_path();
tracing::info!("saving config to {}", path.display());
Ok(cfg.to_file(path.display().to_string())?)
}
}
3 changes: 3 additions & 0 deletions sequencer/src/persistence/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ pub type Persistence = DataSource;
#[async_trait]
impl SequencerPersistence for Persistence {
async fn load_config(&self) -> anyhow::Result<Option<NetworkConfig>> {
tracing::info!("loading config from Postgres");
// Select the most recent config (although there should only be one).
let Some(row) = self
.query_opt_static("SELECT config FROM network_config ORDER BY id DESC LIMIT 1")
.await?
else {
tracing::info!("config not found");
return Ok(None);
};
let config = row.try_get("config")?;
Ok(serde_json::from_value(config)?)
}

async fn save_config(&mut self, cfg: &NetworkConfig) -> anyhow::Result<()> {
tracing::info!("saving config to Postgres");
let json = serde_json::to_value(cfg)?;
self.transaction()
.await?
Expand Down