Set voter to DA attestation (#498)

This commit is contained in:
Youngjoon Lee 2023-11-02 18:44:31 +09:00 committed by GitHub
parent ba90ed1b55
commit c3478cf6a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 13 deletions

View File

@ -57,6 +57,7 @@ http:
da: da:
da_protocol: 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 num_attestations: 1
backend: backend:
max_capacity: 10 max_capacity: 10

View File

@ -28,3 +28,4 @@ reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
thiserror = "1.0" thiserror = "1.0"
hex = "0.4.3"

View File

@ -1,6 +1,7 @@
use clap::{Args, ValueEnum}; use clap::{Args, ValueEnum};
use full_replication::{AbsoluteNumber, Attestation, Certificate, FullReplication}; use full_replication::{AbsoluteNumber, Attestation, Certificate, FullReplication, Voter};
use futures::StreamExt; use futures::StreamExt;
use hex::FromHex;
use nomos_core::{da::DaProtocol, wire}; use nomos_core::{da::DaProtocol, wire};
use nomos_da::network::{adapters::libp2p::Libp2pAdapter, NetworkAdapter}; use nomos_da::network::{adapters::libp2p::Libp2pAdapter, NetworkAdapter};
use nomos_network::{backends::libp2p::Libp2p, NetworkService}; use nomos_network::{backends::libp2p::Libp2p, NetworkService};
@ -17,6 +18,7 @@ use overwatch_rs::{
use reqwest::{Client, Url}; use reqwest::{Client, Url};
use serde::Serialize; use serde::Serialize;
use std::{ use std::{
error::Error,
path::PathBuf, path::PathBuf,
sync::{mpsc::Sender, Arc}, sync::{mpsc::Sender, Arc},
time::Duration, time::Duration,
@ -218,9 +220,12 @@ impl TryFrom<DaProtocolChoice> for FullReplication<AbsoluteNumber<Attestation, C
type Error = &'static str; type Error = &'static str;
fn try_from(value: DaProtocolChoice) -> Result<Self, Self::Error> { fn try_from(value: DaProtocolChoice) -> Result<Self, Self::Error> {
match (value.da_protocol, value.settings) { match (value.da_protocol, value.settings) {
(Protocol::FullReplication, ProtocolSettings { full_replication }) => Ok( (Protocol::FullReplication, ProtocolSettings { full_replication }) => {
FullReplication::new(AbsoluteNumber::new(full_replication.num_attestations)), Ok(FullReplication::new(
), full_replication.voter,
AbsoluteNumber::new(full_replication.num_attestations),
))
}
} }
} }
} }
@ -239,6 +244,7 @@ pub enum Protocol {
impl Default for FullReplicationSettings { impl Default for FullReplicationSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
voter: [0; 32],
num_attestations: 1, num_attestations: 1,
} }
} }
@ -246,6 +252,12 @@ impl Default for FullReplicationSettings {
#[derive(Debug, Clone, Args)] #[derive(Debug, Clone, Args)]
pub struct FullReplicationSettings { pub struct FullReplicationSettings {
#[clap(long, value_parser = parse_key, default_value = "0000000000000000000000000000000000000000000000000000000000000000")]
pub voter: Voter,
#[clap(long, default_value = "1")] #[clap(long, default_value = "1")]
pub num_attestations: usize, pub num_attestations: usize,
} }
fn parse_key(s: &str) -> Result<Voter, Box<dyn Error + Send + Sync + 'static>> {
Ok(<[u8; 32]>::from_hex(s)?)
}

View File

@ -24,6 +24,7 @@ pub mod openapi {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct FullReplication<CertificateStrategy> { pub struct FullReplication<CertificateStrategy> {
voter: Voter,
certificate_strategy: CertificateStrategy, certificate_strategy: CertificateStrategy,
output_buffer: Vec<Bytes>, output_buffer: Vec<Bytes>,
attestations: Vec<Attestation>, attestations: Vec<Attestation>,
@ -31,8 +32,9 @@ pub struct FullReplication<CertificateStrategy> {
} }
impl<S> FullReplication<S> { impl<S> FullReplication<S> {
pub fn new(strategy: S) -> Self { pub fn new(voter: Voter, strategy: S) -> Self {
Self { Self {
voter,
certificate_strategy: strategy, certificate_strategy: strategy,
output_buffer: Vec::new(), output_buffer: Vec::new(),
attestations: Vec::new(), attestations: Vec::new(),
@ -69,6 +71,7 @@ impl<A, C> AbsoluteNumber<A, C> {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Settings { pub struct Settings {
pub voter: Voter,
pub num_attestations: usize, pub num_attestations: usize,
} }
@ -92,9 +95,11 @@ impl CertificateStrategy for AbsoluteNumber<Attestation, Certificate> {
} }
} }
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub type Voter = [u8; 32];
#[derive(Debug, Clone, Serialize, Deserialize, Eq, Hash, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Blob { pub struct Blob {
data: Bytes, data: Bytes,
} }
@ -120,7 +125,7 @@ impl blob::Blob for Blob {
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] #[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
pub struct Attestation { pub struct Attestation {
blob: [u8; 32], blob: [u8; 32],
voter: [u8; 32], voter: Voter,
} }
impl attestation::Attestation for Attestation { impl attestation::Attestation for Attestation {
@ -188,7 +193,10 @@ impl DaProtocol for FullReplication<AbsoluteNumber<Attestation, Certificate>> {
type Settings = Settings; type Settings = Settings;
fn new(settings: Self::Settings) -> Self { 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> { fn encode<T: AsRef<[u8]>>(&self, data: T) -> Vec<Self::Blob> {
@ -208,8 +216,7 @@ impl DaProtocol for FullReplication<AbsoluteNumber<Attestation, Certificate>> {
fn attest(&self, blob: &Self::Blob) -> Self::Attestation { fn attest(&self, blob: &Self::Blob) -> Self::Attestation {
Attestation { Attestation {
blob: hasher(blob), blob: hasher(blob),
// TODO: voter id? voter: self.voter,
voter: [0; 32],
} }
} }

View File

@ -256,7 +256,7 @@ fn create_node_configs(
fn create_node_config( fn create_node_config(
nodes: Vec<NodeId>, nodes: Vec<NodeId>,
private_key: [u8; 32], id: [u8; 32],
threshold: Fraction, threshold: Fraction,
timeout: Duration, timeout: Duration,
mixnet_node_config: Option<MixnetNodeConfig>, mixnet_node_config: Option<MixnetNodeConfig>,
@ -285,7 +285,7 @@ fn create_node_config(
}, },
}, },
consensus: CarnotSettings { consensus: CarnotSettings {
private_key, private_key: id,
overlay_settings: TreeOverlaySettings { overlay_settings: TreeOverlaySettings {
nodes, nodes,
leader: RoundRobin::new(), leader: RoundRobin::new(),
@ -314,6 +314,7 @@ fn create_node_config(
metrics: Default::default(), metrics: Default::default(),
da: nomos_da::Settings { da: nomos_da::Settings {
da_protocol: full_replication::Settings { da_protocol: full_replication::Settings {
voter: id,
num_attestations: 1, num_attestations: 1,
}, },
backend: nomos_da::backend::memory_cache::BlobCacheSettings { backend: nomos_da::backend::memory_cache::BlobCacheSettings {

View File

@ -28,6 +28,7 @@ async fn disseminate_blob() {
da_protocol: Protocol::FullReplication, da_protocol: Protocol::FullReplication,
settings: ProtocolSettings { settings: ProtocolSettings {
full_replication: FullReplicationSettings { full_replication: FullReplicationSettings {
voter: [0; 32],
num_attestations: 1, num_attestations: 1,
}, },
}, },