Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed May 16, 2024
1 parent 95e5264 commit b8022c5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
4 changes: 2 additions & 2 deletions code/actors/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ where

if state.connected_peers.len() == state.validator_set.count() - 1 {
info!(
"Enough peers ({}) ready to start consensus",
"Enough peers ({}) connected to start consensus",
state.connected_peers.len()
);

Expand All @@ -663,7 +663,7 @@ where
// TODO: pause/stop consensus, if necessary
}

GossipEvent::Message(_from, _, data) => {
GossipEvent::Message(_, _, data) => {
let msg = NetworkMsg::from_network_bytes(data).unwrap(); // FIXME

let Some(msg_height) = msg.msg_height() else {
Expand Down
19 changes: 11 additions & 8 deletions code/actors/src/gossip.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::BTreeSet;
use std::sync::Arc;

use async_trait::async_trait;
Expand Down Expand Up @@ -51,8 +52,7 @@ pub struct Args {
pub enum State {
Stopped,
Running {
expected_peers: Vec<PeerId>,
peers: Vec<PeerId>,
peers: BTreeSet<PeerId>,
subscribers: Vec<ActorRef<Arc<Event>>>,
ctrl_handle: CtrlHandle,
recv_task: JoinHandle<()>,
Expand Down Expand Up @@ -95,8 +95,7 @@ impl Actor for Gossip {
});

Ok(State::Running {
expected_peers: args.peer_ids,
peers: Vec::new(),
peers: BTreeSet::new(),
subscribers: Vec::new(),
ctrl_handle,
recv_task,
Expand All @@ -118,7 +117,6 @@ impl Actor for Gossip {
state: &mut State,
) -> Result<(), ActorProcessingErr> {
let State::Running {
expected_peers,
peers,
subscribers,
ctrl_handle,
Expand All @@ -132,11 +130,16 @@ impl Actor for Gossip {
Msg::Subscribe(subscriber) => subscribers.push(subscriber),
Msg::Broadcast(channel, data) => ctrl_handle.broadcast(channel, data).await?,
Msg::NewEvent(event) => {
if let Event::PeerConnected(peer_id) = event {
if expected_peers.contains(&peer_id) {
peers.push(peer_id);
match &event {
Event::PeerConnected(peer_id) => {
peers.insert(*peer_id);
}
Event::PeerDisconnected(peer_id) => {
peers.remove(peer_id);
}
_ => {}
}

let event = Arc::new(event);
for subscriber in subscribers {
subscriber.cast(Arc::clone(&event))?;
Expand Down
10 changes: 5 additions & 5 deletions code/actors/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ where
params.gossip_mempool,
params.mempool,
proposal_builder,
// params.start_height,
params.start_height,
);

let actor = node.spawn().await?;
Ok(actor)
}

#[allow(dead_code)]
pub struct Node<Ctx: Context> {
#[allow(dead_code)]
ctx: Ctx,
cal: ActorRef<CALMsg<Ctx>>,
gossip: ActorRef<GossipMsg>,
consensus: ActorRef<ConsensusMsg<Ctx>>,
gossip_mempool: ActorRef<GossipMempoolMsg>,
mempool: ActorRef<MempoolMsg>,
proposal_builder: ActorRef<ProposalBuilderMsg<Ctx>>,
// start_height: Ctx::Height,
start_height: Ctx::Height,
}

impl<Ctx> Node<Ctx>
Expand All @@ -120,7 +120,7 @@ where
gossip_mempool: ActorRef<GossipMempoolMsg>,
mempool: ActorRef<MempoolMsg>,
proposal_builder: ActorRef<ProposalBuilderMsg<Ctx>>,
// start_height: Ctx::Height,
start_height: Ctx::Height,
) -> Self {
Self {
ctx,
Expand All @@ -130,7 +130,7 @@ where
gossip_mempool,
mempool,
proposal_builder,
// start_height,
start_height,
}
}

Expand Down
14 changes: 2 additions & 12 deletions code/common/src/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@ use core::fmt::{Debug, Display};
/// A height of 0 represents a chain which has not yet produced a block.
pub trait Height
where
Self: Default
+ Copy
+ Clone
+ Debug
+ Display
+ PartialEq
+ Eq
+ PartialOrd
+ Ord
+ Send
+ Sync
+ From<u64>,
Self:
Default + Copy + Clone + Debug + Display + PartialEq + Eq + PartialOrd + Ord + Send + Sync,
{
/// Increment the height by one.
fn increment(&self) -> Self;
Expand Down
6 changes: 0 additions & 6 deletions code/test/src/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ impl fmt::Debug for Height {
}
}

impl From<u64> for Height {
fn from(height: u64) -> Self {
Self::new(height)
}
}

impl malachite_common::Height for Height {
fn increment(&self) -> Self {
Self(self.0 + 1)
Expand Down

0 comments on commit b8022c5

Please sign in to comment.