-
Notifications
You must be signed in to change notification settings - Fork 12
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
Create message_validator crate #152
base: unstable
Are you sure you want to change the base?
Conversation
c9ab914
to
81b0b55
Compare
81b0b55
to
6804d78
Compare
@@ -0,0 +1 @@ | |||
mod validation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why a submodule?
pub(crate) fn validate( | ||
&mut self, | ||
_message: SignedSSVMessage, | ||
) -> std::result::Result<Result, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: no need to specify the full type path
|
||
pub struct Validator; | ||
|
||
pub enum Error {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a separate error instead of just returning the ValidationFailure
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to return ValidationFailure
? We return the local Result
and Error
is an error in the validation process. Maybe we don't need the Error, I don't know if it can fail yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should be like this?
pub enum Result {
Accept,
Reject(ValidationFailure),
Ignore,
}
impl Validator {
pub(crate) fn validate(
&mut self,
_message: SignedSSVMessage,
) -> Result {
Accept
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah, now I also understand why you specified the path for the std Result
type.
Well, we will need to report the validation result to the network crate via a queue. So validate
should not return anything, right?
Nesting a validation failure into the Result
also feels incorrect: we have a specific validation failure, and this maps to a way we handle the message. And this will be what we report to network
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this?
pub fn start_validator_service(validator: Validator) -> (Sender<SignedSSVMessage>, Receiver<ValidationResult>) {
// Channel for receiving messages to validate.
let (msg_tx, msg_rx) = mpsc::channel::<SignedSSVMessage>();
// Channel for sending back validation results.
let (result_tx, result_rx) = mpsc::channel::<ValidationResult>();
spawn(move || {
for signed_msg in msg_rx {
let validation_result = validator.validate(signed_msg);
if result_tx.send(validation_result).is_err() {
break;
}
}
});
(msg_tx, result_rx)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I believe we'd need to adapt it to go through the processor as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a centralized validator task, as there are no central resources to manage. Just create a closure, and send it to a processor queue via send_blocking
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nesting a validation failure into the Result also feels incorrect
We might need it, cause the result can also be Accept
. There's also a difference between Reject
and Ignore
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need it, but we do not need to embed the validation failure into it, because we create the validation result (=the way we treat the message) from the validation failure, right? In other words, the failure variant determines whether to Ignore
or Reject
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send_blocking doesn't work:
61 | pub fn send_blocking<F: FnOnce() + Send + 'static>(
| ^^^^^^^^ required by this bound in `Sender::send_blocking`
How about (ignore the Result for now)?
pub fn start_validator_service(
validator: Validator,
) -> (Sender<SignedSSVMessage>, Receiver<Result>) {
let (msg_tx, mut msg_rx) = mpsc::channel::<SignedSSVMessage>(100);
let (result_tx, result_rx) = mpsc::channel::<Result>(100);
validator
.processor
.urgent_consensus
.send_async(
async move {
while let Some(signed_msg) = msg_rx.recv().await {
let result = validate(signed_msg);
// If the send fails, we can assume the receiver is dropped.
if result_tx.send(result).await.is_err() {
break;
}
}
},
"validator_service",
)
.unwrap();
(msg_tx, result_rx)
}
5c476e3
to
84b2aa0
Compare
77acb4f
to
452be56
Compare
452be56
to
f868709
Compare
Issue Addressed
Extracts validation from #147.
Related to #161.
Proposed Changes
Create a crate for validation that doesn't depend on other crates.
Additional Info
I added in common for now, but not sure it's necessary.