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

Wait for genesis time #2310

Merged
merged 5 commits into from
Dec 29, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Make the ledger wait for genesis before starting up any processes ([\#2310](https://github.com/anoma/namada/pull/2310))
40 changes: 40 additions & 0 deletions apps/src/lib/node/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use futures::future::TryFutureExt;
use namada::core::ledger::governance::storage::keys as governance_storage;
use namada::eth_bridge::ethers::providers::{Http, Provider};
use namada::types::storage::Key;
use namada::types::time::{DateTimeUtc, Utc};
use namada_sdk::tendermint::abci::request::CheckTxKind;
use once_cell::unsync::Lazy;
use sysinfo::{RefreshKind, System, SystemExt};
Expand Down Expand Up @@ -241,6 +242,12 @@ pub fn rollback(config: config::Ledger) -> Result<(), shell::Error> {
///
/// All must be alive for correct functioning.
async fn run_aux(config: config::Ledger, wasm_dir: PathBuf) {
// wait for genesis time
let genesis_time = DateTimeUtc::try_from(config.genesis_time.clone())
.expect("Should be able to parse genesis time");
if let std::ops::ControlFlow::Break(_) = sleep_until(genesis_time).await {
return;
}
let setup_data = run_aux_setup(&config, &wasm_dir).await;

// Create an `AbortableSpawner` for signalling shut down from the shell or
Expand Down Expand Up @@ -748,3 +755,36 @@ async fn maybe_start_ethereum_oracle(
fn spawn_dummy_task<T: Send + 'static>(ready: T) -> task::JoinHandle<T> {
tokio::spawn(async { std::future::ready(ready).await })
}

/// Sleep until the genesis time if necessary.
async fn sleep_until(time: DateTimeUtc) -> std::ops::ControlFlow<()> {
// Sleep until start time if needed
let sleep = async {
if let Ok(sleep_time) =
time.0.signed_duration_since(Utc::now()).to_std()
{
if !sleep_time.is_zero() {
tracing::info!(
"Waiting for ledger genesis time: {:?}, time left: {:?}",
time,
sleep_time
);
tokio::time::sleep(sleep_time).await
}
}
};
let shutdown_signal = async {
let (tx, rx) = tokio::sync::oneshot::channel();
namada_sdk::control_flow::shutdown_send(tx).await;
rx.await
};
tokio::select! {
_ = shutdown_signal => {
std::ops::ControlFlow::Break(())
}
_ = sleep => {
tracing::info!("Genesis time reached, starting ledger");
std::ops::ControlFlow::Continue(())
}
}
}
4 changes: 2 additions & 2 deletions sdk/src/control_flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn install_shutdown_signal() -> ShutdownSignal {
}

#[cfg(unix)]
async fn shutdown_send(tx: oneshot::Sender<()>) {
pub async fn shutdown_send(tx: oneshot::Sender<()>) {
use tokio::signal::unix::{signal, SignalKind};
let mut sigterm = signal(SignalKind::terminate()).unwrap();
let mut sighup = signal(SignalKind::hangup()).unwrap();
Expand Down Expand Up @@ -107,7 +107,7 @@ async fn shutdown_send(tx: oneshot::Sender<()>) {
}

#[cfg(windows)]
async fn shutdown_send(tx: oneshot::Sender<()>) {
pub async fn shutdown_send(tx: oneshot::Sender<()>) {
let mut sigbreak = tokio::signal::windows::ctrl_break().unwrap();
tokio::select! {
signal = tokio::signal::ctrl_c() => {
Expand Down
Loading