Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions node/src/components/consensus/highway_core/active_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
#[derive(Clone, Eq, PartialEq, Debug)]
pub(crate) enum Effect<C: Context> {
/// Newly vertex that should be gossiped to peers and added to the protocol state.
// TODO: This should contain a `ValidVertex`, since we created it ourselves.
NewVertex(ValidVertex<C>),
/// `handle_timer` needs to be called at the specified time.
ScheduleTimer(Timestamp),
Expand Down Expand Up @@ -103,8 +102,10 @@ impl<C: Context> ActiveValidator<C> {
effects.push(Effect::RequestNewBlock(bctx));
} else if round_offset == self.witness_offset() {
let panorama = state.panorama_cutoff(state.panorama(), timestamp);
let witness_vote = self.new_vote(panorama, timestamp, None, state);
effects.push(Effect::NewVertex(ValidVertex(Vertex::Vote(witness_vote))))
if !panorama.is_empty() {
let witness_vote = self.new_vote(panorama, timestamp, None, state);
effects.push(Effect::NewVertex(ValidVertex(Vertex::Vote(witness_vote))))
}
}
effects
}
Expand All @@ -120,9 +121,11 @@ impl<C: Context> ActiveValidator<C> {
warn!(%timestamp, "skipping outdated confirmation");
} else if self.should_send_confirmation(vhash, timestamp, state) {
let panorama = self.confirmation_panorama(vhash, state);
let confirmation_vote = self.new_vote(panorama, timestamp, None, state);
let vv = ValidVertex(Vertex::Vote(confirmation_vote));
return vec![Effect::NewVertex(vv)];
if !panorama.is_empty() {
let confirmation_vote = self.new_vote(panorama, timestamp, None, state);
let vv = ValidVertex(Vertex::Vote(confirmation_vote));
return vec![Effect::NewVertex(vv)];
}
}
vec![]
}
Expand Down
3 changes: 1 addition & 2 deletions node/src/components/consensus/highway_core/highway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ impl<C: Context> Highway<C> {
match self.active_validator.as_mut() {
None => {
// TODO: Error?
// At least add logging about the event.
warn!(%timestamp, "Observer node was called with `handle_timer` event.");
vec![]
}
Expand Down Expand Up @@ -239,7 +238,7 @@ impl<C: Context> Highway<C> {
fn do_pre_validate_vertex(&self, vertex: &Vertex<C>) -> Result<(), VertexError> {
match vertex {
Vertex::Vote(vote) => {
if !C::validate_signature(&vote.hash(), self.validator_pk(&vote), &vote.signature) {
if !C::verify_signature(&vote.hash(), self.validator_pk(&vote), &vote.signature) {
return Err(VoteError::Signature.into());
}
Ok(self.state.pre_validate_vote(vote)?)
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/consensus/highway_core/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ pub(crate) mod tests {
hasher.finish()
}

fn validate_signature(
fn verify_signature(
hash: &Self::Hash,
public_key: &Self::ValidatorId,
signature: &<Self::ValidatorSecret as ValidatorSecret>::Signature,
Expand Down
1 change: 0 additions & 1 deletion node/src/components/consensus/highway_core/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ impl<C: Context> Panorama<C> {
/// A vote sent to or received from the network.
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct Vote<C: Context> {
// TODO: Signature
/// The list of latest messages and faults observed by the creator of this message.
pub(crate) panorama: Panorama<C>,
/// The number of earlier messages by the same creator.
Expand Down
12 changes: 7 additions & 5 deletions node/src/components/consensus/protocols/highway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,15 @@ where
}

fn run(mut self) -> Vec<ConsensusProtocolResult<I, C::ConsensusValue>> {
while let Some(effect) = self.synchronizer_effects_queue.pop() {
self.process_synchronizer_effect(effect);
while let Some((sender, vertex)) = self.vertex_queue.pop() {
loop {
if let Some(effect) = self.synchronizer_effects_queue.pop() {
self.process_synchronizer_effect(effect);
} else if let Some((sender, vertex)) = self.vertex_queue.pop() {
self.process_vertex(sender, vertex);
} else {
return self.results;
}
}
self.results
}

fn process_vertex(&mut self, sender: I, vertex: PreValidatedVertex<C>) {
Expand Down Expand Up @@ -377,7 +379,7 @@ impl Context for HighwayContext {
hash(data)
}

fn validate_signature(hash: &Digest, public_key: &PublicKey, signature: &Signature) -> bool {
fn verify_signature(hash: &Digest, public_key: &PublicKey, signature: &Signature) -> bool {
verify(hash, signature, public_key).is_ok()
}
}
2 changes: 1 addition & 1 deletion node/src/components/consensus/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) trait Context: Clone + Debug + Eq + Ord + Hash {

fn hash(data: &[u8]) -> Self::Hash;

fn validate_signature(
fn verify_signature(
hash: &Self::Hash,
public_key: &Self::ValidatorId,
signature: &<Self::ValidatorSecret as ValidatorSecret>::Signature,
Expand Down