Skip to content

Commit

Permalink
add validate_justifications
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Mar 5, 2025
1 parent 2b07331 commit f1038ee
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions anchor/message_validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,27 @@ impl Validator {
});
}

self.validate_justifications(consensus_message)?;

Ok(())
}

fn validate_justifications(
&self,
consensus_message: &QbftMessage,
) -> Result<(), ValidationFailure> {
// Rule: Can only exist for Proposal messages
let prepare_justifications = &consensus_message.prepare_justification;
if !prepare_justifications.is_empty() && consensus_message.qbft_message_type != QbftMessageType::Proposal {
return Err(ValidationFailure::UnexpectedPrepareJustifications);
}

// Rule: Can only exist for Proposal or Round-Change messages
let round_change_justifications = &consensus_message.round_change_justification;
if !round_change_justifications.is_empty() && consensus_message.qbft_message_type != QbftMessageType::Proposal && consensus_message.qbft_message_type != QbftMessageType::RoundChange {
return Err(ValidationFailure::UnexpectedRoundChangeJustifications);
}

Ok(())
}
}
Expand Down

0 comments on commit f1038ee

Please sign in to comment.