mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Spawn the task to select validators to dial
This commit is contained in:
@@ -28,13 +28,19 @@ const TARGET_PEERS_PER_NETWORK: usize = 5;
|
|||||||
*/
|
*/
|
||||||
// TODO const TARGET_DIALED_PEERS_PER_NETWORK: usize = 3;
|
// TODO const TARGET_DIALED_PEERS_PER_NETWORK: usize = 3;
|
||||||
|
|
||||||
struct DialTask {
|
pub(crate) struct DialTask {
|
||||||
serai: Serai,
|
serai: Serai,
|
||||||
validators: Validators,
|
validators: Validators,
|
||||||
peers: Peers,
|
peers: Peers,
|
||||||
to_dial: mpsc::UnboundedSender<DialOpts>,
|
to_dial: mpsc::UnboundedSender<DialOpts>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DialTask {
|
||||||
|
pub(crate) fn new(serai: Serai, peers: Peers, to_dial: mpsc::UnboundedSender<DialOpts>) -> Self {
|
||||||
|
DialTask { serai: serai.clone(), validators: Validators::new(serai), peers, to_dial }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ContinuallyRan for DialTask {
|
impl ContinuallyRan for DialTask {
|
||||||
// Only run every five minutes, not the default of every five seconds
|
// Only run every five minutes, not the default of every five seconds
|
||||||
const DELAY_BETWEEN_ITERATIONS: u64 = 5 * 60;
|
const DELAY_BETWEEN_ITERATIONS: u64 = 5 * 60;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use serai_client::{
|
|||||||
|
|
||||||
use tokio::sync::{mpsc, RwLock};
|
use tokio::sync::{mpsc, RwLock};
|
||||||
|
|
||||||
use serai_task::Task;
|
use serai_task::{Task, ContinuallyRan};
|
||||||
|
|
||||||
use libp2p::{
|
use libp2p::{
|
||||||
multihash::Multihash,
|
multihash::Multihash,
|
||||||
@@ -26,7 +26,7 @@ use libp2p::{
|
|||||||
|
|
||||||
/// A struct to sync the validators from the Serai node in order to keep track of them.
|
/// A struct to sync the validators from the Serai node in order to keep track of them.
|
||||||
mod validators;
|
mod validators;
|
||||||
use validators::{Validators, UpdateValidatorsTask};
|
use validators::UpdateValidatorsTask;
|
||||||
|
|
||||||
/// The authentication protocol upgrade to limit the P2P network to active validators.
|
/// The authentication protocol upgrade to limit the P2P network to active validators.
|
||||||
mod authenticate;
|
mod authenticate;
|
||||||
@@ -34,6 +34,7 @@ use authenticate::OnlyValidators;
|
|||||||
|
|
||||||
/// The dial task, to find new peers to connect to
|
/// The dial task, to find new peers to connect to
|
||||||
mod dial;
|
mod dial;
|
||||||
|
use dial::DialTask;
|
||||||
|
|
||||||
/// The request-response messages and behavior
|
/// The request-response messages and behavior
|
||||||
mod reqres;
|
mod reqres;
|
||||||
@@ -105,7 +106,10 @@ pub(crate) fn new(serai_key: &Zeroizing<Keypair>, serai: Serai) -> P2p {
|
|||||||
// Define the dial task
|
// Define the dial task
|
||||||
let (dial_task_def, dial_task) = Task::new();
|
let (dial_task_def, dial_task) = Task::new();
|
||||||
let (to_dial_send, to_dial_recv) = mpsc::unbounded_channel();
|
let (to_dial_send, to_dial_recv) = mpsc::unbounded_channel();
|
||||||
todo!("TODO: Dial task");
|
tokio::spawn(
|
||||||
|
DialTask::new(serai.clone(), peers.clone(), to_dial_send)
|
||||||
|
.continually_run(dial_task_def, vec![]),
|
||||||
|
);
|
||||||
|
|
||||||
// Define the Validators object used for validating new connections
|
// Define the Validators object used for validating new connections
|
||||||
let connection_validators = UpdateValidatorsTask::spawn(serai.clone());
|
let connection_validators = UpdateValidatorsTask::spawn(serai.clone());
|
||||||
@@ -166,5 +170,7 @@ pub(crate) fn new(serai_key: &Zeroizing<Keypair>, serai: Serai) -> P2p {
|
|||||||
inbound_request_responses_recv,
|
inbound_request_responses_recv,
|
||||||
);
|
);
|
||||||
|
|
||||||
todo!("TODO")
|
// gossip_send, signed_cosigns_recv, tributary_gossip_recv, outbound_requests_send,
|
||||||
|
// heartbeat_requests_recv, notable_cosign_requests_recv, inbound_request_responses_send
|
||||||
|
todo!("TODO");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ pub(crate) struct Validators {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Validators {
|
impl Validators {
|
||||||
|
pub(crate) fn new(serai: Serai) -> Self {
|
||||||
|
Validators {
|
||||||
|
serai,
|
||||||
|
sessions: HashMap::new(),
|
||||||
|
by_network: HashMap::new(),
|
||||||
|
validators: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn session_changes(
|
async fn session_changes(
|
||||||
serai: impl Borrow<Serai>,
|
serai: impl Borrow<Serai>,
|
||||||
sessions: impl Borrow<HashMap<NetworkId, Session>>,
|
sessions: impl Borrow<HashMap<NetworkId, Session>>,
|
||||||
@@ -138,12 +147,7 @@ impl UpdateValidatorsTask {
|
|||||||
/// This returns a reference to the Validators it updates after spawning itself.
|
/// This returns a reference to the Validators it updates after spawning itself.
|
||||||
pub(crate) fn spawn(serai: Serai) -> Arc<RwLock<Validators>> {
|
pub(crate) fn spawn(serai: Serai) -> Arc<RwLock<Validators>> {
|
||||||
// The validators which will be updated
|
// The validators which will be updated
|
||||||
let validators = Arc::new(RwLock::new(Validators {
|
let validators = Arc::new(RwLock::new(Validators::new(serai)));
|
||||||
serai,
|
|
||||||
sessions: HashMap::new(),
|
|
||||||
by_network: HashMap::new(),
|
|
||||||
validators: HashMap::new(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Define the task
|
// Define the task
|
||||||
let (update_validators_task, update_validators_task_handle) = Task::new();
|
let (update_validators_task, update_validators_task_handle) = Task::new();
|
||||||
|
|||||||
Reference in New Issue
Block a user