Adopt a sans-IO style for DaProtocol (#395)
* Adopt a sans-IO style for DaProtocol 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. * add forgotten &mut to certify_dispersal * add forgotten &self param to validate certificate
This commit is contained in:
parent
7cabddc71f
commit
1eeeeb1834
|
@ -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;
|
||||
|
@ -17,14 +14,24 @@ pub trait DaProtocol {
|
|||
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;
|
||||
|
||||
fn validate_certificate(certificate: &Self::Certificate) -> bool;
|
||||
/// 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(&mut self) -> Option<Self::Certificate>;
|
||||
/// Validate a certificate.
|
||||
fn validate_certificate(&self, certificate: &Self::Certificate) -> bool;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue