From 286962b99b347b5b66f1aeda491cb33344291574 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 5 Mar 2024 16:22:34 +0000 Subject: [PATCH 1/2] chore(node-core): log errors in debug when ETA fails to calculate --- crates/node-core/src/events/node.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/node-core/src/events/node.rs b/crates/node-core/src/events/node.rs index 0de1987a7c6e..9721fb83f2a6 100644 --- a/crates/node-core/src/events/node.rs +++ b/crates/node-core/src/events/node.rs @@ -23,7 +23,7 @@ use std::{ time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; use tokio::time::Interval; -use tracing::{info, warn}; +use tracing::{debug, info, warn}; /// Interval of reporting node state. const INFO_MESSAGE_INTERVAL: Duration = Duration::from_secs(25); @@ -483,14 +483,21 @@ impl Eta { let Some(current) = checkpoint.entities() else { return }; if let Some(last_checkpoint_time) = &self.last_checkpoint_time { - let processed_since_last = current.processed - self.last_checkpoint.processed; + let Some(processed_since_last) = current.processed.checked_sub(self.last_checkpoint.processed) else { + self.eta = None; + debug!(target: "reth::cli", ?current, ?self.last_checkpoint, "Failed to calculate the ETA: processed entities is less than the last checkpoint"); + return + }; let elapsed = last_checkpoint_time.elapsed(); let per_second = processed_since_last as f64 / elapsed.as_secs_f64(); - self.eta = Duration::try_from_secs_f64( - ((current.total - current.processed) as f64) / per_second, - ) - .ok(); + let Some(remaining) = current.total.checked_sub(current.processed) else { + self.eta = None; + debug!(target: "reth::cli", ?current, "Failed to calculate the ETA: total entities is less than processed entities"); + return + }; + + self.eta = Duration::try_from_secs_f64(remaining as f64 / per_second).ok(); } self.last_checkpoint = current; From 170706a2f3d777df3619d7308e1ce77091285af5 Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 5 Mar 2024 16:46:34 +0000 Subject: [PATCH 2/2] fix fmt --- bin/reth/src/sigsegv_handler.rs | 2 +- crates/ethereum-forks/src/hardfork.rs | 20 +++++++++---------- crates/node-core/src/events/node.rs | 4 +++- .../transaction-pool/src/test_utils/mock.rs | 4 ++-- examples/custom-node/src/main.rs | 4 +--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bin/reth/src/sigsegv_handler.rs b/bin/reth/src/sigsegv_handler.rs index 5494d6755f9a..79f9bf30987e 100644 --- a/bin/reth/src/sigsegv_handler.rs +++ b/bin/reth/src/sigsegv_handler.rs @@ -51,7 +51,7 @@ extern "C" fn print_stack_trace(_: libc::c_int) { // Collect return addresses let depth = libc::backtrace(STACK_TRACE.as_mut_ptr(), MAX_FRAMES as i32); if depth == 0 { - return; + return } &STACK_TRACE.as_slice()[0..(depth as _)] }; diff --git a/crates/ethereum-forks/src/hardfork.rs b/crates/ethereum-forks/src/hardfork.rs index 46bc451e5727..8ed84160969e 100644 --- a/crates/ethereum-forks/src/hardfork.rs +++ b/crates/ethereum-forks/src/hardfork.rs @@ -91,22 +91,22 @@ impl Hardfork { /// Retrieves the activation block for the specified hardfork on the given chain. pub fn activation_block(&self, chain: Chain) -> Option { if chain == Chain::mainnet() { - return self.mainnet_activation_block(); + return self.mainnet_activation_block() } if chain == Chain::sepolia() { - return self.sepolia_activation_block(); + return self.sepolia_activation_block() } if chain == Chain::holesky() { - return self.holesky_activation_block(); + return self.holesky_activation_block() } #[cfg(feature = "optimism")] { if chain == Chain::base_sepolia() { - return self.base_sepolia_activation_block(); + return self.base_sepolia_activation_block() } if chain == Chain::base_mainnet() { - return self.base_mainnet_activation_block(); + return self.base_mainnet_activation_block() } } @@ -252,21 +252,21 @@ impl Hardfork { /// Retrieves the activation timestamp for the specified hardfork on the given chain. pub fn activation_timestamp(&self, chain: Chain) -> Option { if chain == Chain::mainnet() { - return self.mainnet_activation_timestamp(); + return self.mainnet_activation_timestamp() } if chain == Chain::sepolia() { - return self.sepolia_activation_timestamp(); + return self.sepolia_activation_timestamp() } if chain == Chain::holesky() { - return self.holesky_activation_timestamp(); + return self.holesky_activation_timestamp() } #[cfg(feature = "optimism")] { if chain == Chain::base_sepolia() { - return self.base_sepolia_activation_timestamp(); + return self.base_sepolia_activation_timestamp() } if chain == Chain::base_mainnet() { - return self.base_mainnet_activation_timestamp(); + return self.base_mainnet_activation_timestamp() } } diff --git a/crates/node-core/src/events/node.rs b/crates/node-core/src/events/node.rs index 9721fb83f2a6..a63132ee3f99 100644 --- a/crates/node-core/src/events/node.rs +++ b/crates/node-core/src/events/node.rs @@ -483,7 +483,9 @@ impl Eta { let Some(current) = checkpoint.entities() else { return }; if let Some(last_checkpoint_time) = &self.last_checkpoint_time { - let Some(processed_since_last) = current.processed.checked_sub(self.last_checkpoint.processed) else { + let Some(processed_since_last) = + current.processed.checked_sub(self.last_checkpoint.processed) + else { self.eta = None; debug!(target: "reth::cli", ?current, ?self.last_checkpoint, "Failed to calculate the ETA: processed entities is less than the last checkpoint"); return diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index b8cc6db36bda..20f75f6b3b9b 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -642,7 +642,7 @@ impl PoolTransaction for MockTransaction { // If the maximum fee per gas is less than the base fee, return None if max_fee_per_gas < base_fee { - return None; + return None } // Calculate the fee by subtracting the base fee from the maximum fee per gas @@ -651,7 +651,7 @@ impl PoolTransaction for MockTransaction { // If the maximum priority fee per gas is available, return the minimum of fee and priority // fee if let Some(priority_fee) = self.max_priority_fee_per_gas() { - return Some(fee.min(priority_fee)); + return Some(fee.min(priority_fee)) } // Otherwise, return the calculated fee diff --git a/examples/custom-node/src/main.rs b/examples/custom-node/src/main.rs index b494c5cbf89b..ea4db0e997c0 100644 --- a/examples/custom-node/src/main.rs +++ b/examples/custom-node/src/main.rs @@ -99,9 +99,7 @@ impl PayloadAttributes for CustomPayloadAttributes { // custom validation logic - ensure that the custom field is not zero if self.custom == 0 { - return Err(AttributesValidationError::invalid_params( - CustomError::CustomFieldIsNotZero, - )); + return Err(AttributesValidationError::invalid_params(CustomError::CustomFieldIsNotZero)) } Ok(())