Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
813 changes: 524 additions & 289 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ tokio.workspace = true
tracing.workspace = true
console-subscriber = "0.5.0"

# pprof dependencies
pprof = { version = "0.15.0", features = ["flamegraph", "protobuf-codec"] }
hyper = { version = "1.5", features = ["full"] }
hyper-util = { version = "0.1", features = ["tokio"] }
http-body-util = "0.1"

[dev-dependencies]
alloy-chains.workspace = true
alloy-eips.workspace = true
Expand Down
29 changes: 28 additions & 1 deletion crates/node/src/add_ons/rollup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::args::ScrollRollupNodeConfig;
use crate::{args::ScrollRollupNodeConfig, pprof::PprofConfig};

use reth_chainspec::NamedChain;
use reth_network::NetworkProtocols;
Expand All @@ -14,6 +14,7 @@ use scroll_alloy_hardforks::ScrollHardforks;
use scroll_wire::ScrollWireEvent;
use std::sync::Arc;
use tokio::sync::mpsc::{Sender, UnboundedReceiver};
use tracing::{error, info};

/// Implementing the trait allows the type to return whether it is configured for dev chain.
#[auto_impl::auto_impl(Arc)]
Expand Down Expand Up @@ -61,6 +62,32 @@ impl RollupManagerAddOn {
ChainConfig<Config = ScrollChainConfig> + ScrollHardforks + IsDevChain,
N::Network: NetworkProtocols + FullNetwork<Primitives = ScrollNetworkPrimitives>,
{
// Start pprof server if enabled
if self.config.pprof_args.enabled {
let addr = self.config.pprof_args.addr.parse().map_err(|e| {
eyre::eyre!("Invalid pprof address '{}': {}", self.config.pprof_args.addr, e)
})?;

let pprof_config = PprofConfig::new(addr)
.with_default_duration(self.config.pprof_args.default_duration);

match pprof_config.launch_server().await {
Ok(handle) => {
info!(target: "rollup_node::pprof", "pprof server started successfully");
// Spawn the pprof server task
ctx.node.task_executor().spawn_critical("pprof_server", async move {
if let Err(e) = handle.await {
error!(target: "rollup_node::pprof", "pprof server error: {:?}", e);
}
});
}
Err(e) => {
error!(target: "rollup_node::pprof", "Failed to start pprof server: {}", e);
return Err(e);
}
}
}

let (chain_orchestrator, handle, l1_notification_tx) = self
.config
.build((&ctx).into(), self.scroll_wire_event, rpc.rpc_server_handles)
Expand Down
42 changes: 42 additions & 0 deletions crates/node/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub struct ScrollRollupNodeConfig {
/// The gas price oracle args
#[command(flatten)]
pub gas_price_oracle_args: RollupNodeGasPriceOracleArgs,
/// The pprof server arguments
#[command(flatten)]
pub pprof_args: PprofArgs,
/// The database connection (not parsed via CLI but hydrated after validation).
#[arg(skip)]
pub database: Option<Arc<Database>>,
Expand Down Expand Up @@ -819,6 +822,40 @@ pub struct RollupNodeGasPriceOracleArgs {
pub default_suggested_priority_fee: u64,
}

/// The arguments for the pprof server.
#[derive(Debug, Clone, clap::Args)]
pub struct PprofArgs {
/// Enable the pprof HTTP server for performance profiling
#[arg(id = "pprof.enabled", long = "pprof.enabled", help = "Enable the pprof HTTP server")]
pub enabled: bool,

/// The address to bind the pprof HTTP server to
#[arg(
id = "pprof.url",
long = "pprof.addr",
value_name = "PPROF_URL",
help = "Address to bind the pprof HTTP server (e.g., 0.0.0.0:6868)",
default_value = constants::DEFAULT_PPROF_URL
)]
pub addr: String,

/// Default profiling duration in seconds
#[arg(
id = "pprof.default_duration",
value_name = "PPROF_DEFAULT_DURATION",
long = "pprof.default-duration",
help = "Default CPU profiling duration in seconds",
default_value_t = constants::DEFAULT_PPROF_DEFAULT_DURATION
)]
pub default_duration: u64,
}

impl Default for PprofArgs {
fn default() -> Self {
Self { enabled: false, addr: "0.0.0.0:6868".to_string(), default_duration: 30 }
}
}

/// Returns the total difficulty constant for the given chain.
const fn td_constant(chain: Option<NamedChain>) -> U128 {
match chain {
Expand Down Expand Up @@ -905,6 +942,7 @@ mod tests {
},
database: None,
rpc_args: RpcArgs::default(),
pprof_args: PprofArgs::default(),
};

let result = config.validate();
Expand Down Expand Up @@ -937,6 +975,7 @@ mod tests {
},
database: None,
rpc_args: RpcArgs::default(),
pprof_args: PprofArgs::default(),
};

let result = config.validate();
Expand Down Expand Up @@ -964,6 +1003,7 @@ mod tests {
consensus_args: ConsensusArgs::noop(),
database: None,
rpc_args: RpcArgs::default(),
pprof_args: PprofArgs::default(),
};

assert!(config.validate().is_ok());
Expand All @@ -989,6 +1029,7 @@ mod tests {
consensus_args: ConsensusArgs::noop(),
database: None,
rpc_args: RpcArgs::default(),
pprof_args: PprofArgs::default(),
};

assert!(config.validate().is_ok());
Expand All @@ -1010,6 +1051,7 @@ mod tests {
consensus_args: ConsensusArgs::noop(),
database: None,
rpc_args: RpcArgs::default(),
pprof_args: PprofArgs::default(),
};

assert!(config.validate().is_ok());
Expand Down
6 changes: 6 additions & 0 deletions crates/node/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ pub(crate) const SCROLL_MAINNET_SIGNER: Address =
/// The authorized signer address for Scroll sepolia.
pub(crate) const SCROLL_SEPOLIA_SIGNER: Address =
address!("0x687E0E85AD67ff71aC134CF61b65905b58Ab43b2");

/// The url for pprof
pub(crate) const DEFAULT_PPROF_URL: &str = "0.0.0.0:6868";

/// The default duration for pprof
pub(crate) const DEFAULT_PPROF_DEFAULT_DURATION: u64 = 30;
1 change: 1 addition & 0 deletions crates/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod builder;
pub mod constants;
mod context;
mod node;
pub mod pprof;
#[cfg(feature = "test-utils")]
pub mod test_utils;

Expand Down
Loading