mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 04:09:23 +00:00
Define an array of all NetworkIds in serai_primitives
This commit is contained in:
@@ -987,7 +987,10 @@ pub async fn handle_processors<D: Db, Pro: Processors, P: P2p>(
|
|||||||
mut new_tributary: broadcast::Receiver<ActiveTributary<D, P>>,
|
mut new_tributary: broadcast::Receiver<ActiveTributary<D, P>>,
|
||||||
) {
|
) {
|
||||||
let mut channels = HashMap::new();
|
let mut channels = HashMap::new();
|
||||||
for network in [NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero] {
|
for network in serai_client::primitives::NETWORKS {
|
||||||
|
if network == NetworkId::Serai {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let (send, recv) = mpsc::unbounded_channel();
|
let (send, recv) = mpsc::unbounded_channel();
|
||||||
tokio::spawn(handle_processor_messages(
|
tokio::spawn(handle_processor_messages(
|
||||||
db.clone(),
|
db.clone(),
|
||||||
|
|||||||
@@ -183,14 +183,14 @@ async fn main() {
|
|||||||
Some(<Ristretto as Ciphersuite>::G::from_bytes(&repr).unwrap())
|
Some(<Ristretto as Ciphersuite>::G::from_bytes(&repr).unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
const ALL_EXT_NETWORKS: [NetworkId; 3] =
|
|
||||||
[NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero];
|
|
||||||
|
|
||||||
let register_service = |service, key| {
|
let register_service = |service, key| {
|
||||||
(*KEYS).write().unwrap().insert(service, key);
|
(*KEYS).write().unwrap().insert(service, key);
|
||||||
let mut queues = (*QUEUES).write().unwrap();
|
let mut queues = (*QUEUES).write().unwrap();
|
||||||
if service == Service::Coordinator {
|
if service == Service::Coordinator {
|
||||||
for network in ALL_EXT_NETWORKS {
|
for network in serai_primitives::NETWORKS {
|
||||||
|
if network == NetworkId::Serai {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
queues.insert(
|
queues.insert(
|
||||||
(service, Service::Processor(network)),
|
(service, Service::Processor(network)),
|
||||||
RwLock::new(Queue(db.clone(), service, Service::Processor(network))),
|
RwLock::new(Queue(db.clone(), service, Service::Processor(network))),
|
||||||
@@ -205,7 +205,10 @@ async fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Make queues for each NetworkId, other than Serai
|
// Make queues for each NetworkId, other than Serai
|
||||||
for network in ALL_EXT_NETWORKS {
|
for network in serai_primitives::NETWORKS {
|
||||||
|
if network == NetworkId::Serai {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// Use a match so we error if the list of NetworkIds changes
|
// Use a match so we error if the list of NetworkIds changes
|
||||||
let Some(key) = read_key(match network {
|
let Some(key) = read_key(match network {
|
||||||
NetworkId::Serai => unreachable!(),
|
NetworkId::Serai => unreachable!(),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use rand_core::{RngCore, OsRng};
|
|||||||
use sp_core::{sr25519::Public, Pair};
|
use sp_core::{sr25519::Public, Pair};
|
||||||
|
|
||||||
use serai_client::{
|
use serai_client::{
|
||||||
primitives::{NetworkId, insecure_pair_from_name},
|
primitives::{NETWORKS, NetworkId, insecure_pair_from_name},
|
||||||
validator_sets::{
|
validator_sets::{
|
||||||
primitives::{Session, ValidatorSet, musig_key},
|
primitives::{Session, ValidatorSet, musig_key},
|
||||||
ValidatorSetsEvent,
|
ValidatorSetsEvent,
|
||||||
@@ -38,7 +38,7 @@ serai_test!(
|
|||||||
.get_new_set_events(serai.get_block_by_number(0).await.unwrap().unwrap().hash())
|
.get_new_set_events(serai.get_block_by_number(0).await.unwrap().unwrap().hash())
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
[NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero]
|
NETWORKS
|
||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.map(|network| ValidatorSetsEvent::NewSet {
|
.map(|network| ValidatorSetsEvent::NewSet {
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ fn testnet_genesis(
|
|||||||
|
|
||||||
validator_sets: ValidatorSetsConfig {
|
validator_sets: ValidatorSetsConfig {
|
||||||
stake: Amount(1_000_000 * 10_u64.pow(8)),
|
stake: Amount(1_000_000 * 10_u64.pow(8)),
|
||||||
// TODO: Array of these in primitives
|
networks: serai_runtime::primitives::NETWORKS.to_vec(),
|
||||||
networks: vec![NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero],
|
|
||||||
participants: validators.iter().map(|name| account_from_name(name)).collect(),
|
participants: validators.iter().map(|name| account_from_name(name)).collect(),
|
||||||
},
|
},
|
||||||
session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() },
|
session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() },
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ pub enum NetworkId {
|
|||||||
Monero,
|
Monero,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const NETWORKS: [NetworkId; 4] =
|
||||||
|
[NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero];
|
||||||
|
|
||||||
/// The type used to identify coins.
|
/// The type used to identify coins.
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone,
|
Clone,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// Every participant at genesis will automatically be assumed to have this much stake.
|
/// Every participant at genesis will automatically be assumed to have this much stake.
|
||||||
/// This stake cannot be withdrawn however as there's no actual stake behind it.
|
/// This stake cannot be withdrawn however as there's no actual stake behind it.
|
||||||
// TODO: Localize stake to network?
|
// TODO: Localize stake to network
|
||||||
pub stake: Amount,
|
pub stake: Amount,
|
||||||
/// Networks to spawn Serai with.
|
/// Networks to spawn Serai with.
|
||||||
pub networks: Vec<NetworkId>,
|
pub networks: Vec<NetworkId>,
|
||||||
@@ -572,9 +572,7 @@ pub mod pallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_session() {
|
pub fn new_session() {
|
||||||
// TODO: Define an array of all networks in primitives
|
for network in serai_primitives::NETWORKS {
|
||||||
let networks = [NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero];
|
|
||||||
for network in networks {
|
|
||||||
let current_session = Self::session(network);
|
let current_session = Self::session(network);
|
||||||
// Only spawn a NewSet if the current set was actually established with a completed
|
// Only spawn a NewSet if the current set was actually established with a completed
|
||||||
// handover protocol
|
// handover protocol
|
||||||
|
|||||||
Reference in New Issue
Block a user