Skip to content

Commit

Permalink
Merge branch 'main' into task-impls-fix-lints
Browse files Browse the repository at this point in the history
  • Loading branch information
elliedavidson committed Aug 22, 2023
2 parents e8807bd + ff8b2a3 commit a114828
Show file tree
Hide file tree
Showing 55 changed files with 1,754 additions and 1,377 deletions.
186 changes: 103 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ tokio = { version = "1", optional = true, features = [
] }

tracing = "0.1.37"
ethereum-types = { version = "0.14.1", features = ["impl-serde"] }
bitvec = { version = "1.0.1", default-features = false, features = ["alloc", "atomic", "serde"] }
typenum = { version = "1.16.0" }

[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
Expand Down
6 changes: 5 additions & 1 deletion consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ tokio = { version = "1", optional = true, features = [
"tracing",
] }
tracing = "0.1.37"
time = "0.3.23"
time = "0.3.22" # 0.3.23
bitvec = { version = "1.0.1", default-features = false, features = ["alloc", "atomic", "serde"] }
hotshot-primitives = { git = "https://github.com/EspressoSystems/hotshot-primitives", branch = 'hotshot-compat'} # rev = "4aee90c" for 'hotshot-compat'
jf-primitives = { git = "https://github.com/EspressoSystems/jellyfish", branch = 'hotshot-compat'} # rev = "470a833" for branch = 'hotshot-compat'
blake3 = { version = "1.3.3", features = ["traits-preview"] }
2 changes: 0 additions & 2 deletions consensus/src/da_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,13 @@ impl<
if view_leader_key != sender {
continue;
}

let block_commitment = p.data.deltas.commit();
if !view_leader_key
.validate(&p.signature, block_commitment.as_ref())
{
warn!(?p.signature, "Could not verify proposal.");
continue;
}

let vote_token = self.exchange.make_vote_token(self.cur_view);
match vote_token {
Err(e) => {
Expand Down
30 changes: 18 additions & 12 deletions consensus/src/sequencing_leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use async_compatibility_layer::{
async_primitives::subscribable_rwlock::{ReadView, SubscribableRwLock},
};
use async_lock::{Mutex, RwLock};
use bitvec::prelude::*;
use commit::Commitment;
use commit::Committable;
use either::Either;
use either::{Left, Right};
use hotshot_types::data::QuorumProposal;
use hotshot_types::message::Message;
use hotshot_types::traits::election::CommitteeExchangeType;
use hotshot_types::traits::election::ConsensusExchange;
Expand All @@ -22,8 +22,8 @@ use hotshot_types::traits::node_implementation::{
};
use hotshot_types::traits::state::State;
use hotshot_types::{
certificate::{DACertificate, QuorumCertificate, YesNoSignature},
data::{DAProposal, SequencingLeaf},
certificate::{AssembledSignature, DACertificate, QuorumCertificate},
data::{DAProposal, QuorumProposal, SequencingLeaf},
message::{
CommitteeConsensusMessage, ConsensusMessageType, GeneralConsensusMessage, InternalTrigger,
ProcessedCommitteeConsensusMessage, ProcessedGeneralConsensusMessage,
Expand Down Expand Up @@ -98,16 +98,22 @@ where
&self,
cur_view: TYPES::Time,
threshold: NonZeroU64,
total_nodes_num: usize,
block_commitment: Commitment<<TYPES as NodeType>::BlockType>,
) -> Option<DACertificate<TYPES>> {
let lock = self.vote_collection_chan.lock().await;
let mut accumulator = VoteAccumulator {
total_vote_outcomes: HashMap::new(),
da_vote_outcomes: HashMap::new(),
yes_vote_outcomes: HashMap::new(),
no_vote_outcomes: HashMap::new(),
viewsync_precommit_vote_outcomes: HashMap::new(),
viewsync_commit_vote_outcomes: HashMap::new(),
viewsync_finalize_vote_outcomes: HashMap::new(),
success_threshold: threshold,
failure_threshold: threshold,
sig_lists: Vec::new(),
signers: bitvec![0; total_nodes_num],
};

while let Ok(msg) = lock.recv().await {
Expand Down Expand Up @@ -157,9 +163,8 @@ where
}
Either::Right(qc) => {
match qc.clone().signatures {
YesNoSignature::Yes(map) => {
info!("Number of DA signatures in this QC: {}", map.len());
}
AssembledSignature::Yes(_signature) => {}
AssembledSignature::DA(_signature) => {}
_ => unimplemented!(),
};
return Some(qc);
Expand Down Expand Up @@ -297,6 +302,7 @@ where
.wait_for_votes(
self.cur_view,
self.committee_exchange.success_threshold(),
self.committee_exchange.total_nodes(),
block_commitment,
)
.await
Expand Down Expand Up @@ -385,7 +391,6 @@ where
dac: Some(self.cert),
proposer_id: leaf.proposer_id,
};

let message =
SequencingMessage::<TYPES, I>(Left(GeneralConsensusMessage::Proposal(Proposal {
data: proposal,
Expand Down Expand Up @@ -459,14 +464,18 @@ where
pub async fn run_view(self) -> QuorumCertificate<TYPES, SequencingLeaf<TYPES>> {
let mut qcs = HashSet::<QuorumCertificate<TYPES, SequencingLeaf<TYPES>>>::new();
qcs.insert(self.generic_qc.clone());

let mut accumulator = VoteAccumulator {
total_vote_outcomes: HashMap::new(),
da_vote_outcomes: HashMap::new(),
yes_vote_outcomes: HashMap::new(),
no_vote_outcomes: HashMap::new(),
viewsync_precommit_vote_outcomes: HashMap::new(),
viewsync_commit_vote_outcomes: HashMap::new(),
viewsync_finalize_vote_outcomes: HashMap::new(),
success_threshold: self.quorum_exchange.success_threshold(),
failure_threshold: self.quorum_exchange.failure_threshold(),
sig_lists: Vec::new(),
signers: bitvec![0; self.quorum_exchange.total_nodes()],
};

let lock = self.vote_collection_chan.lock().await;
Expand Down Expand Up @@ -501,10 +510,7 @@ where
}
Either::Right(qc) => {
match qc.clone().signatures {
YesNoSignature::Yes(map) => info!(
"Number of qurorum signatures in this QC: {}",
map.len()
),
AssembledSignature::Yes(_signature) => {}
_ => unimplemented!(),
};
return qc;
Expand Down
17 changes: 14 additions & 3 deletions examples/infra/mod.rs
Original file line number Diff line number Diff line change
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 All @@ -57,6 +64,10 @@ pub fn load_config_from_file<TYPES: NodeType>(
})
.collect();

config.config.known_nodes_with_stake = (0..config.config.total_nodes.get())
.map(|node_id| config.config.known_nodes[node_id].get_stake_table_entry(1u64))
.collect();

config
}

Expand Down
44 changes: 34 additions & 10 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 All @@ -225,12 +228,12 @@ pub trait RunDA<

let config = self.get_config();

// Get KeyPair for certificate Aggregation
let (pk, sk) =
TYPES::SignatureKey::generated_from_seed_indexed(config.seed, config.node_index);
let ek = jf_primitives::aead::KeyPair::generate(&mut rand_chacha::ChaChaRng::from_seed(
config.seed,
));
let known_nodes = config.config.known_nodes.clone();
let known_nodes_with_stake = config.config.known_nodes_with_stake.clone();
let entry = pk.get_stake_table_entry(1u64);

let da_network = self.get_da_network();
let quorum_network = self.get_quorum_network();
Expand All @@ -252,6 +255,7 @@ pub trait RunDA<
);

let exchanges = NODE::Exchanges::create(
known_nodes_with_stake.clone(),
known_nodes.clone(),
(quorum_election_config, committee_election_config),
(
Expand All @@ -260,8 +264,8 @@ pub trait RunDA<
view_sync_network.clone(),
),
pk.clone(),
entry.clone(),
sk.clone(),
ek.clone(),
);

SystemContext::init(
Expand Down Expand Up @@ -424,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 @@ -452,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 @@ -522,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 @@ -615,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
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions orchestrator/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use async_compatibility_layer::art::async_sleep;
use clap::Parser;
use futures::{Future, FutureExt};

use hotshot_types::traits::node_implementation::NodeType;
use hotshot_types::traits::{node_implementation::NodeType, signature_key::SignatureKey};
use surf_disco::{error::ClientError, Client};

/// Holds the client connection to the orchestrator
Expand Down Expand Up @@ -60,14 +60,24 @@ 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,
) -> NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType> {
) -> NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
> {
let f = |client: Client<ClientError>| {
async move {
let config: Result<
NetworkConfig<TYPES::SignatureKey, TYPES::ElectionConfigType>,
NetworkConfig<
TYPES::SignatureKey,
<TYPES::SignatureKey as SignatureKey>::StakeTableEntry,
TYPES::ElectionConfigType,
>,
ClientError,
> = client
.post(&format!("api/config/{node_index}"))
Expand Down
Loading

0 comments on commit a114828

Please sign in to comment.