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

Downtime simulator #4017

Merged
merged 5 commits into from
Jun 1, 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
1 change: 1 addition & 0 deletions massa-consensus-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ itertools = "0.10"

[features]
sandbox = []
bootstrap_server = []
20 changes: 20 additions & 0 deletions massa-consensus-worker/src/state/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ impl ConsensusState {
// take care of block db changes
self.block_db_changed()?;

let now = massa_time::MassaTime::now().expect("could not get now time");

use massa_models::config::constants::DOWNTIME_END_TIMESTAMP;
use massa_models::config::constants::DOWNTIME_START_TIMESTAMP;

// Simulate downtime
// last_start_period should be set to trigger after the DOWNTIME_END_TIMESTAMP
#[cfg(not(feature = "bootstrap_server"))]
if now >= DOWNTIME_START_TIMESTAMP && now <= DOWNTIME_END_TIMESTAMP {
let (days, hours, mins, secs) = DOWNTIME_END_TIMESTAMP
.saturating_sub(now)
.days_hours_mins_secs()
.unwrap();

panic!(
"We are in downtime! {} days, {} hours, {} minutes, {} seconds remaining to the end of the downtime",
days, hours, mins, secs,
);
}

Ok(())
}
}
5 changes: 5 additions & 0 deletions massa-models/src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ use massa_signature::KeyPair;
use massa_time::MassaTime;
use num::rational::Ratio;

/// Downtime simulation start timestamp
pub const DOWNTIME_START_TIMESTAMP: MassaTime = MassaTime::from_millis(1686312000000); // Friday 9 June 2023 12:00:00 UTC
/// Downtime simulation end timestamp
pub const DOWNTIME_END_TIMESTAMP: MassaTime = MassaTime::from_millis(1686319200000); // Friday 9 June 2023 14:00:00 UTC

/// IMPORTANNT TODO: should be removed after the bootstrap messages refacto
pub const SIGNATURE_DESER_SIZE: usize = 64 + 1;

Expand Down
2 changes: 1 addition & 1 deletion massa-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ massa_db = { path = "../massa-db" }
[features]
beta = []
deadlock_detection = []
bootstrap_server = []
bootstrap_server = ["massa_consensus_worker/bootstrap_server"]
sandbox = ["massa_bootstrap/sandbox", "massa_consensus_worker/sandbox", "massa_execution_worker/sandbox", "massa_final_state/sandbox", "massa_models/sandbox"]
30 changes: 30 additions & 0 deletions massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,36 @@ async fn launch(
}
}

use massa_models::config::constants::DOWNTIME_END_TIMESTAMP;
use massa_models::config::constants::DOWNTIME_START_TIMESTAMP;

// Simulate downtime
// last_start_period should be set to trigger after the DOWNTIME_END_TIMESTAMP
#[cfg(not(feature = "bootstrap_server"))]
if now >= DOWNTIME_START_TIMESTAMP && now <= DOWNTIME_END_TIMESTAMP {
let (days, hours, mins, secs) = DOWNTIME_END_TIMESTAMP
.saturating_sub(now)
.days_hours_mins_secs()
.unwrap();

if let Ok(Some(end_period)) = massa_models::timeslots::get_latest_block_slot_at_timestamp(
THREAD_COUNT,
T0,
*GENESIS_TIMESTAMP,
DOWNTIME_END_TIMESTAMP,
) {
panic!(
"We are in downtime! {} days, {} hours, {} minutes, {} seconds remaining to the end of the downtime. Downtime end period: {}",
days, hours, mins, secs, end_period.period
);
}

panic!(
"We are in downtime! {} days, {} hours, {} minutes, {} seconds remaining to the end of the downtime",
days, hours, mins, secs,
);
}

// Storage shared by multiple components.
let shared_storage: Storage = Storage::create_root();

Expand Down