//! Standard variant implementation for Marshal. //! //! The standard variant broadcasts complete blocks to all peers. Each validator //! receives the full block directly from the proposer or via gossip. use crate::{ marshal::core::{Buffer, Variant}, types::Round, Block, }; use commonware_broadcast::{buffered, Broadcaster}; use commonware_cryptography::{Digestible, PublicKey}; use commonware_p2p::Recipients; use commonware_utils::channel::oneshot; /// The standard variant of Marshal, which broadcasts complete blocks. /// /// This variant sends the entire block to all peers. #[derive(Default, Clone, Copy)] pub struct Standard(std::marker::PhantomData); impl Variant for Standard where B: Block, { type ApplicationBlock = B; type Block = B; type StoredBlock = B; type Commitment = ::Digest; fn commitment(block: &Self::Block) -> Self::Commitment { // Standard variant commitment is exactly the block digest. block.digest() } fn commitment_to_inner(commitment: Self::Commitment) -> ::Digest { // Trivial left-inverse: digest == commitment in this variant. commitment } fn parent_commitment(block: &Self::Block) -> Self::Commitment { // In standard mode, commitments are digests, so parent commitment is parent digest. block.parent() } fn into_inner(block: Self::Block) -> Self::ApplicationBlock { block } } impl Buffer> for buffered::Mailbox where B: Block, K: PublicKey, { type CachedBlock = B; async fn find_by_digest(&self, digest: B::Digest) -> Option { self.get(digest).await } async fn find_by_commitment(&self, commitment: B::Digest) -> Option { self.find_by_digest(commitment).await } async fn subscribe_by_digest(&self, digest: B::Digest) -> oneshot::Receiver { let (tx, rx) = oneshot::channel(); self.subscribe_prepared(digest, tx).await; rx } async fn subscribe_by_commitment( &self, commitment: B::Digest, ) -> oneshot::Receiver { self.subscribe_by_digest(commitment).await } async fn finalized(&self, _commitment: B::Digest) { // No cleanup needed in standard mode - the buffer handles its own pruning } async fn proposed(&self, _round: Round, block: B) { let _peers = Broadcaster::broadcast(self, Recipients::All, block).await; } }