Skip to content

Commit

Permalink
feat(sequencing): add cende module and main types (#2714)
Browse files Browse the repository at this point in the history
  • Loading branch information
DvirYo-starkware authored Dec 19, 2024
1 parent 6383355 commit 24503a1
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
80 changes: 80 additions & 0 deletions crates/sequencing/papyrus_consensus_orchestrator/src/cende/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use std::sync::Arc;

use async_trait::async_trait;
use futures::channel::oneshot;
use tokio::sync::Mutex;
use tokio::task::{self};
use tracing::debug;

// TODO(dvir): add tests when will have more logic.

/// A chunk of all the data to write to Aersopike.
#[derive(Debug)]
pub(crate) struct AerospikeBlob {
// TODO(yael, dvir): add the blob fields.
}

#[async_trait]
pub(crate) trait CendeContext: Send + Sync {
/// Write the previous height blob to Aerospike. Returns a cell with an inner boolean indicating
/// whether the write was successful.
fn write_prev_height_blob(&self) -> oneshot::Receiver<bool>;

// Prepares the previous height blob that will be written in the next height.
async fn prepare_blob_for_next_height(&self, blob_parameters: BlobParameters);
}

#[derive(Clone, Debug)]
pub(crate) struct CendeAmbassador {
// TODO(dvir): consider creating enum varaiant instead of the `Option<AerospikeBlob>`.
// `None` indicates that there is no blob to write, and therefore, the node can't be the
// proposer.
prev_height_blob: Arc<Mutex<Option<AerospikeBlob>>>,
}

impl CendeAmbassador {
pub(crate) fn new() -> Self {
CendeAmbassador { prev_height_blob: Arc::new(Mutex::new(None)) }
}
}

#[async_trait]
impl CendeContext for CendeAmbassador {
fn write_prev_height_blob(&self) -> oneshot::Receiver<bool> {
let (sender, reciver) = oneshot::channel();
let prev_height_blob = self.prev_height_blob.clone();
task::spawn(async move {
let Some(ref _blob) = *prev_height_blob.lock().await else {
debug!("No blob to write to Aerospike.");
sender.send(false).expect("Writing to a one-shot sender should succeed.");
return;
};
// TODO(dvir): write blob to AS.
// TODO(dvir): consider set `prev_height_blob` to `None` after writing to AS.
debug!("Writing blob to Aerospike.");
sender.send(true).expect("Writing to a one-shot sender should succeed.");
debug!("Blob writing to Aerospike completed.");
});

reciver
}

async fn prepare_blob_for_next_height(&self, blob_parameters: BlobParameters) {
// TODO(dvir, yael): make the full creation of blob.
// TODO(dvir): as optimization, call the `into` and other preperation when writing to AS.
*self.prev_height_blob.lock().await = Some(blob_parameters.into());
}
}

#[derive(Clone, Debug, Default)]
pub(crate) struct BlobParameters {
// TODO(dvir): add here all the information needed for creating the blob: tranasctions, classes,
// block info, BlockExecutionArtifacts.
}

impl From<BlobParameters> for AerospikeBlob {
fn from(_blob_parameters: BlobParameters) -> Self {
// TODO(yael): make the full creation of blob.
AerospikeBlob {}
}
}
5 changes: 5 additions & 0 deletions crates/sequencing/papyrus_consensus_orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
pub mod papyrus_consensus_context;
#[allow(missing_docs)]
pub mod sequencer_consensus_context;

/// Centralized and decentralized communication types and functionallity.
// TODO(dvir): delete this when using the types in consensus.
#[allow(dead_code)]
mod cende;

0 comments on commit 24503a1

Please sign in to comment.