Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8484ab2
validation when signers > 1
diegomrsantos Mar 4, 2025
7467879
add validate_consensus_message_semantics
diegomrsantos Mar 5, 2025
a41c6cb
add validate_justifications
diegomrsantos Mar 5, 2025
6109eb7
get committee members from the NetworkState
diegomrsantos Mar 6, 2025
1b40fa0
multi index with 4 indices
diegomrsantos Mar 7, 2025
e039197
fix naming
diegomrsantos Mar 7, 2025
dc3bd78
add tests
diegomrsantos Mar 7, 2025
878c0de
improve tests
diegomrsantos Mar 10, 2025
e88d3cf
Merge branch 'unstable' into qbft-message-validation
diegomrsantos Mar 10, 2025
e5158db
fix comments
diegomrsantos Mar 10, 2025
87da566
add new test
diegomrsantos Mar 10, 2025
5a966e5
remove do_validate
diegomrsantos Mar 10, 2025
a4a58be
decode msgs to PartialSignatureMessages
diegomrsantos Mar 10, 2025
72ae550
Merge branch 'unstable' into qbft-message-validation
diegomrsantos Mar 11, 2025
fd3b7c9
Merge branch 'unstable' into qbft-message-validation
jking-aus Mar 11, 2025
c933390
Merge branch 'unstable' into qbft-message-validation
diegomrsantos Mar 11, 2025
ec791c7
add Rule: Duty role has consensus (true except for ValidatorRegistrat…
diegomrsantos Mar 11, 2025
66b4e3f
remove unused code
diegomrsantos Mar 11, 2025
0e73245
add comment
diegomrsantos Mar 11, 2025
a52f6f2
improve comment for decided msg
diegomrsantos Mar 11, 2025
fab2f25
remove redundant root hash check
diegomrsantos Mar 11, 2025
51c9718
Merge remote-tracking branch 'network/unstable' into qbft-message-val…
jking-aus Mar 12, 2025
75fe744
small typos
jking-aus Mar 12, 2025
74d07a8
Merge branch 'unstable' into qbft-message-validation
diegomrsantos Mar 12, 2025
a7c537d
Merge branch 'qbft-message-validation' of https://github.com/diegomrs…
diegomrsantos Mar 12, 2025
f4806ef
Update consensus.rs
jking-aus Mar 12, 2025
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
8 changes: 8 additions & 0 deletions Cargo.lock

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

8 changes: 6 additions & 2 deletions anchor/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use beacon_node_fallback::{
};
pub use cli::Anchor;
use config::Config;
use database::NetworkDatabase;
use database::{NetworkDatabase, WatchableNetworkState};
use eth2::reqwest::{Certificate, ClientBuilder};
use eth2::{BeaconNodeHttpClient, Timeouts};
use message_sender::NetworkMessageSender;
Expand Down Expand Up @@ -362,7 +362,11 @@ impl Client {
)?;

let (results_tx, results_rx) = mpsc::channel::<message_validator::Outcome>(9000);
let message_validator = Validator::new(processor_senders.clone(), results_tx);
let message_validator = Validator::new(
processor_senders.clone(),
results_tx,
Arc::new(WatchableNetworkState::new(database.watch())),
);

// Start the p2p network
let network = Network::try_new(
Expand Down
24 changes: 3 additions & 21 deletions anchor/common/qbft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ where
&self,
wrapped_msg: &WrappedQbftMessage,
) -> Option<(Option<ValidData<D>>, OperatorId)> {
// Validate the qbft message
if !wrapped_msg.qbft_message.validate() {
warn!("Invalid qbft_message");
return None;
}

// Ensure that this message is for the correct round
let current_round = self.current_round.get();
if (wrapped_msg.qbft_message.round < current_round as u64)
Expand Down Expand Up @@ -251,21 +245,9 @@ where

// The rest of the verification only pertains to messages with one signature
if wrapped_msg.signed_message.operator_ids().len() != 1 {
// If there is more than one signer, we also have to check if this is a decided message.
if matches!(
wrapped_msg.qbft_message.qbft_message_type,
QbftMessageType::Commit
) {
// Do not care about data here, just that we had a success
let valid_data = Some(ValidData::new(None, wrapped_msg.qbft_message.root));
return Some((valid_data, OperatorId::from(0)));
}
// Otherwise, this is invalid data
warn!(
num_signers = wrapped_msg.signed_message.operator_ids().len(),
"Message only allows one signer"
);
return None;
// Do not care about data here, just that we had a success
let valid_data = Some(ValidData::new(None, wrapped_msg.qbft_message.root));
return Some((valid_data, OperatorId::from(0)));
}

// Message is not a decide message, we know there is only one signer
Expand Down
14 changes: 8 additions & 6 deletions anchor/common/ssv_types/src/consensus.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::message::*;
use crate::msgid::MessageId;
use crate::msgid::{MessageId, Role};
use crate::ValidatorIndex;
use sha2::{Digest, Sha256};
use ssz::{Decode, DecodeError, Encode};
Expand Down Expand Up @@ -60,12 +60,14 @@ pub struct QbftMessage {
}

impl QbftMessage {
/// Do QBFTMessage specific validation
pub fn validate(&self) -> bool {
if self.qbft_message_type > QbftMessageType::RoundChange {
return false;
pub fn max_round(&self) -> Option<u64> {
match self.identifier.role() {
Some(role) => match role {
Role::Committee | Role::Aggregator => Some(12),
Role::Proposer | Role::SyncCommittee => Some(6),
},
None => None,
}
true
}
}

Expand Down
2 changes: 2 additions & 0 deletions anchor/common/ssv_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ mod share;
mod sql_conversions;
mod util;

pub use indexmap::IndexSet;
pub use share::ENCRYPTED_KEY_LENGTH;
pub use types::Slot;
27 changes: 15 additions & 12 deletions anchor/database/src/cluster_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,30 @@ impl NetworkDatabase {

// Save the keyshare
state.multi_state.shares.insert(
&validator.public_key, // The validator this keyshare belongs to
&cluster.cluster_id, // The id of the cluster
&cluster.owner, // The owner of the cluster
share.to_owned(), // The keyshare itself
&validator.public_key, // The validator this keyshare belongs to
&cluster.cluster_id, // The id of the cluster
&cluster.owner, // The owner of the cluster
&cluster.committee_id(), // The committee id of the cluster
share.to_owned(), // The keyshare itself
);
}

// Save all cluster related information
state.multi_state.clusters.insert(
&cluster.cluster_id, // The id of the cluster
&validator.public_key, // The public key of validator added to the cluster
&cluster.owner, // Owner of the cluster
cluster.to_owned(), // The Cluster and all containing information
&cluster.cluster_id, // The id of the cluster
&validator.public_key, // The public key of validator added to the cluster
&cluster.owner, // Owner of the cluster
&cluster.committee_id(), // The committee id of the cluster
cluster.to_owned(), // The Cluster and all containing information
);

// Save the metadata for the validators
state.multi_state.validator_metadata.insert(
&validator.public_key, // The public key of the validator
&cluster.cluster_id, // The id of the cluster the validator belongs to
&cluster.owner, // The owner of the cluster
validator.to_owned(), // The metadata of the validator
&validator.public_key, // The public key of the validator
&cluster.cluster_id, // The id of the cluster the validator belongs to
&cluster.owner, // The owner of the cluster
&cluster.committee_id(), // The committee id of the cluster
validator.to_owned(), // The metadata of the validator
);
});

Expand Down
30 changes: 25 additions & 5 deletions anchor/database/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use openssl::{pkey::Public, rsa::Rsa};
use r2d2_sqlite::SqliteConnectionManager;
use rusqlite::params;
use ssv_types::{Cluster, ClusterId, Operator, OperatorId, Share, ValidatorMetadata};
use ssv_types::{Cluster, ClusterId, CommitteeId, Operator, OperatorId, Share, ValidatorMetadata};
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::path::Path;
Expand All @@ -13,6 +13,7 @@ use types::{Address, PublicKeyBytes};
pub use crate::error::DatabaseError;
pub use crate::multi_index::{MultiIndexMap, *};
use crate::sql_operations::{SqlStatement, SQL};
pub use crate::state::{NetworkStateService, WatchableNetworkState};

mod cluster_operations;
mod error;
Expand All @@ -36,8 +37,16 @@ type PoolConn = r2d2::PooledConnection<SqliteConnectionManager>;
/// Primary: public key of validator. uniquely identifies share
/// Secondary: cluster id. corresponds to a list of shares
/// Tertiary: owner of the cluster. corresponds to a list of shares
pub(crate) type ShareMultiIndexMap =
MultiIndexMap<PublicKeyBytes, ClusterId, Address, Share, NonUniqueTag, NonUniqueTag>;
pub(crate) type ShareMultiIndexMap = MultiIndexMap<
PublicKeyBytes,
ClusterId,
Address,
CommitteeId,
Share,
NonUniqueTag,
NonUniqueTag,
NonUniqueTag,
>;
/// Metadata for all validators in the network
/// Primary: public key of the validator. uniquely identifies the metadata
/// Secondary: cluster id. corresponds to list of metadata for all validators
Expand All @@ -46,23 +55,34 @@ pub(crate) type MetadataMultiIndexMap = MultiIndexMap<
PublicKeyBytes,
ClusterId,
Address,
CommitteeId,
ValidatorMetadata,
NonUniqueTag,
NonUniqueTag,
NonUniqueTag,
>;
/// All of the clusters in the network
/// Primary: cluster id. uniquely identifies a cluster
/// Secondary: public key of the validator. uniquely identifies a cluster
/// Tertiary: owner of the cluster. uniquely identifies a cluster
pub(crate) type ClusterMultiIndexMap =
MultiIndexMap<ClusterId, PublicKeyBytes, Address, Cluster, UniqueTag, UniqueTag>;
pub(crate) type ClusterMultiIndexMap = MultiIndexMap<
ClusterId,
PublicKeyBytes,
Address,
CommitteeId,
Cluster,
UniqueTag,
UniqueTag,
NonUniqueTag,
>;

// Information that needs to be accessed via multiple different indicies
#[derive(Debug)]
struct MultiState {
shares: ShareMultiIndexMap,
validator_metadata: MetadataMultiIndexMap,
clusters: ClusterMultiIndexMap,
// Be careful when adding new maps here. If you really must to, it must be updated in the operations files
}

// General information that can be single index access
Expand Down
Loading
Loading