Skip to content

Commit

Permalink
Merge branch 'main' into romac/tendermint
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 21, 2023
2 parents c462be8 + 0ea4ce9 commit 5534ae9
Show file tree
Hide file tree
Showing 62 changed files with 3,192 additions and 857 deletions.
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: llvm-tools-preview
- name: Install cargo-nextest
uses: taiki-e/install-action@cargo-nextest
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/quint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ jobs:
quint-typecheck:
name: Typecheck
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./Specs/Quint
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "18"
- run: npm install -g @informalsystems/quint
- run: npx @informalsystems/quint typecheck consensus.qnt
- run: npx @informalsystems/quint typecheck voteBookkeeper.qnt
- run: bash Scripts/quint-forall.sh typecheck Specs/Quint/*.qnt

quint-test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "18"
- run: npm install -g @informalsystems/quint
- run: bash Scripts/quint-forall.sh test Specs/Quint/*Test.qnt

8 changes: 6 additions & 2 deletions Code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ resolver = "2"
members = [
"common",
"driver",
"itf",
"round",
"vote",
"tendermint",
"test",
"vote",
]

[workspace.package]
Expand All @@ -18,9 +19,12 @@ license = "Apache-2.0"
publish = false

[workspace.dependencies]
async-trait = "0.1"
futures = "0.3"
ed25519-consensus = "2.1.0"
itf = "0.1.2"
rand = { version = "0.8.5", features = ["std_rng"] }
secrecy = "0.8.0"
serde = "1.0"
sha2 = "0.10.8"
signature = "2.1.0"
tendermint = { version = "0.34.0", default-features = false, features = ["rust-crypto"] }
1 change: 0 additions & 1 deletion Code/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ license.workspace = true
publish.workspace = true

[dependencies]
secrecy.workspace = true
signature.workspace = true
11 changes: 6 additions & 5 deletions Code/common/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
Address, Height, PrivateKey, Proposal, PublicKey, Round, Signature, SignedVote, SigningScheme,
Validator, ValidatorSet, Value, ValueId, Vote,
Address, Height, Proposal, PublicKey, Round, SignedVote, SigningScheme, Validator,
ValidatorSet, Value, ValueId, Vote,
};

/// This trait allows to abstract over the various datatypes
Expand All @@ -18,9 +18,8 @@ where
type Vote: Vote<Self>;
type SigningScheme: SigningScheme; // TODO: Do we need to support multiple signing schemes?

/// Sign the given vote using the given private key.
/// TODO: Maybe move this as concrete methods in `SignedVote`?
fn sign_vote(&self, vote: &Self::Vote, private_key: &PrivateKey<Self>) -> Signature<Self>;
/// Sign the given vote with our private key.
fn sign_vote(&self, vote: Self::Vote) -> SignedVote<Self>;

/// Verify the given vote's signature using the given public key.
/// TODO: Maybe move this as concrete methods in `SignedVote`?
Expand All @@ -41,6 +40,7 @@ where
/// Build a new prevote vote by the validator with the given address,
/// for the value identified by the given value id, at the given round.
fn new_prevote(
height: Self::Height,
round: Round,
value_id: Option<ValueId<Self>>,
address: Self::Address,
Expand All @@ -49,6 +49,7 @@ where
/// Build a new precommit vote by the validator with the given address,
/// for the value identified by the given value id, at the given round.
fn new_precommit(
height: Self::Height,
round: Round,
value_id: Option<ValueId<Self>>,
address: Self::Address,
Expand Down
2 changes: 1 addition & 1 deletion Code/common/src/height.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ use core::fmt::Debug;
pub trait Height
where
// TODO: Require Copy as well?
Self: Clone + Debug + PartialEq + Eq + PartialOrd + Ord,
Self: Default + Clone + Debug + PartialEq + Eq + PartialOrd + Ord,
{
}
1 change: 1 addition & 0 deletions Code/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
variant_size_differences
)]
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::panic))]
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

mod context;
mod height;
Expand Down
36 changes: 35 additions & 1 deletion Code/common/src/signed_vote.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use core::fmt;

use crate::{Context, Signature, Vote};

// TODO: Do we need to abstract over `SignedVote` as well?

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SignedVote<Ctx>
where
Ctx: Context,
Expand All @@ -23,3 +24,36 @@ where
self.vote.validator_address()
}
}

// NOTE: We have to derive these instances manually, otherwise
// the compiler would infer a Clone/Debug/PartialEq/Eq bound on `Ctx`,
// which may not hold for all contexts.

impl<Ctx: Context> Clone for SignedVote<Ctx> {
#[cfg_attr(coverage_nightly, coverage(off))]
fn clone(&self) -> Self {
Self {
vote: self.vote.clone(),
signature: self.signature.clone(),
}
}
}

impl<Ctx: Context> fmt::Debug for SignedVote<Ctx> {
#[cfg_attr(coverage_nightly, coverage(off))]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("SignedVote")
.field("vote", &self.vote)
.field("signature", &self.signature)
.finish()
}
}

impl<Ctx: Context> PartialEq for SignedVote<Ctx> {
#[cfg_attr(coverage_nightly, coverage(off))]
fn eq(&self, other: &Self) -> bool {
self.vote == other.vote && self.signature == other.signature
}
}

impl<Ctx: Context> Eq for SignedVote<Ctx> {}
8 changes: 1 addition & 7 deletions Code/common/src/signing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::fmt::Debug;

use secrecy::{CloneableSecret, DebugSecret, Zeroize};
use signature::{Keypair, Signer, Verifier};

pub trait SigningScheme
Expand All @@ -11,10 +10,5 @@ where

type PublicKey: Clone + Debug + Eq + Verifier<Self::Signature>;

type PrivateKey: Clone
+ Signer<Self::Signature>
+ Keypair<VerifyingKey = Self::PublicKey>
+ Zeroize
+ DebugSecret
+ CloneableSecret;
type PrivateKey: Clone + Signer<Self::Signature> + Keypair<VerifyingKey = Self::PublicKey>;
}
4 changes: 2 additions & 2 deletions Code/common/src/validator_set.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::fmt::Debug;
use core::fmt::{Debug, Display};

use crate::{Context, PublicKey};

Expand All @@ -12,7 +12,7 @@ pub type VotingPower = u64;
/// TODO: Keep this trait or just add the bounds to Consensus::Address?
pub trait Address
where
Self: Clone + Debug + Eq + Ord,
Self: Clone + Debug + Display + Eq + Ord,
{
}

Expand Down
3 changes: 3 additions & 0 deletions Code/common/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ where
Self: Clone + Debug + Eq,
Ctx: Context,
{
/// The height for which the vote is for.
fn height(&self) -> Ctx::Height;

/// The round for which the vote is for.
fn round(&self) -> Round;

Expand Down
2 changes: 1 addition & 1 deletion Code/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ malachite-common = { version = "0.1.0", path = "../common" }
malachite-round = { version = "0.1.0", path = "../round" }
malachite-vote = { version = "0.1.0", path = "../vote" }

secrecy.workspace = true
async-trait.workspace = true
14 changes: 0 additions & 14 deletions Code/driver/src/client.rs

This file was deleted.

Loading

0 comments on commit 5534ae9

Please sign in to comment.