Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
api!: remove size fields within routing::Config
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Nov 3, 2020
1 parent 686c248 commit 9dfb935
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ mod section;
/// More nodes might be added if requested by the upper layers.
/// This number also detemines when split happens - if both post-split sections would have at least
/// this number of nodes.
const RECOMMENDED_SECTION_SIZE: usize = 10;
pub const RECOMMENDED_SECTION_SIZE: usize = 10;

/// Number of elders per section.
const ELDER_SIZE: usize = 5;
pub const ELDER_SIZE: usize = 5;

/// Number of votes required to agree
/// with a strict majority (i.e. > 50%)
Expand Down
9 changes: 1 addition & 8 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::{
node::Node,
peer::Peer,
section::{EldersInfo, SectionProofChain},
TransportConfig, ELDER_SIZE, RECOMMENDED_SECTION_SIZE,
TransportConfig,
};
use bytes::Bytes;
use ed25519_dalek::{Keypair, PublicKey, Signature, Signer};
Expand All @@ -48,11 +48,6 @@ pub struct Config {
pub keypair: Option<Keypair>,
/// Configuration for the underlying network transport.
pub transport_config: TransportConfig,
/// Global network parameters. Must be identical for all nodes in the network.
/// The number of elders per section
pub elder_size: usize,
/// Recommended number of nodes in a section.
pub recommended_section_size: usize,
}

impl Default for Config {
Expand All @@ -61,8 +56,6 @@ impl Default for Config {
first: false,
keypair: None,
transport_config: TransportConfig::default(),
elder_size: ELDER_SIZE,
recommended_section_size: RECOMMENDED_SECTION_SIZE,
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ed25519_dalek::Keypair;
use futures::future;
use sn_routing::{
event::{Connected, Event},
EventStream, Routing,
EventStream, Routing, ELDER_SIZE,
};
use tokio::time;
use utils::*;
Expand Down Expand Up @@ -74,12 +74,7 @@ async fn test_node_bootstrapping() -> Result<()> {

#[tokio::test]
async fn test_section_bootstrapping() -> Result<()> {
let num_of_nodes = 7;
let (genesis_node, mut event_stream) = RoutingBuilder::new(None)
.elder_size(num_of_nodes)
.first()
.create()
.await?;
let (genesis_node, mut event_stream) = RoutingBuilder::new(None).first().create().await?;

// spawn genesis node events listener
let genesis_handler = tokio::spawn(async move {
Expand All @@ -94,7 +89,7 @@ async fn test_section_bootstrapping() -> Result<()> {
_other => {}
}

if joined_nodes.len() == num_of_nodes {
if joined_nodes.len() == ELDER_SIZE {
break;
}
}
Expand All @@ -104,8 +99,8 @@ async fn test_section_bootstrapping() -> Result<()> {

// bootstrap several nodes with genesis to form a section
let genesis_contact = genesis_node.our_connection_info()?;
let mut nodes_joining_tasks = Vec::with_capacity(num_of_nodes);
for _ in 0..num_of_nodes {
let mut nodes_joining_tasks = Vec::with_capacity(ELDER_SIZE);
for _ in 0..ELDER_SIZE {
nodes_joining_tasks.push(async {
let (node, mut event_stream) = RoutingBuilder::new(None)
.with_contact(genesis_contact)
Expand All @@ -131,7 +126,7 @@ async fn test_section_bootstrapping() -> Result<()> {
let found = joined_nodes.iter().find(|n| **n == name);
assert!(found.is_some());

verify_invariants_for_node(&node, num_of_nodes).await?;
verify_invariants_for_node(&node, ELDER_SIZE).await?;
}

Ok(())
Expand Down
5 changes: 0 additions & 5 deletions tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ impl<'a> RoutingBuilder {
self
}

pub fn elder_size(mut self, size: usize) -> Self {
self.config.elder_size = size;
self
}

pub fn keypair(mut self, keypair: Keypair) -> Self {
self.config.keypair = Some(keypair);
self
Expand Down

0 comments on commit 9dfb935

Please sign in to comment.