Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions chain/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use commonware_utils::{Acknowledgement, SystemTimeExt};
use futures::StreamExt;
use rand::Rng;
use std::{
marker::PhantomData,
num::NonZeroU64,
time::{Duration, SystemTime},
};
Expand All @@ -29,13 +30,14 @@ const MAX_BLOCK_TIMESTAMP_MS: u64 = 7_258_118_400_000;
const MAX_FUTURE_SKEW_MS: u64 = 1_000;

#[derive(Clone)]
pub struct Application {
pub struct Application<S: Scheme> {
backfiller: Option<indexer::Producer>,
delay_ms: NonZeroU64,
block_size: u32,
_scheme: PhantomData<S>,
}

impl Application {
impl<S: Scheme> Application<S> {
pub fn genesis() -> Block {
let genesis_context = Context {
round: Round::new(EPOCH, View::zero()),
Expand All @@ -56,6 +58,7 @@ impl Application {
backfiller: None,
delay_ms,
block_size: 0,
_scheme: PhantomData,
}
}

Expand All @@ -70,11 +73,12 @@ impl Application {
}
}

impl<E> ConsensusApplication<E> for Application
impl<E, S> ConsensusApplication<E> for Application<S>
where
E: Rng + Spawner + Metrics + Clock + Storage,
S: Scheme,
{
type SigningScheme = Scheme;
type SigningScheme = S;
type Context = Context;
type Block = Block;
type Input = ();
Expand Down Expand Up @@ -156,7 +160,7 @@ where
}
}

impl Reporter for Application {
impl<S: Scheme> Reporter for Application<S> {
type Activity = Update<Block>;

fn report(&mut self, activity: Self::Activity) -> Feedback {
Expand All @@ -183,6 +187,7 @@ impl Reporter for Application {
#[cfg(test)]
mod tests {
use super::*;
use alto_types::VrfScheme;
use commonware_consensus::marshal::ancestry;
use commonware_runtime::{deterministic, Runner as _, Supervisor as _};
use commonware_utils::NZU64;
Expand All @@ -198,7 +203,7 @@ mod tests {

async fn verify_block(
context: deterministic::Context,
application: &mut Application,
application: &mut Application<VrfScheme>,
block: &Block,
parent: &Block,
) -> bool {
Expand All @@ -208,7 +213,7 @@ mod tests {

async fn propose_child(
context: deterministic::Context,
application: &mut Application,
application: &mut Application<VrfScheme>,
child_context: Context,
parent: &Block,
) -> Block {
Expand Down
Loading
Loading