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

Commit

Permalink
feat(event): add separate genesis event
Browse files Browse the repository at this point in the history
  • Loading branch information
oetyng authored and joshuef committed Mar 22, 2021
1 parent 0718e0c commit 681d2c7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ rand_chacha = "~0.2.2"
thiserror = "1.0.23"
xor_name = "1.1.0"
resource_proof = "0.8.0"
sn_messaging = { git = "https://github.com/oetyng/sn_messaging", branch = "split-section-funds" }
sn_data_types = "~0.15.3"
sn_messaging = { git = "https://github.com/oetyng/sn_messaging", branch = "new-split-section-funds" }
sn_data_types = { git = "https://github.com/oetyng/sn_data_types", branch = "new-split-section-funds" }
# sn_data_types = "~0.15.3"

[dependencies.bls]
package = "threshold_crypto"
Expand Down
8 changes: 5 additions & 3 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ fn run_node(index: usize, mut node: Routing, mut event_stream: EventStream) -> J
// Handles the event emitted by the node.
async fn handle_event(index: usize, node: &mut Routing, event: Event) -> bool {
match event {
Event::Genesis => {
info!("Node #{} is Genesis", index);
}
Event::MemberJoined {
name,
previous_name,
Expand All @@ -239,14 +242,13 @@ async fn handle_event(index: usize, node: &mut Routing, event: Event) -> bool {
Event::EldersChanged {
prefix,
key,
previous_key,
sibling_key,
elders,
self_status_change,
} => {
info!(
"Node #{} elders changed - prefix: {:b}, key: {:?}, previous_key: {:?}, sibling key: {:?}, elders: {:?}, node elder status change: {:?}",
index, prefix, key, previous_key, sibling_key, elders, self_status_change
"Node #{} elders changed - prefix: {:b}, key: {:?}, sibling key: {:?}, elders: {:?}, node elder status change: {:?}",
index, prefix, key, sibling_key, elders, self_status_change
);
}
Event::MessageReceived { content, src, dst } => info!(
Expand Down
2 changes: 1 addition & 1 deletion examples/stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl Network {
let dst = match dst {
DstLocation::Section(name) => name,
DstLocation::Node(name) => name,
DstLocation::Direct | DstLocation::EndUser(_) => {
DstLocation::Direct | DstLocation::EndUser(_) | DstLocation::ElderPeers => {
return Err(format_err!("unexpected probe message dst: {:?}", dst))
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ pub enum NodeElderChange {
///
/// `Request` and `Response` events from section locations are only raised once the majority has
/// been reached, i.e. enough members of the section have sent the same message.
#[allow(clippy::large_enum_variant)]
pub enum Event {
/// This is the very first node in a network.
Genesis,
/// Received a message.
MessageReceived {
/// The content of the message.
Expand Down Expand Up @@ -70,8 +73,6 @@ pub enum Event {
prefix: Prefix,
/// The BLS public key of our section.
key: bls::PublicKey,
/// The previous BLS public key of our section.
previous_key: bls::PublicKey,
/// The BLS public key of the sibling section, if this event is fired during a split.
/// Otherwise `None`.
sibling_key: Option<bls::PublicKey>,
Expand Down Expand Up @@ -110,6 +111,7 @@ pub enum Event {
impl Debug for Event {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
match self {
Self::Genesis => write!(formatter, "Genesis"),
Self::MessageReceived { content, src, dst } => write!(
formatter,
"MessageReceived {{ content: \"{:<8}\", src: {:?}, dst: {:?} }}",
Expand All @@ -135,15 +137,13 @@ impl Debug for Event {
Self::EldersChanged {
prefix,
key,
previous_key,
sibling_key,
elders,
self_status_change,
} => formatter
.debug_struct("EldersChanged")
.field("prefix", prefix)
.field("key", key)
.field("previous_key", previous_key)
.field("sibling_key", sibling_key)
.field("elders", elders)
.field("self_status_change", self_status_change)
Expand Down
2 changes: 1 addition & 1 deletion src/routing/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,6 @@ impl Approved {
self.send_event(Event::EldersChanged {
prefix: new_prefix,
key: new_last_key,
previous_key: old_last_key,
sibling_key,
elders: self.section.elders_info().elders.keys().copied().collect(),
self_status_change,
Expand Down Expand Up @@ -2145,6 +2144,7 @@ impl Approved {
};
let mut commands = vec![];

// consider removing this, we are getting duplciate msgs by it
if itinerary
.dst
.contains(&self.node.name(), self.section.prefix())
Expand Down
17 changes: 5 additions & 12 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use self::{
use crate::{
crypto,
error::Result,
event::{Event, NodeElderChange},
event::Event,
messages::Message,
node::Node,
peer::Peer,
Expand Down Expand Up @@ -99,20 +99,13 @@ impl Routing {
let (connection_event_tx, mut connection_event_rx) = mpsc::channel(1);

let (state, comm, backlog) = if config.first {
info!("{} Starting a new network as the seed node.", node_name);
info!("{} Starting a new network as the genesis node.", node_name);
let comm = Comm::new(config.transport_config, connection_event_tx).await?;
let node = Node::new(keypair, comm.our_connection_info()).with_age(MIN_AGE + 1);
let state = Approved::first_node(node, event_tx)?;
let section = state.section();

state.send_event(Event::EldersChanged {
prefix: *section.prefix(),
key: *section.chain().last_key(),
previous_key: *section.chain().last_key(),
sibling_key: None,
elders: section.elders_info().elders.keys().copied().collect(),
self_status_change: NodeElderChange::Promoted,
});
//let section = state.section();

state.send_event(Event::Genesis);

(state, comm, vec![])
} else {
Expand Down

0 comments on commit 681d2c7

Please sign in to comment.