-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Eigenda disperser /get/
and /put/
endpoints
#313
base: eigenda-disperser-client
Are you sure you want to change the base?
Changes from 5 commits
7b4ced0
790ab84
924f788
cdec06c
aff1048
680a207
1054ca5
beb2c1d
4f204c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,37 @@ use std::net::SocketAddr; | |
|
||
use anyhow::Context as _; | ||
use axum::{ | ||
routing::{get, put}, | ||
extract::Path, | ||
routing::{get, post}, | ||
Router, | ||
}; | ||
use eigenda_client::EigenDAClient; | ||
use request_processor::RequestProcessor; | ||
use tokio::sync::watch; | ||
use zksync_config::configs::da_client::eigen_da::EigenDAConfig; | ||
|
||
mod blob_info; | ||
mod eigenda_client; | ||
mod errors; | ||
mod memstore; | ||
mod request_processor; | ||
|
||
pub async fn run_server(mut stop_receiver: watch::Receiver<bool>) -> anyhow::Result<()> { | ||
pub async fn run_server( | ||
config: EigenDAConfig, | ||
mut stop_receiver: watch::Receiver<bool>, | ||
) -> anyhow::Result<()> { | ||
// TODO: Replace port for config | ||
|
||
let bind_address = SocketAddr::from(([0, 0, 0, 0], 4242)); | ||
tracing::debug!("Starting eigenda proxy on {bind_address}"); | ||
let app = create_eigenda_proxy_router(); | ||
|
||
let eigenda_client = match config { | ||
EigenDAConfig::Disperser(disperser_config) => EigenDAClient::new(disperser_config) | ||
.await | ||
.map_err(|e| anyhow::anyhow!("Failed to create EigenDA client: {:?}", e))?, | ||
_ => panic!("memstore unimplemented"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next would be implementing this for memstore also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! Working on it |
||
}; | ||
let app = create_eigenda_proxy_router(eigenda_client); | ||
|
||
let listener = tokio::net::TcpListener::bind(bind_address) | ||
.await | ||
|
@@ -38,15 +55,21 @@ pub async fn run_server(mut stop_receiver: watch::Receiver<bool>) -> anyhow::Res | |
Ok(()) | ||
} | ||
|
||
fn create_eigenda_proxy_router() -> Router { | ||
fn create_eigenda_proxy_router(eigenda_client: EigenDAClient) -> Router { | ||
let get_blob_id_processor = RequestProcessor::new(eigenda_client); | ||
let pub_blob_id_processor = get_blob_id_processor.clone(); | ||
let router = Router::new() | ||
.route( | ||
"/get/", | ||
get(|| async { todo!("Handle eigenda proxy get request") }), | ||
"/get/:l1_batch_number", | ||
get(move |blob_id: Path<String>| async move { | ||
get_blob_id_processor.get_blob_id(blob_id).await | ||
}), | ||
) | ||
.route( | ||
"/put/", | ||
put(|| async { todo!("Handle eigenda proxy put request") }), | ||
post(move |blob_id: Path<String>| async move { | ||
pub_blob_id_processor.put_blob_id(blob_id).await | ||
}), | ||
); | ||
router | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ impl MemStore { | |
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use std::time::Duration; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use axum::{extract::Path, http::Response}; | ||
|
||
use crate::{eigenda_client::EigenDAClient, errors::RequestProcessorError}; | ||
|
||
#[derive(Clone)] | ||
pub(crate) struct RequestProcessor { | ||
eigenda_client: EigenDAClient, | ||
} | ||
|
||
impl RequestProcessor { | ||
pub(crate) fn new(eigenda_client: EigenDAClient) -> Self { | ||
Self { eigenda_client } | ||
} | ||
|
||
pub(crate) async fn get_blob_id( | ||
&self, | ||
Path(blob_id): Path<String>, | ||
) -> Result<axum::response::Response, RequestProcessorError> { | ||
let blob_id_bytes = hex::decode(blob_id).unwrap(); | ||
let response = self | ||
.eigenda_client | ||
.get_blob(blob_id_bytes) | ||
.await | ||
.map_err(|e| RequestProcessorError::EigenDA(e))?; | ||
Ok(Response::new(response.into())) | ||
} | ||
|
||
pub(crate) async fn put_blob_id( | ||
&self, | ||
Path(data): Path<String>, | ||
) -> Result<axum::response::Response, RequestProcessorError> { | ||
let data_bytes = hex::decode(data).unwrap(); | ||
let response = self | ||
.eigenda_client | ||
.put_blob(data_bytes) | ||
.await | ||
.map_err(|e| RequestProcessorError::EigenDA(e))?; | ||
Ok(Response::new(response.into())) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct, addressed in 680a207