Skip to content
Closed
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
14 changes: 13 additions & 1 deletion node/src/components/consensus/highway_core/active_validator.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{self, Debug};

use tracing::warn;

use super::{
Expand Down Expand Up @@ -36,7 +38,6 @@ pub(crate) enum Effect<C: Context> {
/// If the rounds are long enough (i.e. message delivery is fast enough) and there are enough
/// honest validators, there will be a lot of confirmations for the proposal, and enough witness
/// votes citing all those confirmations, to create a summit and finalize the proposal.
#[derive(Debug)]
pub(crate) struct ActiveValidator<C: Context> {
/// Our own validator index.
vidx: ValidatorIndex,
Expand All @@ -48,6 +49,17 @@ pub(crate) struct ActiveValidator<C: Context> {
next_timer: u64,
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `Debug`
impl<C: Context> Debug for ActiveValidator<C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ActiveValidator")
.field("vidx", &self.vidx)
.field("round_exp", &self.round_exp)
.field("next_timer", &self.next_timer)
.finish()
}
}

impl<C: Context> ActiveValidator<C> {
/// Creates a new `ActiveValidator` and the timer effect for the first call.
pub(crate) fn new(
Expand Down
37 changes: 35 additions & 2 deletions node/src/components/consensus/highway_core/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::iter;
use std::{
fmt::{self, Debug},
iter,
};

use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -51,7 +54,7 @@ impl<C: Context> Vertex<C> {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
#[serde(bound(
serialize = "C::Hash: Serialize",
deserialize = "C::Hash: Deserialize<'de>",
Expand All @@ -61,6 +64,36 @@ pub(crate) struct SignedWireVote<C: Context> {
pub(crate) signature: <C::ValidatorSecret as ValidatorSecret>::Signature,
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `Clone`
impl<C: Context> Clone for SignedWireVote<C> {
fn clone(&self) -> Self {
Self {
wire_vote: self.wire_vote.clone(),
signature: self.signature.clone(),
}
}
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `Debug`
impl<C: Context> Debug for SignedWireVote<C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("SignedWireVote")
.field("wire_vote", &self.wire_vote)
.field("signature", &self.signature)
.finish()
}
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `PartialEq`
impl<C: Context> PartialEq for SignedWireVote<C> {
fn eq(&self, other: &SignedWireVote<C>) -> bool {
self.wire_vote == other.wire_vote && self.signature == other.signature
}
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `Eq`
impl<C: Context> Eq for SignedWireVote<C> {}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's happening here? Is it using the PartialEq?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Trait Eq is just a marker which says that the PartialEq implementation has some specific properties. It doesn't add any methods itself.


impl<C: Context> SignedWireVote<C> {
pub(crate) fn new(wire_vote: WireVote<C>, secret_key: &C::ValidatorSecret) -> Self {
let signature = secret_key.sign(&wire_vote.hash());
Expand Down
49 changes: 48 additions & 1 deletion node/src/components/consensus/highway_core/vote.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{self, Debug};

use serde::{Deserialize, Serialize};

use super::{state::State, validators::ValidatorIndex, vertex::WireVote};
Expand Down Expand Up @@ -103,7 +105,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.
Expand All @@ -125,6 +126,52 @@ pub(crate) struct Vote<C: Context> {
pub(crate) signature: <C::ValidatorSecret as ValidatorSecret>::Signature,
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `Clone`
impl<C: Context> Clone for Vote<C> {
fn clone(&self) -> Self {
Self {
panorama: self.panorama.clone(),
seq_number: self.seq_number,
creator: self.creator,
block: self.block.clone(),
skip_idx: self.skip_idx.clone(),
timestamp: self.timestamp,
signature: self.signature.clone(),
}
}
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `Debug`
impl<C: Context> Debug for Vote<C> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Vote")
.field("panorama", &self.panorama)
.field("seq_number", &self.seq_number)
.field("creator", &self.creator)
.field("block", &self.block)
.field("skip_idx", &self.skip_idx)
.field("timestamp", &self.timestamp)
.field("signature", &self.signature)
.finish()
}
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `PartialEq`
impl<C: Context> PartialEq for Vote<C> {
fn eq(&self, other: &Vote<C>) -> bool {
self.panorama == other.panorama
&& self.seq_number == other.seq_number
&& self.creator == other.creator
&& self.block == other.block
&& self.skip_idx == other.skip_idx
&& self.timestamp == other.timestamp
&& self.signature == other.signature
}
}

// `#[derive]` doesn't work if `C::ValidatorSecret` is not `Eq`
impl<C: Context> Eq for Vote<C> {}

impl<C: Context> Vote<C> {
/// Creates a new `Vote` from the `WireVote`, and returns the value if it contained any.
/// Values must be stored as a block, with the same hash.
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/consensus/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) trait HashT:
impl<H> HashT for H where H: Eq + Ord + Clone + Debug + Hash + Serialize + DeserializeOwned {}

/// A validator's secret signing key.
pub(crate) trait ValidatorSecret: Debug + Eq + Clone {
pub(crate) trait ValidatorSecret {
type Hash;

type Signature: Eq + PartialEq + Clone + Debug + Hash + Serialize + DeserializeOwned;
Expand Down