authors = ["Greg Burri <greg.burri@gmail.com>"]
edition = "2021"
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
[dependencies]
anyhow = "1.0"
-itertools = "0.11"
+itertools = "0.13"
-reqwest = { version = "0.11", features = [
+reqwest = { version = "0.12", features = [
"blocking",
"json",
], default-features = false }
-lettre = { version = "0.10", features = [
+lettre = { version = "0.11", features = [
"rustls-tls",
"smtp-transport",
"builder",
serde_json = "1.0"
ron = "0.8" # Rust object notation, to load configuration files.
-
[profile.release]
codegen-units = 1
lto = true
+strip = true
panic = 'abort'
def invoke_ssh [command: string] {
let args = $ssh_args ++ $command
print $"Executing: ssh ($args)"
- ssh $args
+ ssh ...$args
}
def copy_ssh [source: string, destination: string] {
let args = $scp_args ++ [$source $"($host):($destination)"]
print $"Executing: scp ($args)"
- scp $args
+ scp ...$args
}
# Don't know how to dynamically pass variable arguments.
/*
* API Reference: https://ethereum.github.io/beacon-APIs/
+ *
+ * TODO:
+ * - Check that some processes (nethermind, lightouse) do not exceed a percentage
+ * of total memory. For example 40 %.
*/
use std::{
const FILE_CONF: &str = "config.ron";
const CHECK_PERIOD: Duration = Duration::from_secs(10); // 10 s.
const PING_TIMEOUT: Duration = Duration::from_secs(10); // 10 s.
+
const NUMBER_SUCCESSIVE_ERRORS_SEND_EMAIL: i32 = 2; // Send an email after 2 successive errors.
+
+// Send an emergency email after 10 successive errors.
+const NUMBER_SUCCESSIVE_ERRORS_SEND_EMEGENCY_EMAIL: i32 = 10;
+
const EMAIL_RESEND_PERIOD: Duration = Duration::from_secs(2 * 60 * 60); // 2 h.
const STATE_PRINT_PERIOD: Duration = Duration::from_secs(15 * 60); // 15 min.
const BASE_URI: &str = "http://localhost:5052/eth/v1/";
.and(check_alive_error_mutex.lock().unwrap().as_ref())
{
error_count += 1;
- println!("Error (error_count={}): {:?}", error_count, error);
+ println!("Error {:?} (error_count={}): {}", error, error_count, error);
if error_count >= NUMBER_SUCCESSIVE_ERRORS_SEND_EMAIL
&& time::Instant::now() - time_last_email_send >= EMAIL_RESEND_PERIOD
{
time_last_email_send = time::Instant::now();
}
}
+ } else if error_count == NUMBER_SUCCESSIVE_ERRORS_SEND_EMEGENCY_EMAIL {
+ // Send e-mail.
+ println!("Sending EMERGENCY email...");
+ match send_email(
+ "[EMERGENCY] Watchdog: Staking error",
+ &format!(
+ "[EMERGENCY] Error: {}\n\nNumber of error: {}",
+ error, error_count
+ ),
+ &config.smtp_relay_address,
+ &config.smtp_login,
+ &config.smtp_password,
+ ) {
+ Err(email_error) => println!("Error sending email: {:?}", email_error),
+ _ => {
+ println!("Email successfully sent");
+ time_last_email_send = time::Instant::now();
+ }
+ }
}
} else {
if error_count > 0 {