mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 03:42:46 +00:00
Begin threading execution layer into BeaconChain
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use engine_api::{http::HttpJsonRpc, Error as ApiError, *};
|
||||
use engine_api::{Error as ApiError, *};
|
||||
use engines::{Engine, EngineError, Engines};
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slog::Logger;
|
||||
use task_executor::TaskExecutor;
|
||||
|
||||
pub use engine_api::http::HttpJsonRpc;
|
||||
|
||||
mod engine_api;
|
||||
mod engines;
|
||||
@@ -19,12 +22,18 @@ impl From<ApiError> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ExecutionLayer<T> {
|
||||
engines: Engines<T>,
|
||||
pub struct ExecutionLayer {
|
||||
engines: Engines<HttpJsonRpc>,
|
||||
/// Allows callers to execute async tasks in a non-async environment, if they desire.
|
||||
pub executor: TaskExecutor,
|
||||
}
|
||||
|
||||
impl ExecutionLayer<HttpJsonRpc> {
|
||||
pub fn from_urls(urls: Vec<SensitiveUrl>, log: Logger) -> Result<Self, Error> {
|
||||
impl ExecutionLayer {
|
||||
pub fn from_urls(
|
||||
urls: Vec<SensitiveUrl>,
|
||||
executor: TaskExecutor,
|
||||
log: Logger,
|
||||
) -> Result<Self, Error> {
|
||||
let engines = urls
|
||||
.into_iter()
|
||||
.map(|url| {
|
||||
@@ -36,11 +45,12 @@ impl ExecutionLayer<HttpJsonRpc> {
|
||||
|
||||
Ok(Self {
|
||||
engines: Engines { engines, log },
|
||||
executor,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EngineApi> ExecutionLayer<T> {
|
||||
impl ExecutionLayer {
|
||||
pub async fn prepare_payload(
|
||||
&self,
|
||||
parent_hash: Hash256,
|
||||
|
||||
@@ -95,7 +95,6 @@ pub struct Context<T> {
|
||||
pub struct Config {
|
||||
pub listen_addr: Ipv4Addr,
|
||||
pub listen_port: u16,
|
||||
pub allow_origin: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -103,7 +102,6 @@ impl Default for Config {
|
||||
Self {
|
||||
listen_addr: Ipv4Addr::new(127, 0, 0, 1),
|
||||
listen_port: 0,
|
||||
allow_origin: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,19 +128,6 @@ pub fn serve<T: EthSpec>(
|
||||
let config = &ctx.config;
|
||||
let log = ctx.log.clone();
|
||||
|
||||
// Configure CORS.
|
||||
let cors_builder = {
|
||||
let builder = warp::cors()
|
||||
.allow_method("GET")
|
||||
.allow_headers(vec!["Content-Type"]);
|
||||
|
||||
warp_utils::cors::set_builder_origins(
|
||||
builder,
|
||||
config.allow_origin.as_deref(),
|
||||
(config.listen_addr, config.listen_port),
|
||||
)?
|
||||
};
|
||||
|
||||
let inner_ctx = ctx.clone();
|
||||
let routes = warp::post()
|
||||
.and(warp::path("echo"))
|
||||
@@ -155,8 +140,7 @@ pub fn serve<T: EthSpec>(
|
||||
)
|
||||
})
|
||||
// Add a `Server` header.
|
||||
.map(|reply| warp::reply::with_header(reply, "Server", "lighthouse-mock-execution-client"))
|
||||
.with(cors_builder.build());
|
||||
.map(|reply| warp::reply::with_header(reply, "Server", "lighthouse-mock-execution-client"));
|
||||
|
||||
let (listening_socket, server) = warp::serve(routes).try_bind_with_graceful_shutdown(
|
||||
SocketAddrV4::new(config.listen_addr, config.listen_port),
|
||||
|
||||
Reference in New Issue
Block a user