From 4f42036fae2c43c3113046260a48917787191bd1 Mon Sep 17 00:00:00 2001 From: Gusto Date: Mon, 27 May 2024 17:08:27 +0300 Subject: [PATCH] Da verifier http method --- nomos-services/api/Cargo.toml | 3 ++ nomos-services/api/src/http/da.rs | 75 ++++++++++++++++++++++++++++++ nomos-services/api/src/http/mod.rs | 1 + 3 files changed, 79 insertions(+) create mode 100644 nomos-services/api/src/http/da.rs diff --git a/nomos-services/api/Cargo.toml b/nomos-services/api/Cargo.toml index acab9f8c..7b9403f1 100644 --- a/nomos-services/api/Cargo.toml +++ b/nomos-services/api/Cargo.toml @@ -9,11 +9,14 @@ axum = ["dep:axum", "dep:hyper", "dep:tower-http", "utoipa-swagger-ui/axum"] [dependencies] async-trait = "0.1" +bytes = "1.2" overwatch-rs = { git = "https://github.com/logos-co/Overwatch", rev = "2f70806" } overwatch-derive = { git = "https://github.com/logos-co/Overwatch", rev = "ac28d01" } tracing = "0.1" nomos-core = { path = "../../nomos-core" } cryptarchia-consensus = { path = "../cryptarchia-consensus" } +nomos-da-indexer = { path = "../data-availability/indexer", features = ["rocksdb-backend"] } +nomos-da-verifier = { path = "../data-availability/verifier", features = ["rocksdb-backend", "libp2p"] } nomos-network = { path = "../../nomos-services/network" } nomos-mempool = { path = "../../nomos-services/mempool", features = [ "mock", diff --git a/nomos-services/api/src/http/da.rs b/nomos-services/api/src/http/da.rs new file mode 100644 index 00000000..6a042111 --- /dev/null +++ b/nomos-services/api/src/http/da.rs @@ -0,0 +1,75 @@ +use bytes::Bytes; +use cryptarchia_consensus::network::adapters::libp2p::LibP2pAdapter as ConsensusNetworkAdapter; +use nomos_core::da::attestation::Attestation; +use nomos_core::da::blob::Blob; +use nomos_core::da::certificate::{self, select::FillSize as FillSizeWithBlobsCertificate}; +use nomos_core::da::DaVerifier as CoreDaVerifier; +use nomos_core::header::HeaderId; +use nomos_core::tx::{select::FillSize as FillSizeWithTx, Transaction}; +use nomos_da_indexer::storage::adapters::rocksdb::RocksAdapter as IndexerStorageAdapter; +use nomos_da_indexer::{ + consensus::adapters::cryptarchia::CryptarchiaConsensusAdapter, DataIndexerService, +}; +use nomos_da_verifier::backend::VerifierBackend; +use nomos_da_verifier::network::adapters::libp2p::Libp2pAdapter; +use nomos_da_verifier::storage::adapters::rocksdb::RocksAdapter as VerifierStorageAdapter; +use nomos_da_verifier::{DaVerifierMsg, DaVerifierService}; +use nomos_mempool::backend::mockpool::MockPool; +use nomos_mempool::da::verify::fullreplication::DaVerificationProvider as MempoolVerificationProvider; +use nomos_mempool::network::adapters::libp2p::Libp2pAdapter as MempoolNetworkAdapter; +use nomos_storage::backends::rocksdb::RocksBackend; +use nomos_storage::backends::StorageSerde; +use overwatch_rs::overwatch::handle::OverwatchHandle; +use overwatch_rs::DynError; +use serde::de::DeserializeOwned; +use serde::Serialize; +use std::error::Error; +use tokio::sync::oneshot; + +pub type DaIndexer = DataIndexerService< + // Indexer specific. + Bytes, + IndexerStorageAdapter, + CryptarchiaConsensusAdapter, + // Cryptarchia specific. + ConsensusNetworkAdapter, + MockPool::Hash>, + MempoolNetworkAdapter::Hash>, + MockPool::CertificateId>, + MempoolNetworkAdapter::Id>, + MempoolVerificationProvider, + FillSizeWithTx, + FillSizeWithBlobsCertificate, + RocksBackend, +>; + +pub type DaVerifier = + DaVerifierService, VerifierStorageAdapter>; + +pub async fn da_add_blob( + handle: &OverwatchHandle, + blob: B, +) -> Result, DynError> +where + A: Attestation + Serialize + DeserializeOwned + Clone + Send + Sync + 'static, + B: Blob + Serialize + DeserializeOwned + Clone + Send + Sync + 'static, + ::BlobId: AsRef<[u8]> + Send + Sync + 'static, + VB: VerifierBackend + CoreDaVerifier, + ::Settings: Clone, + ::Error: Error, + SS: StorageSerde + Send + Sync + 'static, +{ + let relay = handle.relay::>().connect().await?; + let (sender, receiver) = oneshot::channel(); + relay + .send(DaVerifierMsg::AddBlob { + blob, + reply_channel: sender, + }) + .await + .map_err(|(e, _)| e)?; + + Ok(receiver.await?) +} + +pub async fn da_get_range() {} diff --git a/nomos-services/api/src/http/mod.rs b/nomos-services/api/src/http/mod.rs index d63a1021..6ab13b2a 100644 --- a/nomos-services/api/src/http/mod.rs +++ b/nomos-services/api/src/http/mod.rs @@ -1,6 +1,7 @@ pub type DynError = Box; pub mod cl; pub mod consensus; +pub mod da; pub mod libp2p; pub mod mempool; pub mod metrics;