Skip to content

Commit

Permalink
cargo fmt --all -- --config imports_granularity=Crate
Browse files Browse the repository at this point in the history
  • Loading branch information
SurfingNerd committed Feb 8, 2024
1 parent 1b82825 commit a7fb83e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ pub fn is_connectivity_loss_reported(
)?);
}


pub fn get_current_flagged_validators_from_contract(
client: &dyn EngineClient,
block_id: BlockId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn to_toml(
}

let mut misc = Map::new();

// example for a more verbose logging.
// Value::String("txqueue=trace,consensus=debug,engine=trace,own_tx=trace,miner=trace,tx_filter=trace".into())
misc.insert(
Expand Down
37 changes: 21 additions & 16 deletions crates/ethcore/src/engines/hbbft/hbbft_early_epoch_end_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use std::{
};

use super::{
contracts::connectivity_tracker_hbbft::{
report_reconnect, is_connectivity_loss_reported,
},
contracts::connectivity_tracker_hbbft::{is_connectivity_loss_reported, report_reconnect},
hbbft_message_memorium::HbbftMessageMemorium,
NodeId,
};
Expand Down Expand Up @@ -129,19 +127,23 @@ impl HbbftEarlyEpochEndManager {
signing_address: &Address,
epoch: u64,
) -> Vec<NodeId> {

let mut result = Vec::<NodeId>::new();

for validator in validators.iter() {

let validator_address = if let Some(a) = node_id_to_address.get(validator) {
a
} else {
error!(target: "engine", "early-epoch-end: could not find address for validator in node_id_to_address cache.");
continue;
};

if let Ok(reported) = is_connectivity_loss_reported(client, block_id, signing_address, epoch, validator_address) {
if let Ok(reported) = is_connectivity_loss_reported(
client,
block_id,
signing_address,
epoch,
validator_address,
) {
if reported {
result.push(validator.clone());
}
Expand Down Expand Up @@ -227,9 +229,18 @@ impl HbbftEarlyEpochEndManager {
}
}

pub fn is_reported(&self, client: &dyn EngineClient, other_validator_address: &Address) -> bool {

let result = is_connectivity_loss_reported(client, BlockId::Latest, &self.signing_address, self.current_tracked_epoch_number, other_validator_address);
pub fn is_reported(
&self,
client: &dyn EngineClient,
other_validator_address: &Address,
) -> bool {
let result = is_connectivity_loss_reported(
client,
BlockId::Latest,
&self.signing_address,
self.current_tracked_epoch_number,
other_validator_address,
);

if let Ok(r) = result {
return r;
Expand Down Expand Up @@ -259,7 +270,6 @@ impl HbbftEarlyEpochEndManager {
return;
}


if full_client.is_syncing() {
// if we are syncing, we wont do any blaming.
debug!(target: "engine", "early-epoch-end: detected attempt to break because of is_major_syncing() instead of is_synincg()no decision: syncing");
Expand Down Expand Up @@ -294,7 +304,7 @@ impl HbbftEarlyEpochEndManager {
continue;
}
};

if let Some(node_history) = epoch_history.get_history_for_node(validator) {
let last_sealing_message = node_history.get_sealing_message();

Expand All @@ -305,22 +315,17 @@ impl HbbftEarlyEpochEndManager {
// this function will also add the validator to the list of flagged validators.
self.notify_about_missing_validator(&validator, client, full_client);
}

} else {
// this validator is OK.
// maybe it was flagged and we need to unflag it ?



if self.is_reported(client, validator_address) {
self.notify_about_validator_reconnect(&validator, full_client, client);
}
}
} else {

debug!(target: "engine", "early-epoch-end: no history info for validator {validator}");


// we do not have any history for this node.
if !self.is_reported(client, validator_address) {
// this function will also add the validator to the list of flagged validators.
Expand Down
21 changes: 8 additions & 13 deletions crates/ethcore/src/engines/hbbft/hbbft_network_fork_manager.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::VecDeque;

use ethereum_types::Address;
use hbbft::sync_key_gen::Ack;
use hbbft::sync_key_gen::Part;
use hbbft::sync_key_gen::{Ack, Part};

struct HbbftForkKeys {
validators: Vec<Address>,
Expand All @@ -19,13 +18,11 @@ struct HbbftFork {
validator_set: HbbftForkKeys,
}


/// Hbbft network fork manager.
/// This manager is responsible for managing the forks.
/// It allows cheap queries to see if a Fork is pending,
/// and stores information about a fork that is finished.
pub struct HbbftNetworkForkManager {

/// If a fork is currently in progress, this is true.
is_currently_forking: bool,

Expand All @@ -37,19 +34,17 @@ pub struct HbbftNetworkForkManager {
pending_forks: VecDeque<HbbftFork>,
}


impl HbbftNetworkForkManager {



/// Returns None if not forking
/// Returns a List of Addresses that become the new validator set and
/// declares the fork as active,
pub fn should_fork(&mut self,last_block_number: u64, last_block_time_stamp: u64) -> Option<Vec<Address>> {
/// declares the fork as active,
pub fn should_fork(
&mut self,
last_block_number: u64,
last_block_time_stamp: u64,
) -> Option<Vec<Address>> {
// fields omitted


None
}

}
}
3 changes: 1 addition & 2 deletions crates/ethcore/src/engines/hbbft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ mod contracts;
mod contribution;
mod hbbft_early_epoch_end_manager;
mod hbbft_engine;
mod hbbft_network_fork_manager;
mod hbbft_message_memorium;
mod hbbft_network_fork_manager;
mod hbbft_peers_management;
mod hbbft_state;
mod keygen_transactions;
Expand All @@ -18,7 +18,6 @@ pub use self::hbbft_engine::HoneyBadgerBFT;
use crypto::publickey::Public;
use std::fmt;


#[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct NodeId(pub Public);

Expand Down
30 changes: 17 additions & 13 deletions crates/ethjson/src/spec/hbbft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ pub struct HbbftNetworkFork {
/// Block number at which the fork starts.
pub block_number_start: u64,
/// Validator set at the fork.
pub validators: Vec<Address>,
#[serde_as(as = "Vec<serde_with::hex::Hex>")]
pub parts: Vec<Vec<u8>>,
#[serde_as(as = "Vec<serde_with::hex::Hex>")]
pub acks: Vec<Vec<u8>>,
pub acks: Vec<Vec<u8>>,
}


/// Hbbft parameters.
#[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -120,8 +118,8 @@ mod tests {
#[test]
fn hbbft_deserialization_forks() {
// let s = r#"{
// "params": {
// "forks": {
// "params": {
// "forks": {
// {
// "blockNumberStart" : 777,
// "validators": [
Expand All @@ -135,8 +133,8 @@ mod tests {
// ]
// }
// }
// }
// }"#;
// }
// }"#;

let s = r#"{
"params": {
Expand All @@ -159,12 +157,18 @@ mod tests {
}"#;

let deserialized: Hbbft = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.params.forks.len() , 1);
assert_eq!(deserialized.params.forks.get(0).expect("").block_number_start , 777);
assert_eq!(deserialized.params.forks.get(0).expect("").parts.len() , 1);
assert_eq!(deserialized.params.forks.get(0).expect("").acks.len() , 1);


assert_eq!(deserialized.params.forks.len(), 1);
assert_eq!(
deserialized
.params
.forks
.get(0)
.expect("")
.block_number_start,
777
);
assert_eq!(deserialized.params.forks.get(0).expect("").parts.len(), 1);
assert_eq!(deserialized.params.forks.get(0).expect("").acks.len(), 1);
}

#[test]
Expand Down

0 comments on commit a7fb83e

Please sign in to comment.