From c3478cf6a604a013345c0cbad3f8614207698a0e Mon Sep 17 00:00:00 2001 From: Youngjoon Lee Date: Thu, 2 Nov 2023 18:44:31 +0900 Subject: [PATCH] Set voter to DA attestation (#498) --- nodes/nomos-node/config.yaml | 1 + nomos-cli/Cargo.toml | 3 ++- nomos-cli/src/da/disseminate.rs | 20 ++++++++++++++++---- nomos-da/full-replication/src/lib.rs | 19 +++++++++++++------ tests/src/nodes/nomos.rs | 5 +++-- tests/src/tests/cli.rs | 1 + 6 files changed, 36 insertions(+), 13 deletions(-) diff --git a/nodes/nomos-node/config.yaml b/nodes/nomos-node/config.yaml index 149d0ace..41c92f8b 100644 --- a/nodes/nomos-node/config.yaml +++ b/nodes/nomos-node/config.yaml @@ -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 diff --git a/nomos-cli/Cargo.toml b/nomos-cli/Cargo.toml index 8e9bef1e..18ffd504 100644 --- a/nomos-cli/Cargo.toml +++ b/nomos-cli/Cargo.toml @@ -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" \ No newline at end of file +thiserror = "1.0" +hex = "0.4.3" diff --git a/nomos-cli/src/da/disseminate.rs b/nomos-cli/src/da/disseminate.rs index d9231d69..aea9fce6 100644 --- a/nomos-cli/src/da/disseminate.rs +++ b/nomos-cli/src/da/disseminate.rs @@ -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}; @@ -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, @@ -218,9 +220,12 @@ impl TryFrom for FullReplication Result { 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), + )) + } } } } @@ -239,6 +244,7 @@ pub enum Protocol { impl Default for FullReplicationSettings { fn default() -> Self { Self { + voter: [0; 32], num_attestations: 1, } } @@ -246,6 +252,12 @@ impl Default for FullReplicationSettings { #[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> { + Ok(<[u8; 32]>::from_hex(s)?) +} diff --git a/nomos-da/full-replication/src/lib.rs b/nomos-da/full-replication/src/lib.rs index c8c122a6..f221f9d2 100644 --- a/nomos-da/full-replication/src/lib.rs +++ b/nomos-da/full-replication/src/lib.rs @@ -24,6 +24,7 @@ pub mod openapi { #[derive(Debug, Clone)] pub struct FullReplication { + voter: Voter, certificate_strategy: CertificateStrategy, output_buffer: Vec, attestations: Vec, @@ -31,8 +32,9 @@ pub struct FullReplication { } impl FullReplication { - 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(), @@ -69,6 +71,7 @@ impl AbsoluteNumber { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct Settings { + pub voter: Voter, pub num_attestations: usize, } @@ -92,9 +95,11 @@ impl CertificateStrategy for AbsoluteNumber { } } +#[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, } @@ -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 { @@ -188,7 +193,10 @@ impl DaProtocol for FullReplication> { 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>(&self, data: T) -> Vec { @@ -208,8 +216,7 @@ impl DaProtocol for FullReplication> { fn attest(&self, blob: &Self::Blob) -> Self::Attestation { Attestation { blob: hasher(blob), - // TODO: voter id? - voter: [0; 32], + voter: self.voter, } } diff --git a/tests/src/nodes/nomos.rs b/tests/src/nodes/nomos.rs index 0bc8f7a6..a3b3d289 100644 --- a/tests/src/nodes/nomos.rs +++ b/tests/src/nodes/nomos.rs @@ -256,7 +256,7 @@ fn create_node_configs( fn create_node_config( nodes: Vec, - private_key: [u8; 32], + id: [u8; 32], threshold: Fraction, timeout: Duration, mixnet_node_config: Option, @@ -285,7 +285,7 @@ fn create_node_config( }, }, consensus: CarnotSettings { - private_key, + private_key: id, overlay_settings: TreeOverlaySettings { nodes, leader: RoundRobin::new(), @@ -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 { diff --git a/tests/src/tests/cli.rs b/tests/src/tests/cli.rs index 39f14a5b..e5f2a126 100644 --- a/tests/src/tests/cli.rs +++ b/tests/src/tests/cli.rs @@ -28,6 +28,7 @@ async fn disseminate_blob() { da_protocol: Protocol::FullReplication, settings: ProtocolSettings { full_replication: FullReplicationSettings { + voter: [0; 32], num_attestations: 1, }, },