Set voter to DA attestation (#498)
This commit is contained in:
parent
ba90ed1b55
commit
c3478cf6a6
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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<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),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<Voter, Box<dyn Error + Send + Sync + 'static>> {
|
||||
Ok(<[u8; 32]>::from_hex(s)?)
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ pub mod openapi {
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FullReplication<CertificateStrategy> {
|
||||
voter: Voter,
|
||||
certificate_strategy: CertificateStrategy,
|
||||
output_buffer: Vec<Bytes>,
|
||||
attestations: Vec<Attestation>,
|
||||
@ -31,8 +32,9 @@ pub struct FullReplication<CertificateStrategy> {
|
||||
}
|
||||
|
||||
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(),
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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)]
|
||||
#[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<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> {
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>,
|
||||
@ -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 {
|
||||
|
@ -28,6 +28,7 @@ async fn disseminate_blob() {
|
||||
da_protocol: Protocol::FullReplication,
|
||||
settings: ProtocolSettings {
|
||||
full_replication: FullReplicationSettings {
|
||||
voter: [0; 32],
|
||||
num_attestations: 1,
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user