Skip to content

Commit

Permalink
Define an array of all NetworkIds in serai_primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Oct 13, 2023
1 parent b7746aa commit 6a4c57e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
5 changes: 4 additions & 1 deletion coordinator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,10 @@ pub async fn handle_processors<D: Db, Pro: Processors, P: P2p>(
mut new_tributary: broadcast::Receiver<ActiveTributary<D, P>>,
) {
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();
tokio::spawn(handle_processor_messages(
db.clone(),
Expand Down
13 changes: 8 additions & 5 deletions message-queue/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ async fn main() {
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| {
(*KEYS).write().unwrap().insert(service, key);
let mut queues = (*QUEUES).write().unwrap();
if service == Service::Coordinator {
for network in ALL_EXT_NETWORKS {
for network in serai_primitives::NETWORKS {
if network == NetworkId::Serai {
continue;
}
queues.insert(
(service, Service::Processor(network)),
RwLock::new(Queue(db.clone(), service, Service::Processor(network))),
Expand All @@ -205,7 +205,10 @@ async fn main() {
};

// 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
let Some(key) = read_key(match network {
NetworkId::Serai => unreachable!(),
Expand Down
4 changes: 2 additions & 2 deletions substrate/client/tests/validator_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rand_core::{RngCore, OsRng};
use sp_core::{sr25519::Public, Pair};

use serai_client::{
primitives::{NetworkId, insecure_pair_from_name},
primitives::{NETWORKS, NetworkId, insecure_pair_from_name},
validator_sets::{
primitives::{Session, ValidatorSet, musig_key},
ValidatorSetsEvent,
Expand Down Expand Up @@ -38,7 +38,7 @@ serai_test!(
.get_new_set_events(serai.get_block_by_number(0).await.unwrap().unwrap().hash())
.await
.unwrap(),
[NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero]
NETWORKS
.iter()
.copied()
.map(|network| ValidatorSetsEvent::NewSet {
Expand Down
3 changes: 1 addition & 2 deletions substrate/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ fn testnet_genesis(

validator_sets: ValidatorSetsConfig {
stake: Amount(1_000_000 * 10_u64.pow(8)),
// TODO: Array of these in primitives
networks: vec![NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero],
networks: serai_runtime::primitives::NETWORKS.to_vec(),
participants: validators.iter().map(|name| account_from_name(name)).collect(),
},
session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() },
Expand Down
3 changes: 3 additions & 0 deletions substrate/primitives/src/networks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub enum NetworkId {
Monero,
}

pub const NETWORKS: [NetworkId; 4] =
[NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero];

/// The type used to identify coins.
#[derive(
Clone,
Expand Down
6 changes: 2 additions & 4 deletions substrate/validator-sets/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod pallet {
///
/// 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.
// TODO: Localize stake to network?
// TODO: Localize stake to network
pub stake: Amount,
/// Networks to spawn Serai with.
pub networks: Vec<NetworkId>,
Expand Down Expand Up @@ -572,9 +572,7 @@ pub mod pallet {
}

pub fn new_session() {
// TODO: Define an array of all networks in primitives
let networks = [NetworkId::Serai, NetworkId::Bitcoin, NetworkId::Ethereum, NetworkId::Monero];
for network in networks {
for network in serai_primitives::NETWORKS {
let current_session = Self::session(network);
// Only spawn a NewSet if the current set was actually established with a completed
// handover protocol
Expand Down

0 comments on commit 6a4c57e

Please sign in to comment.