-
Notifications
You must be signed in to change notification settings - Fork 28
Validate qbft logic #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate qbft logic #191
Changes from 8 commits
c171db7
3c319a6
78c7ed0
72b401e
78dfa65
cc6e8b3
6c4bd50
a49b0a9
079ff28
8fced11
e608736
6a1a4e2
444d776
1802f49
14fc0de
c1dd2d7
9c2beab
2868c95
6344362
f8bef0e
b0c804e
7046e93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| use derive_more::Deref; | ||
| use std::fmt; | ||
| use std::fmt::{Display, Formatter}; | ||
| use std::num::NonZeroUsize; | ||
| use std::ops::Add; | ||
|
|
||
| /// This represents an individual round, these change on regular time intervals | ||
| #[derive(Clone, Copy, Debug, Deref, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
| pub struct Round(NonZeroUsize); | ||
|
|
||
| impl From<u64> for Round { | ||
| fn from(round: u64) -> Round { | ||
| Round(NonZeroUsize::new(round as usize).expect("round == 0")) | ||
diegomrsantos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| impl From<Round> for u64 { | ||
| fn from(round: Round) -> u64 { | ||
| round.0.get() as u64 | ||
| } | ||
| } | ||
|
|
||
| impl Add<u64> for Round { | ||
| type Output = Round; | ||
|
|
||
| fn add(self, rhs: u64) -> Round { | ||
| Round(NonZeroUsize::new(self.0.get() + rhs as usize).expect("round == 0")) | ||
| } | ||
| } | ||
|
|
||
| impl Default for Round { | ||
| fn default() -> Self { | ||
| // rounds are indexed starting at 1 | ||
| Round(NonZeroUsize::new(1).expect("1 != 0")) | ||
| } | ||
| } | ||
|
|
||
| impl Display for Round { | ||
| fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
| write!(f, "{}", self.0) | ||
| } | ||
| } | ||
|
|
||
| impl Round { | ||
| /// Returns the next round | ||
| pub fn next(&self) -> Option<Round> { | ||
| self.0.checked_add(1).map(Round) | ||
| } | ||
|
|
||
| /// Sets the current round | ||
| pub fn set(&mut self, round: Round) { | ||
| *self = round; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| use crate::MessageReceiver; | ||
| use database::{NetworkState, UniqueIndex}; | ||
| use gossipsub::{Message, MessageAcceptance, MessageId}; | ||
| use libp2p::PeerId; | ||
| use message_validator::Validator; | ||
| use message_validator::{ValidatedMessage, ValidatedSSVMessage}; | ||
| use qbft_manager::QbftManager; | ||
| use signature_collector::SignatureCollectorManager; | ||
| use slot_clock::SlotClock; | ||
| use ssv_types::msgid::DutyExecutor; | ||
| use std::sync::Arc; | ||
| use tokio::sync::mpsc::error::TrySendError; | ||
|
|
@@ -20,18 +22,38 @@ pub struct Outcome { | |
| } | ||
|
|
||
| /// A message receiver that passes messages to responsible managers. | ||
| pub struct MessageReceiver { | ||
| pub struct NetworkMessageReceiver<S: SlotClock> { | ||
| processor: processor::Senders, | ||
| qbft_manager: Arc<QbftManager>, | ||
| signature_collector: Arc<SignatureCollectorManager>, | ||
| network_state_rx: watch::Receiver<NetworkState>, | ||
| outcome_tx: mpsc::Sender<Outcome>, | ||
| validator: Validator, | ||
| validator: Validator<S>, | ||
|
||
| } | ||
|
|
||
| impl MessageReceiver { | ||
| pub fn receive( | ||
| self: Arc<Self>, | ||
| impl<S: SlotClock + 'static> NetworkMessageReceiver<S> { | ||
| pub fn new( | ||
| processor: processor::Senders, | ||
| qbft_manager: Arc<QbftManager>, | ||
| signature_collector: Arc<SignatureCollectorManager>, | ||
| network_state_rx: watch::Receiver<NetworkState>, | ||
| outcome_tx: mpsc::Sender<Outcome>, | ||
| validator: Validator<S>, | ||
| ) -> Arc<Self> { | ||
| Arc::new(Self { | ||
| processor, | ||
| qbft_manager, | ||
| signature_collector, | ||
| network_state_rx, | ||
| outcome_tx, | ||
| validator, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl<S: SlotClock + 'static> MessageReceiver for Arc<NetworkMessageReceiver<S>> { | ||
| fn receive( | ||
| &self, | ||
| propagation_source: PeerId, | ||
| message_id: MessageId, | ||
| message: Message, | ||
|
|
@@ -119,23 +141,3 @@ impl MessageReceiver { | |
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl MessageReceiver { | ||
| pub fn new( | ||
| processor: processor::Senders, | ||
| qbft_manager: Arc<QbftManager>, | ||
| signature_collector: Arc<SignatureCollectorManager>, | ||
| network_state_rx: watch::Receiver<NetworkState>, | ||
| outcome_tx: mpsc::Sender<Outcome>, | ||
| validator: Validator, | ||
| ) -> Arc<Self> { | ||
| Arc::new(Self { | ||
| processor, | ||
| qbft_manager, | ||
| signature_collector, | ||
| network_state_rx, | ||
| outcome_tx, | ||
| validator, | ||
| }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.