Skip to content

Commit

Permalink
Merge pull request #2006 from b-zee/refactor-deps-lazy-static
Browse files Browse the repository at this point in the history
refactor: remove some lazy_static deps; unused dep
  • Loading branch information
joshuef authored Jul 29, 2024
2 parents bc37597 + 9e2c533 commit 4b0be6d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 27 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion node-launchpad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fs_extra = "1.3.0"
human-panic = "1.2.0"
itertools = "~0.12.1"
json5 = "0.4.1"
lazy_static = "1.4.0"
libc = "0.2.148"
log = "0.4.20"
pretty_assertions = "1.4.0"
Expand Down
4 changes: 1 addition & 3 deletions sn_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "0.109.0"
default = []
local-discovery = ["sn_networking/local-discovery"]
open-metrics = ["sn_networking/open-metrics", "prometheus-client"]
test-utils = ["sn_peers_acquisition", "lazy_static", "eyre"]
test-utils = ["sn_peers_acquisition", "eyre"]
# required to pass on flag to node builds
websockets = ["sn_networking/websockets", "sn_protocol/websockets"]

Expand Down Expand Up @@ -51,7 +51,6 @@ self_encryption = "~0.29.0"
serde = { version = "1.0.133", features = ["derive", "rc"] }
sn_networking = { path = "../sn_networking", version = "0.17.1" }
sn_protocol = { path = "../sn_protocol", version = "0.17.6" }
serde_json = "1.0"
sn_registers = { path = "../sn_registers", version = "0.3.16" }
sn_transfers = { path = "../sn_transfers", version = "0.18.9" }
tempfile = "3.6.0"
Expand All @@ -61,7 +60,6 @@ tracing = { version = "~0.1.26" }
xor_name = "5.0.0"
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.4.1", optional = true }
eyre = { version = "0.6.8", optional = true }
lazy_static = { version = "~1.4.0", optional = true }

[dev-dependencies]
assert_matches = "1.5.0"
Expand Down
7 changes: 2 additions & 5 deletions sn_client/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use sn_transfers::{HotWallet, NanoTokens};
use bls::SecretKey;
use bytes::Bytes;
use eyre::{bail, Result};
use lazy_static::lazy_static;
use rand::distributions::{Distribution, Standard};
use std::path::Path;
use tokio::{
Expand All @@ -32,10 +31,8 @@ pub const AMOUNT_TO_FUND_WALLETS: u64 = 100 * 1_000_000_000;
// The number of times to try to load the faucet wallet
const LOAD_FAUCET_WALLET_RETRIES: usize = 6;

lazy_static! {
// mutex to restrict access to faucet wallet from concurrent tests
static ref FAUCET_WALLET_MUTEX: Mutex<()> = Mutex::new(());
}
// mutex to restrict access to faucet wallet from concurrent tests
static FAUCET_WALLET_MUTEX: Mutex<()> = Mutex::const_new(());

/// Get a new Client for testing
pub async fn get_new_client(owner_sk: SecretKey) -> Result<Client> {
Expand Down
1 change: 0 additions & 1 deletion sn_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ file-rotate = "0.7.3"
futures = "~0.3.13"
hex = "~0.4.3"
itertools = "~0.12.1"
lazy_static = "~1.4.0"
libp2p = { version = "0.53", features = ["tokio", "dns", "kad", "macros"] }
prometheus-client = { version = "0.22", optional = true }
# watch out updating this, protoc compiler needs to be installed on all build systems
Expand Down
7 changes: 2 additions & 5 deletions sn_node/tests/common/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// permissions and limitations relating to use of the SAFE Network Software.

use eyre::{bail, OptionExt, Result};
use lazy_static::lazy_static;
use libp2p::PeerId;
use sn_client::{
acc_packet::{create_faucet_account_and_wallet, load_account_wallet_or_create_with_mnemonic},
Expand Down Expand Up @@ -45,10 +44,8 @@ pub const LOCAL_NODE_COUNT: usize = 25;
// The number of times to try to load the faucet wallet
const LOAD_FAUCET_WALLET_RETRIES: usize = 6;

lazy_static! {
// mutex to restrict access to faucet wallet from concurrent tests
static ref FAUCET_WALLET_MUTEX: Mutex<()> = Mutex::new(());
}
// mutex to restrict access to faucet wallet from concurrent tests
static FAUCET_WALLET_MUTEX: Mutex<()> = Mutex::const_new(());

/// Load HotWallet from dir
pub fn get_wallet(root_dir: &Path) -> HotWallet {
Expand Down
15 changes: 7 additions & 8 deletions sn_transfers/src/wallet/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::wallet::Result;
use crate::MainSecretKey;
use bls::SecretKey;
use hex::encode;
use lazy_static::lazy_static;
use rand::Rng;
use ring::aead::{BoundKey, Nonce, NonceSequence};
use ring::error::Unspecified;
Expand All @@ -20,11 +19,11 @@ use std::io::Read;
use std::num::NonZeroU32;
use std::path::Path;

lazy_static! {
/// Number of iterations for pbkdf2.
static ref ITERATIONS: NonZeroU32 =
NonZeroU32::new(100_000).expect("ITERATIONS should be > 0.");
}
/// Number of iterations for pbkdf2.
const ITERATIONS: NonZeroU32 = match NonZeroU32::new(100_000) {
Some(v) => v,
None => panic!("`100_000` is not be zero"),
};

/// Filename for the encrypted secret key.
pub const ENCRYPTED_MAIN_SECRET_KEY_FILENAME: &str = "main_secret_key.encrypted";
Expand Down Expand Up @@ -94,7 +93,7 @@ impl EncryptedSecretKey {
// Reconstruct the key from salt and password
ring::pbkdf2::derive(
ring::pbkdf2::PBKDF2_HMAC_SHA512,
*ITERATIONS,
ITERATIONS,
&salt,
password.as_bytes(),
&mut key,
Expand Down Expand Up @@ -168,7 +167,7 @@ pub(crate) fn encrypt_secret_key(
// HMAC<Sha512> is used as the pseudorandom function for its security properties
ring::pbkdf2::derive(
ring::pbkdf2::PBKDF2_HMAC_SHA512,
*ITERATIONS,
ITERATIONS,
&salt,
password.as_bytes(),
&mut key,
Expand Down

0 comments on commit 4b0be6d

Please sign in to comment.