Skip to content

Commit 2b672bf

Browse files
committed
feat: Erasure coding mk2
1 parent 958bcff commit 2b672bf

File tree

16 files changed

+360
-479
lines changed

16 files changed

+360
-479
lines changed

Cargo.lock

Lines changed: 66 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ license = "MIT OR Apache-2.0"
1515
[workspace.dependencies]
1616
alto-client = { version = "0.0.16", path = "client" }
1717
alto-types = { version = "0.0.16", path = "types" }
18-
commonware-broadcast ="0.0.63"
19-
commonware-codec ="0.0.63"
20-
commonware-consensus ="0.0.63"
21-
commonware-cryptography ="0.0.63"
22-
commonware-deployer = { version = "0.0.63", default-features = false }
23-
commonware-macros ="0.0.63"
24-
commonware-p2p ="0.0.63"
25-
commonware-resolver ="0.0.63"
26-
commonware-runtime ="0.0.63"
27-
commonware-storage ="0.0.63"
28-
commonware-stream ="0.0.63"
29-
commonware-utils ="0.0.63"
18+
commonware-broadcast = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
19+
commonware-codec = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
20+
commonware-consensus = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
21+
commonware-cryptography = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
22+
commonware-coding = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
23+
commonware-deployer = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2", default-features = false }
24+
commonware-macros = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
25+
commonware-p2p = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
26+
commonware-resolver = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
27+
commonware-runtime = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
28+
commonware-storage = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
29+
commonware-stream = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
30+
commonware-utils = { git = "https://github.com/commonwarexyz/monorepo.git", branch = "cl/consensus-coding-mk2" }
3031
thiserror = "2.0.12"
3132
bytes = "1.7.1"
3233
rand = "0.8.5"
@@ -58,3 +59,7 @@ overflow-checks = true
5859
# Although overflow checks are enabled by default in "test", we explicitly
5960
# enable them here for clarity.
6061
overflow-checks = true
62+
63+
[profile.profiling]
64+
inherits = "release"
65+
debug = true

chain/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ alto-types = { workspace = true }
1515
alto-client = { workspace = true }
1616
commonware-broadcast = { workspace = true }
1717
commonware-codec = { workspace = true }
18+
commonware-coding = { workspace = true }
1819
commonware-consensus = { workspace = true }
1920
commonware-cryptography = { workspace = true }
2021
commonware-deployer = { workspace = true }

chain/src/application.rs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
use alto_types::{Block, PublicKey, Scheme};
2+
use commonware_consensus::{
3+
marshal::{
4+
ancestry::{AncestorStream, AncestryProvider},
5+
coding::types::CodingCommitment,
6+
Update,
7+
},
8+
simplex::types::Context,
9+
Application, Block as _, Reporter,
10+
};
11+
use commonware_cryptography::{Digestible, Hasher, Sha256};
12+
use commonware_runtime::{Clock, Metrics, Spawner};
13+
use commonware_utils::{SystemTimeExt, Acknowledgement};
14+
use futures::StreamExt;
15+
use rand::Rng;
16+
use tracing::info;
17+
18+
/// Genesis message to use during initialization.
19+
const GENESIS: &[u8] = b"commonware is neat";
20+
21+
#[derive(Clone)]
22+
pub struct AltoApp {
23+
genesis: Block,
24+
}
25+
26+
impl AltoApp {
27+
pub fn new() -> Self {
28+
let genesis = Block::new(Sha256::hash(GENESIS), 0, 0, Vec::new());
29+
Self { genesis }
30+
}
31+
}
32+
33+
impl Default for AltoApp {
34+
fn default() -> Self {
35+
Self::new()
36+
}
37+
}
38+
39+
impl<E> Application<E> for AltoApp
40+
where
41+
E: Rng + Spawner + Metrics + Clock,
42+
{
43+
type SigningScheme = Scheme;
44+
type Context = Context<CodingCommitment, PublicKey>;
45+
type Block = Block;
46+
47+
async fn genesis(&mut self) -> Self::Block {
48+
self.genesis.clone()
49+
}
50+
51+
async fn propose<A: AncestryProvider<Block = Self::Block>>(
52+
&mut self,
53+
(mut runtime_context, _context): (E, Self::Context),
54+
mut ancestry: AncestorStream<A, Self::Block>,
55+
) -> Option<Self::Block> {
56+
let parent = ancestry.next().await?;
57+
58+
// Create a new block
59+
let mut current = runtime_context.current().epoch_millis();
60+
if current <= parent.timestamp {
61+
current = parent.timestamp + 1;
62+
}
63+
64+
// Generate some random data.
65+
let mut junk = vec![0u8; 8 * 1024 * 1024];
66+
runtime_context.fill_bytes(&mut junk);
67+
68+
Some(Block::new(
69+
parent.digest(),
70+
parent.height + 1,
71+
current,
72+
junk,
73+
))
74+
}
75+
}
76+
77+
impl Reporter for AltoApp {
78+
type Activity = Update<Block>;
79+
80+
async fn report(&mut self, activity: Self::Activity) {
81+
if let Update::Block(block, ack_rx) = activity {
82+
info!(height = block.height(), "finalized block");
83+
ack_rx.acknowledge();
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)