Update dependencies master
authorGreg Burri <greg.burri@gmail.com>
Sun, 27 Oct 2024 10:26:50 +0000 (11:26 +0100)
committerGreg Burri <greg.burri@gmail.com>
Sun, 27 Oct 2024 10:26:50 +0000 (11:26 +0100)
Cargo.toml
deploy.nu
src/main.rs

index c4c3a8a..d6c3b2f 100644 (file)
@@ -4,18 +4,16 @@ version = "0.1.0"
 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",
@@ -25,8 +23,8 @@ serde = { version = "1.0", features = ["derive"] }
 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'
index f97e6ce..633c0ae 100644 (file)
--- a/deploy.nu
+++ b/deploy.nu
@@ -11,13 +11,13 @@ def main [host: string, destination: string, ssh_key: path] {
     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.
index 60d0724..41a6312 100644 (file)
@@ -1,5 +1,9 @@
 /*
  * 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::{
@@ -24,7 +28,12 @@ mod config;
 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/";
@@ -56,7 +65,7 @@ fn main() -> Result<()> {
             .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
             {
@@ -75,6 +84,25 @@ fn main() -> Result<()> {
                         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 {