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

fix: remove #[allow(unused, clippy::upper_case_acronyms, clippy::enum_variant_names)] #3011

Merged
merged 25 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aec0845
feat: unused items removed
aatifsyed Jun 20, 2023
4a132db
fix: MockBeacon
aatifsyed Jun 20, 2023
8858710
fix: HeadChange
aatifsyed Jun 20, 2023
7818b0e
fix: json::bigint
aatifsyed Jun 20, 2023
2b6dac5
fix: ipld
aatifsyed Jun 20, 2023
5788028
fix: wallet
aatifsyed Jun 20, 2023
d3383be
fix: trivial test-only items
aatifsyed Jun 20, 2023
bf9d0bf
fix: msg_chain and msgpool
aatifsyed Jun 20, 2023
642b5b7
fix: msgpool/test_provider
aatifsyed Jun 20, 2023
fb5343e
fix: remove dead rpc entrypoints
aatifsyed Jun 20, 2023
986fc2d
fix: punt api items
aatifsyed Jun 20, 2023
9d509ab
fix: test_utils is #[cfg(test)], and simpler
aatifsyed Jun 20, 2023
a6906ce
fix: just allow the actor names
aatifsyed Jun 20, 2023
685f9a7
fix: file_backed_obj
aatifsyed Jun 20, 2023
cebd969
fix: json/go_vec_visitor
aatifsyed Jun 20, 2023
4c5ead3
fix: punt removal of visitreason
aatifsyed Jun 20, 2023
cfb1d59
feat: remove #[allow(clippy::upper_case_acronyms)]
aatifsyed Jun 20, 2023
736c251
feat: remove #[allow(clippy::enum_variant_names)]
aatifsyed Jun 20, 2023
bcd9f9b
fix: unused fn param in migrator
aatifsyed Jun 21, 2023
c9ca841
fix: remove #[allow(unused)]
aatifsyed Jun 21, 2023
4bec3dc
parallelize debug/release unit tests (#3073)
LesnyRumcajs Jun 26, 2023
818a716
chore: fixup new unused code
aatifsyed Jun 26, 2023
e4244e5
feat: run clippy on tests
aatifsyed Jun 26, 2023
d763780
review: remove new, and add efault
aatifsyed Jun 26, 2023
d9b5c60
fix: unused code after remove deleg_cns
aatifsyed Jun 26, 2023
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ lint: license clean lint-clippy
# --quiet: don't show build logs
lint-clippy:
cargo clippy --quiet --no-deps -- --deny=warnings
cargo clippy --tests --quiet --no-deps -- --deny=warnings

# add-on features
cargo clippy --features=insecure_post --quiet --no-deps -- --deny=warnings
Expand Down
15 changes: 1 addition & 14 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crate::key_management::KeyInfo;
use crate::shim::crypto::SignatureType;
use chrono::{Duration, Utc};
use jsonrpc_v2::Error as JsonRpcError;
use jsonwebtoken::{decode, encode, errors::Result as JWTResult, DecodingKey, EncodingKey, Header};
use once_cell::sync::Lazy;
use rand::Rng;
Expand Down Expand Up @@ -72,21 +71,9 @@ pub fn verify_token(token: &str, key: &[u8]) -> JWTResult<Vec<String>> {
Ok(token.claims.allow)
}

/// Check whether or not header has required permissions
pub fn has_perms(header_raw: String, required: &str, key: &[u8]) -> Result<(), JsonRpcError> {
if header_raw.starts_with("Bearer ") {
let token = header_raw.trim_start_matches("Bearer ");
let perms = verify_token(token, key).map_err(|err| Error::Other(err.to_string()))?;
if !perms.contains(&required.to_string()) {
return Err(JsonRpcError::from(Error::InvalidPermissions));
}
}
Ok(())
}

pub fn generate_priv_key() -> KeyInfo {
let priv_key = rand::thread_rng().gen::<[u8; 32]>();
// TODO temp use of bls key as placeholder, need to update keyinfo to use string
// instead of keyinfo for key type
KeyInfo::new(SignatureType::BLS, priv_key.to_vec())
KeyInfo::new(SignatureType::Bls, priv_key.to_vec())
}
14 changes: 2 additions & 12 deletions src/beacon/mock_beacon.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
// Copyright 2019-2023 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use std::time::Duration;

use crate::shim::version::NetworkVersion;
use crate::utils::encoding::blake2b_256;
use async_trait::async_trait;
use byteorder::{BigEndian, ByteOrder};

use crate::beacon::{Beacon, BeaconEntry};

/// Mock beacon used for testing. Deterministic based on an interval.
pub struct MockBeacon {
interval: Duration,
}
#[derive(Default)]
pub struct MockBeacon {}
aatifsyed marked this conversation as resolved.
Show resolved Hide resolved

impl MockBeacon {
pub fn new(interval: Duration) -> Self {
MockBeacon { interval }
}
fn entry_for_index(index: u64) -> BeaconEntry {
let mut buf = [0; 8];
BigEndian::write_u64(&mut buf, index);
let rval = blake2b_256(&buf);
BeaconEntry::new(index, rval.to_vec())
}
pub fn round_time(&self) -> Duration {
self.interval
}
}

#[async_trait]
Expand Down
4 changes: 2 additions & 2 deletions src/beacon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

pub mod beacon_entries;
mod drand;
mod mock_beacon;
#[cfg(test)]
pub mod mock_beacon;

pub use beacon_entries::*;
pub use drand::*;
pub use mock_beacon::*;
#[cfg(test)]
mod tests {
mod drand;
Expand Down
8 changes: 4 additions & 4 deletions src/blocks/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::fmt;

use crate::beacon::{self, Beacon, BeaconEntry, BeaconSchedule};
use crate::beacon::{Beacon, BeaconEntry, BeaconSchedule};
use crate::shim::clock::ChainEpoch;
use crate::shim::{
address::Address,
Expand Down Expand Up @@ -456,9 +456,9 @@ impl fmt::Display for BlockHeader {

#[cfg(test)]
mod tests {
use std::{sync::Arc, time::Duration};
use std::sync::Arc;

use crate::beacon::{BeaconEntry, BeaconPoint, BeaconSchedule, MockBeacon};
use crate::beacon::{mock_beacon::MockBeacon, BeaconEntry, BeaconPoint, BeaconSchedule};
use crate::shim::{address::Address, version::NetworkVersion};
use fvm_ipld_encoding::Cbor;

Expand Down Expand Up @@ -492,7 +492,7 @@ mod tests {
.unwrap();
let beacon_schedule = Arc::new(BeaconSchedule(vec![BeaconPoint {
height: 0,
beacon: Arc::new(MockBeacon::new(Duration::from_secs(1))),
beacon: Arc::new(MockBeacon::default()),
}]));
let chain_epoch = 0;
let beacon_entry = BeaconEntry::new(1, vec![]);
Expand Down
6 changes: 1 addition & 5 deletions src/blocks/tests/serialization_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
use crate::blocks::{header, BlockHeader};
use crate::json::{message, signature};
use crate::message::signed_message::SignedMessage;
use crate::shim::{
address::{CurrentNetwork, Network},
crypto::Signature,
message::Message,
};
use crate::shim::{crypto::Signature, message::Message};
/// These tests use the `serialization-vectors` submodule at the root of this repo
use base64::{prelude::BASE64_STANDARD, Engine};
use bls_signatures::{PrivateKey, Serialize};
Expand Down
1 change: 0 additions & 1 deletion src/chain/store/base_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub const BLOCK_GAS_TARGET: u64 = BLOCK_GAS_LIMIT / 2;
pub const BASE_FEE_MAX_CHANGE_DENOM: i64 = 8;

/// Genesis base fee.
pub const INITIAL_BASE_FEE: i64 = 100000000;
pub const PACKING_EFFICIENCY_DENOM: u64 = 5;
pub const PACKING_EFFICIENCY_NUM: u64 = 4;
pub const MINIMUM_BASE_FEE: i64 = 100;
Expand Down
86 changes: 1 addition & 85 deletions src/chain/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ use crate::metrics;
use crate::networks::{ChainConfig, NetworkChain};
use crate::shim::clock::ChainEpoch;
use crate::shim::{
address::Address,
crypto::{Signature, SignatureType},
econ::TokenAmount,
executor::Receipt,
message::Message,
state_tree::StateTree,
address::Address, econ::TokenAmount, executor::Receipt, message::Message, state_tree::StateTree,
};
use crate::utils::{
db::{
Expand All @@ -31,7 +26,6 @@ use crate::utils::{
use ahash::{HashMap, HashMapExt, HashSet};
use anyhow::{Context, Result};
use async_compression::futures::write::ZstdEncoder;
use bls_signatures::Serialize as SerializeBls;
use cid::Cid;
use digest::Digest;
use futures::{io::BufWriter, AsyncWrite};
Expand Down Expand Up @@ -66,9 +60,7 @@ const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(8192usize);
/// contained in message type.
#[derive(Clone, Debug)]
pub enum HeadChange {
Current(Arc<Tipset>),
Apply(Arc<Tipset>),
Revert(Arc<Tipset>),
}

/// Stores chain data such as heaviest tipset and cached tipset info at each
Expand Down Expand Up @@ -861,91 +853,15 @@ pub mod headchange_json {
Revert(TipsetJson),
}

pub type SubscriptionHeadChange = (i64, Vec<HeadChangeJson>);

impl From<HeadChange> for HeadChangeJson {
fn from(wrapper: HeadChange) -> Self {
match wrapper {
HeadChange::Current(tipset) => HeadChangeJson::Current(TipsetJson(tipset)),
HeadChange::Apply(tipset) => HeadChangeJson::Apply(TipsetJson(tipset)),
HeadChange::Revert(tipset) => HeadChangeJson::Revert(TipsetJson(tipset)),
}
}
}
}

/// Result of persisting a vector of `SignedMessage`s that are to be included in
/// a block.
///
/// The fields are public so they can be partially moved, but they should not be
/// modified.
pub struct PersistedBlockMessages {
/// Overall CID to be included in the `BlockHeader`.
pub msg_cid: Cid,
/// All CIDs of SECP messages, to be included in `BlockMsg`.
pub secp_cids: Vec<Cid>,
/// All CIDs of BLS messages, to be included in `BlockMsg`.
pub bls_cids: Vec<Cid>,
/// Aggregated signature of all BLS messages, to be included in the
/// `BlockHeader`.
pub bls_agg: Signature,
}

/// Partition the messages into SECP and BLS variants, store them individually
/// in the IPLD store, and the corresponding `TxMeta` as well, returning its CID
/// so that it can be put in a block header. Also return the aggregated BLS
/// signature of all BLS messages.
pub fn persist_block_messages<DB: Blockstore>(
db: &DB,
messages: Vec<&SignedMessage>,
) -> anyhow::Result<PersistedBlockMessages> {
let mut bls_cids = Vec::new();
let mut secp_cids = Vec::new();

let mut bls_sigs = Vec::new();
for msg in messages {
if msg.signature().signature_type() == SignatureType::BLS {
let c = db.put_cbor_default(&msg.message)?;
bls_cids.push(c);
bls_sigs.push(&msg.signature);
} else {
let c = db.put_cbor_default(&msg)?;
secp_cids.push(c);
}
}

let bls_msg_root = Amt::new_from_iter(db, bls_cids.iter().copied())?;
let secp_msg_root = Amt::new_from_iter(db, secp_cids.iter().copied())?;

let mmcid = db.put_cbor_default(&TxMeta {
bls_message_root: bls_msg_root,
secp_message_root: secp_msg_root,
})?;

let bls_agg = if bls_sigs.is_empty() {
Signature::new_bls(vec![])
} else {
Signature::new_bls(
bls_signatures::aggregate(
&bls_sigs
.iter()
.map(|s| s.bytes())
.map(bls_signatures::Signature::from_bytes)
.collect::<Result<Vec<_>, _>>()?,
)
.unwrap()
.as_bytes(),
)
};

Ok(PersistedBlockMessages {
msg_cid: mmcid,
secp_cids,
bls_cids,
bls_agg,
})
}

#[cfg(test)]
mod tests {
use crate::shim::address::Address;
Expand Down
3 changes: 0 additions & 3 deletions src/chain/store/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ pub enum Error {
/// Key was not found
#[error("Invalid tipset: {0}")]
UndefinedKey(String),
/// Tipset contains no blocks
#[error("No blocks for tipset")]
NoBlocks,
/// Key not found in database
#[error("{0} not found")]
NotFound(String),
Expand Down
34 changes: 4 additions & 30 deletions src/chain_sync/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ use std::{
sync::Arc,
};

use crate::blocks::{Block, GossipBlock, Tipset};
use crate::blocks::{Block, Tipset};
use crate::chain::Scale;
use crate::libp2p::{NetworkMessage, Topic, PUBSUB_BLOCK_STR};
use crate::message::SignedMessage;
use crate::message_pool::MessagePool;
use crate::state_manager::StateManager;
use async_trait::async_trait;
use futures::{stream::FuturesUnordered, StreamExt};
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::Cbor;
use nonempty::NonEmpty;
use tokio::task::JoinSet;

Expand Down Expand Up @@ -167,34 +165,10 @@ where
///
/// Similar to `sync_api::sync_submit_block` but assumes that the block is
/// correct and already persisted.
pub struct SyncGossipSubmitter {
network_name: String,
network_tx: flume::Sender<NetworkMessage>,
tipset_tx: flume::Sender<Arc<Tipset>>,
}
pub struct SyncGossipSubmitter {}

impl SyncGossipSubmitter {
pub fn new(
network_name: String,
network_tx: flume::Sender<NetworkMessage>,
tipset_tx: flume::Sender<Arc<Tipset>>,
) -> Self {
Self {
network_name,
network_tx,
tipset_tx,
}
}

pub async fn submit_block(&self, block: GossipBlock) -> anyhow::Result<()> {
let data = block.marshal_cbor()?;
let ts = Arc::new(Tipset::from(&block.header));
let msg = NetworkMessage::PubsubMessage {
topic: Topic::new(format!("{}/{}", PUBSUB_BLOCK_STR, self.network_name)),
message: data,
};
self.tipset_tx.send_async(ts).await?;
self.network_tx.send_async(msg).await?;
Ok(())
pub fn new() -> Self {
Self {}
}
}
38 changes: 0 additions & 38 deletions src/cli/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,41 +201,3 @@ fn prompt_confirm() -> bool {
let line = line.trim().to_lowercase();
line == "y" || line == "yes"
}

#[cfg(test)]
mod test {
use crate::cli_shared::cli::to_size_string;
use num::{BigInt, Zero};

#[test]
fn to_size_string_valid_input() {
let cases = [
(BigInt::zero(), "0 B"),
(BigInt::from(1 << 10), "1024 B"),
(BigInt::from((1 << 10) + 1), "1.00 KiB"),
(BigInt::from((1 << 10) + 512), "1.50 KiB"),
(BigInt::from(1 << 20), "1024.00 KiB"),
(BigInt::from((1 << 20) + 1), "1.00 MiB"),
(BigInt::from(1 << 29), "512.00 MiB"),
(BigInt::from((1 << 30) + 1), "1.00 GiB"),
(BigInt::from((1u64 << 40) + 1), "1.00 TiB"),
(BigInt::from((1u64 << 50) + 1), "1.00 PiB"),
// ZiB is 2^70, 288230376151711744 is 2^58
(BigInt::from(u128::MAX), "288230376151711744.00 ZiB"),
];

for (input, expected) in cases {
assert_eq!(to_size_string(&input).unwrap(), expected.to_string());
}
}

#[test]
fn to_size_string_negative_input_should_fail() {
assert!(to_size_string(&BigInt::from(-1i8)).is_err());
}

#[test]
fn to_size_string_too_large_input_should_fail() {
assert!(to_size_string(&(BigInt::from(u128::MAX) + 1)).is_err());
}
}
4 changes: 2 additions & 2 deletions src/cli/subcommands/wallet_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::json::{
use crate::key_management::json::KeyInfoJson;
use crate::rpc_client::wallet_ops::*;
use crate::shim::{
address::{Address, Protocol, StrictAddress},
address::{Protocol, StrictAddress},
crypto::{Signature, SignatureType},
econ::TokenAmount,
};
Expand Down Expand Up @@ -104,7 +104,7 @@ impl WalletCommands {
Self::New { signature_type } => {
let signature_type = match signature_type.to_lowercase().as_str() {
"secp256k1" => SignatureType::Secp256k1,
_ => SignatureType::BLS,
_ => SignatureType::Bls,
};

let signature_type_json = SignatureTypeJson(signature_type);
Expand Down
Loading