Skip to content

Commit a354d02

Browse files
Merge pull request #328 from opentensor/chore/clippy_lints
Chore/clippy lints
2 parents 1282cc0 + 4072973 commit a354d02

40 files changed

+592
-566
lines changed

justfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env just --justfile
2+
3+
export RUST_BACKTRACE := "full"
4+
export SKIP_WASM_BUILD := "1"
5+
export RUST_BIN_DIR := "target/x86_64-unknown-linux-gnu"
6+
export TARGET := "x86_64-unknown-linux-gnu"
7+
export RUSTV := "nightly-2024-03-05"
8+
export RELEASE_NAME := "development"
9+
10+
fmt:
11+
@echo "Running cargo fmt..."
12+
cargo +{{RUSTV}} fmt --all
13+
14+
check:
15+
@echo "Running cargo check..."
16+
cargo +{{RUSTV}} check --workspace
17+
18+
test:
19+
@echo "Running cargo test..."
20+
cargo +{{RUSTV}} test --workspace
21+
22+
benchmarks:
23+
@echo "Running cargo test with benchmarks..."
24+
cargo +{{RUSTV}} test --workspace --features=runtime-benchmarks
25+
26+
clippy:
27+
@echo "Running cargo clippy..."
28+
cargo +{{RUSTV}} clippy -- -D clippy::panic \
29+
-D clippy::todo \
30+
-D clippy::unimplemented
31+
32+
clippy-fix:
33+
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
34+
cargo +{{RUSTV}} clippy --fix --allow-dirty -- -A clippy::panic \
35+
-A clippy::todo \
36+
-A clippy::unimplemented
37+
fix:
38+
@echo "Running cargo fix..."
39+
cargo +{{RUSTV}} fix --workspace
40+
git diff --exit-code || (echo "There are local changes after running 'cargo fix --workspace' ❌" && exit 1)

node/src/chain_spec.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
9090
Vec<(sp_runtime::AccountId32, (u64, u16))>,
9191
)> = Vec::new();
9292
for (coldkey_str, hotkeys) in old_state.stakes.iter() {
93-
let coldkey = <sr25519::Public as Ss58Codec>::from_ss58check(&coldkey_str).unwrap();
93+
let coldkey = <sr25519::Public as Ss58Codec>::from_ss58check(coldkey_str).unwrap();
9494
let coldkey_account = sp_runtime::AccountId32::from(coldkey);
9595

9696
let mut processed_hotkeys: Vec<(sp_runtime::AccountId32, (u64, u16))> = Vec::new();
9797

9898
for (hotkey_str, amount_uid) in hotkeys.iter() {
9999
let (amount, uid) = amount_uid;
100-
let hotkey = <sr25519::Public as Ss58Codec>::from_ss58check(&hotkey_str).unwrap();
100+
let hotkey = <sr25519::Public as Ss58Codec>::from_ss58check(hotkey_str).unwrap();
101101
let hotkey_account = sp_runtime::AccountId32::from(hotkey);
102102

103103
processed_hotkeys.push((hotkey_account, (*amount, *uid)));
@@ -109,7 +109,7 @@ pub fn finney_mainnet_config() -> Result<ChainSpec, String> {
109109
let mut balances_issuance: u64 = 0;
110110
let mut processed_balances: Vec<(sp_runtime::AccountId32, u64)> = Vec::new();
111111
for (key_str, amount) in old_state.balances.iter() {
112-
let key = <sr25519::Public as Ss58Codec>::from_ss58check(&key_str).unwrap();
112+
let key = <sr25519::Public as Ss58Codec>::from_ss58check(key_str).unwrap();
113113
let key_account = sp_runtime::AccountId32::from(key);
114114

115115
processed_balances.push((key_account, *amount));
@@ -266,14 +266,14 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
266266
Vec<(sp_runtime::AccountId32, (u64, u16))>,
267267
)> = Vec::new();
268268
for (coldkey_str, hotkeys) in old_state.stakes.iter() {
269-
let coldkey = <sr25519::Public as Ss58Codec>::from_ss58check(&coldkey_str).unwrap();
269+
let coldkey = <sr25519::Public as Ss58Codec>::from_ss58check(coldkey_str).unwrap();
270270
let coldkey_account = sp_runtime::AccountId32::from(coldkey);
271271

272272
let mut processed_hotkeys: Vec<(sp_runtime::AccountId32, (u64, u16))> = Vec::new();
273273

274274
for (hotkey_str, amount_uid) in hotkeys.iter() {
275275
let (amount, uid) = amount_uid;
276-
let hotkey = <sr25519::Public as Ss58Codec>::from_ss58check(&hotkey_str).unwrap();
276+
let hotkey = <sr25519::Public as Ss58Codec>::from_ss58check(hotkey_str).unwrap();
277277
let hotkey_account = sp_runtime::AccountId32::from(hotkey);
278278

279279
processed_hotkeys.push((hotkey_account, (*amount, *uid)));
@@ -285,7 +285,7 @@ pub fn finney_testnet_config() -> Result<ChainSpec, String> {
285285
let mut balances_issuance: u64 = 0;
286286
let mut processed_balances: Vec<(sp_runtime::AccountId32, u64)> = Vec::new();
287287
for (key_str, amount) in old_state.balances.iter() {
288-
let key = <sr25519::Public as Ss58Codec>::from_ss58check(&key_str).unwrap();
288+
let key = <sr25519::Public as Ss58Codec>::from_ss58check(key_str).unwrap();
289289
let key_account = sp_runtime::AccountId32::from(key);
290290

291291
processed_balances.push((key_account, *amount));
@@ -570,7 +570,7 @@ fn finney_genesis(
570570
balances: BalancesConfig {
571571
// Configure endowed accounts with initial balance of 1 << 60.
572572
//balances: balances.iter().cloned().map(|k| k).collect(),
573-
balances: balances.iter().cloned().map(|k| k).collect(),
573+
balances: balances.to_vec(),
574574
},
575575
aura: AuraConfig {
576576
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
@@ -590,8 +590,8 @@ fn finney_genesis(
590590
},
591591
transaction_payment: Default::default(),
592592
subtensor_module: SubtensorModuleConfig {
593-
stakes: stakes,
594-
balances_issuance: balances_issuance,
593+
stakes,
594+
balances_issuance,
595595
},
596596
triumvirate: TriumvirateConfig {
597597
// Add initial authorities as collective members

node/src/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
192192
let (network, system_rpc_tx, tx_handler_controller, network_starter, sync_service) =
193193
sc_service::build_network(sc_service::BuildNetworkParams {
194194
config: &config,
195-
net_config: net_config,
195+
net_config,
196196
client: client.clone(),
197197
transaction_pool: transaction_pool.clone(),
198198
spawn_handle: task_manager.spawn_handle(),

pallets/admin-utils/tests/mock.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,19 @@ impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> f
256256
}
257257

258258
fn get_root_netuid() -> u16 {
259-
return SubtensorModule::get_root_netuid();
259+
SubtensorModule::get_root_netuid()
260260
}
261261

262262
fn if_subnet_exist(netuid: u16) -> bool {
263-
return SubtensorModule::if_subnet_exist(netuid);
263+
SubtensorModule::if_subnet_exist(netuid)
264264
}
265265

266266
fn create_account_if_non_existent(coldkey: &AccountId, hotkey: &AccountId) {
267-
return SubtensorModule::create_account_if_non_existent(coldkey, hotkey);
267+
SubtensorModule::create_account_if_non_existent(coldkey, hotkey)
268268
}
269269

270270
fn coldkey_owns_hotkey(coldkey: &AccountId, hotkey: &AccountId) -> bool {
271-
return SubtensorModule::coldkey_owns_hotkey(coldkey, hotkey);
271+
SubtensorModule::coldkey_owns_hotkey(coldkey, hotkey)
272272
}
273273

274274
fn increase_stake_on_coldkey_hotkey_account(
@@ -280,31 +280,31 @@ impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> f
280280
}
281281

282282
fn u64_to_balance(input: u64) -> Option<Balance> {
283-
return SubtensorModule::u64_to_balance(input);
283+
SubtensorModule::u64_to_balance(input)
284284
}
285285

286286
fn add_balance_to_coldkey_account(coldkey: &AccountId, amount: Balance) {
287287
SubtensorModule::add_balance_to_coldkey_account(coldkey, amount);
288288
}
289289

290290
fn get_current_block_as_u64() -> u64 {
291-
return SubtensorModule::get_current_block_as_u64();
291+
SubtensorModule::get_current_block_as_u64()
292292
}
293293

294294
fn get_subnetwork_n(netuid: u16) -> u16 {
295-
return SubtensorModule::get_subnetwork_n(netuid);
295+
SubtensorModule::get_subnetwork_n(netuid)
296296
}
297297

298298
fn get_max_allowed_uids(netuid: u16) -> u16 {
299-
return SubtensorModule::get_max_allowed_uids(netuid);
299+
SubtensorModule::get_max_allowed_uids(netuid)
300300
}
301301

302302
fn append_neuron(netuid: u16, new_hotkey: &AccountId, block_number: u64) {
303-
return SubtensorModule::append_neuron(netuid, new_hotkey, block_number);
303+
SubtensorModule::append_neuron(netuid, new_hotkey, block_number)
304304
}
305305

306306
fn get_neuron_to_prune(netuid: u16) -> u16 {
307-
return SubtensorModule::get_neuron_to_prune(netuid);
307+
SubtensorModule::get_neuron_to_prune(netuid)
308308
}
309309

310310
fn replace_neuron(netuid: u16, uid_to_replace: u16, new_hotkey: &AccountId, block_number: u64) {
@@ -371,7 +371,7 @@ impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> f
371371
}
372372

373373
fn ensure_subnet_owner_or_root(o: RuntimeOrigin, netuid: u16) -> Result<(), DispatchError> {
374-
return SubtensorModule::ensure_subnet_owner_or_root(o, netuid);
374+
SubtensorModule::ensure_subnet_owner_or_root(o, netuid)
375375
}
376376

377377
fn set_rho(netuid: u16, rho: u16) {
@@ -419,7 +419,7 @@ impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> f
419419
}
420420

421421
fn is_hotkey_registered_on_network(netuid: u16, hotkey: &AccountId) -> bool {
422-
return SubtensorModule::is_hotkey_registered_on_network(netuid, hotkey);
422+
SubtensorModule::is_hotkey_registered_on_network(netuid, hotkey)
423423
}
424424

425425
fn init_new_network(netuid: u16, tempo: u16) {

0 commit comments

Comments
 (0)