mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-03 21:53:09 +00:00
Merge branch 'more-regions' into track-msg-delay-script
This commit is contained in:
commit
0a34168bb0
7
.github/workflows/ci.yaml
vendored
7
.github/workflows/ci.yaml
vendored
@ -20,7 +20,6 @@ jobs:
|
||||
- name: Build
|
||||
working-directory: simlib
|
||||
run: cargo build -v
|
||||
# TODO: uncomment this after fixing tests
|
||||
# - name: Unit tests
|
||||
# working-directory: simlib
|
||||
# run: cargo test -v
|
||||
- name: Unit tests
|
||||
working-directory: simlib
|
||||
run: cargo test -v
|
||||
|
||||
@ -1,26 +1,86 @@
|
||||
{
|
||||
"network_settings": {
|
||||
"network_behaviors": {
|
||||
"north america:north america": "50ms",
|
||||
"north america:europe": "100ms",
|
||||
"north america:asia": "120ms",
|
||||
"north america west:north america west": "40ms",
|
||||
"north america west:north america east": "70ms",
|
||||
"north america west:north america central": "50ms",
|
||||
"north america west:europe": "150ms",
|
||||
"north america west:northern europe": "170ms",
|
||||
"north america west:east asia": "180ms",
|
||||
"north america west:southeast asia": "200ms",
|
||||
"north america west:australia": "250ms",
|
||||
"north america east:north america west": "70ms",
|
||||
"north america east:north america east": "40ms",
|
||||
"north america east:north america central": "50ms",
|
||||
"north america east:europe": "130ms",
|
||||
"north america east:northern europe": "140ms",
|
||||
"north america east:east asia": "250ms",
|
||||
"north america east:southeast asia": "300ms",
|
||||
"north america east:australia": "230ms",
|
||||
"north america central:north america west": "50ms",
|
||||
"north america central:north america east": "50ms",
|
||||
"north america central:north america central": "20ms",
|
||||
"north america central:europe": "140ms",
|
||||
"north america central:northern europe": "150ms",
|
||||
"north america central:east asia": "200ms",
|
||||
"north america central:southeast asia": "280ms",
|
||||
"north america central:australia": "220ms",
|
||||
"europe:north america west": "150ms",
|
||||
"europe:north america east": "130ms",
|
||||
"europe:north america central": "140ms",
|
||||
"europe:europe": "50ms",
|
||||
"europe:asia": "100ms",
|
||||
"europe:north america": "120ms",
|
||||
"asia:north america": "100ms",
|
||||
"asia:europe": "120ms",
|
||||
"asia:asia": "40ms"
|
||||
"europe:northern europe": "60ms",
|
||||
"europe:east asia": "300ms",
|
||||
"europe:southeast asia": "300ms",
|
||||
"europe:australia": "300ms",
|
||||
"northern europe:north america west": "170ms",
|
||||
"northern europe:north america east": "140ms",
|
||||
"northern europe:north america central": "150ms",
|
||||
"northern europe:europe": "60ms",
|
||||
"northern europe:northern europe": "30ms",
|
||||
"northern europe:east asia": "400ms",
|
||||
"northern europe:southeast asia": "320ms",
|
||||
"northern europe:australia": "300ms",
|
||||
"east asia:north america west": "180ms",
|
||||
"east asia:north america east": "250ms",
|
||||
"east asia:north america central": "200ms",
|
||||
"east asia:europe": "300ms",
|
||||
"east asia:northern europe": "400ms",
|
||||
"east asia:east asia": "50ms",
|
||||
"east asia:southeast asia": "90ms",
|
||||
"east asia:australia": "150ms",
|
||||
"southeast asia:north america west": "200ms",
|
||||
"southeast asia:north america east": "300ms",
|
||||
"southeast asia:north america central": "280ms",
|
||||
"southeast asia:europe": "300ms",
|
||||
"southeast asia:northern europe": "320ms",
|
||||
"southeast asia:east asia": "90ms",
|
||||
"southeast asia:southeast asia": "40ms",
|
||||
"southeast asia:australia": "150ms",
|
||||
"australia:north america west": "250ms",
|
||||
"australia:north america east": "230ms",
|
||||
"australia:north america central": "220ms",
|
||||
"australia:europe": "300ms",
|
||||
"australia:northern europe": "300ms",
|
||||
"australia:east asia": "150ms",
|
||||
"australia:southeast asia": "150ms",
|
||||
"australia:australia": "50ms"
|
||||
},
|
||||
"regions": {
|
||||
"north america": 0.4,
|
||||
"europe": 0.4,
|
||||
"asia": 0.3
|
||||
"north america west": 0.06,
|
||||
"north america east": 0.15,
|
||||
"north america central": 0.02,
|
||||
"europe": 0.47,
|
||||
"northern europe": 0.10,
|
||||
"east asia": 0.10,
|
||||
"southeast asia": 0.07,
|
||||
"australia": 0.03
|
||||
}
|
||||
},
|
||||
"node_settings": {
|
||||
"timeout": "1000ms"
|
||||
},
|
||||
"step_time": "40ms",
|
||||
"step_time": "20ms",
|
||||
"runner_settings": "Sync",
|
||||
"stream_settings": {
|
||||
"path": "test.json"
|
||||
|
||||
@ -524,7 +524,7 @@ mod tests {
|
||||
|
||||
impl PayloadSize for () {
|
||||
fn size_bytes(&self) -> u32 {
|
||||
todo!()
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@ -618,16 +618,16 @@ mod tests {
|
||||
let node_c = NodeId::from_index(2);
|
||||
|
||||
let regions = HashMap::from([
|
||||
(Region::Asia, vec![node_a, node_b]),
|
||||
(Region::EastAsia, vec![node_a, node_b]),
|
||||
(Region::Europe, vec![node_c]),
|
||||
]);
|
||||
let behaviour = HashMap::from([
|
||||
(
|
||||
NetworkBehaviourKey::new(Region::Asia, Region::Asia),
|
||||
NetworkBehaviourKey::new(Region::EastAsia, Region::EastAsia),
|
||||
NetworkBehaviour::new(Duration::from_millis(100), 0.0),
|
||||
),
|
||||
(
|
||||
NetworkBehaviourKey::new(Region::Asia, Region::Europe),
|
||||
NetworkBehaviourKey::new(Region::EastAsia, Region::Europe),
|
||||
NetworkBehaviour::new(Duration::from_millis(500), 0.0),
|
||||
),
|
||||
(
|
||||
|
||||
@ -10,9 +10,13 @@ use super::{NetworkBehaviourKey, NetworkSettings};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum Region {
|
||||
NorthAmerica,
|
||||
NorthAmericaWest,
|
||||
NorthAmericaCentral,
|
||||
NorthAmericaEast,
|
||||
Europe,
|
||||
Asia,
|
||||
NorthernEurope,
|
||||
EastAsia,
|
||||
SoutheastAsia,
|
||||
Africa,
|
||||
SouthAmerica,
|
||||
Australia,
|
||||
@ -21,9 +25,13 @@ pub enum Region {
|
||||
impl core::fmt::Display for Region {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let s = match self {
|
||||
Self::NorthAmerica => "NorthAmerica",
|
||||
Self::NorthAmericaWest => "NorthAmericaWest",
|
||||
Self::NorthAmericaCentral => "NorthAmericaCentral",
|
||||
Self::NorthAmericaEast => "NorthAmericaEast",
|
||||
Self::Europe => "Europe",
|
||||
Self::Asia => "Asia",
|
||||
Self::NorthernEurope => "NorthernEurope",
|
||||
Self::EastAsia => "EastAsia",
|
||||
Self::SoutheastAsia => "SoutheastAsia",
|
||||
Self::Africa => "Africa",
|
||||
Self::SouthAmerica => "SouthAmerica",
|
||||
Self::Australia => "Australia",
|
||||
@ -42,9 +50,13 @@ impl FromStr for Region {
|
||||
.replace(['-', '_', ' '], "")
|
||||
.as_str()
|
||||
{
|
||||
"northamerica" | "na" => Ok(Self::NorthAmerica),
|
||||
"northamericawest" | "naw" => Ok(Self::NorthAmericaWest),
|
||||
"northamericacentral" | "nac" => Ok(Self::NorthAmericaCentral),
|
||||
"northamericaeast" | "nae" => Ok(Self::NorthAmericaEast),
|
||||
"europe" | "eu" => Ok(Self::Europe),
|
||||
"asia" | "as" => Ok(Self::Asia),
|
||||
"northerneurope" | "neu" => Ok(Self::NorthernEurope),
|
||||
"eastasia" | "eas" => Ok(Self::EastAsia),
|
||||
"southeastasia" | "seas" => Ok(Self::SoutheastAsia),
|
||||
"africa" | "af" => Ok(Self::Africa),
|
||||
"southamerica" | "sa" => Ok(Self::SouthAmerica),
|
||||
"australia" | "au" => Ok(Self::Australia),
|
||||
@ -56,9 +68,13 @@ impl FromStr for Region {
|
||||
impl Serialize for Region {
|
||||
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
let s = match self {
|
||||
Self::NorthAmerica => "North America",
|
||||
Self::NorthAmericaWest => "North America West",
|
||||
Self::NorthAmericaCentral => "North America Central",
|
||||
Self::NorthAmericaEast => "North America East",
|
||||
Self::Europe => "Europe",
|
||||
Self::Asia => "Asia",
|
||||
Self::NorthernEurope => "Northern Europe",
|
||||
Self::EastAsia => "EastAsia",
|
||||
Self::SoutheastAsia => "Southeast Asia",
|
||||
Self::Africa => "Africa",
|
||||
Self::SouthAmerica => "South America",
|
||||
Self::Australia => "Australia",
|
||||
@ -156,7 +172,6 @@ pub fn create_regions<R: Rng>(
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use consensus_engine::NodeId;
|
||||
use rand::rngs::mock::StepRng;
|
||||
|
||||
use crate::{
|
||||
@ -164,7 +179,7 @@ mod tests {
|
||||
regions::{create_regions, Region},
|
||||
NetworkSettings,
|
||||
},
|
||||
node::NodeIdExt,
|
||||
node::{NodeId, NodeIdExt},
|
||||
};
|
||||
|
||||
#[test]
|
||||
@ -208,9 +223,13 @@ mod tests {
|
||||
.collect::<Vec<NodeId>>();
|
||||
|
||||
let available_regions = [
|
||||
Region::NorthAmerica,
|
||||
Region::NorthAmericaWest,
|
||||
Region::NorthAmericaCentral,
|
||||
Region::NorthAmericaEast,
|
||||
Region::Europe,
|
||||
Region::Asia,
|
||||
Region::NorthernEurope,
|
||||
Region::EastAsia,
|
||||
Region::SoutheastAsia,
|
||||
Region::Africa,
|
||||
Region::SouthAmerica,
|
||||
Region::Australia,
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::warding::WardCondition;
|
||||
|
||||
use super::{Node, NodeId};
|
||||
|
||||
#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)]
|
||||
@ -40,6 +42,16 @@ impl<S> Node for DummyStreamingNode<S> {
|
||||
}
|
||||
|
||||
fn step(&mut self, _: Duration) {
|
||||
todo!()
|
||||
self.state.counter += 1;
|
||||
}
|
||||
|
||||
fn analyze(&self, ward: &mut crate::warding::WardCondition) -> bool {
|
||||
match ward {
|
||||
WardCondition::Max(ward) => self.state.counter >= ward.max_count,
|
||||
WardCondition::Sum(condition) => {
|
||||
*condition.step_result.borrow_mut() += self.state.counter;
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,8 +163,14 @@ impl Node for usize {
|
||||
self.add_assign(1);
|
||||
}
|
||||
|
||||
fn analyze(&self, _: &mut WardCondition) -> bool {
|
||||
todo!()
|
||||
fn analyze(&self, ward: &mut WardCondition) -> bool {
|
||||
match ward {
|
||||
WardCondition::Max(ward) => *self >= ward.max_count,
|
||||
WardCondition::Sum(condition) => {
|
||||
*condition.step_result.borrow_mut() += *self;
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -114,11 +114,9 @@ where
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use consensus_engine::View;
|
||||
|
||||
use crate::{
|
||||
network::{
|
||||
behaviour::NetworkBehaviour,
|
||||
@ -135,12 +133,13 @@ mod tests {
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct IORecord {
|
||||
states: HashMap<NodeId, View>,
|
||||
struct IORecord<T> {
|
||||
states: HashMap<NodeId, T>,
|
||||
}
|
||||
|
||||
impl<S, T: Serialize> TryFrom<&SimulationState<S, T>> for IORecord {
|
||||
impl<S, T: Serialize + Clone> TryFrom<&SimulationState<S, T>> for IORecord<T> {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: &SimulationState<S, T>) -> Result<Self, Self::Error> {
|
||||
@ -148,7 +147,7 @@ mod tests {
|
||||
Ok(Self {
|
||||
states: nodes
|
||||
.iter()
|
||||
.map(|node| (node.id(), node.current_view()))
|
||||
.map(|node| (node.id(), node.state().clone()))
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
@ -175,43 +174,19 @@ mod tests {
|
||||
RegionsData {
|
||||
regions: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(region, vec![NodeId::from_index(idx)])
|
||||
})
|
||||
.collect(),
|
||||
node_region: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(NodeId::from_index(idx), region)
|
||||
})
|
||||
.collect(),
|
||||
region_network_behaviour: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(
|
||||
NetworkBehaviourKey::new(region, region),
|
||||
NetworkBehaviour {
|
||||
@ -232,4 +207,20 @@ mod tests {
|
||||
.stop_after(Duration::from_millis(100))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub(crate) fn region_from_index(idx: usize) -> Region {
|
||||
match idx % 10 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthernEurope,
|
||||
2 => Region::NorthAmericaWest,
|
||||
3 => Region::NorthAmericaCentral,
|
||||
4 => Region::NorthAmericaEast,
|
||||
5 => Region::SouthAmerica,
|
||||
6 => Region::EastAsia,
|
||||
7 => Region::SoutheastAsia,
|
||||
8 => Region::Africa,
|
||||
9 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,8 +103,6 @@ where
|
||||
mod tests {
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use consensus_engine::View;
|
||||
|
||||
use crate::{
|
||||
network::{
|
||||
behaviour::NetworkBehaviour,
|
||||
@ -117,16 +115,17 @@ mod tests {
|
||||
},
|
||||
output_processors::OutData,
|
||||
runner::SimulationRunner,
|
||||
streaming::io::tests::region_from_index,
|
||||
warding::SimulationState,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
struct RuntimeRecord {
|
||||
states: HashMap<NodeId, View>,
|
||||
struct RuntimeRecord<T> {
|
||||
states: HashMap<NodeId, T>,
|
||||
}
|
||||
|
||||
impl<S, T: Serialize> TryFrom<&SimulationState<S, T>> for RuntimeRecord {
|
||||
impl<S, T: Serialize + Clone> TryFrom<&SimulationState<S, T>> for RuntimeRecord<T> {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(value: &SimulationState<S, T>) -> Result<Self, Self::Error> {
|
||||
@ -135,7 +134,7 @@ mod tests {
|
||||
.nodes
|
||||
.read()
|
||||
.iter()
|
||||
.map(|node| (node.id(), node.current_view()))
|
||||
.map(|node| (node.id(), node.state().clone()))
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
@ -162,43 +161,19 @@ mod tests {
|
||||
RegionsData {
|
||||
regions: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(region, vec![NodeId::from_index(idx)])
|
||||
})
|
||||
.collect(),
|
||||
node_region: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(NodeId::from_index(idx), region)
|
||||
})
|
||||
.collect(),
|
||||
region_network_behaviour: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(
|
||||
NetworkBehaviourKey::new(region, region),
|
||||
NetworkBehaviour {
|
||||
|
||||
@ -102,9 +102,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashSet;
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
type View = usize;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::{
|
||||
network::{
|
||||
@ -118,6 +116,7 @@ mod tests {
|
||||
},
|
||||
output_processors::OutData,
|
||||
runner::SimulationRunner,
|
||||
streaming::io::tests::region_from_index,
|
||||
warding::SimulationState,
|
||||
};
|
||||
|
||||
@ -158,43 +157,19 @@ mod tests {
|
||||
RegionsData {
|
||||
regions: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(region, vec![NodeId::from_index(idx)])
|
||||
})
|
||||
.collect(),
|
||||
node_region: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(NodeId::from_index(idx), region)
|
||||
})
|
||||
.collect(),
|
||||
region_network_behaviour: (0..6)
|
||||
.map(|idx| {
|
||||
let region = match idx % 6 {
|
||||
0 => Region::Europe,
|
||||
1 => Region::NorthAmerica,
|
||||
2 => Region::SouthAmerica,
|
||||
3 => Region::Asia,
|
||||
4 => Region::Africa,
|
||||
5 => Region::Australia,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let region = region_from_index(idx);
|
||||
(
|
||||
NetworkBehaviourKey::new(region, region),
|
||||
NetworkBehaviour {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user