-
Notifications
You must be signed in to change notification settings - Fork 18
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
Da blob api #487
Da blob api #487
Changes from 4 commits
fa2b9ce
43f1b2e
57b9dac
8a75873
c4a7d7e
6d808be
29bd99f
71a3057
f24e686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ use crate::{ | |
#[derive(Clone)] | ||
pub struct AxumBackendSettings { | ||
pub addr: SocketAddr, | ||
pub da_mempool: OverwatchHandle, | ||
pub da: OverwatchHandle, | ||
pub cl: OverwatchHandle, | ||
pub carnot: OverwatchHandle, | ||
|
@@ -84,6 +85,7 @@ where | |
.merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi())) | ||
.route("/da/metrics", routing::get(da_metrics)) | ||
.route("/da/status", routing::post(da_status)) | ||
.route("/da/blob", routing::post(da_blob)) | ||
.route("/cl/metrics", routing::get(cl_metrics::<T>)) | ||
.route("/cl/status", routing::post(cl_status::<T>)) | ||
.route("/carnot/info", routing::get(carnot_info::<T, S, SIZE>)) | ||
|
@@ -105,7 +107,7 @@ where | |
) | ||
)] | ||
async fn da_metrics(State(store): State<Store>) -> impl IntoResponse { | ||
match da::da_mempool_metrics(&store.da).await { | ||
match da::da_mempool_metrics(&store.da_mempool).await { | ||
Ok(metrics) => (StatusCode::OK, Json(metrics)).into_response(), | ||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(), | ||
} | ||
|
@@ -123,7 +125,25 @@ async fn da_status( | |
State(store): State<Store>, | ||
Json(items): Json<Vec<<Blob as blob::Blob>::Hash>>, | ||
) -> impl IntoResponse { | ||
match da::da_mempool_status(&store.da, items).await { | ||
match da::da_mempool_status(&store.da_mempool, items).await { | ||
Ok(status) => (StatusCode::OK, Json(status)).into_response(), | ||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(), | ||
} | ||
} | ||
|
||
#[utoipa::path( | ||
post, | ||
path = "/da/blob", | ||
responses( | ||
(status = 200, description = "Query the mempool status of the da service", body = Vec<Blob>), | ||
(status = 500, description = "Internal server error", body = String), | ||
) | ||
)] | ||
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. If we return all blobs it is better that the path is |
||
async fn da_blob( | ||
State(store): State<Store>, | ||
Json(items): Json<Vec<<Blob as blob::Blob>::Hash>>, | ||
) -> impl IntoResponse { | ||
match da::da_blob(&store.da, items).await { | ||
Ok(status) => (StatusCode::OK, Json(status)).into_response(), | ||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(), | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
use full_replication::{Blob, Certificate}; | ||
use full_replication::{AbsoluteNumber, Attestation, Blob, Certificate, FullReplication}; | ||
use nomos_core::da::blob; | ||
use nomos_da::{ | ||
backend::memory_cache::BlobCache, network::adapters::libp2p::Libp2pAdapter as DaLibp2pAdapter, | ||
DaMsg, DataAvailabilityService, | ||
}; | ||
use nomos_mempool::{ | ||
backend::mockpool::MockPool, | ||
network::adapters::libp2p::Libp2pAdapter, | ||
|
@@ -8,13 +12,19 @@ | |
}; | ||
use tokio::sync::oneshot; | ||
|
||
pub(crate) type DaMempoolService = MempoolService< | ||
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Check (libp2p)
Check failure on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Rust lints (libp2p)
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 15 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, macos-latest)
|
||
Libp2pAdapter<Certificate, <Blob as blob::Blob>::Hash>, | ||
MockPool<Certificate, <Blob as blob::Blob>::Hash>, | ||
CertDiscriminant, | ||
>; | ||
|
||
pub type DataAvailability = DataAvailabilityService< | ||
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Check (libp2p)
Check failure on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Rust lints (libp2p)
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 21 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, macos-latest)
|
||
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. better to reuse the type in nomos-node 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. @al8n, refactor for this will be done later on? Let's open an issue for tracking it please! 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. Yeah, will open a new PR soon for this. |
||
FullReplication<AbsoluteNumber<Attestation, Certificate>>, | ||
BlobCache<<Blob as nomos_core::da::blob::Blob>::Hash, Blob>, | ||
DaLibp2pAdapter<Blob, Attestation>, | ||
>; | ||
|
||
pub(crate) async fn da_mempool_metrics( | ||
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Check (libp2p)
Check failure on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Rust lints (libp2p)
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 27 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, macos-latest)
|
||
handle: &overwatch_rs::overwatch::handle::OverwatchHandle, | ||
) -> Result<MempoolMetrics, super::DynError> { | ||
let relay = handle.relay::<DaMempoolService>().connect().await?; | ||
|
@@ -29,7 +39,7 @@ | |
Ok(receiver.await.unwrap()) | ||
} | ||
|
||
pub(crate) async fn da_mempool_status( | ||
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Check (libp2p)
Check failure on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Rust lints (libp2p)
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 42 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, macos-latest)
|
||
handle: &overwatch_rs::overwatch::handle::OverwatchHandle, | ||
items: Vec<<Blob as blob::Blob>::Hash>, | ||
) -> Result<Vec<Status>, super::DynError> { | ||
|
@@ -45,3 +55,20 @@ | |
|
||
Ok(receiver.await.unwrap()) | ||
} | ||
|
||
pub(crate) async fn da_blob( | ||
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Check (libp2p)
Check failure on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Rust lints (libp2p)
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, ubuntu-latest)
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, windows-latest)
Check warning on line 59 in nodes/nomos-node-api/src/http/da.rs GitHub Actions / Test Suite (libp2p, macos-latest)
|
||
handle: &overwatch_rs::overwatch::handle::OverwatchHandle, | ||
ids: Vec<<Blob as blob::Blob>::Hash>, | ||
) -> Result<Vec<Blob>, super::DynError> { | ||
let relay = handle.relay::<DataAvailability>().connect().await?; | ||
let (reply_channel, receiver) = oneshot::channel(); | ||
relay | ||
.send(DaMsg::Get { | ||
ids: Box::new(ids.into_iter()), | ||
reply_channel, | ||
}) | ||
.await | ||
.map_err(|(e, _)| e)?; | ||
|
||
Ok(receiver.await?) | ||
} |
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.
Same comment as in other PRs not sure why do we return
IntoResponse
when we already transform everything into a response inside.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.
Because the type returned in ok arm and err arm are not actually the same, we have to call
into_response
to convert toResponse
.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.
Yes I guessed that, but why return
IntoResponse
later when we already got a response? Is it to avoid boxing?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.
Ah yes, we can use
Response
as the returned type in our case.