Skip to content

Commit

Permalink
Add cryptarchia consensus service (#612)
Browse files Browse the repository at this point in the history
* add cryptarchia consensus service

* fmt

* clippy happy

* review comments
  • Loading branch information
zeegomo authored Mar 15, 2024
1 parent dbda061 commit 1b925d9
Show file tree
Hide file tree
Showing 14 changed files with 639 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"nomos-services/network",
"nomos-services/storage",
"nomos-services/carnot-consensus",
"nomos-services/cryptarchia-consensus",
"nomos-services/mempool",
"nomos-services/http",
"nomos-services/data-availability",
Expand Down
6 changes: 0 additions & 6 deletions consensus/carnot-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ mod types;
pub use overlay::Overlay;
pub use types::*;

/// Re-export of the OpenAPI types
#[cfg(feature = "openapi")]
pub mod openapi {
pub use crate::types::BlockId;
}

#[derive(Clone, Debug, PartialEq)]
pub struct Carnot<O: Overlay, Id: Eq + Hash> {
id: NodeId,
Expand Down
1 change: 1 addition & 0 deletions consensus/cryptarchia-engine/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Config {
// The k parameter in the Common Prefix property.
Expand Down
1 change: 1 addition & 0 deletions consensus/cryptarchia-engine/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::ops::Add;
#[derive(Clone, Debug, Eq, PartialEq, Copy, Hash, PartialOrd, Ord)]
pub struct Slot(u64);

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq, Copy, Hash, PartialOrd, Ord)]
pub struct Epoch(u32);

Expand Down
2 changes: 1 addition & 1 deletion ledger/cryptarchia-ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ cryptarchia-engine = { path = "../../consensus/cryptarchia-engine" }
nomos-utils = { path = "../../nomos-utils", optional = true }

[features]
serde = ["dep:serde", "nomos-utils/serde"]
serde = ["dep:serde", "nomos-utils/serde", "rpds/serde"]
1 change: 1 addition & 0 deletions ledger/cryptarchia-ledger/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cryptarchia_engine::{Epoch, Slot};

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq)]
pub struct Config {
// The stake distribution is always taken at the beginning of the previous epoch.
Expand Down
5 changes: 4 additions & 1 deletion ledger/cryptarchia-ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ mod utils;
use blake2::Digest;
use cryptarchia_engine::{Epoch, Slot};
use crypto::Blake2b;
use rpds::HashTrieSet;
use std::{collections::HashMap, hash::Hash};
use thiserror::Error;

type HashTrieSet<T> = rpds::HashTrieSetSync<T>;

pub use config::Config;
pub use leader_proof::*;
pub use nonce::*;
Expand All @@ -31,6 +32,7 @@ pub enum LedgerError<Id> {
OrphanMissing(Id),
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EpochState {
// The epoch this snapshot is for
Expand Down Expand Up @@ -131,6 +133,7 @@ where
}
}

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Eq, PartialEq)]
pub struct LedgerState {
// commitments to coins that can be used to propose new blocks
Expand Down
42 changes: 42 additions & 0 deletions nomos-services/cryptarchia-consensus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "cryptarchia-consensus"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1"
bytes = "1.3"
chrono = "0.4"
cryptarchia-engine = { path = "../../consensus/cryptarchia-engine", features = ["serde"] }
cryptarchia-ledger = { path = "../../ledger/cryptarchia-ledger", features = ["serde"] }
futures = "0.3"
nomos-network = { path = "../network" }
nomos-mempool = { path = "../mempool" }
nomos-core = { path = "../../nomos-core" }
overwatch-rs = { git = "https://github.com/logos-co/Overwatch", rev = "2f70806" }
nomos-storage = { path = "../storage" }
rand_chacha = "0.3"
rand = "0.8"
serde = { version = "1", features = ["derive"] }
thiserror = "1.0"
tokio = { version = "1", features = ["sync"] }
tokio-stream = "0.1"
tokio-util = "0.7"
tracing = "0.1"
bls-signatures = "0.14"
serde_with = "3.0.0"
nomos-libp2p = { path = "../../nomos-libp2p", optional = true }
blake2 = "0.10"

utoipa = { version = "4.0", optional = true }
serde_json = { version = "1", optional = true }

[features]
default = []
libp2p = ["nomos-network/libp2p", "nomos-libp2p"]
openapi = ["dep:utoipa", "serde_json"]

[dev-dependencies]
serde_json = "1.0.96"
1 change: 1 addition & 0 deletions nomos-services/cryptarchia-consensus/src/leadership.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 1b925d9

Please sign in to comment.