Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
elliedavidson committed Aug 21, 2023
1 parent 10c2b0a commit 821b47a
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 40 deletions.
15 changes: 11 additions & 4 deletions examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use hotshot_types::traits::node_implementation::NodeType;
use hotshot_types::traits::signature_key::SignatureKey;
use libp2p::{
identity::{
bn254::{Keypair as EdKeypair, SecretKey},
ed25519::{Keypair as EdKeypair, SecretKey},
Keypair,
},
multiaddr::{self},
Expand Down Expand Up @@ -36,15 +36,22 @@ pub struct OrchestratorArgs {
/// Reads a network configuration from a given filepath
pub fn load_config_from_file<TYPES: NodeType>(
config_file: String,
) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> {
let config_file_as_string: String = fs::read_to_string(config_file.as_str())
.unwrap_or_else(|_| panic!("Could not read config file located at {config_file}"));
let config_toml: NetworkConfigFile =
toml::from_str::<NetworkConfigFile>(&config_file_as_string)
.expect("Unable to convert config file to TOML");

let mut config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> =
config_toml.into();
let mut config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> = config_toml.into();

// Generate network's public keys
config.config.known_nodes = (0..config.config.total_nodes.get())
Expand Down
35 changes: 29 additions & 6 deletions examples/infra/modDA.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ use hotshot_types::{
// };
// use libp2p_identity::PeerId;
// use libp2p_networking::network::{MeshParams, NetworkNodeConfigBuilder, NetworkNodeType};
use rand::SeedableRng;
use std::fmt::Debug;
use std::net::Ipv4Addr;
use std::{
Expand Down Expand Up @@ -208,7 +207,11 @@ pub trait RunDA<
{
/// Initializes networking, returns self
async fn initialize_networking(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
) -> Self;

/// Initializes the genesis state and HotShot instance; does not start HotShot consensus
Expand Down Expand Up @@ -425,7 +428,13 @@ pub trait RunDA<
fn get_view_sync_network(&self) -> VIEWSYNCNETWORK;

/// Returns the config for this run
fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>;
fn get_config(
&self,
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>;
}

// WEB SERVER
Expand Down Expand Up @@ -453,7 +462,11 @@ pub struct WebServerDARun<
I: NodeImplementation<TYPES>,
MEMBERSHIP: Membership<TYPES>,
> {
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
quorum_network: StaticQuorumComm<TYPES, I, MEMBERSHIP>,
da_network: StaticDAComm<TYPES, I, MEMBERSHIP>,
view_sync_network: StaticViewSyncComm<TYPES, I, MEMBERSHIP>,
Expand Down Expand Up @@ -523,7 +536,11 @@ where
Self: Sync,
{
async fn initialize_networking(
config: NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
config: NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
) -> WebServerDARun<TYPES, NODE, MEMBERSHIP> {
// Generate our own key
let (pub_key, _priv_key) =
Expand Down Expand Up @@ -616,7 +633,13 @@ where
self.view_sync_network.clone()
}

fn get_config(&self) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
fn get_config(
&self,
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> {
self.config.clone()
}
}
Expand Down
2 changes: 2 additions & 0 deletions orchestrator/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ impl OrchestratorClient {

/// Returns the run configuration from the orchestrator
/// Will block until the configuration is returned
#[allow(clippy::type_complexity)]

pub async fn get_config_from_orchestrator<TYPES: NodeType>(
&self,
node_index: u16,
Expand Down
2 changes: 2 additions & 0 deletions src/traits/election/static_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ use tracing::debug;
pub struct GeneralStaticCommittee<T, LEAF: LeafType<NodeType = T>, PUBKEY: SignatureKey> {
/// All the nodes participating
nodes: Vec<PUBKEY>,
/// All the nodes participating and their stake
nodes_with_stake: Vec<PUBKEY::StakeTableEntry>,
/// The nodes on the static committee
committee_nodes: Vec<PUBKEY>,
/// The nodes on the static committee and their stake
committee_nodes_with_stake: Vec<PUBKEY::StakeTableEntry>,
/// Node type phantom
_type_phantom: PhantomData<T>,
Expand Down
6 changes: 2 additions & 4 deletions src/traits/networking/libp2p_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>>
TestableNetworkingImplementation<TYPES, Message<TYPES, I>>
for Libp2pNetwork<Message<TYPES, I>, TYPES::SignatureKey>
where
TYPES::SignatureKey: TestableSignatureKey,
MessageKind<TYPES::ConsensusType, TYPES, I>: ViewMessage<TYPES>,
MessageKind<TYPES, I>: ViewMessage<TYPES>,
{
/// Returns a boxed function `f(node_id, public_key) -> Libp2pNetwork`
/// with the purpose of generating libp2p networks.
Expand Down Expand Up @@ -750,8 +749,7 @@ impl<
> TestableNetworkingImplementation<TYPES, Message<TYPES, I>>
for Libp2pCommChannel<TYPES, I, PROPOSAL, VOTE, MEMBERSHIP>
where
TYPES::SignatureKey: TestableSignatureKey,
MessageKind<TYPES::ConsensusType, TYPES, I>: ViewMessage<TYPES>,
MessageKind<TYPES, I>: ViewMessage<TYPES>,
{
/// Returns a boxed function `f(node_id, public_key) -> Libp2pNetwork`
/// with the purpose of generating libp2p networks.
Expand Down
3 changes: 1 addition & 2 deletions src/traits/networking/memory_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ impl<
> TestableNetworkingImplementation<TYPES, Message<TYPES, I>>
for MemoryCommChannel<TYPES, I, PROPOSAL, VOTE, MEMBERSHIP>
where
TYPES::SignatureKey: TestableSignatureKey,
MessageKind<TYPES::ConsensusType, TYPES, I>: ViewMessage<TYPES>,
MessageKind<TYPES, I>: ViewMessage<TYPES>,
{
fn generator(
expected_node_count: usize,
Expand Down
1 change: 0 additions & 1 deletion testing/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use hotshot_types::{
HotShotConfig,
};
#[allow(deprecated)]
use rand::SeedableRng;
use tracing::info;

#[derive(Clone)]
Expand Down
42 changes: 19 additions & 23 deletions types/src/traits/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use crate::vote::{Accumulator, DAVote, QuorumVote, TimeoutVote, VoteType, YesOrN
use crate::{data::LeafType, traits::signature_key::SignatureKey};
use bincode::Options;
use commit::{Commitment, Committable};
use core::panic;
use derivative::Derivative;
use either::Either;
use ethereum_types::U256;
Expand Down Expand Up @@ -90,32 +89,32 @@ impl<COMMITTABLE: Committable + Serialize + Clone> Committable for VoteData<COMM
fn commit(&self) -> Commitment<Self> {
match self {
VoteData::DA(block_commitment) => commit::RawCommitmentBuilder::new("DA Block Commit")
.field("block_commitment", block_commitment.clone())
.field("block_commitment", *block_commitment)
.finalize(),
VoteData::Yes(leaf_commitment) => commit::RawCommitmentBuilder::new("Yes Vote Commit")
.field("leaf_commitment", leaf_commitment.clone())
.field("leaf_commitment", *leaf_commitment)
.finalize(),
VoteData::No(leaf_commitment) => commit::RawCommitmentBuilder::new("No Vote Commit")
.field("leaf_commitment", leaf_commitment.clone())
.field("leaf_commitment", *leaf_commitment)
.finalize(),
VoteData::Timeout(view_number_commitment) => {
commit::RawCommitmentBuilder::new("Timeout View Number Commit")
.field("view_number_commitment", view_number_commitment.clone())
.field("view_number_commitment", *view_number_commitment)
.finalize()
}
VoteData::ViewSyncPreCommit(commitment) => {
commit::RawCommitmentBuilder::new("ViewSyncPreCommit")
.field("commitment", commitment.clone())
.field("commitment", *commitment)
.finalize()
}
VoteData::ViewSyncCommit(commitment) => {
commit::RawCommitmentBuilder::new("ViewSyncCommit")
.field("commitment", commitment.clone())
.field("commitment", *commitment)
.finalize()
}
VoteData::ViewSyncFinalize(commitment) => {
commit::RawCommitmentBuilder::new("ViewSyncFinalize")
.field("commitment", commitment.clone())
.field("commitment", *commitment)
.finalize()
}
}
Expand Down Expand Up @@ -375,13 +374,12 @@ pub trait ConsensusExchange<TYPES: NodeType, M: NetworkMsg>: Send + Sync {
);
<TYPES::SignatureKey as SignatureKey>::check(&real_qc_pp, real_commit.as_ref(), &qc)
}
AssembledSignature::Genesis() => {
return true;
}
AssembledSignature::Genesis() => true,
AssembledSignature::ViewSyncPreCommit(_)
| AssembledSignature::ViewSyncCommit(_)
| AssembledSignature::ViewSyncFinalize(_) => {
panic!("QC should not be ViewSync type here");
error!("QC should not be ViewSync type here");
false
}
}
}
Expand Down Expand Up @@ -566,7 +564,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
&VoteData::<TYPES::BlockType>::DA(block_commitment)
VoteData::<TYPES::BlockType>::DA(block_commitment)
.commit()
.as_ref(),
);
Expand Down Expand Up @@ -827,7 +825,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
&VoteData::<LEAF>::Yes(leaf_commitment).commit().as_ref(),
VoteData::<LEAF>::Yes(leaf_commitment).commit().as_ref(),
);
(self.public_key.to_bytes(), signature)
}
Expand All @@ -843,7 +841,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
&VoteData::<LEAF>::No(leaf_commitment).commit().as_ref(),
VoteData::<LEAF>::No(leaf_commitment).commit().as_ref(),
);
(self.public_key.to_bytes(), signature)
}
Expand All @@ -858,7 +856,7 @@ impl<
fn sign_timeout_vote(&self, view_number: TYPES::Time) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
&VoteData::<TYPES::Time>::Timeout(view_number.commit())
VoteData::<TYPES::Time>::Timeout(view_number.commit())
.commit()
.as_ref(),
);
Expand Down Expand Up @@ -1110,7 +1108,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
&VoteData::ViewSyncPreCommit(commitment).commit().as_ref(),
VoteData::ViewSyncPreCommit(commitment).commit().as_ref(),
);

(self.public_key.to_bytes(), signature)
Expand Down Expand Up @@ -1151,7 +1149,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
&VoteData::ViewSyncCommit(commitment).commit().as_ref(),
VoteData::ViewSyncCommit(commitment).commit().as_ref(),
);

(self.public_key.to_bytes(), signature)
Expand Down Expand Up @@ -1192,7 +1190,7 @@ impl<
) -> (EncodedPublicKey, EncodedSignature) {
let signature = TYPES::SignatureKey::sign(
&self.private_key,
&VoteData::ViewSyncFinalize(commitment).commit().as_ref(),
VoteData::ViewSyncFinalize(commitment).commit().as_ref(),
);

(self.public_key.to_bytes(), signature)
Expand All @@ -1211,8 +1209,7 @@ impl<
(certificate_internal, self.failure_threshold(), vote_data)
}
ViewSyncCertificate::Commit(certificate_internal)
| ViewSyncCertificate::Finalize(certificate_internal)
=> {
| ViewSyncCertificate::Finalize(certificate_internal) => {
let vote_data = ViewSyncData::<TYPES> {
relay: self
.get_leader(round + certificate_internal.relay)
Expand Down Expand Up @@ -1264,8 +1261,7 @@ impl<
}

fn sign_certificate_proposal(&self, certificate: Self::Certificate) -> EncodedSignature {
let signature =
TYPES::SignatureKey::sign(&self.private_key, certificate.commit().as_ref());
let signature = TYPES::SignatureKey::sign(&self.private_key, certificate.commit().as_ref());
signature
}
}
Expand Down
1 change: 1 addition & 0 deletions types/src/traits/signature_key/bn254/bn254_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl BN254Priv {
}
}

#[must_use]
/// Get real seed used for random key generation funtion
pub fn get_seed_from_seed_indexed(seed: [u8; 32], index: u64) -> [u8; 32] {
let mut hasher = blake3::Hasher::new();
Expand Down
1 change: 1 addition & 0 deletions types/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ impl<TOKEN, LEAF: Committable + Serialize + Clone, TYPES: NodeType>
where
TOKEN: Clone + VoteToken,
{
#![allow(clippy::too_many_lines)]
fn append(
mut self,
val: (
Expand Down

0 comments on commit 821b47a

Please sign in to comment.