Skip to content

Commit

Permalink
Adopt a sans-IO style for DaProtocol
Browse files Browse the repository at this point in the history
Remove async streams from the DaProtocol trait to avoid creating
dependencies on actual I/O. The protocol it's now transformed into
a state machine with an input and output buffer.

In addition, a method to create an attestation was added to the
trait.
  • Loading branch information
zeegomo committed Sep 12, 2023
1 parent 7cabddc commit 8cdce81
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions nomos-core/src/da/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// std
use std::error::Error;
// crates
use bytes::Bytes;
use futures::Stream;
// internal
use crate::da::attestation::Attestation;
use crate::da::blob::Blob;
Expand All @@ -11,20 +8,31 @@ use crate::da::certificate::Certificate;
pub mod attestation;
pub mod blob;
pub mod certificate;
pub mod full_replication;

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Check (libp2p)

file not found for module `full_replication`

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite (libp2p, ubuntu-latest)

file not found for module `full_replication`

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite (libp2p, macos-latest)

file not found for module `full_replication`

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite (waku, ubuntu-latest)

file not found for module `full_replication`

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite (libp2p, windows-latest)

file not found for module `full_replication`

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite (waku, macos-latest)

file not found for module `full_replication`

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Test

file not found for module `full_replication`

Check failure on line 11 in nomos-core/src/da/mod.rs

View workflow job for this annotation

GitHub Actions / Test Suite (waku, windows-latest)

file not found for module `full_replication`

pub trait DaProtocol {
type Blob: Blob;
type Attestation: Attestation;
type Certificate: Certificate;

fn encode<T: AsRef<[u8]>>(&self, data: T) -> Box<dyn Stream<Item = Self::Blob>>;
fn decode<S: Stream<Item = Self::Blob>>(&self, s: S) -> Result<Bytes, Box<dyn Error>>;
/// Encode bytes into blobs
fn encode<T: AsRef<[u8]>>(&self, data: T) -> Vec<Self::Blob>;
/// Feed a blob for decoding.
/// Depending on the protocol, it may be necessary to feed multiple blobs to
/// recover the initial data.
fn recv_blob(&mut self, blob: Self::Blob);
/// Attempt to recover the initial data from feeded blobs.
/// If the protocol is not yet ready to return the data, return None.
fn extract(&mut self) -> Option<Bytes>;
/// Attest that we have received and stored a blob.
fn attest(&self, blob: &Self::Blob) -> Self::Attestation;
/// Validate that an attestation is valid for a blob.
fn validate_attestation(&self, blob: &Self::Blob, attestation: &Self::Attestation) -> bool;

fn certificate_dispersal<S: Stream<Item = Self::Attestation>>(
&self,
attestations: S,
) -> Self::Certificate;

/// Buffer attestations to produce a certificate of correct dispersal.
fn recv_attestation(&mut self, attestation: Self::Attestation);
/// Attempt to produce a certificate of correct disperal for a blob.
/// If the protocol is not yet ready to return the certificate, return None.
fn certify_dispersal(&self) -> Option<Self::Certificate>;
/// Validate a certificate.
fn validate_certificate(certificate: &Self::Certificate) -> bool;
}

0 comments on commit 8cdce81

Please sign in to comment.