From 8da13f7012ca8fb7b55432a815a8692204cd23d8 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Mon, 11 Sep 2023 17:44:26 +0200 Subject: [PATCH] Da nomos core (#390) * Refactor da modules Include da core module in nomos-core * Include attestation trait * Added initial approach for Da protocol * Added empty certificate trait * Added certificate dispersal method * Rename validate method to validate attestation * Clippy happy * Add validate certificate method --- Cargo.toml | 4 +-- nomos-core/src/da/attestation/mod.rs | 8 +++++ nomos-core/src/{ => da}/blob/mod.rs | 0 nomos-core/src/da/certificate/mod.rs | 1 + nomos-core/src/da/mod.rs | 30 +++++++++++++++++++ nomos-core/src/lib.rs | 2 +- {nomos-da-core => nomos-da}/kzg/Cargo.toml | 0 .../kzg/benches/nomos_kzg.rs | 0 .../kzg/src/dynamic_kzg.rs | 0 {nomos-da-core => nomos-da}/kzg/src/lib.rs | 0 {nomos-da-core => nomos-da}/kzg/src/types.rs | 0 .../reed-solomon/Cargo.toml | 0 .../reed-solomon/src/lib.rs | 0 .../src/backend/memory_cache.rs | 2 +- .../data-availability/src/backend/mod.rs | 2 +- nomos-services/data-availability/src/lib.rs | 2 +- 16 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 nomos-core/src/da/attestation/mod.rs rename nomos-core/src/{ => da}/blob/mod.rs (100%) create mode 100644 nomos-core/src/da/certificate/mod.rs create mode 100644 nomos-core/src/da/mod.rs rename {nomos-da-core => nomos-da}/kzg/Cargo.toml (100%) rename {nomos-da-core => nomos-da}/kzg/benches/nomos_kzg.rs (100%) rename {nomos-da-core => nomos-da}/kzg/src/dynamic_kzg.rs (100%) rename {nomos-da-core => nomos-da}/kzg/src/lib.rs (100%) rename {nomos-da-core => nomos-da}/kzg/src/types.rs (100%) rename {nomos-da-core => nomos-da}/reed-solomon/Cargo.toml (100%) rename {nomos-da-core => nomos-da}/reed-solomon/src/lib.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 816dc9cf..09d907a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ members = [ "nomos-services/mempool", "nomos-services/http", "nomos-services/data-availability", - "nomos-da-core/reed-solomon", - "nomos-da-core/kzg", + "nomos-da/reed-solomon", + "nomos-da/kzg", "nodes/nomos-node", "simulations", "consensus-engine", diff --git a/nomos-core/src/da/attestation/mod.rs b/nomos-core/src/da/attestation/mod.rs new file mode 100644 index 00000000..52b24167 --- /dev/null +++ b/nomos-core/src/da/attestation/mod.rs @@ -0,0 +1,8 @@ +use crate::da::blob::Blob; +use bytes::Bytes; + +pub trait Attestation { + type Blob: Blob; + fn blob(&self) -> ::Hash; + fn as_bytes(&self) -> Bytes; +} diff --git a/nomos-core/src/blob/mod.rs b/nomos-core/src/da/blob/mod.rs similarity index 100% rename from nomos-core/src/blob/mod.rs rename to nomos-core/src/da/blob/mod.rs diff --git a/nomos-core/src/da/certificate/mod.rs b/nomos-core/src/da/certificate/mod.rs new file mode 100644 index 00000000..35600aaf --- /dev/null +++ b/nomos-core/src/da/certificate/mod.rs @@ -0,0 +1 @@ +pub trait Certificate {} diff --git a/nomos-core/src/da/mod.rs b/nomos-core/src/da/mod.rs new file mode 100644 index 00000000..ac876b95 --- /dev/null +++ b/nomos-core/src/da/mod.rs @@ -0,0 +1,30 @@ +// std +use std::error::Error; +// crates +use bytes::Bytes; +use futures::Stream; +// internal +use crate::da::attestation::Attestation; +use crate::da::blob::Blob; +use crate::da::certificate::Certificate; + +pub mod attestation; +pub mod blob; +pub mod certificate; + +pub trait DaProtocol { + type Blob: Blob; + type Attestation: Attestation; + type Certificate: Certificate; + + fn encode>(&self, data: T) -> Box>; + fn decode>(&self, s: S) -> Result>; + fn validate_attestation(&self, blob: &Self::Blob, attestation: &Self::Attestation) -> bool; + + fn certificate_dispersal>( + &self, + attestations: S, + ) -> Self::Certificate; + + fn validate_certificate(certificate: &Self::Certificate) -> bool; +} diff --git a/nomos-core/src/lib.rs b/nomos-core/src/lib.rs index ded3b7a2..1152a55a 100644 --- a/nomos-core/src/lib.rs +++ b/nomos-core/src/lib.rs @@ -1,7 +1,7 @@ pub mod account; -pub mod blob; pub mod block; pub mod crypto; +pub mod da; pub mod fountain; pub mod staking; pub mod tx; diff --git a/nomos-da-core/kzg/Cargo.toml b/nomos-da/kzg/Cargo.toml similarity index 100% rename from nomos-da-core/kzg/Cargo.toml rename to nomos-da/kzg/Cargo.toml diff --git a/nomos-da-core/kzg/benches/nomos_kzg.rs b/nomos-da/kzg/benches/nomos_kzg.rs similarity index 100% rename from nomos-da-core/kzg/benches/nomos_kzg.rs rename to nomos-da/kzg/benches/nomos_kzg.rs diff --git a/nomos-da-core/kzg/src/dynamic_kzg.rs b/nomos-da/kzg/src/dynamic_kzg.rs similarity index 100% rename from nomos-da-core/kzg/src/dynamic_kzg.rs rename to nomos-da/kzg/src/dynamic_kzg.rs diff --git a/nomos-da-core/kzg/src/lib.rs b/nomos-da/kzg/src/lib.rs similarity index 100% rename from nomos-da-core/kzg/src/lib.rs rename to nomos-da/kzg/src/lib.rs diff --git a/nomos-da-core/kzg/src/types.rs b/nomos-da/kzg/src/types.rs similarity index 100% rename from nomos-da-core/kzg/src/types.rs rename to nomos-da/kzg/src/types.rs diff --git a/nomos-da-core/reed-solomon/Cargo.toml b/nomos-da/reed-solomon/Cargo.toml similarity index 100% rename from nomos-da-core/reed-solomon/Cargo.toml rename to nomos-da/reed-solomon/Cargo.toml diff --git a/nomos-da-core/reed-solomon/src/lib.rs b/nomos-da/reed-solomon/src/lib.rs similarity index 100% rename from nomos-da-core/reed-solomon/src/lib.rs rename to nomos-da/reed-solomon/src/lib.rs diff --git a/nomos-services/data-availability/src/backend/memory_cache.rs b/nomos-services/data-availability/src/backend/memory_cache.rs index a97d7d09..94d71d34 100644 --- a/nomos-services/data-availability/src/backend/memory_cache.rs +++ b/nomos-services/data-availability/src/backend/memory_cache.rs @@ -1,6 +1,6 @@ use crate::backend::{DaBackend, DaError}; use moka::future::{Cache, CacheBuilder}; -use nomos_core::blob::Blob; +use nomos_core::da::blob::Blob; use std::time::Duration; #[derive(Clone, Copy)] diff --git a/nomos-services/data-availability/src/backend/mod.rs b/nomos-services/data-availability/src/backend/mod.rs index d19c3e81..ecae876f 100644 --- a/nomos-services/data-availability/src/backend/mod.rs +++ b/nomos-services/data-availability/src/backend/mod.rs @@ -1,6 +1,6 @@ mod memory_cache; -use nomos_core::blob::Blob; +use nomos_core::da::blob::Blob; use overwatch_rs::DynError; #[derive(Debug)] diff --git a/nomos-services/data-availability/src/lib.rs b/nomos-services/data-availability/src/lib.rs index 4b3c8205..42c647a0 100644 --- a/nomos-services/data-availability/src/lib.rs +++ b/nomos-services/data-availability/src/lib.rs @@ -10,7 +10,7 @@ use tokio::sync::oneshot::Sender; // internal use crate::backend::{DaBackend, DaError}; use crate::network::NetworkAdapter; -use nomos_core::blob::Blob; +use nomos_core::da::blob::Blob; use nomos_network::NetworkService; use overwatch_rs::services::handle::ServiceStateHandle; use overwatch_rs::services::relay::{Relay, RelayMessage};