add mixnet backed for cryptarchia consensus

This commit is contained in:
Youngjoon Lee 2024-03-15 17:54:01 +09:00
parent ca4f8f8ce3
commit 244d9d149f
No known key found for this signature in database
GPG Key ID: FC4855084E0B6A46
3 changed files with 15 additions and 10 deletions

View File

@ -36,6 +36,7 @@ serde_json = { version = "1", optional = true }
[features]
default = []
libp2p = ["nomos-network/libp2p", "nomos-libp2p"]
mixnet = ["nomos-network/mixnet", "nomos-libp2p"]
openapi = ["dep:utoipa", "serde_json"]
[dev-dependencies]

View File

@ -1,2 +1,2 @@
#[cfg(feature = "libp2p")]
pub mod libp2p;
#[cfg(any(feature = "libp2p", feature = "mixnet"))]
pub mod p2p;

View File

@ -7,8 +7,12 @@ use tokio_stream::{wrappers::BroadcastStream, StreamExt};
// internal
use crate::network::{messages::NetworkMessage, BoxedStream, NetworkAdapter};
use nomos_core::{block::Block, wire};
#[cfg(feature = "libp2p")]
use nomos_network::backends::libp2p::Libp2p as Backend;
#[cfg(feature = "mixnet")]
use nomos_network::backends::mixnet::MixnetNetworkBackend as Backend;
use nomos_network::{
backends::libp2p::{Command, Event, EventKind, Libp2p},
backends::libp2p::{Command, Event, EventKind},
NetworkMsg, NetworkService,
};
use overwatch_rs::services::{relay::OutboundRelay, ServiceData};
@ -18,21 +22,21 @@ const BUFFER_SIZE: usize = 64;
type Relay<T> = OutboundRelay<<NetworkService<T> as ServiceData>::Message>;
#[derive(Clone)]
pub struct LibP2pAdapter<Tx, BlobCert>
pub struct P2pAdapter<Tx, BlobCert>
where
Tx: Clone + Eq + Hash,
BlobCert: Clone + Eq + Hash,
{
network_relay: OutboundRelay<<NetworkService<Libp2p> as ServiceData>::Message>,
network_relay: OutboundRelay<<NetworkService<Backend> as ServiceData>::Message>,
blocks: tokio::sync::broadcast::Sender<Block<Tx, BlobCert>>,
}
impl<Tx, BlobCert> LibP2pAdapter<Tx, BlobCert>
impl<Tx, BlobCert> P2pAdapter<Tx, BlobCert>
where
Tx: Clone + Eq + Hash + Serialize,
BlobCert: Clone + Eq + Hash + Serialize,
{
async fn subscribe(relay: &Relay<Libp2p>, topic: &str) {
async fn subscribe(relay: &Relay<Backend>, topic: &str) {
if let Err((e, _)) = relay
.send(NetworkMsg::Process(Command::Subscribe(topic.into())))
.await
@ -43,16 +47,16 @@ where
}
#[async_trait::async_trait]
impl<Tx, BlobCert> NetworkAdapter for LibP2pAdapter<Tx, BlobCert>
impl<Tx, BlobCert> NetworkAdapter for P2pAdapter<Tx, BlobCert>
where
Tx: Serialize + DeserializeOwned + Clone + Eq + Hash + Send + 'static,
BlobCert: Serialize + DeserializeOwned + Clone + Eq + Hash + Send + 'static,
{
type Backend = Libp2p;
type Backend = Backend;
type Tx = Tx;
type BlobCertificate = BlobCert;
async fn new(network_relay: Relay<Libp2p>) -> Self {
async fn new(network_relay: Relay<Self::Backend>) -> Self {
let relay = network_relay.clone();
Self::subscribe(&relay, TOPIC).await;
let blocks = tokio::sync::broadcast::Sender::new(BUFFER_SIZE);