From 7995abbb13fcac9a86bd43b856e1172dbba24fa9 Mon Sep 17 00:00:00 2001 From: danielsanchezq Date: Wed, 6 Sep 2023 15:48:35 +0200 Subject: [PATCH] Make da backend async --- nomos-services/data-availability/src/backend/mod.rs | 7 +++++-- nomos-services/data-availability/src/lib.rs | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/nomos-services/data-availability/src/backend/mod.rs b/nomos-services/data-availability/src/backend/mod.rs index 52ee258ad..c22431761 100644 --- a/nomos-services/data-availability/src/backend/mod.rs +++ b/nomos-services/data-availability/src/backend/mod.rs @@ -1,3 +1,5 @@ +mod memory_cache; + use overwatch_rs::DynError; #[derive(Debug)] @@ -5,6 +7,7 @@ pub enum DaError { Dyn(DynError), } +#[async_trait::async_trait] pub trait DaBackend { type Settings: Clone; @@ -12,7 +15,7 @@ pub trait DaBackend { fn new(settings: Self::Settings) -> Self; - fn add_blob(&mut self, blob: Self::Blob) -> Result<(), DaError>; + async fn add_blob(&mut self, blob: Self::Blob) -> Result<(), DaError>; - fn pending_blobs(&self) -> Box + Send>; + async fn pending_blobs(&self) -> Box + Send>; } diff --git a/nomos-services/data-availability/src/lib.rs b/nomos-services/data-availability/src/lib.rs index 9101a5bff..7ff0653cf 100644 --- a/nomos-services/data-availability/src/lib.rs +++ b/nomos-services/data-availability/src/lib.rs @@ -61,7 +61,7 @@ where #[async_trait::async_trait] impl ServiceCore for DataAvailabilityService where - B: DaBackend + Send, + B: DaBackend + Send + Sync, B::Settings: Clone + Send + Sync + 'static, B::Blob: Send, // TODO: Reply type must be piped together, for now empty array. @@ -115,7 +115,7 @@ async fn handle_new_blob Result<(), DaError> { // we need to handle the reply (verification + signature) - backend.add_blob(blob)?; + backend.add_blob(blob).await?; adapter .send_attestation([0u8; 32]) .await @@ -125,7 +125,7 @@ async fn handle_new_blob(backend: &mut B, msg: DaMsg) -> Result<(), DaError> { match msg { DaMsg::PendingBlobs { reply_channel } => { - let pending_blobs = backend.pending_blobs(); + let pending_blobs = backend.pending_blobs().await; if reply_channel.send(pending_blobs).is_err() { tracing::debug!("Could not send pending blobs"); }