Skip to content

Commit

Permalink
[refactor]: Split view changes from normal messages
Browse files Browse the repository at this point in the history
Signed-off-by: Sam H. Smith <[email protected]>
  • Loading branch information
SamHSmith committed Dec 20, 2023
1 parent 50ec2bc commit c1e4b97
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 225 deletions.
7 changes: 5 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ impl NetworkRelay {
}

match msg {
SumeragiPacket(data) => {
self.sumeragi.incoming_message(*data);
SumeragiBlock(data) => {
self.sumeragi.incoming_block_message(*data);
}
SumeragiControlFlow(data) => {
self.sumeragi.incoming_control_flow_message(*data);
}
BlockSync(data) => self.block_sync.message(*data).await,
TransactionGossiper(data) => self.gossiper.gossip(*data).await,
Expand Down
10 changes: 4 additions & 6 deletions core/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl BlockSynchronizer {
pub mod message {
//! Module containing messages for [`BlockSynchronizer`](super::BlockSynchronizer).
use super::*;
use crate::sumeragi::view_change::ProofChain;

/// Get blocks after some block
#[derive(Debug, Clone, Decode, Encode)]
Expand Down Expand Up @@ -234,12 +233,11 @@ pub mod message {
}
}
Message::ShareBlocks(ShareBlocks { blocks, .. }) => {
use crate::sumeragi::message::{Message, MessagePacket};
use crate::sumeragi::message::BlockMessage;
for block in blocks.clone() {
block_sync.sumeragi.incoming_message(MessagePacket::new(
ProofChain::default(),
Some(Message::BlockSyncUpdate(block.into())),
));
block_sync
.sumeragi
.incoming_block_message(BlockMessage::BlockSyncUpdate(block.into()));
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ use parity_scale_codec::{Decode, Encode};
use tokio::sync::broadcast;

use crate::{
block_sync::message::Message as BlockSyncMessage, prelude::*,
sumeragi::message::MessagePacket as SumeragiPacket,
block_sync::message::Message as BlockSyncMessage,
prelude::*,
sumeragi::message::{BlockMessage, ControlFlowMessage},
};

/// The interval at which sumeragi checks if there are tx in the `queue`.
Expand Down Expand Up @@ -60,8 +61,10 @@ pub type EventsSender = broadcast::Sender<Event>;
/// The network message
#[derive(Clone, Debug, Encode, Decode)]
pub enum NetworkMessage {
/// Blockchain message
SumeragiPacket(Box<SumeragiPacket>),
/// Blockchain concensus data message
SumeragiBlock(Box<BlockMessage>),
/// Blockchain concensus control flow message
SumeragiControlFlow(Box<ControlFlowMessage>),
/// Block sync message
BlockSync(Box<BlockSyncMessage>),
/// Transaction gossiper message
Expand Down
Loading

0 comments on commit c1e4b97

Please sign in to comment.