This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bootstrapping task-manager through feature flags (#266)
Signed-off-by: Simon Paitrault <[email protected]> Co-authored-by: Simon Paitrault <[email protected]>
- Loading branch information
Showing
16 changed files
with
583 additions
and
820 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
use std::collections::HashSet; | ||
use tce_transport::{ProtocolEvents, ReliableBroadcastParams}; | ||
use tokio::sync::mpsc::Receiver; | ||
use tokio::sync::{mpsc, oneshot}; | ||
use topos_tce_broadcast::double_echo::DoubleEcho; | ||
use topos_tce_broadcast::sampler::SubscriptionsView; | ||
use topos_test_sdk::certificates::create_certificate_chain; | ||
use topos_test_sdk::constants::{SOURCE_SUBNET_ID_1, TARGET_SUBNET_ID_1}; | ||
|
||
const CHANNEL_SIZE: usize = 256_000; | ||
|
||
struct TceParams { | ||
nb_peers: usize, | ||
broadcast_params: ReliableBroadcastParams, | ||
} | ||
|
||
struct Context { | ||
event_receiver: Receiver<ProtocolEvents>, | ||
} | ||
|
||
pub async fn processing_double_echo(n: u64) { | ||
let (subscriptions_view_sender, subscriptions_view_receiver) = mpsc::channel(CHANNEL_SIZE); | ||
|
||
let (_cmd_sender, cmd_receiver) = mpsc::channel(CHANNEL_SIZE); | ||
let (event_sender, event_receiver) = mpsc::channel(CHANNEL_SIZE); | ||
let (_double_echo_shutdown_sender, double_echo_shutdown_receiver) = | ||
mpsc::channel::<oneshot::Sender<()>>(1); | ||
let (task_manager_message_sender, task_manager_message_receiver) = mpsc::channel(CHANNEL_SIZE); | ||
|
||
let params = TceParams { | ||
nb_peers: 10, | ||
broadcast_params: ReliableBroadcastParams { | ||
echo_threshold: 8, | ||
ready_threshold: 5, | ||
delivery_threshold: 8, | ||
}, | ||
}; | ||
|
||
let mut ctx = Context { event_receiver }; | ||
|
||
let mut double_echo = DoubleEcho::new( | ||
params.broadcast_params, | ||
task_manager_message_sender.clone(), | ||
cmd_receiver, | ||
event_sender, | ||
double_echo_shutdown_receiver, | ||
0, | ||
); | ||
|
||
// List of peers | ||
let mut peers = HashSet::new(); | ||
for i in 0..params.nb_peers { | ||
let peer = topos_p2p::utils::local_key_pair(Some(i as u8)) | ||
.public() | ||
.to_peer_id(); | ||
peers.insert(peer); | ||
} | ||
|
||
// Subscriptions | ||
double_echo.subscriptions.echo = peers.clone(); | ||
double_echo.subscriptions.ready = peers.clone(); | ||
double_echo.subscriptions.network_size = params.nb_peers; | ||
|
||
let msg = SubscriptionsView { | ||
echo: peers.clone(), | ||
ready: peers.clone(), | ||
network_size: params.nb_peers, | ||
}; | ||
|
||
subscriptions_view_sender.send(msg).await.unwrap(); | ||
|
||
double_echo.spawn_task_manager(subscriptions_view_receiver, task_manager_message_receiver); | ||
|
||
let certificates = | ||
create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], n as usize); | ||
|
||
let double_echo_selected_echo = double_echo | ||
.subscriptions | ||
.echo | ||
.iter() | ||
.take(double_echo.params.echo_threshold) | ||
.cloned() | ||
.collect::<Vec<_>>(); | ||
|
||
let double_echo_selected_ready = double_echo | ||
.subscriptions | ||
.ready | ||
.iter() | ||
.take(double_echo.params.delivery_threshold) | ||
.cloned() | ||
.collect::<Vec<_>>(); | ||
|
||
for cert in &certificates { | ||
double_echo.broadcast(cert.clone(), true).await; | ||
} | ||
|
||
for cert in &certificates { | ||
for p in &double_echo_selected_echo { | ||
double_echo.handle_echo(*p, cert.id).await; | ||
} | ||
|
||
for p in &double_echo_selected_ready { | ||
double_echo.handle_ready(*p, cert.id).await; | ||
} | ||
} | ||
|
||
let mut count = 0; | ||
|
||
while let Some(event) = ctx.event_receiver.recv().await { | ||
if let ProtocolEvents::CertificateDelivered { .. } = event { | ||
count += 1; | ||
|
||
if count == n { | ||
break; | ||
} | ||
} | ||
} | ||
} |
61 changes: 0 additions & 61 deletions
61
crates/topos-tce-broadcast/benches/task_manager_channels.rs
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
crates/topos-tce-broadcast/benches/task_manager_futures.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.