Skip to content

Commit

Permalink
Set voter to DA attestation (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngjoon-lee authored Nov 2, 2023
1 parent ba90ed1 commit c3478cf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
1 change: 1 addition & 0 deletions nodes/nomos-node/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ http:

da:
da_protocol:
voter: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
num_attestations: 1
backend:
max_capacity: 10
Expand Down
3 changes: 2 additions & 1 deletion nomos-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ full-replication = { path = "../nomos-da/full-replication" }
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
thiserror = "1.0"
hex = "0.4.3"
20 changes: 16 additions & 4 deletions nomos-cli/src/da/disseminate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::{Args, ValueEnum};
use full_replication::{AbsoluteNumber, Attestation, Certificate, FullReplication};
use full_replication::{AbsoluteNumber, Attestation, Certificate, FullReplication, Voter};
use futures::StreamExt;
use hex::FromHex;
use nomos_core::{da::DaProtocol, wire};
use nomos_da::network::{adapters::libp2p::Libp2pAdapter, NetworkAdapter};
use nomos_network::{backends::libp2p::Libp2p, NetworkService};
Expand All @@ -17,6 +18,7 @@ use overwatch_rs::{
use reqwest::{Client, Url};
use serde::Serialize;
use std::{
error::Error,
path::PathBuf,
sync::{mpsc::Sender, Arc},
time::Duration,
Expand Down Expand Up @@ -218,9 +220,12 @@ impl TryFrom<DaProtocolChoice> for FullReplication<AbsoluteNumber<Attestation, C
type Error = &'static str;
fn try_from(value: DaProtocolChoice) -> Result<Self, Self::Error> {
match (value.da_protocol, value.settings) {
(Protocol::FullReplication, ProtocolSettings { full_replication }) => Ok(
FullReplication::new(AbsoluteNumber::new(full_replication.num_attestations)),
),
(Protocol::FullReplication, ProtocolSettings { full_replication }) => {
Ok(FullReplication::new(
full_replication.voter,
AbsoluteNumber::new(full_replication.num_attestations),
))
}
}
}
}
Expand All @@ -239,13 +244,20 @@ pub enum Protocol {
impl Default for FullReplicationSettings {
fn default() -> Self {
Self {
voter: [0; 32],
num_attestations: 1,
}
}
}

#[derive(Debug, Clone, Args)]
pub struct FullReplicationSettings {
#[clap(long, value_parser = parse_key, default_value = "0000000000000000000000000000000000000000000000000000000000000000")]
pub voter: Voter,
#[clap(long, default_value = "1")]
pub num_attestations: usize,
}

fn parse_key(s: &str) -> Result<Voter, Box<dyn Error + Send + Sync + 'static>> {
Ok(<[u8; 32]>::from_hex(s)?)
}
19 changes: 13 additions & 6 deletions nomos-da/full-replication/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ pub mod openapi {

#[derive(Debug, Clone)]
pub struct FullReplication<CertificateStrategy> {
voter: Voter,
certificate_strategy: CertificateStrategy,
output_buffer: Vec<Bytes>,
attestations: Vec<Attestation>,
output_certificate_buf: Vec<Certificate>,
}

impl<S> FullReplication<S> {
pub fn new(strategy: S) -> Self {
pub fn new(voter: Voter, strategy: S) -> Self {
Self {
voter,
certificate_strategy: strategy,
output_buffer: Vec::new(),
attestations: Vec::new(),
Expand Down Expand Up @@ -69,6 +71,7 @@ impl<A, C> AbsoluteNumber<A, C> {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Settings {
pub voter: Voter,
pub num_attestations: usize,
}

Expand All @@ -92,9 +95,11 @@ impl CertificateStrategy for AbsoluteNumber<Attestation, Certificate> {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub type Voter = [u8; 32];

#[derive(Debug, Clone, Serialize, Deserialize, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Blob {
data: Bytes,
}
Expand All @@ -120,7 +125,7 @@ impl blob::Blob for Blob {
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Attestation {
blob: [u8; 32],
voter: [u8; 32],
voter: Voter,
}

impl attestation::Attestation for Attestation {
Expand Down Expand Up @@ -188,7 +193,10 @@ impl DaProtocol for FullReplication<AbsoluteNumber<Attestation, Certificate>> {
type Settings = Settings;

fn new(settings: Self::Settings) -> Self {
Self::new(AbsoluteNumber::new(settings.num_attestations))
Self::new(
settings.voter,
AbsoluteNumber::new(settings.num_attestations),
)
}

fn encode<T: AsRef<[u8]>>(&self, data: T) -> Vec<Self::Blob> {
Expand All @@ -208,8 +216,7 @@ impl DaProtocol for FullReplication<AbsoluteNumber<Attestation, Certificate>> {
fn attest(&self, blob: &Self::Blob) -> Self::Attestation {
Attestation {
blob: hasher(blob),
// TODO: voter id?
voter: [0; 32],
voter: self.voter,
}
}

Expand Down
5 changes: 3 additions & 2 deletions tests/src/nodes/nomos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn create_node_configs(

fn create_node_config(
nodes: Vec<NodeId>,
private_key: [u8; 32],
id: [u8; 32],
threshold: Fraction,
timeout: Duration,
mixnet_node_config: Option<MixnetNodeConfig>,
Expand Down Expand Up @@ -285,7 +285,7 @@ fn create_node_config(
},
},
consensus: CarnotSettings {
private_key,
private_key: id,
overlay_settings: TreeOverlaySettings {
nodes,
leader: RoundRobin::new(),
Expand Down Expand Up @@ -314,6 +314,7 @@ fn create_node_config(
metrics: Default::default(),
da: nomos_da::Settings {
da_protocol: full_replication::Settings {
voter: id,
num_attestations: 1,
},
backend: nomos_da::backend::memory_cache::BlobCacheSettings {
Expand Down
1 change: 1 addition & 0 deletions tests/src/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async fn disseminate_blob() {
da_protocol: Protocol::FullReplication,
settings: ProtocolSettings {
full_replication: FullReplicationSettings {
voter: [0; 32],
num_attestations: 1,
},
},
Expand Down

0 comments on commit c3478cf

Please sign in to comment.