Skip to content

Commit

Permalink
update rust && fix lint (aptos-labs#2306)
Browse files Browse the repository at this point in the history
  • Loading branch information
uvd authored Jul 30, 2022
1 parent addbb4b commit a1549ec
Show file tree
Hide file tree
Showing 34 changed files with 70 additions and 67 deletions.
3 changes: 2 additions & 1 deletion config/management/operational/src/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use aptos_types::{
use itertools::Itertools;
use std::{
collections::{HashMap, HashSet},
fmt::Write,
path::Path,
};
use structopt::StructOpt;
Expand Down Expand Up @@ -736,7 +737,7 @@ fn backend_args(backend: &config::SecureBackend) -> Result<String, Error> {
path = config.path.to_str().unwrap(),
);
if let Some(namespace) = config.namespace.as_ref() {
s.push_str(&format!(";namespace={}", namespace));
write!(s, ";namespace={}", namespace).unwrap();
}

Ok(s)
Expand Down
3 changes: 2 additions & 1 deletion consensus/consensus-types/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use aptos_types::{account_address::AccountAddress, transaction::SignedTransaction};
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fmt::Write;

/// The round of a block is a consensus-internal counter, which starts with 0 and increases
/// monotonically. It is used for the protocol safety and liveness (please see the detailed
Expand Down Expand Up @@ -113,7 +114,7 @@ impl fmt::Display for PayloadFilter {
PayloadFilter::DirectMempool(excluded_txns) => {
let mut txns_str = "".to_string();
for tx in excluded_txns.iter() {
txns_str += &format!("{} ", tx);
write!(txns_str, "{} ", tx)?;
}
write!(f, "{}", txns_str)
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/commit_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::error::QuorumStoreError;
use crate::monitor;
use anyhow::{format_err, Result};
use aptos_infallible::Mutex;
use aptos_metrics_core::monitor;
use consensus_types::{common::Round, request_response::ConsensusRequest};
use futures::channel::{mpsc, mpsc::Sender, oneshot};
use std::time::Duration;
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/epoch_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::monitor;
use crate::{
block_storage::BlockStore,
commit_notifier::CommitNotifier,
Expand Down Expand Up @@ -39,7 +40,6 @@ use aptos_config::config::{ConsensusConfig, NodeConfig};
use aptos_infallible::{duration_since_epoch, Mutex};
use aptos_logger::prelude::*;
use aptos_mempool::QuorumStoreRequest;
use aptos_metrics_core::monitor;
use aptos_types::{
account_address::AccountAddress,
epoch_change::EpochChangeProof,
Expand Down
16 changes: 16 additions & 0 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ pub use consensusdb::CONSENSUS_DB_NAME;

#[cfg(feature = "fuzzing")]
pub use round_manager::round_manager_fuzzing;

/// Helper function to record metrics for external calls.
/// Include call counts, time, and whether it's inside or not (1 or 0).
/// It assumes a OpMetrics defined as OP_COUNTERS in crate::counters;
#[macro_export]
macro_rules! monitor {
( $name:literal, $fn:expr ) => {{
use $crate::counters::OP_COUNTERS;
let _timer = OP_COUNTERS.timer($name);
let gauge = OP_COUNTERS.gauge(concat!($name, "_running"));
gauge.inc();
let result = $fn;
gauge.dec();
result
}};
}
2 changes: 1 addition & 1 deletion consensus/src/metrics_safety_rules.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::monitor;
use crate::persistent_liveness_storage::PersistentLivenessStorage;
use aptos_crypto::bls12381;
use aptos_logger::prelude::info;
use aptos_metrics_core::monitor;
use aptos_types::{
epoch_change::EpochChangeProof,
ledger_info::{LedgerInfo, LedgerInfoWithSignatures},
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::monitor;
use crate::{
counters,
logging::LogEvent,
network_interface::{ConsensusMsg, ConsensusNetworkEvents, ConsensusNetworkSender},
};
use anyhow::{anyhow, ensure};
use aptos_logger::prelude::*;
use aptos_metrics_core::monitor;
use aptos_types::{
account_address::AccountAddress, epoch_change::EpochChangeProof,
ledger_info::LedgerInfoWithSignatures, validator_verifier::ValidatorVerifier,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/payload_manager.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::monitor;
use crate::{error::QuorumStoreError, state_replication::PayloadManager};
use anyhow::Result;
use aptos_logger::prelude::*;
use aptos_metrics_core::monitor;
use consensus_types::{
common::{Payload, PayloadFilter},
request_response::{ConsensusRequest, ConsensusResponse},
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/quorum_store/direct_mempool_quorum_store.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::monitor;
use crate::quorum_store::counters;
use anyhow::Result;
use aptos_logger::prelude::*;
use aptos_mempool::{QuorumStoreRequest, QuorumStoreResponse};
use aptos_metrics_core::monitor;
use aptos_types::transaction::SignedTransaction;
use consensus_types::{
common::{Payload, PayloadFilter, TransactionSummary},
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/round_manager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::monitor;
use crate::{
block_storage::{
tracing::{observe_block, BlockStage},
Expand All @@ -24,7 +25,6 @@ use crate::{
use anyhow::{bail, ensure, Context, Result};
use aptos_infallible::{checked, Mutex};
use aptos_logger::prelude::*;
use aptos_metrics_core::monitor;
use aptos_types::{
epoch_state::EpochState, on_chain_config::OnChainConsensusConfig,
validator_verifier::ValidatorVerifier,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/state_computer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

use crate::monitor;
use crate::{
block_storage::tracing::{observe_block, BlockStage},
commit_notifier::CommitNotifier,
Expand All @@ -13,7 +14,6 @@ use anyhow::Result;
use aptos_crypto::HashValue;
use aptos_infallible::Mutex;
use aptos_logger::prelude::*;
use aptos_metrics_core::monitor;
use aptos_types::{
account_address::AccountAddress, contract_event::ContractEvent, epoch_state::EpochState,
ledger_info::LedgerInfoWithSignatures, transaction::Transaction,
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/txn_notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

use crate::error::MempoolError;
use crate::monitor;
use anyhow::{format_err, Result};
use aptos_mempool::QuorumStoreRequest;
use aptos_metrics_core::monitor;
use aptos_types::transaction::TransactionStatus;
use consensus_types::{block::Block, common::TransactionSummary};
use executor_types::StateComputeResult;
Expand Down
16 changes: 0 additions & 16 deletions crates/aptos-metrics-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,3 @@ pub use prometheus::{
};

pub mod op_counters;

/// Helper function to record metrics for external calls.
/// Include call counts, time, and whether it's inside or not (1 or 0).
/// It assumes a OpMetrics defined as OP_COUNTERS in crate::counters;
#[macro_export]
macro_rules! monitor {
( $name:literal, $fn:expr ) => {{
use crate::counters::OP_COUNTERS;
let _timer = OP_COUNTERS.timer($name);
let gauge = OP_COUNTERS.gauge(concat!($name, "_running"));
gauge.inc();
let result = $fn;
gauge.dec();
result
}};
}
2 changes: 1 addition & 1 deletion crates/aptos-rosetta/src/types/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ impl Transfer {

// Check that the currency is supported
// TODO: in future use currency, since there's more than just 1
let _ = is_native_coin(&withdraw_amount.currency)?;
is_native_coin(&withdraw_amount.currency)?;

let withdraw_value = i64::from_str(&withdraw_amount.value).map_err(|_| {
ApiError::InvalidTransferOperations(Some("Withdraw amount is invalid"))
Expand Down
29 changes: 14 additions & 15 deletions crates/aptos/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,21 +674,20 @@ impl CliCommand<()> for RunLocalTestnet {
}

// Start the faucet
Some(
FaucetArgs {
address: "0.0.0.0".to_string(),
port: self.faucet_port,
server_url: rest_url,
mint_key_file_path: test_dir.join("mint.key"),
mint_key: None,
mint_account_address: None,
chain_id: ChainId::test(),
maximum_amount: None,
do_not_delegate: false,
}
.run()
.await,
)
FaucetArgs {
address: "0.0.0.0".to_string(),
port: self.faucet_port,
server_url: rest_url,
mint_key_file_path: test_dir.join("mint.key"),
mint_key: None,
mint_account_address: None,
chain_id: ChainId::test(),
maximum_amount: None,
do_not_delegate: false,
}
.run()
.await;
Some(())
} else {
None
};
Expand Down
1 change: 1 addition & 0 deletions ecosystem/indexer/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

//! Database-related functions
#![allow(clippy::extra_unused_lifetimes)]
use std::sync::Arc;

use diesel::{
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/indexer/src/models/collection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::extra_unused_lifetimes)]
use crate::schema::collections;
use serde::Serialize;

Expand Down
2 changes: 1 addition & 1 deletion ecosystem/indexer/src/models/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::extra_unused_lifetimes)]
use crate::{models::transactions::Transaction, schema::events};
use aptos_rest_client::aptos_api_types::Event as APIEvent;
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/indexer/src/models/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::extra_unused_lifetimes)]
use crate::schema::metadatas;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion ecosystem/indexer/src/models/ownership.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::extra_unused_lifetimes)]
use crate::schema::ownerships;
use serde::Serialize;

Expand Down
2 changes: 1 addition & 1 deletion ecosystem/indexer/src/models/processor_statuses.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::extra_unused_lifetimes)]
use crate::{
indexer::{errors::TransactionProcessingError, processing_result::ProcessingResult},
schema::processor_statuses as processor_statuss,
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/indexer/src/models/token.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::extra_unused_lifetimes)]
use crate::{models::events::Event, schema::tokens};
use aptos_rest_client::types;
use std::{collections::HashMap, fmt, fmt::Formatter, str::FromStr};
Expand Down
1 change: 1 addition & 0 deletions ecosystem/indexer/src/models/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

// This is required because a diesel macro makes clippy sad
#![allow(clippy::extra_unused_lifetimes)]
#![allow(clippy::unused_unit)]

use crate::{
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/indexer/src/models/write_set_changes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Aptos
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::extra_unused_lifetimes)]
use crate::{models::transactions::Transaction, schema::write_set_changes};
use aptos_rest_client::aptos_api_types::{
DeleteModule, DeleteResource, DeleteTableItem, WriteModule, WriteResource,
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/node-checker/src/configuration/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum FileType {
Json(PathBuf),
}

impl<'a> TryFrom<PathBuf> for FileType {
impl TryFrom<PathBuf> for FileType {
type Error = anyhow::Error;

fn try_from(path: PathBuf) -> Result<Self> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ impl Evaluator for StateSyncVersionEvaluator {
#[cfg(test)]
mod test {
use super::{super::super::parse_metrics, *};

use std::fmt::Write;
fn get_metric_string(value: u64) -> String {
let mut metric_string = r#"aptos_state_sync_version{type="synced"} "#.to_string();
metric_string.push_str(&format!("{}", value));
write!(metric_string, "{}", value).unwrap();
metric_string
}

Expand Down
8 changes: 4 additions & 4 deletions mempool/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use aptos_logger::Schema;
use aptos_types::{account_address::AccountAddress, on_chain_config::OnChainConfigPayload};
use mempool_notifications::MempoolCommitNotification;
use serde::Serialize;
use std::{fmt, time::SystemTime};
use std::{fmt, fmt::Write, time::SystemTime};

pub struct TxnsLog {
txns: Vec<(AccountAddress, u64, Option<String>, Option<SystemTime>)>,
Expand Down Expand Up @@ -53,13 +53,13 @@ impl fmt::Display for TxnsLog {
for (account, seq_num, status, timestamp) in self.txns.iter() {
let mut txn = format!("{}:{}", account, seq_num);
if let Some(status) = status {
txn += &format!(":{}", status)
write!(txn, ":{}", status)?;
}
if let Some(timestamp) = timestamp {
txn += &format!(":{:?}", timestamp)
write!(txn, ":{:?}", timestamp)?;
}

txns += &format!("{} ", txn);
write!(txns, "{} ", txn)?;
}

write!(f, "{}", txns)
Expand Down
5 changes: 3 additions & 2 deletions mempool/src/shared_mempool/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use serde::{Deserialize, Serialize};
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
fmt,
fmt::Write,
pin::Pin,
sync::Arc,
task::Waker,
Expand Down Expand Up @@ -174,7 +175,7 @@ impl fmt::Display for QuorumStoreRequest {
QuorumStoreRequest::GetBatchRequest(batch_size, excluded_txns, _) => {
let mut txns_str = "".to_string();
for tx in excluded_txns.iter() {
txns_str += &format!("{} ", tx);
write!(txns_str, "{} ", tx)?;
}
format!(
"GetBatchRequest [batch_size: {}, excluded_txns: {}]",
Expand All @@ -184,7 +185,7 @@ impl fmt::Display for QuorumStoreRequest {
QuorumStoreRequest::RejectNotification(rejected_txns, _) => {
let mut txns_str = "".to_string();
for tx in rejected_txns.iter() {
txns_str += &format!("{} ", tx);
write!(txns_str, "{} ", tx)?;
}
format!("RejectNotification [rejected_txns: {}]", txns_str)
}
Expand Down
2 changes: 1 addition & 1 deletion mempool/src/tests/test_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl MempoolNode {
let bytes = protocol_id.to_bytes(&response).unwrap();

if let Some(rpc_sender) = maybe_rpc_sender {
let _ = rpc_sender.send(Ok(bytes.into())).unwrap();
rpc_sender.send(Ok(bytes.into())).unwrap();
} else {
let notif = PeerManagerNotification::RecvMessage(
peer_id,
Expand Down
Loading

0 comments on commit a1549ec

Please sign in to comment.