Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cargo +nightly fmt with wrap_comments = true #2485

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion chain/src/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,12 @@ fn test_next_epoch_ext() {
// upper bound trigger
assert_eq!(epoch.length(), 800, "epoch length {}", epoch.length());

// orphan_rate_estimation = 1 / ( (1 + o_i ) * L_ideal * C_i,m / (o_i * L_i * C_i+1,m) − 1) = 133 / 9587
// orphan_rate_estimation
// = 1 / ( (1 + o_i ) * L_ideal * C_i,m / (o_i * L_i * C_i+1,m) − 1)
// = 133 / 9587
//
// Diff_i+1 = (HPS_i · L_ideal) / (1 + orphan_rate_estimation ) * C_i+1,m
//
// 50 * 14400 * 9587 / ((133 + 9587) * 800)
assert_eq!(
epoch.compact_target(),
Expand Down
3 changes: 2 additions & 1 deletion chain/src/tests/load_input_data_hash_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ fn test_load_input_data_hash_cell() {
let entry0 = vec![TxEntry::new(tx0, 0, Capacity::shannons(0), 100, vec![])];
tx_pool.plug_entry(entry0, PlugTarget::Proposed).unwrap();

// Ensure tx which calls syscall load_cell_data_hash will got reject even previous tx is already in tx-pool
// Ensure tx which calls syscall load_cell_data_hash will got reject even previous tx is already
// in tx-pool
let ret = tx_pool.submit_txs(vec![tx1]).unwrap();
assert!(ret.is_err());
assert!(format!("{}", ret.err().unwrap()).contains("ValidationFailure(2)"));
Expand Down
3 changes: 2 additions & 1 deletion ckb-bin/src/subcommand/list_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl TryFrom<ChainSpec> for SpecHashes {
let cellbase = &block.transactions()[0];
let dep_group_tx = &block.transactions()[1];

// Zip name with the transaction outputs. System cells start from 1 in the genesis cellbase outputs.
// Zip name with the transaction outputs. System cells start from 1 in the genesis cellbase
// outputs.
let cells_hashes = spec
.genesis
.system_cells
Expand Down
3 changes: 2 additions & 1 deletion error/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub struct OtherError(String);

/// A list specifying categories of ckb internal error.
///
/// This list is intended to grow over time and it is not recommended to exhaustively match against it.
/// This list is intended to grow over time and it is not recommended to exhaustively match against
/// it.
///
/// It is used with the [`InternalError`].
///
Expand Down
3 changes: 2 additions & 1 deletion error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub struct AnyError(Arc<anyhow::Error>);

/// A list specifying categories of ckb error.
///
/// This list is intended to grow over time and it is not recommended to exhaustively match against it.
/// This list is intended to grow over time and it is not recommended to exhaustively match against
/// it.
///
/// It is used with [`Error`].
///
Expand Down
3 changes: 2 additions & 1 deletion error/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ macro_rules! impl_error_conversion_with_kind {
};
}

/// A macro to implement conversion from source type to target type based on an implicit middle adaptor.
/// A macro to implement conversion from source type to target type based on an implicit middle
/// adaptor.
///
/// ## Examples
///
Expand Down
3 changes: 2 additions & 1 deletion indexer/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,8 @@ impl IndexerStoreTransaction {
}

fn commit(self) {
// only log the error, indexer store commit failure should not causing the thread to panic entirely.
// only log the error, indexer store commit failure should not causing the thread to panic
// entirely.
if let Err(err) = self.txn.commit() {
error!("indexer db failed to commit txn, error: {:?}", err)
}
Expand Down
3 changes: 2 additions & 1 deletion miner/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ impl Rpc {
let (stop, stop_rx) = oneshot::channel::<()>();

let thread = thread::spawn(move || {
// 1 is number of blocking DNS threads, this connector will use plain HTTP if the URL provded uses the HTTP scheme.
// 1 is number of blocking DNS threads, this connector will use plain HTTP if the URL
// provded uses the HTTP scheme.
let https =
hyper_tls::HttpsConnector::new(1).expect("init https connector should be OK");
let client = HttpClient::builder().keep_alive(true).build(https);
Expand Down
5 changes: 2 additions & 3 deletions network/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! ckb network module
//!
//! This module is based on the Tentacle library, once again abstract the context that protocols can use,
//! and providing a unified implementation of the peer storage and registration mechanism.
//! This module is based on the Tentacle library, once again abstract the context that protocols can
//! use, and providing a unified implementation of the peer storage and registration mechanism.
//!
//! And implemented several basic protocols: identify, discovery, ping, feeler, disconnect_message
//!

mod behaviour;
mod compress;
Expand Down
7 changes: 4 additions & 3 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ impl NetworkState {
}
}

/// Network message processing controller, default is true, if false, discard any received messages
/// Network message processing controller, default is true, if false, discard any received
/// messages
pub fn is_active(&self) -> bool {
self.active.load(Ordering::Relaxed)
}
Expand Down Expand Up @@ -939,8 +940,8 @@ impl<T: ExitHandler> NetworkService<T> {
// and the administrator permissions of group permissions must be turned on.
// This operation is very burdensome for windows users, so it is turned off by default
//
// The integration test fails after MacOS is turned on, the behavior is different from linux.
// Decision to turn off it
// The integration test fails after MacOS is turned on, the behavior is different from
// linux. Decision to turn off it
let p2p_service = service_builder.build(event_handler);

// == Build background service tasks
Expand Down
3 changes: 2 additions & 1 deletion network/src/protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ pub trait CKBProtocolContext: Send {
fn quick_send_message_to(&self, peer_index: PeerIndex, data: Bytes) -> Result<(), Error>;
/// Filter broadcast message through quick queue
fn quick_filter_broadcast(&self, target: TargetSession, data: Bytes) -> Result<(), Error>;
/// spawn a future task, if `blocking` is true we use tokio_threadpool::blocking to handle the task.
/// spawn a future task, if `blocking` is true we use tokio_threadpool::blocking to handle the
/// task.
fn future_task(&self, task: BoxedFutureTask, blocking: bool) -> Result<(), Error>;
/// Send message
fn send_message(
Expand Down
3 changes: 2 additions & 1 deletion network/src/protocols/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const CONTROL_CHANNEL_BUFFER_SIZE: usize = 2;
/// Ping protocol handler.
///
/// The interval means that we send ping to peers.
/// The timeout means that consider peer is timeout if during a timeout we still have not received pong from a peer
/// The timeout means that consider peer is timeout if during a timeout we still have not received
/// pong from a peer
pub struct PingHandler {
interval: Duration,
timeout: Duration,
Expand Down
23 changes: 13 additions & 10 deletions network/src/protocols/support_protocols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use tokio_util::codec::length_delimited;

/// All supported protocols
///
/// The underlying network of CKB is flexible and complex. The flexibility lies in that it can support any number of protocols.
/// Therefore, it is also relatively complex. Now, CKB has a bunch of protocols open by default,
/// but not all protocols have to be open. In other words, if you want to interact with ckb nodes at the p2p layer,
/// you only need to implement a few core protocols.
/// The underlying network of CKB is flexible and complex. The flexibility lies in that it can
/// support any number of protocols. Therefore, it is also relatively complex. Now, CKB has a bunch
/// of protocols open by default, but not all protocols have to be open. In other words, if you want
/// to interact with ckb nodes at the p2p layer, you only need to implement a few core protocols.
///
/// Core protocol: identify/discovery/sync/relay
#[derive(Clone, Debug)]
Expand All @@ -22,7 +22,8 @@ pub enum SupportProtocols {
/// to build a robust network topology as much as possible.
Discovery,
/// Identify: the first protocol opened when the nodes are interconnected,
/// used to obtain the features, versions, and observation addresses supported by the other node.
/// used to obtain the features, versions, and observation addresses supported by the other
/// node.
///
/// [RFC](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0012-node-discovery/0012-node-discovery.md)
Identify,
Expand All @@ -31,8 +32,9 @@ pub enum SupportProtocols {
/// [RFC](https://github.com/nervosnetwork/rfcs/blob/v2020.01.15/rfcs/0007-scoring-system-and-network-security/0007-scoring-system-and-network-security.md#feeler-connection)
/// [Eclipse Attacks on Bitcoin's Peer-to-Peer Network](https://cryptographylab.bitbucket.io/slides/Eclipse%20Attacks%20on%20Bitcoin%27s%20Peer-to-Peer%20Network.pdf)
Feeler,
/// Disconnect message: used to give the remote node a debug message when the node decides to disconnect.
/// This message must be as quick as possible, otherwise the message may not be sent. So, use a separate protocol to support it.
/// Disconnect message: used to give the remote node a debug message when the node decides to
/// disconnect. This message must be as quick as possible, otherwise the message may not be
/// sent. So, use a separate protocol to support it.
DisconnectMessage,
/// Sync: ckb's main communication protocol for synchronize all blocks.
///
Expand All @@ -42,7 +44,8 @@ pub enum SupportProtocols {
///
/// [RFC](https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0004-ckb-block-sync/0004-ckb-block-sync.md#new-block-announcement)
Relay,
/// Time: A protocol used for node pairing that warns if there is a large gap between the local time and the remote node.
/// Time: A protocol used for node pairing that warns if there is a large gap between the local
/// time and the remote node.
Time,
/// Alert: A protocol reserved by the Nervos Foundation to publish network-wide announcements.
/// Any information sent from the protocol is verified by multi-signature
Expand Down Expand Up @@ -84,8 +87,8 @@ impl SupportProtocols {

/// Support versions
pub fn support_versions(&self) -> Vec<String> {
// we didn't invoke MetaBuilder#support_versions fn for these protocols (Ping/Discovery/Identify/Feeler/DisconnectMessage)
// in previous code, so the default 0.0.1 value is used ( https://github.com/nervosnetwork/tentacle/blob/master/src/builder.rs#L312 )
// we didn't invoke MetaBuilder#support_versions fn for these protocols
// (Ping/Discovery/Identify/Feeler/DisconnectMessage) in previous code, so the default 0.0.1 value is used ( https://github.com/nervosnetwork/tentacle/blob/master/src/builder.rs#L312 )
// have to keep 0.0.1 for compatibility...
match self {
SupportProtocols::Ping => vec!["0.0.1".to_owned()],
Expand Down
2 changes: 1 addition & 1 deletion network/src/services/dns_seeding/seed_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const SEP: char = ';';

// Typical txt record:
// ==================
// 47.103.65.40;49582;QmbU82jmDbu8AsUfa6bDKPHxTpwnPfcRQrzNPacKcSyM1Y;1574942409;K1vAkHZZ8to5VmjD4eyv65ENLbNa9Tda4Aytd8DE9iipFQanRpcZtSPyRiiGHThRGJPVRD18KAsGb8kV2s2WBK39R
// 47.103.65.40;49582;QmbU82jmDbu8AsUfa6bDKPHxTpwnPfcRQrzNPacKcSyM1Y;1574942409;K1vAkHZZ8to5VmjD4eyv65ENLbNa9Tda4Aytd8DE9iipFQanRpcZtSPyRiiGHThRGJPVRD18KAsGb8kV2s2WBK39R
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct SeedRecord {
ip: IpAddr,
Expand Down
5 changes: 3 additions & 2 deletions network/src/services/protocol_type_checker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// CKB evicts inactive peers in `sync` protocol; but due to P2P connection design,
/// a malicious peer may choose not to open `sync` protocol, to sneak from the eviction mechanism;
/// this service periodically check peers opened sub-protocols, to make sure no malicious connection.
/// a malicious peer may choose not to open `sync` protocol, to sneak from the eviction
/// mechanism; this service periodically check peers opened sub-protocols, to make sure no
/// malicious connection.
///
/// Currently, 2 sub-protocols types are valid:
///
Expand Down
4 changes: 2 additions & 2 deletions resource/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use std::io;
/// The block starts with the line ending with ` # {{` (the leading space is required) and ends
/// with a line `# }}`.
///
/// Between the start and end markers, every line is a branch starting with `# SPEC => CONTENT`, where
/// `SPEC` is the branch spec name, and `CONTENT` is the text to be replaced for the spec.
/// Between the start and end markers, every line is a branch starting with `# SPEC => CONTENT`,
/// where `SPEC` is the branch spec name, and `CONTENT` is the text to be replaced for the spec.
/// A special spec name `_` acts as a wildcard which matches any spec name.
///
/// The spec name is required to render the template, see [`Template::new`]. The block including
Expand Down
25 changes: 14 additions & 11 deletions rpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use std::fmt::{Debug, Display};
/// * -1000 ~ -2999 are module-specific errors. Each module generally gets 100 reserved error
/// codes.
///
/// Unless otherwise noted, all the errors return optional detailed information as `string` in the error
/// object `data` field.
/// Unless otherwise noted, all the errors return optional detailed information as `string` in the
/// error object `data` field.
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum RPCError {
/// (-1): CKB internal errors are considered to never happen or only happen when the system
Expand Down Expand Up @@ -65,8 +65,8 @@ pub enum RPCError {
DatabaseError = -200,
/// (-201): The chain index is inconsistent.
///
/// An example of an inconsistent index is that the chain index says a block hash is in the chain
/// but the block cannot be read from the database.
/// An example of an inconsistent index is that the chain index says a block hash is in the
/// chain but the block cannot be read from the database.
///
/// This is a fatal error usually due to a serious bug. Please back up the data directory and
/// re-sync the chain from scratch.
Expand All @@ -76,27 +76,30 @@ pub enum RPCError {
/// This is a fatal error usually caused by the underlying database used by CKB. Please back up
/// the data directory and re-sync the chain from scratch.
DatabaseIsCorrupt = -202,
/// (-301): Failed to resolve the referenced cells and headers used in the transaction, as inputs or
/// dependencies.
/// (-301): Failed to resolve the referenced cells and headers used in the transaction, as
/// inputs or dependencies.
TransactionFailedToResolve = -301,
/// (-302): Failed to verify the transaction.
TransactionFailedToVerify = -302,
/// (-1000): Some signatures in the submit alert are invalid.
AlertFailedToVerifySignatures = -1000,
/// (-1102): The transaction is rejected by the outputs validator specified by the RPC parameter.
/// (-1102): The transaction is rejected by the outputs validator specified by the RPC
/// parameter.
PoolRejectedTransactionByOutputsValidator = -1102,
/// (-1103): Pool rejects some transactions which seem contain invalid VM instructions. See the issue
/// link in the error message for details.
/// (-1103): Pool rejects some transactions which seem contain invalid VM instructions. See the
/// issue link in the error message for details.
PoolRejectedTransactionByIllTransactionChecker = -1103,
/// (-1104): The transaction fee rate must be greater than or equal to the config option `tx_pool.min_fee_rate`
/// (-1104): The transaction fee rate must be greater than or equal to the config option
/// `tx_pool.min_fee_rate`
///
/// The fee rate is calculated as:
///
/// ```text
/// fee / (1000 * tx_serialization_size_in_block_in_bytes)
/// ```
PoolRejectedTransactionByMinFeeRate = -1104,
/// (-1105): The in-pool ancestors count must be less than or equal to the config option `tx_pool.max_ancestors_count`
/// (-1105): The in-pool ancestors count must be less than or equal to the config option
/// `tx_pool.max_ancestors_count`
///
/// Pool rejects a large package of chained transactions to avoid certain kinds of DoS attacks.
PoolRejectedTransactionByMaxAncestorsCountLimit = -1105,
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/module/alert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::sync::Arc;
///
/// An alert is a message about critical problems to be broadcast to all nodes via the p2p network.
///
/// The alerts must be signed by 2-of-4 signatures, where the public keys are hard-coded in the source code
/// and belong to early CKB developers.
/// The alerts must be signed by 2-of-4 signatures, where the public keys are hard-coded in the
/// source code and belong to early CKB developers.
#[rpc(server)]
pub trait AlertRpc {
/// Sends an alert.
Expand Down
Loading