Skip to content

Comments

Stateless QBFT consensus message semantic validation#171

Merged
diegomrsantos merged 26 commits intosigp:unstablefrom
diegomrsantos:qbft-message-validation
Mar 12, 2025
Merged

Stateless QBFT consensus message semantic validation#171
diegomrsantos merged 26 commits intosigp:unstablefrom
diegomrsantos:qbft-message-validation

Conversation

@diegomrsantos
Copy link
Member

@diegomrsantos diegomrsantos commented Mar 4, 2025

Issue Addressed

#161

Proposed Changes

Add an initial validation for QBFT consensus messages that doesn't depend on the consensus state.

Additional Info

Validation using consensus state is coming in the next PR.

@diegomrsantos diegomrsantos force-pushed the qbft-message-validation branch 2 times, most recently from 91d58e5 to 2b07331 Compare March 5, 2025 11:31
@diegomrsantos diegomrsantos self-assigned this Mar 5, 2025
@diegomrsantos diegomrsantos force-pushed the qbft-message-validation branch from f1038ee to 4b08b92 Compare March 5, 2025 13:52
@diegomrsantos diegomrsantos changed the title Qbft message validation Stateless Qbft consensus message validation Mar 5, 2025
@diegomrsantos diegomrsantos changed the title Stateless Qbft consensus message validation Stateless QBFT consensus message validation Mar 5, 2025
@diegomrsantos
Copy link
Member Author

This is based on #160, as soon as it gets merged, I'll remove the common code and make it ready for review. But feel free to take a look in the mean time.

@diegomrsantos diegomrsantos force-pushed the qbft-message-validation branch from 4b08b92 to a41c6cb Compare March 6, 2025 08:40
@diegomrsantos diegomrsantos force-pushed the qbft-message-validation branch from c34cd52 to 1b40fa0 Compare March 7, 2025 13:33
@diegomrsantos diegomrsantos requested review from Zacholme7, dknopik and jking-aus and removed request for Zacholme7 March 10, 2025 12:51
@diegomrsantos diegomrsantos marked this pull request as ready for review March 10, 2025 12:52
@diegomrsantos diegomrsantos force-pushed the qbft-message-validation branch from 0e902a6 to e5158db Compare March 10, 2025 15:25
@diegomrsantos
Copy link
Member Author

@jking-aus @dknopik @Zacholme7 Sorry for the big PR. I can move the tests to a new one if necessary.

Comment on lines +227 to +230
let committee_id = match signed_ssv_message.ssv_message().msg_id().duty_executor() {
Some(DutyExecutor::Committee(id)) => id,
_ => return Err(ValidationFailure::NonExistentCommitteeID),
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incomplete, I'm not handling the validator case. But this PR is already quite big, I will handle it in my next one which is coming soon.

hash
}

#[cfg(test)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests could be greatly simplified if it's possible to call the validation functions without creating a validator. It's an interesting idea that I'll explore in a new PR.

@diegomrsantos diegomrsantos added the ready-for-review This PR is ready to be reviewed label Mar 11, 2025
Copy link
Member

@Zacholme7 Zacholme7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thanks for doing this. Have a few comments.

Comment on lines +301 to +322

pub struct WatchableNetworkState {
state_rx: watch::Receiver<NetworkState>,
}

impl WatchableNetworkState {
pub fn new(state_rx: watch::Receiver<NetworkState>) -> Self {
Self { state_rx }
}
}

impl NetworkStateService for WatchableNetworkState {
fn get_cluster_members(&self, committee_id: &CommitteeId) -> Option<IndexSet<OperatorId>> {
let db_state = self.state_rx.borrow();
db_state
.multi_state
.clusters
.get_all_by(committee_id)
.and_then(|clusters| clusters.first().cloned())
.map(|cluster| cluster.cluster_members)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Can get_cluster_members just be defined on the network state and then use state() and watch() on the database to get access to NetworkState?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean why the trait is needed? If so, it's much easier to use it in the tests then recreating the whole NetworkState. But after talking to @dknopik, there might be an easier solution if we extract the validation to functions that can be called without a validator instance. I'll explore this design in a new PR.

Copy link
Member

@jking-aus jking-aus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work as usual diego -- just a couple of comments and resolve the conflicts please

self.identifier.role().and_then(|role| match role {
Role::Committee | Role::Aggregator => Some(12),
Role::Proposer | Role::SyncCommittee => Some(6),
_ => None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be obvious and I'm not getting it but why are we hardcoding 12 and 6 as max rounds? is that ssv spec? 2secs per round and 2 slot window?

Copy link
Member Author

@diegomrsantos diegomrsantos Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good we need to match them on this or we won't timeout at the same time. I would like to ask them where they're pulling this number from because I would assume it's just a guess like follow distance. I will just add an inline comment saying where it's from.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used only for validation, maybe I shouldn't have added it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move it to the validator if you think it's better.

jking-aus and others added 3 commits March 12, 2025 21:13
# Conflicts:
#	anchor/client/src/lib.rs
#	anchor/message_validator/src/lib.rs
@diegomrsantos diegomrsantos changed the title Stateless QBFT consensus message validation Stateless QBFT consensus message semantic validation Mar 12, 2025
@diegomrsantos diegomrsantos requested a review from jking-aus March 12, 2025 20:54
Copy link
Member

@jking-aus jking-aus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@diegomrsantos diegomrsantos merged commit 90335d8 into sigp:unstable Mar 12, 2025
10 checks passed
@dknopik dknopik removed the ready-for-review This PR is ready to be reviewed label Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants