From 21ff825e091d6e48b3d2cd8f7e67481367778fd7 Mon Sep 17 00:00:00 2001 From: supernovahs Date: Wed, 16 Aug 2023 20:52:38 +0530 Subject: [PATCH 1/4] debug_backtraceAt --- Cargo.lock | 1 + crates/rpc/rpc-api/src/debug.rs | 6 ++++++ crates/rpc/rpc/Cargo.toml | 1 + crates/rpc/rpc/src/debug.rs | 34 +++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 4a8d706e779a..5d6f10e61e7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5964,6 +5964,7 @@ dependencies = [ "hyper", "jsonrpsee", "jsonwebtoken", + "lazy_static", "pin-project", "rand 0.8.5", "rayon", diff --git a/crates/rpc/rpc-api/src/debug.rs b/crates/rpc/rpc-api/src/debug.rs index 6fba56c83d78..125631c9c762 100644 --- a/crates/rpc/rpc-api/src/debug.rs +++ b/crates/rpc/rpc-api/src/debug.rs @@ -123,4 +123,10 @@ pub trait DebugApi { opts: Option, state_override: Option, ) -> RpcResult>; + + ///Sets the logging backtrace location. When a backtrace location is set and a log message is + /// emitted at that location, the stack of the goroutine executing the log statement will + /// be printed to stderr. + #[method(name = "backtraceAt")] + async fn debug_backtrace_at(&self, location: &str) -> RpcResult<()>; } diff --git a/crates/rpc/rpc/Cargo.toml b/crates/rpc/rpc/Cargo.toml index 756fefd8a1e3..3be464d0afba 100644 --- a/crates/rpc/rpc/Cargo.toml +++ b/crates/rpc/rpc/Cargo.toml @@ -25,6 +25,7 @@ reth-tasks.workspace = true reth-metrics.workspace = true reth-consensus-common = { path = "../../consensus/common" } reth-rpc-types-compat.workspace = true +lazy_static = "*" # eth revm = { workspace = true, features = [ diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 147c2a9f359c..e770bd24dc53 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -45,6 +45,12 @@ use std::sync::Arc; use tokio::sync::{mpsc, AcquireError, OwnedSemaphorePermit}; use tokio_stream::{wrappers::ReceiverStream, StreamExt}; +use lazy_static::lazy_static; +use std::sync::Mutex; +lazy_static! { + static ref LOCATION: Mutex = Mutex::new(String::new()); + static ref BACKTRACE_ENABLED: Mutex = Mutex::new(false); +} /// `debug` API implementation. /// /// This type provides the functionality for handling `debug` related requests. @@ -643,6 +649,34 @@ where Ok(res.into()) } + async fn debug_backtrace_at(&self, location: &str) -> RpcResult<()> { + let mut parts: Vec<&str> = location.split(':').collect(); + if parts.len() != 2 { + return Err(internal_rpc_err("Invalid location format".to_string())) + } + parts[0] = parts[0].trim(); + parts[1] = parts[1].trim(); + + if parts[0].len() == 0 || parts[1].len() == 0 { + return Err(internal_rpc_err("Invalid location format".to_string())) + } + if !parts[0].ends_with(".rust") { + return Err(internal_rpc_err("Invalid location format".to_string())) + } + + if parts[1].parse::().is_err() { + return Err(internal_rpc_err("Invalid location format".to_string())) + } + + let mut location_lock = LOCATION.lock().unwrap(); + *location_lock = location.to_string(); + + let mut backtrace_enabled_lock = BACKTRACE_ENABLED.lock().unwrap(); + *backtrace_enabled_lock = location.len() > 0; + + Ok(()) + } + /// Handler for `debug_getRawBlock` async fn raw_block(&self, block_id: BlockId) -> RpcResult { let block = self.inner.provider.block_by_id(block_id).to_rpc_result()?; From ece402eb2203ffa37469cbe6d819e6825aadca9b Mon Sep 17 00:00:00 2001 From: supernovahs Date: Wed, 16 Aug 2023 20:57:52 +0530 Subject: [PATCH 2/4] clippy happy --- crates/rpc/rpc/src/debug.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index e770bd24dc53..02c10af2f4c7 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -657,7 +657,7 @@ where parts[0] = parts[0].trim(); parts[1] = parts[1].trim(); - if parts[0].len() == 0 || parts[1].len() == 0 { + if parts[0].is_empty() || parts[1].is_empty() { return Err(internal_rpc_err("Invalid location format".to_string())) } if !parts[0].ends_with(".rust") { @@ -672,7 +672,7 @@ where *location_lock = location.to_string(); let mut backtrace_enabled_lock = BACKTRACE_ENABLED.lock().unwrap(); - *backtrace_enabled_lock = location.len() > 0; + *backtrace_enabled_lock = !location.is_empty(); Ok(()) } From 5f93aa1681d62f9c1206d6872e27c84e00a6d391 Mon Sep 17 00:00:00 2001 From: supernovahs Date: Fri, 18 Aug 2023 14:28:04 +0530 Subject: [PATCH 3/4] remove impl --- crates/rpc/rpc-api/src/debug.rs | 5 ++++- crates/rpc/rpc/src/debug.rs | 34 ++++----------------------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/crates/rpc/rpc-api/src/debug.rs b/crates/rpc/rpc-api/src/debug.rs index 125631c9c762..c1bc4458731b 100644 --- a/crates/rpc/rpc-api/src/debug.rs +++ b/crates/rpc/rpc-api/src/debug.rs @@ -124,9 +124,12 @@ pub trait DebugApi { state_override: Option, ) -> RpcResult>; - ///Sets the logging backtrace location. When a backtrace location is set and a log message is + /// Sets the logging backtrace location. When a backtrace location is set and a log message is /// emitted at that location, the stack of the goroutine executing the log statement will /// be printed to stderr. #[method(name = "backtraceAt")] async fn debug_backtrace_at(&self, location: &str) -> RpcResult<()>; + + + } diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 02c10af2f4c7..90cbf6ae148b 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -45,12 +45,7 @@ use std::sync::Arc; use tokio::sync::{mpsc, AcquireError, OwnedSemaphorePermit}; use tokio_stream::{wrappers::ReceiverStream, StreamExt}; -use lazy_static::lazy_static; -use std::sync::Mutex; -lazy_static! { - static ref LOCATION: Mutex = Mutex::new(String::new()); - static ref BACKTRACE_ENABLED: Mutex = Mutex::new(false); -} + /// `debug` API implementation. /// /// This type provides the functionality for handling `debug` related requests. @@ -649,34 +644,13 @@ where Ok(res.into()) } - async fn debug_backtrace_at(&self, location: &str) -> RpcResult<()> { - let mut parts: Vec<&str> = location.split(':').collect(); - if parts.len() != 2 { - return Err(internal_rpc_err("Invalid location format".to_string())) - } - parts[0] = parts[0].trim(); - parts[1] = parts[1].trim(); - - if parts[0].is_empty() || parts[1].is_empty() { - return Err(internal_rpc_err("Invalid location format".to_string())) - } - if !parts[0].ends_with(".rust") { - return Err(internal_rpc_err("Invalid location format".to_string())) - } - - if parts[1].parse::().is_err() { - return Err(internal_rpc_err("Invalid location format".to_string())) - } - - let mut location_lock = LOCATION.lock().unwrap(); - *location_lock = location.to_string(); - - let mut backtrace_enabled_lock = BACKTRACE_ENABLED.lock().unwrap(); - *backtrace_enabled_lock = !location.is_empty(); + async fn debug_backtrace_at(&self, _location: &str) -> RpcResult<()> { Ok(()) } + + /// Handler for `debug_getRawBlock` async fn raw_block(&self, block_id: BlockId) -> RpcResult { let block = self.inner.provider.block_by_id(block_id).to_rpc_result()?; From 603627465bc602e01d39ac466133f92e1ecf6fba Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 18 Aug 2023 13:16:17 +0200 Subject: [PATCH 4/4] rustfmt --- crates/rpc/rpc-api/src/debug.rs | 3 --- crates/rpc/rpc/src/debug.rs | 4 ---- 2 files changed, 7 deletions(-) diff --git a/crates/rpc/rpc-api/src/debug.rs b/crates/rpc/rpc-api/src/debug.rs index c1bc4458731b..91377017425c 100644 --- a/crates/rpc/rpc-api/src/debug.rs +++ b/crates/rpc/rpc-api/src/debug.rs @@ -129,7 +129,4 @@ pub trait DebugApi { /// be printed to stderr. #[method(name = "backtraceAt")] async fn debug_backtrace_at(&self, location: &str) -> RpcResult<()>; - - - } diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 90cbf6ae148b..aac4f176efdf 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -45,7 +45,6 @@ use std::sync::Arc; use tokio::sync::{mpsc, AcquireError, OwnedSemaphorePermit}; use tokio_stream::{wrappers::ReceiverStream, StreamExt}; - /// `debug` API implementation. /// /// This type provides the functionality for handling `debug` related requests. @@ -645,12 +644,9 @@ where } async fn debug_backtrace_at(&self, _location: &str) -> RpcResult<()> { - Ok(()) } - - /// Handler for `debug_getRawBlock` async fn raw_block(&self, block_id: BlockId) -> RpcResult { let block = self.inner.provider.block_by_id(block_id).to_rpc_result()?;