Skip to content

Commit 9ba5c0e

Browse files
committed
[consensus] New Application interface
Defines a new interface for applications that employ erasure coding
1 parent 4e5b83d commit 9ba5c0e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

consensus/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ cfg_if::cfg_if! {
5656
use commonware_cryptography::{Digest, PublicKey};
5757
use futures::channel::{oneshot, mpsc};
5858
use std::future::Future;
59+
use rand::Rng;
60+
use commonware_runtime::{Clock, Metrics, Spawner};
5961

6062
pub mod marshal;
6163
mod reporter;
@@ -102,6 +104,38 @@ cfg_if::cfg_if! {
102104
) -> impl Future<Output = oneshot::Receiver<bool>> + Send;
103105
}
104106

107+
/// Application is the interface responsible for building new blocks on top of consensus-provided parent
108+
/// commitments as well as receiving finalized blocks from marshal.
109+
pub trait Application<E>: Clone + Send + 'static
110+
where
111+
E: Rng + Spawner + Metrics + Clock
112+
{
113+
/// Context is metadata provided by the consensus engine associated with a given payload.
114+
///
115+
/// This often includes things like the proposer, view number, the height, or the epoch.
116+
type Context: Epochable;
117+
118+
/// The block type produced by the application's builder.
119+
type Block: Block;
120+
121+
/// Payload used to initialize the consensus engine.
122+
fn genesis(
123+
&mut self,
124+
epoch: <Self::Context as Epochable>::Epoch
125+
) -> impl Future<Output = Self::Block> + Send;
126+
127+
/// Build a new block on top of the provided parent commitment / block.
128+
fn build(
129+
&mut self,
130+
context: E,
131+
parent_commitment: <Self::Block as Committable>::Commitment,
132+
parent_block: Self::Block,
133+
) -> impl Future<Output = Self::Block> + Send;
134+
135+
/// Receive a finalized block from marshal.
136+
fn finalize(&mut self, block: Self::Block) -> impl Future<Output = ()> + Send;
137+
}
138+
105139
/// Relay is the interface responsible for broadcasting payloads to the network.
106140
///
107141
/// The consensus engine is only aware of a payload's digest, not its contents. It is up

0 commit comments

Comments
 (0)