Skip to content

Commit 1b73e61

Browse files
authored
Merge pull request #120 from worldcoin/forerunner/deadlock-fix
Better LRU and Fix for Deadlock
2 parents 0a76f18 + 99232e3 commit 1b73e61

File tree

11 files changed

+263
-199
lines changed

11 files changed

+263
-199
lines changed

Cargo.lock

+63-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rollup-boost"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
op-alloy-rpc-types-engine = "0.7.3"
@@ -18,7 +18,7 @@ serde = { version = "1", features = ["derive"] }
1818
thiserror = "1.0"
1919
clap = { version = "4", features = ["derive", "env"] }
2020
jsonrpsee = { version = "0.24", features = ["server", "http-client", "macros"] }
21-
lru = "0.10.0"
21+
moka = { version = "0.12.10", features = ["sync"] }
2222
reqwest = "0.12.5"
2323
http = "1.1.0"
2424
dotenv = "0.15.0"
@@ -28,7 +28,7 @@ http-body-util = "0.1.2"
2828
hyper = { version = "1.4.1", features = ["full"] }
2929
hyper-util = { version = "0.1", features = ["full"] }
3030
hyper-rustls = { version = "0.27.0", features = ["ring"] }
31-
rustls = {version = "0.23.23", features = ["ring"] }
31+
rustls = { version = "0.23.23", features = ["ring"] }
3232
serde_json = "1.0.96"
3333
opentelemetry = { version = "0.26.0", features = ["trace"] }
3434
opentelemetry-http = "0.26.0"
@@ -54,6 +54,7 @@ paste = "1.0.15"
5454
time = { version = "0.3.36", features = ["macros", "formatting", "parsing"] }
5555
futures-util = "0.3.31"
5656
lazy_static = "1.5.0"
57+
parking_lot = "0.12.3"
5758

5859
[dev-dependencies]
5960
anyhow = "1.0"

src/auth_layer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// From reth_rpc_layer
22
use alloy_rpc_types_engine::{Claims, JwtSecret};
3-
use http::{header::AUTHORIZATION, HeaderValue};
3+
use http::{HeaderValue, header::AUTHORIZATION};
44
use std::{
55
task::{Context, Poll},
66
time::{Duration, SystemTime, UNIX_EPOCH},

src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloy_rpc_types_engine::{
66
ExecutionPayload, ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, JwtError, JwtSecret,
77
PayloadId, PayloadStatus,
88
};
9-
use clap::{arg, Parser};
9+
use clap::{Parser, arg};
1010
use http::{StatusCode, Uri};
1111
use jsonrpsee::core::{ClientError, RpcResult};
1212
use jsonrpsee::http_client::transport::HttpBackend;

src/debug_api.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use jsonrpsee::core::{async_trait, RpcResult};
1+
use jsonrpsee::core::{RpcResult, async_trait};
22
use jsonrpsee::http_client::HttpClient;
33
use jsonrpsee::proc_macros::rpc;
44
use jsonrpsee::server::Server;
5+
use parking_lot::Mutex;
56
use serde::{Deserialize, Serialize};
67
use std::sync::Arc;
7-
use tokio::sync::Mutex;
88

99
use crate::server::ExecutionMode;
1010

@@ -57,6 +57,14 @@ impl DebugServer {
5757

5858
Ok(())
5959
}
60+
61+
pub fn execution_mode(&self) -> ExecutionMode {
62+
*self.execution_mode.lock()
63+
}
64+
65+
pub fn set_execution_mode(&self, mode: ExecutionMode) {
66+
*self.execution_mode.lock() = mode;
67+
}
6068
}
6169

6270
#[async_trait]
@@ -65,8 +73,7 @@ impl DebugApiServer for DebugServer {
6573
&self,
6674
request: SetExecutionModeRequest,
6775
) -> RpcResult<SetExecutionModeResponse> {
68-
let mut execution_mode = self.execution_mode.lock().await;
69-
*execution_mode = request.execution_mode.clone();
76+
self.set_execution_mode(request.execution_mode);
7077

7178
tracing::info!("Set execution mode to {:?}", request.execution_mode);
7279

@@ -76,9 +83,8 @@ impl DebugApiServer for DebugServer {
7683
}
7784

7885
async fn get_execution_mode(&self) -> RpcResult<GetExecutionModeResponse> {
79-
let execution_mode = self.execution_mode.lock().await;
8086
Ok(GetExecutionModeResponse {
81-
execution_mode: execution_mode.clone(),
87+
execution_mode: self.execution_mode(),
8288
})
8389
}
8490
}
@@ -121,7 +127,7 @@ mod tests {
121127
let execution_mode = Arc::new(Mutex::new(ExecutionMode::Enabled));
122128

123129
let server = DebugServer::new(execution_mode.clone());
124-
let _ = server.run(DEFAULT_ADDR).await.unwrap();
130+
server.run(DEFAULT_ADDR).await.unwrap();
125131

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

src/integration/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use alloy_rpc_types_engine::{
99
ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, PayloadAttributes, PayloadId,
1010
PayloadStatus, PayloadStatusEnum,
1111
};
12-
use jsonrpsee::http_client::{transport::HttpBackend, HttpClient};
12+
use jsonrpsee::http_client::{HttpClient, transport::HttpBackend};
1313
use jsonrpsee::proc_macros::rpc;
1414
use lazy_static::lazy_static;
1515
use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpPayloadAttributes};
16-
use proxy::{start_proxy_server, DynHandlerFn};
16+
use proxy::{DynHandlerFn, start_proxy_server};
1717
use serde_json::Value;
1818
use std::collections::{HashMap, HashSet};
1919
use std::path::{Path, PathBuf};
@@ -28,7 +28,7 @@ use std::{
2828
time::{Duration, SystemTime},
2929
};
3030
use thiserror::Error;
31-
use time::{format_description, OffsetDateTime};
31+
use time::{OffsetDateTime, format_description};
3232

3333
/// Default JWT token for testing purposes
3434
pub const DEFAULT_JWT_TOKEN: &str =
@@ -551,7 +551,7 @@ pub struct RollupBoostTestHarness {
551551
/// Test node P2P configuration (private_key, enode_address)
552552
pub const TEST_NODE_P2P_ADDR: (&str, &str) = (
553553
"a11ac89899cd86e36b6fb881ec1255b8a92a688790b7d950f8b7d8dd626671fb",
554-
"3479db4d9217fb5d7a8ed4d61ac36e120b05d36c2eefb795dc42ff2e971f251a2315f5649ea1833271e020b9adc98d5db9973c7ed92d6b2f1f2223088c3d852f"
554+
"3479db4d9217fb5d7a8ed4d61ac36e120b05d36c2eefb795dc42ff2e971f251a2315f5649ea1833271e020b9adc98d5db9973c7ed92d6b2f1f2223088c3d852f",
555555
);
556556

557557
const PROXY_START_PORT: u16 = 4444;

src/integration/proxy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bytes::Bytes;
22
use http::header;
3-
use http_body_util::{combinators::BoxBody, BodyExt, Full};
3+
use http_body_util::{BodyExt, Full, combinators::BoxBody};
44
use hyper::client::conn::http1::Builder;
55
use hyper::server::conn::http1;
66
use hyper::service::service_fn;

src/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{arg, Parser, Subcommand};
1+
use clap::{Parser, Subcommand, arg};
22
use client::{BuilderArgs, ExecutionClient, L2ClientArgs};
33
use debug_api::DebugClient;
44
use metrics::{ClientMetrics, ServerMetrics};
@@ -10,22 +10,22 @@ use dotenv::dotenv;
1010
use eyre::bail;
1111
use http::StatusCode;
1212
use hyper::service::service_fn;
13-
use hyper::{server::conn::http1, Request, Response};
13+
use hyper::{Request, Response, server::conn::http1};
1414
use hyper_util::rt::TokioIo;
15+
use jsonrpsee::RpcModule;
1516
use jsonrpsee::http_client::HttpBody;
1617
use jsonrpsee::server::Server;
17-
use jsonrpsee::RpcModule;
1818
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
1919
use metrics_util::layers::{PrefixLayer, Stack};
2020
use opentelemetry::global;
2121
use opentelemetry_otlp::WithExportConfig;
22-
use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::Config, Resource};
22+
use opentelemetry_sdk::{Resource, propagation::TraceContextPropagator, trace::Config};
2323
use proxy::ProxyLayer;
2424
use server::{PayloadSource, RollupBoostServer};
2525

2626
use tokio::net::TcpListener;
27-
use tokio::signal::unix::{signal as unix_signal, SignalKind};
28-
use tracing::{error, info, Level};
27+
use tokio::signal::unix::{SignalKind, signal as unix_signal};
28+
use tracing::{Level, error, info};
2929
use tracing_subscriber::EnvFilter;
3030

3131
mod auth_layer;
@@ -369,10 +369,10 @@ mod tests {
369369
use crate::auth_layer::AuthClientService;
370370
use crate::server::PayloadSource;
371371
use alloy_rpc_types_engine::JwtSecret;
372+
use jsonrpsee::RpcModule;
373+
use jsonrpsee::http_client::HttpClient;
372374
use jsonrpsee::http_client::transport::Error as TransportError;
373375
use jsonrpsee::http_client::transport::HttpBackend;
374-
use jsonrpsee::http_client::HttpClient;
375-
use jsonrpsee::RpcModule;
376376
use jsonrpsee::{
377377
core::ClientError,
378378
rpc_params,

src/metrics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use metrics::{counter, histogram, Counter, Histogram};
3+
use metrics::{Counter, Histogram, counter, histogram};
44
use metrics_derive::Metrics;
55

66
use crate::server::PayloadSource;

0 commit comments

Comments
 (0)