Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ L2_TIMEOUT=1000
RPC_HOST=0.0.0.0
RPC_PORT=8081

# Debug Server Args
DEBUG_HOST=127.0.0.1
DEBUG_SERVER_PORT=5555

# Extra Args
TRACING=false
LOG_LEVEL=info
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cargo run -- [OPTIONS]
- `--log-format <FORMAT>`: Log format (default: text)
- `--metrics`: Enable metrics (default: false)
- `--no-boost-sync`: Disables using the proposer to sync the builder node (default: true)
- `--debug-host <HOST>`: Host to run the server on (default: 127.0.0.1)
- `--debug-server-port <PORT>`: Port to run the debug server on (default: 5555)

### Environment Variables
Expand Down
24 changes: 7 additions & 17 deletions src/debug_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use tokio::sync::Mutex;

use crate::server::ExecutionMode;

const DEFAULT_DEBUG_API_PORT: u16 = 5555;

#[derive(Serialize, Deserialize, Debug)]
pub struct SetExecutionModeRequest {
pub execution_mode: ExecutionMode,
Expand Down Expand Up @@ -46,16 +44,12 @@ impl DebugServer {
Self { execution_mode }
}

pub async fn run(self, port: Option<u16>) -> eyre::Result<()> {
let port = port.unwrap_or(DEFAULT_DEBUG_API_PORT);

let server = Server::builder()
.build(format!("127.0.0.1:{}", port))
.await?;
pub async fn run(self, debug_addr: &str) -> eyre::Result<()> {
let server = Server::builder().build(debug_addr).await?;

let handle = server.start(self.into_rpc());

tracing::info!("Debug server started on port {}", port);
tracing::info!("Debug server listening on addr {}", debug_addr);

// In this example we don't care about doing shutdown so let's it run forever.
// You may use the `ServerHandle` to shut it down or manage it yourself.
Expand Down Expand Up @@ -115,25 +109,21 @@ impl DebugClient {
}
}

impl Default for DebugClient {
fn default() -> Self {
Self::new(format!("http://localhost:{}", DEFAULT_DEBUG_API_PORT).as_str()).unwrap()
}
}

#[cfg(test)]
mod tests {
use super::*;

const DEFAULT_ADDR: &str = "127.0.0.1:5555";

#[tokio::test]
async fn test_debug_client() {
// spawn the server and try to modify it with the client
let execution_mode = Arc::new(Mutex::new(ExecutionMode::Enabled));

let server = DebugServer::new(execution_mode.clone());
let _ = server.run(None).await.unwrap();
let _ = server.run(DEFAULT_ADDR).await.unwrap();

let client = DebugClient::default();
let client = DebugClient::new(format!("http://{}", DEFAULT_ADDR).as_str()).unwrap();

// Test setting execution mode to Disabled
let result = client
Expand Down
25 changes: 15 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ struct Args {
#[arg(long, env, default_value = "text")]
log_format: String,

/// Host to run the debug server on
#[arg(long, env, default_value = "127.0.0.1")]
debug_host: String,

/// Debug server port
#[arg(long, env, default_value = "5555")]
debug_server_port: u16,
Expand Down Expand Up @@ -121,26 +125,29 @@ async fn main() -> eyre::Result<()> {
.expect("Failed to install TLS ring CryptoProvider");
let args: Args = Args::parse();

let debug_addr = format!("{}:{}", args.debug_host, args.debug_server_port);

// Handle commands if present
if let Some(cmd) = args.command {
match cmd {
let debug_addr = format!("http://{}", debug_addr);
return match cmd {
Commands::Debug { command } => match command {
DebugCommands::SetExecutionMode { execution_mode } => {
let client = DebugClient::default();
let client = DebugClient::new(debug_addr.as_str())?;
let result = client.set_execution_mode(execution_mode).await.unwrap();
println!("Response: {:?}", result.execution_mode);

return Ok(());
Ok(())
}
DebugCommands::ExecutionMode {} => {
let client = DebugClient::default();
let result = client.get_execution_mode().await.unwrap();
let client = DebugClient::new(debug_addr.as_str())?;
let result = client.get_execution_mode().await?;
println!("Execution mode: {:?}", result.execution_mode);

return Ok(());
Ok(())
}
},
}
};
}

// Initialize logging
Expand Down Expand Up @@ -243,9 +250,7 @@ async fn main() -> eyre::Result<()> {
);

// Spawn the debug server
rollup_boost
.start_debug_server(args.debug_server_port)
.await?;
rollup_boost.start_debug_server(debug_addr.as_str()).await?;

let module: RpcModule<()> = rollup_boost.try_into()?;

Expand Down
5 changes: 2 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ impl RollupBoostServer {
}
}

pub async fn start_debug_server(&self, port: u16) -> eyre::Result<()> {
pub async fn start_debug_server(&self, debug_addr: &str) -> eyre::Result<()> {
let server = DebugServer::new(self.execution_mode.clone());
server.run(Some(port)).await?;

server.run(debug_addr).await?;
Ok(())
}
}
Expand Down
Loading