Skip to content
Open
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
914 changes: 427 additions & 487 deletions Cargo.lock

Large diffs are not rendered by default.

278 changes: 140 additions & 138 deletions Cargo.toml

Large diffs are not rendered by default.

75 changes: 40 additions & 35 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use rayon::prelude::*;
use std::{
env, fs,
path::{Path, PathBuf},
str::FromStr,
sync::mpsc::channel,
};
use walkdir::WalkDir;

use subtensor_linting::*;

const LINT_THREAD_STACK_SIZE: usize = 8 * 1024 * 1024;

fn main() {
// need to list all rust directories here
println!("cargo:rerun-if-changed=pallets");
Expand All @@ -29,45 +30,49 @@ fn main() {
// as we process each Rust file
let (tx, rx) = channel();

// Parse each rust file with syn and run the linting suite on it in parallel
rust_files.par_iter().for_each_with(tx.clone(), |tx, file| {
let is_test = file.display().to_string().contains("test");
let Ok(content) = fs::read_to_string(file) else {
return;
};
let Ok(parsed_tokens) = proc_macro2::TokenStream::from_str(&content) else {
return;
};
let Ok(parsed_file) = syn::parse2::<syn::File>(parsed_tokens) else {
return;
};
let lint_pool = rayon::ThreadPoolBuilder::new()
.stack_size(LINT_THREAD_STACK_SIZE)
.build()
.expect("failed to initialize custom lint thread pool");

let track_lint = |result: Result| {
let Err(errors) = result else {
// Parse each rust file with syn and run the linting suite on it in parallel
lint_pool.install(|| {
rust_files.par_iter().for_each_with(tx.clone(), |tx, file| {
let is_test = file.display().to_string().contains("test");
let Ok(content) = fs::read_to_string(file) else {
return;
};
let Ok(parsed_file) = syn::parse_file(&content) else {
return;
};
let relative_path = file.strip_prefix(workspace_root).unwrap_or(file.as_path());
for error in errors {
let loc = error.span().start();
let file_path = relative_path.display();
// note that spans can't go across thread boundaries without losing their location
// info so we we serialize here and send a String
tx.send(format!(
"cargo:warning={}:{}:{}: {}",
file_path, loc.line, loc.column, error,
))
.unwrap();
}
};

track_lint(ForbidAsPrimitiveConversion::lint(&parsed_file));
track_lint(ForbidKeysRemoveCall::lint(&parsed_file));
track_lint(RequireFreezeStruct::lint(&parsed_file));
track_lint(RequireExplicitPalletIndex::lint(&parsed_file));
let track_lint = |result: Result| {
let Err(errors) = result else {
return;
};
let relative_path = file.strip_prefix(workspace_root).unwrap_or(file.as_path());
for error in errors {
let loc = error.span().start();
let file_path = relative_path.display();
// note that spans can't go across thread boundaries without losing their location
// info so we we serialize here and send a String
tx.send(format!(
"cargo:warning={}:{}:{}: {}",
file_path, loc.line, loc.column, error,
))
.unwrap();
}
};

if is_test {
track_lint(ForbidSaturatingMath::lint(&parsed_file));
}
track_lint(ForbidAsPrimitiveConversion::lint(&parsed_file));
track_lint(ForbidKeysRemoveCall::lint(&parsed_file));
track_lint(RequireFreezeStruct::lint(&parsed_file));
track_lint(RequireExplicitPalletIndex::lint(&parsed_file));

if is_test {
track_lint(ForbidSaturatingMath::lint(&parsed_file));
}
});
});

// Collect and print all errors after the parallel processing is done
Expand Down
12 changes: 6 additions & 6 deletions chain-extensions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pallet-scheduler.workspace = true
pallet-preimage.workspace = true
pallet-timestamp.workspace = true
pallet-crowdloan.workspace = true
pallet-subtensor-utility.workspace = true
pallet-subtensor-proxy.workspace = true
pallet-utility.workspace = true
pallet-proxy.workspace = true
pallet-drand.workspace = true
subtensor-swap-interface.workspace = true
num_enum.workspace = true
Expand Down Expand Up @@ -62,8 +62,8 @@ std = [
"pallet-preimage/std",
"pallet-timestamp/std",
"pallet-crowdloan/std",
"pallet-subtensor-utility/std",
"pallet-subtensor-proxy/std",
"pallet-utility/std",
"pallet-proxy/std",
"pallet-drand/std",
"subtensor-swap-interface/std",
"num_enum/std",
Expand All @@ -81,8 +81,8 @@ runtime-benchmarks = [
"pallet-drand/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-subtensor-proxy/runtime-benchmarks",
"pallet-subtensor-utility/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"subtensor-runtime-common/runtime-benchmarks",
"subtensor-swap-interface/runtime-benchmarks"
Expand Down
3 changes: 1 addition & 2 deletions chain-extensions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use frame_system::RawOrigin;
use pallet_contracts::chain_extension::{
BufInBufOutState, ChainExtension, Environment, Ext, InitState, RetVal, SysConfig,
};
use pallet_proxy::WeightInfo;
use pallet_subtensor::weights::WeightInfo as SubtensorWeightInfo;
use pallet_subtensor_proxy as pallet_proxy;
use pallet_subtensor_proxy::WeightInfo;
use sp_runtime::{DispatchError, Weight, traits::StaticLookup};
use sp_std::marker::PhantomData;
use substrate_fixed::types::U96F32;
Expand Down
4 changes: 2 additions & 2 deletions chain-extensions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use frame_system as system;
use frame_system::{EnsureRoot, RawOrigin, limits, offchain::CreateTransactionBase};
use pallet_contracts::HoldReason as ContractsHoldReason;
use pallet_subtensor::*;
use pallet_subtensor_proxy as pallet_proxy;
use pallet_subtensor_utility as pallet_utility;
use sp_core::{ConstU64, H256, U256, offchain::KeyTypeId};
use sp_runtime::Perbill;
use sp_runtime::{
Expand Down Expand Up @@ -177,6 +175,7 @@ impl frame_support::traits::InstanceFilter<RuntimeCall> for subtensor_runtime_co
}

impl pallet_proxy::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type ProxyType = subtensor_runtime_common::ProxyType;
Expand Down Expand Up @@ -495,6 +494,7 @@ impl pallet_scheduler::Config for Test {
}

impl pallet_utility::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Test>;
Expand Down
14 changes: 6 additions & 8 deletions chain-extensions/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,7 @@ fn add_proxy_success_creates_proxy_relationship() {
add_balance_to_coldkey_account(&delegator, 1_000_000_000.into());

assert_eq!(
pallet_subtensor_proxy::Proxies::<mock::Test>::get(delegator)
.0
.len(),
pallet_proxy::Proxies::<mock::Test>::get(delegator).0.len(),
0
);

Expand All @@ -641,7 +639,7 @@ fn add_proxy_success_creates_proxy_relationship() {
let ret = SubtensorChainExtension::<mock::Test>::dispatch(&mut env).unwrap();
assert_success(ret);

let proxies = pallet_subtensor_proxy::Proxies::<mock::Test>::get(delegator).0;
let proxies = pallet_proxy::Proxies::<mock::Test>::get(delegator).0;
assert_eq!(proxies.len(), 1);
if let Some(proxy) = proxies.first() {
assert_eq!(proxy.delegate, delegate);
Expand All @@ -668,14 +666,14 @@ fn remove_proxy_success_removes_proxy_relationship() {
let ret = SubtensorChainExtension::<mock::Test>::dispatch(&mut add_env).unwrap();
assert_success(ret);

let proxies_before = pallet_subtensor_proxy::Proxies::<mock::Test>::get(delegator).0;
let proxies_before = pallet_proxy::Proxies::<mock::Test>::get(delegator).0;
assert_eq!(proxies_before.len(), 1);

let mut remove_env = MockEnv::new(FunctionId::RemoveProxyV1, delegator, delegate.encode());
let ret = SubtensorChainExtension::<mock::Test>::dispatch(&mut remove_env).unwrap();
assert_success(ret);

let proxies_after = pallet_subtensor_proxy::Proxies::<mock::Test>::get(delegator).0;
let proxies_after = pallet_proxy::Proxies::<mock::Test>::get(delegator).0;
assert_eq!(proxies_after.len(), 0);
});
}
Expand Down Expand Up @@ -2371,7 +2369,7 @@ mod caller_dispatch_tests {
let ret = SubtensorChainExtension::<mock::Test>::dispatch(&mut env).unwrap();
assert_success(ret);

let proxies = pallet_subtensor_proxy::Proxies::<mock::Test>::get(delegator).0;
let proxies = pallet_proxy::Proxies::<mock::Test>::get(delegator).0;
assert_eq!(proxies.len(), 1);
});
}
Expand All @@ -2396,7 +2394,7 @@ mod caller_dispatch_tests {
let ret = SubtensorChainExtension::<mock::Test>::dispatch(&mut remove_env).unwrap();
assert_success(ret);

let proxies_after = pallet_subtensor_proxy::Proxies::<mock::Test>::get(delegator).0;
let proxies_after = pallet_proxy::Proxies::<mock::Test>::get(delegator).0;
assert_eq!(proxies_after.len(), 0);
});
}
Expand Down
4 changes: 2 additions & 2 deletions eco-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pallet-preimage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev
pallet-drand = { path = "../pallets/drand", default-features = false, features = ["std"] }
pallet-subtensor-swap = { path = "../pallets/swap", default-features = false, features = ["std"] }
pallet-crowdloan = { path = "../pallets/crowdloan", default-features = false, features = ["std"] }
pallet-subtensor-proxy = { path = "../pallets/proxy", default-features = false, features = ["std"] }
pallet-subtensor-utility = { path = "../pallets/utility", default-features = false, features = ["std"] }
pallet-proxy = { path = "../pallets/proxy", default-features = false, features = ["std"] }
pallet-utility = { path = "../pallets/utility", default-features = false, features = ["std"] }
pallet-shield = { path = "../pallets/shield", default-features = false, features = ["std"] }
subtensor-runtime-common = { path = "../common", default-features = false, features = ["std"] }
subtensor-swap-interface = { path = "../primitives/swap-interface", default-features = false, features = ["std"] }
Expand Down
4 changes: 1 addition & 3 deletions eco-tests/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use frame_support::{parameter_types, traits::PrivilegeCmp};
use frame_system as system;
use frame_system::{EnsureRoot, limits, offchain::CreateTransactionBase};
use pallet_subtensor::*;
use pallet_subtensor_proxy as pallet_proxy;
use pallet_subtensor_utility as pallet_utility;
use sp_core::{ConstU64, H256, U256, offchain::KeyTypeId};
use sp_runtime::Perbill;
use sp_runtime::{
Expand All @@ -44,7 +42,7 @@ frame_support::construct_runtime!(
Drand: pallet_drand = 8,
Swap: pallet_subtensor_swap = 9,
Crowdloan: pallet_crowdloan = 10,
Proxy: pallet_subtensor_proxy = 11,
Proxy: pallet_proxy = 11,
AlphaAssets: pallet_alpha_assets = 12,
}
);
Expand Down
51 changes: 0 additions & 51 deletions pallets/proxy/Cargo.toml

This file was deleted.

26 changes: 0 additions & 26 deletions pallets/proxy/README.md

This file was deleted.

Loading
Loading