From 33d01d3206ff03a95b219d4ef1def07b907fc76f Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin Date: Tue, 5 Mar 2024 19:20:37 +0000 Subject: [PATCH] chore(node-core): log errors in debug when ETA fails to calculate (#6971) --- bin/reth/src/sigsegv_handler.rs | 2 +- crates/ethereum-forks/src/hardfork.rs | 20 +++++++++--------- crates/node-core/src/events/node.rs | 21 +++++++++++++------ .../transaction-pool/src/test_utils/mock.rs | 4 ++-- examples/custom-node/src/main.rs | 4 +--- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/bin/reth/src/sigsegv_handler.rs b/bin/reth/src/sigsegv_handler.rs index 5494d6755f..79f9bf3098 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 46bc451e57..8ed8416096 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 0de1987a7c..a63132ee3f 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,23 @@ 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; diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index b8cc6db36b..20f75f6b3b 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 b494c5cbf8..ea4db0e997 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(())