Skip to content

Commit

Permalink
refactor: apply cargo +nightly fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kodemartin committed May 28, 2024
1 parent c687953 commit e3df5e3
Show file tree
Hide file tree
Showing 1,157 changed files with 32,565 additions and 25,286 deletions.
23 changes: 12 additions & 11 deletions consensus/config/src/committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use crate::{AuthorityPublicKey, NetworkPublicKey, ProtocolPublicKey};
/// Committee of the consensus protocol is updated each epoch.
pub type Epoch = u64;

/// Voting power of an authority, roughly proportional to the actual amount of Sui staked
/// by the authority.
/// Voting power of an authority, roughly proportional to the actual amount of
/// Sui staked by the authority.
/// Total stake / voting power of all authorities should sum to 10,000.
pub type Stake = u64;

/// Committee is the set of authorities that participate in the consensus protocol for this epoch.
/// Its configuration is stored and computed on chain.
/// Committee is the set of authorities that participate in the consensus
/// protocol for this epoch. Its configuration is stored and computed on chain.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Committee {
/// The epoch number of this committee
Expand Down Expand Up @@ -127,8 +127,8 @@ impl Committee {

/// Represents one authority in the committee.
///
/// NOTE: this is intentionally un-cloneable, to encourage only copying relevant fields.
/// AuthorityIndex should be used to reference an authority instead.
/// NOTE: this is intentionally un-cloneable, to encourage only copying relevant
/// fields. AuthorityIndex should be used to reference an authority instead.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Authority {
/// Voting power of the authority in the committee.
Expand All @@ -145,12 +145,13 @@ pub struct Authority {
pub network_key: NetworkPublicKey,
}

/// Each authority is uniquely identified by its AuthorityIndex in the Committee.
/// AuthorityIndex is between 0 (inclusive) and the total number of authorities (exclusive).
/// Each authority is uniquely identified by its AuthorityIndex in the
/// Committee. AuthorityIndex is between 0 (inclusive) and the total number of
/// authorities (exclusive).
///
/// NOTE: for safety, invalid AuthorityIndex should be impossible to create. So AuthorityIndex
/// should not be created or incremented outside of this file. AuthorityIndex received from peers
/// should be validated before use.
/// NOTE: for safety, invalid AuthorityIndex should be impossible to create. So
/// AuthorityIndex should not be created or incremented outside of this file.
/// AuthorityIndex received from peers should be validated before use.
#[derive(
Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug, Default, Hash, Serialize, Deserialize,
)]
Expand Down
20 changes: 11 additions & 9 deletions consensus/config/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//! Here we select the cryptographic types that are used by default in the code base.
//! The whole code base should only:
//! Here we select the cryptographic types that are used by default in the code
//! base. The whole code base should only:
//! - refer to those aliases and not use the individual scheme implementations
//! - not use the schemes in a way that break genericity (e.g. using their Struct impl functions)
//! - not use the schemes in a way that break genericity (e.g. using their
//! Struct impl functions)
//! - swap one of those aliases to point to another type if necessary
//!
//! Beware: if you change those aliases to point to another scheme implementation, you will have
//! to change all four aliases to point to concrete types that work with each other. Failure to do
//! so will result in a ton of compilation errors, and worse: it will not make sense!
//! Beware: if you change those aliases to point to another scheme
//! implementation, you will have to change all four aliases to point to
//! concrete types that work with each other. Failure to do so will result in a
//! ton of compilation errors, and worse: it will not make sense!
use fastcrypto::{
bls12381, ed25519,
Expand All @@ -32,7 +34,7 @@ impl NetworkPublicKey {
}

pub fn to_bytes(&self) -> [u8; 32] {
self.0 .0.to_bytes()
self.0.0.to_bytes()
}
}

Expand Down Expand Up @@ -118,8 +120,8 @@ impl ProtocolKeySignature {
}
}

/// Authority key represents the identity of an authority. It is only used for identity sanity
/// checks and not used for verification.
/// Authority key represents the identity of an authority. It is only used for
/// identity sanity checks and not used for verification.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct AuthorityPublicKey(bls12381::min_sig::BLS12381PublicKey);
pub struct AuthorityKeyPair(bls12381::min_sig::BLS12381KeyPair);
Expand Down
37 changes: 22 additions & 15 deletions consensus/config/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@ use serde::{Deserialize, Serialize};

/// Operational configurations of a consensus authority.
///
/// All fields should tolerate inconsistencies among authorities, without affecting safety of the
/// protocol. Otherwise, they need to be part of Sui protocol config or epoch state on-chain.
/// All fields should tolerate inconsistencies among authorities, without
/// affecting safety of the protocol. Otherwise, they need to be part of Sui
/// protocol config or epoch state on-chain.
///
/// NOTE: fields with default values are specified in the serde default functions. Most operators
/// should not need to specify any field, except db_path.
/// NOTE: fields with default values are specified in the serde default
/// functions. Most operators should not need to specify any field, except
/// db_path.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Parameters {
/// The number of rounds of blocks to be kept in the Dag state cache per authority. The larger
/// the number the more the blocks that will be kept in memory allowing minimising any potential
/// disk access. Should be careful when tuning this parameter as it could be quite memory expensive.
/// Value should be at minimum 50 rounds to ensure node performance and protocol advance.
/// The number of rounds of blocks to be kept in the Dag state cache per
/// authority. The larger the number the more the blocks that will be
/// kept in memory allowing minimising any potential disk access. Should
/// be careful when tuning this parameter as it could be quite memory
/// expensive. Value should be at minimum 50 rounds to ensure node
/// performance and protocol advance.
#[serde(default = "Parameters::default_dag_state_cached_rounds")]
pub dag_state_cached_rounds: u32,

/// Time to wait for parent round leader before sealing a block.
#[serde(default = "Parameters::default_leader_timeout")]
pub leader_timeout: Duration,

/// Minimum delay between rounds, to avoid generating too many rounds when latency is low.
/// This is especially necessary for tests running locally.
/// If setting a non-default value, it should be set low enough to avoid reducing
/// round rate and increasing latency in realistic and distributed configurations.
/// Minimum delay between rounds, to avoid generating too many rounds when
/// latency is low. This is especially necessary for tests running
/// locally. If setting a non-default value, it should be set low enough
/// to avoid reducing round rate and increasing latency in realistic and
/// distributed configurations.
#[serde(default = "Parameters::default_min_round_delay")]
pub min_round_delay: Duration,

/// Maximum forward time drift (how far in future) allowed for received blocks.
/// Maximum forward time drift (how far in future) allowed for received
/// blocks.
#[serde(default = "Parameters::default_max_forward_time_drift")]
pub max_forward_time_drift: Duration,

Expand Down Expand Up @@ -88,8 +94,9 @@ impl Default for Parameters {

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AnemoParameters {
/// Size in bytes above which network messages are considered excessively large. Excessively
/// large messages will still be handled, but logged and reported in metrics for debugging.
/// Size in bytes above which network messages are considered excessively
/// large. Excessively large messages will still be handled, but logged
/// and reported in metrics for debugging.
///
/// If unspecified, this will default to 8 MiB.
#[serde(default = "AnemoParameters::default_excessive_message_size")]
Expand Down
17 changes: 10 additions & 7 deletions consensus/config/src/test_committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use crate::{
Authority, AuthorityKeyPair, Committee, Epoch, NetworkKeyPair, ProtocolKeyPair, Stake,
};

/// Creates a committee for local testing, and the corresponding key pairs for the authorities.
/// Creates a committee for local testing, and the corresponding key pairs for
/// the authorities.
pub fn local_committee_and_keys(
epoch: Epoch,
authorities_stake: Vec<Stake>,
Expand Down Expand Up @@ -44,9 +45,10 @@ fn get_available_local_address() -> Multiaddr {
format!("/ip4/{}/udp/{}", host, port).parse().unwrap()
}

/// Returns an ephemeral, available port. On unix systems, the port returned will be in the
/// TIME_WAIT state ensuring that the OS won't hand out this port for some grace period.
/// Callers should be able to bind to this port given they use SO_REUSEADDR.
/// Returns an ephemeral, available port. On unix systems, the port returned
/// will be in the TIME_WAIT state ensuring that the OS won't hand out this port
/// for some grace period. Callers should be able to bind to this port given
/// they use SO_REUSEADDR.
fn get_available_port(host: &str) -> u16 {
const MAX_PORT_RETRIES: u32 = 1000;

Expand All @@ -64,9 +66,10 @@ fn get_ephemeral_port(host: &str) -> std::io::Result<u16> {
let listener = TcpListener::bind((host, 0))?;
let addr = listener.local_addr()?;

// Create and accept a connection (which we'll promptly drop) in order to force the port
// into the TIME_WAIT state, ensuring that the port will be reserved from some limited
// amount of time (roughly 60s on some Linux systems)
// Create and accept a connection (which we'll promptly drop) in order to force
// the port into the TIME_WAIT state, ensuring that the port will be
// reserved from some limited amount of time (roughly 60s on some Linux
// systems)
let _sender = TcpStream::connect(addr)?;
let _incoming = listener.accept()?;

Expand Down
5 changes: 3 additions & 2 deletions consensus/config/tests/committee_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use insta::assert_yaml_snapshot;
use mysten_network::Multiaddr;
use rand::{rngs::StdRng, SeedableRng as _};

// Committee is not sent over network or stored on disk itself, but some of its fields are.
// So this test can still be useful to detect accidental format changes.
// Committee is not sent over network or stored on disk itself, but some of its
// fields are. So this test can still be useful to detect accidental format
// changes.
#[test]
fn committee_snapshot_matches() {
let epoch = 100;
Expand Down
6 changes: 4 additions & 2 deletions consensus/core/src/authority_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ use crate::{
};

/// ConsensusAuthority is used by Sui to manage the lifetime of AuthorityNode.
/// It hides the details of the implementation from the caller, MysticetiManager.
/// It hides the details of the implementation from the caller,
/// MysticetiManager.
#[allow(private_interfaces)]
pub enum ConsensusAuthority {
WithAnemo(AuthorityNode<AnemoManager>),
Expand Down Expand Up @@ -176,7 +177,8 @@ where
let mut network_manager = N::new(context.clone());
let network_client = network_manager.client();

// REQUIRED: Broadcaster must be created before Core, to start listen on block broadcasts.
// REQUIRED: Broadcaster must be created before Core, to start listen on block
// broadcasts.
let broadcaster =
Broadcaster::new(context.clone(), network_client.clone(), &signals_receivers);

Expand Down
Loading

0 comments on commit e3df5e3

Please sign in to comment.