Skip to content
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

Qbft new messages #111

Merged
merged 27 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
remove ssv_types dependency on qbft
  • Loading branch information
Zacholme7 committed Jan 15, 2025
commit 73fdbfc11243156d89584a64b9c0156efae4668e
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions anchor/common/qbft/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ edition = { workspace = true }
derive_more = { workspace = true }
indexmap = { workspace = true }
tracing = { workspace = true }
ssv_types = { workspace = true }

[dev-dependencies]
tracing-subscriber = { workspace = true }
11 changes: 2 additions & 9 deletions anchor/common/qbft/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pub use config::{Config, ConfigBuilder};
use std::cmp::Eq;
use std::collections::{HashMap, HashSet};
use std::fmt::Debug;
use std::hash::Hash;
use tracing::{debug, error, warn};
pub use validation::{validate_consensus_data, ValidatedData, ValidationError};

@@ -12,6 +9,8 @@ pub use types::{
Message, OperatorId, Round,
};

use ssv_types::message::Data;

mod config;
mod error;
mod types;
@@ -22,12 +21,6 @@ mod tests;

type RoundChangeMap<D> = HashMap<OperatorId, Option<ConsensusData<D>>>;

pub trait Data: Debug + Clone {
type Hash: Debug + Clone + Eq + Hash;

fn hash(&self) -> Self::Hash;
}

/// The structure that defines the Quorum Based Fault Tolerance (QBFT) instance.
///
/// This builds and runs an entire QBFT process until it completes. It can complete either
1 change: 0 additions & 1 deletion anchor/common/ssv_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ authors = ["Sigma Prime <contact@sigmaprime.io>"]
base64 = { workspace = true }
derive_more = { workspace = true }
openssl = { workspace = true }
qbft = { workspace = true }
rusqlite = { workspace = true }
tree_hash = { workspace = true }
tree_hash_derive = { workspace = true }
16 changes: 12 additions & 4 deletions anchor/common/ssv_types/src/message.rs
Original file line number Diff line number Diff line change
@@ -7,10 +7,18 @@ use types::{
AggregateAndProof, BeaconBlock, BlindedBeaconBlock, Checkpoint, CommitteeIndex, EthSpec,
Hash256, PublicKeyBytes, Signature, Slot, SyncCommitteeContribution, VariableList,
};
use std::fmt::Debug;
use std::hash::Hash;
// todo - dear reader, this mainly serves as plain translation of the types found in the go code
// there are a lot of byte[] there, and that got confusing, below should be more readable.
// it needs some work to actually serialize to the same stuff on wire, and I feel like we can name
// the fields better
//
pub trait Data: Debug + Clone {
type Hash: Debug + Clone + Eq + Hash;

fn hash(&self) -> Self::Hash;
}

#[derive(Clone, Debug)]
pub struct SignedSsvMessage<E: EthSpec> {
@@ -24,7 +32,7 @@ pub struct SignedSsvMessage<E: EthSpec> {
pub struct SsvMessage<E: EthSpec> {
pub msg_type: MsgType,
pub msg_id: MsgId,
pub data: Data<E>,
pub data: SsvData<E>,
}

#[derive(Clone, Debug)]
@@ -34,7 +42,7 @@ pub enum MsgType {
}

#[derive(Clone, Debug)]
pub enum Data<E: EthSpec> {
pub enum SsvData<E: EthSpec> {
QbftMessage(QbftMessage<E>),
PartialSignatureMessage(PartialSignatureMessage),
}
@@ -80,7 +88,7 @@ pub struct ValidatorConsensusData<E: EthSpec> {
pub data_ssz: Box<DataSsz<E>>,
}

impl<E: EthSpec> qbft::Data for ValidatorConsensusData<E> {
impl<E: EthSpec> Data for ValidatorConsensusData<E> {
type Hash = Hash256;

fn hash(&self) -> Self::Hash {
@@ -181,7 +189,7 @@ pub struct BeaconVote {
pub target: Checkpoint,
}

impl qbft::Data for BeaconVote {
impl Data for BeaconVote {
type Hash = Hash256;

fn hash(&self) -> Self::Hash {
11 changes: 6 additions & 5 deletions anchor/qbft_manager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ use qbft::{
Message as NetworkMessage, OperatorId as QbftOperatorId,
};
use slot_clock::SlotClock;
use ssv_types::message::Data;
use ssv_types::message::{BeaconVote, ValidatorConsensusData};
use ssv_types::{Cluster, ClusterId, OperatorId};
use std::fmt::Debug;
@@ -47,13 +48,13 @@ pub enum ValidatorDutyKind {
}

#[derive(Debug)]
pub struct QbftMessage<D: qbft::Data> {
pub struct QbftMessage<D: Data> {
pub kind: QbftMessageKind<D>,
pub drop_on_finish: DropOnFinish,
}

#[derive(Debug)]
pub enum QbftMessageKind<D: qbft::Data> {
pub enum QbftMessageKind<D: Data> {
Initialize {
initial: D,
config: qbft::Config<DefaultLeaderFunction>,
@@ -169,7 +170,7 @@ impl<T: SlotClock, E: EthSpec> QbftManager<T, E> {
}

pub trait QbftDecidable<T: SlotClock + 'static, E: EthSpec>:
qbft::Data<Hash = Hash256> + Send + 'static
Data<Hash = Hash256> + Send + 'static
{
type Id: Hash + Eq + Send;

@@ -220,7 +221,7 @@ impl<T: SlotClock + 'static, E: EthSpec> QbftDecidable<T, E> for BeaconVote {
}
}

enum QbftInstance<D: qbft::Data, S: FnMut(NetworkMessage<D>)> {
enum QbftInstance<D: Data, S: FnMut(NetworkMessage<D>)> {
Uninitialized {
// todo: proooobably limit this
message_buffer: Vec<NetworkMessage<D>>,
@@ -235,7 +236,7 @@ enum QbftInstance<D: qbft::Data, S: FnMut(NetworkMessage<D>)> {
},
}

async fn qbft_instance<D: qbft::Data>(mut rx: UnboundedReceiver<QbftMessage<D>>) {
async fn qbft_instance<D: Data>(mut rx: UnboundedReceiver<QbftMessage<D>>) {
let mut instance = QbftInstance::Uninitialized {
message_buffer: Vec::new(),
};