Skip to content
Merged
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
64 changes: 5 additions & 59 deletions .github/workflows/check-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ jobs:
- name: cargo fmt
run: cargo fmt --check --all

# runs cargo check --workspace
cargo-check:
name: cargo check
# runs cargo clippy --workspace --all-targets --all-features
cargo-clippy:
name: cargo clippy
runs-on: SubtensorCI
strategy:
matrix:
Expand Down Expand Up @@ -117,8 +117,8 @@ jobs:
with:
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}

- name: cargo check --workspace
run: cargo check --workspace
- name: cargo clippy --workspace --all-targets --all-features
run: cargo clippy --workspace --all-targets --all-features

# runs cargo test --workspace
cargo-test:
Expand Down Expand Up @@ -218,60 +218,6 @@ jobs:
- name: cargo test --workspace --features=runtime-benchmarks
run: cargo test --workspace --features=runtime-benchmarks

# runs cargo clippy
clippy:
name: cargo clippy
runs-on: SubtensorCI
strategy:
matrix:
rust-branch:
- nightly-2024-03-05
rust-target:
- x86_64-unknown-linux-gnu
# - x86_64-apple-darwin
os:
- ubuntu-latest
# - macos-latest
include:
- os: ubuntu-latest
# - os: macos-latest
env:
RELEASE_NAME: development
# RUSTFLAGS: -A warnings
RUSTV: ${{ matrix.rust-branch }}
RUST_BACKTRACE: full
RUST_BIN_DIR: target/${{ matrix.rust-target }}
SKIP_WASM_BUILD: 1
TARGET: ${{ matrix.rust-target }}
steps:
- name: Check-out repository under $GITHUB_WORKSPACE
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update &&
sudo apt-get install -y clang curl libssl-dev llvm libudev-dev protobuf-compiler

- name: Install Rust ${{ matrix.rust-branch }}
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: ${{ matrix.rust-branch }}
components: rustfmt, clippy
profile: minimal

- name: Utilize Rust shared cached
uses: Swatinem/rust-cache@v2.2.1
with:
key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }}

- name: cargo clippy
run: |
cargo clippy -- -D clippy::panic \
-D clippy::todo \
-D clippy::unimplemented
# -D clippy::indexing_slicing \
# -D clippy::unwrap_used \

# ensures cargo fix has no trivial changes that can be applied
cargo-fix:
name: cargo fix
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ members = [
]
resolver = "2"

[workspace.lints.clippy]
type_complexity = "allow"

[profile.release]
panic = "unwind"

Expand Down
3 changes: 3 additions & 0 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition = "2021"
license = "Unlicense"
repository = "https://github.com/opentensor/subtensor"

[lints]
workspace = true

[dependencies]

##
Expand Down
3 changes: 3 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ publish = false
repository = "https://github.com/opentensor/subtensor"
build = "build.rs"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

Expand Down
2 changes: 1 addition & 1 deletion node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
acc,
BalancesCall::transfer_keep_alive {
dest: self.dest.clone().into(),
value: self.value.into(),
value: self.value,
}
.into(),
nonce,
Expand Down
2 changes: 2 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ fn localnet_genesis(
}

// Configure initial storage state for FRAME modules.
#[allow(clippy::too_many_arguments)]
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
Expand Down Expand Up @@ -551,6 +552,7 @@ fn testnet_genesis(
}

// Configure initial storage state for FRAME modules.
#[allow(clippy::too_many_arguments)]
fn finney_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
Expand Down
1 change: 1 addition & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Cli {
pub run: RunCmd,
}

#[allow(clippy::large_enum_variant)]
#[derive(Debug, clap::Subcommand)]
pub enum Subcommand {
// Key management cli utilities
Expand Down
1 change: 0 additions & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use node_subtensor_runtime::Block;
use sc_cli::SubstrateCli;
use sc_service::PartialComponents;


impl SubstrateCli for Cli {
fn impl_name() -> String {
"Subtensor Node".into()
Expand Down
8 changes: 4 additions & 4 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use std::sync::Arc;

use jsonrpsee::RpcModule;
use node_subtensor_runtime::{opaque::Block, AccountId, Balance, BlockNumber, Index, Hash};
use node_subtensor_runtime::{opaque::Block, AccountId, Balance, BlockNumber, Hash, Index};
use sc_consensus_grandpa::FinalityProofProvider;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sc_consensus_grandpa::FinalityProofProvider;

pub use sc_rpc_api::DenyUnsafe;

Expand Down Expand Up @@ -64,9 +64,9 @@ where
P: TransactionPool + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use subtensor_custom_rpc::{SubtensorCustom, SubtensorCustomApiServer};
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};

let mut module = RpcModule::new(());
let FullDeps {
Expand Down Expand Up @@ -99,7 +99,7 @@ where
justification_stream,
finality_provider,
)
.into_rpc(),
.into_rpc(),
)?;

// Extend this RPC with a custom API by using the following syntax.
Expand Down
61 changes: 31 additions & 30 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
);
}

let finality_proof_provider = sc_consensus_grandpa::FinalityProofProvider::new_for_service(
backend.clone(),
Some(grandpa_link.shared_authority_set().clone()),
);
let rpc_backend = backend.clone();
let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
let shared_voter_state = SharedVoterState::empty();
let finality_proof_provider = sc_consensus_grandpa::FinalityProofProvider::new_for_service(
backend.clone(),
Some(grandpa_link.shared_authority_set().clone()),
);
let rpc_backend = backend.clone();
let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
let shared_voter_state = SharedVoterState::empty();

let role = config.role.clone();
let force_authoring = config.force_authoring;
Expand All @@ -238,28 +238,29 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
let enable_grandpa = !config.disable_grandpa;
let prometheus_registry = config.prometheus_registry().cloned();

let rpc_extensions_builder = {
let client = client.clone();
let pool = transaction_pool.clone();

Box::new(move |deny_unsafe, subscription_executor: sc_rpc::SubscriptionTaskExecutor| {
let deps =
crate::rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
deny_unsafe,
grandpa: crate::rpc::GrandpaDeps {
shared_voter_state: shared_voter_state.clone(),
shared_authority_set: shared_authority_set.clone(),
justification_stream: justification_stream.clone(),
subscription_executor: subscription_executor.clone(),
finality_provider: finality_proof_provider.clone(),
},
backend: rpc_backend.clone(),
};
crate::rpc::create_full(deps).map_err(Into::into)
})
};
let rpc_extensions_builder = {
let client = client.clone();
let pool = transaction_pool.clone();

Box::new(
move |deny_unsafe, subscription_executor: sc_rpc::SubscriptionTaskExecutor| {
let deps = crate::rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
deny_unsafe,
grandpa: crate::rpc::GrandpaDeps {
shared_voter_state: shared_voter_state.clone(),
shared_authority_set: shared_authority_set.clone(),
justification_stream: justification_stream.clone(),
subscription_executor: subscription_executor.clone(),
finality_provider: finality_proof_provider.clone(),
},
backend: rpc_backend.clone(),
};
crate::rpc::create_full(deps).map_err(Into::into)
},
)
};

let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
Expand Down
3 changes: 3 additions & 0 deletions pallets/admin-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ license = "Unlicense"
publish = false
repository = "https://github.com/opentensor/subtensor"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

Expand Down
1 change: 0 additions & 1 deletion pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@ pub trait SubtensorInterface<AccountId, Balance, RuntimeOrigin> {
hotkey: &AccountId,
increment: u64,
);
fn u64_to_balance(input: u64) -> Option<Balance>;
fn add_balance_to_coldkey_account(coldkey: &AccountId, amount: Balance);
fn get_current_block_as_u64() -> u64;
fn get_subnetwork_n(netuid: u16) -> u16;
Expand Down
4 changes: 0 additions & 4 deletions pallets/admin-utils/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,6 @@ impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> f
SubtensorModule::increase_stake_on_coldkey_hotkey_account(coldkey, hotkey, increment);
}

fn u64_to_balance(input: u64) -> Option<Balance> {
SubtensorModule::u64_to_balance(input)
}

fn add_balance_to_coldkey_account(coldkey: &AccountId, amount: Balance) {
SubtensorModule::add_balance_to_coldkey_account(coldkey, amount);
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/admin-utils/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,13 +881,13 @@ mod sudo_set_nominator_min_required_stake {
#[test]
fn can_only_be_called_by_admin() {
new_test_ext().execute_with(|| {
let to_be_set: u64 = SubtensorModule::get_nominator_min_required_stake() + 5 as u64;
let to_be_set: u64 = SubtensorModule::get_nominator_min_required_stake() + 5_u64;
assert_eq!(
AdminUtils::sudo_set_nominator_min_required_stake(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
to_be_set
),
Err(DispatchError::BadOrigin.into())
Err(DispatchError::BadOrigin)
);
});
}
Expand All @@ -912,7 +912,7 @@ mod sudo_set_nominator_min_required_stake {
#[test]
fn sets_a_higher_value() {
new_test_ext().execute_with(|| {
let to_be_set: u64 = SubtensorModule::get_nominator_min_required_stake() + 5 as u64;
let to_be_set: u64 = SubtensorModule::get_nominator_min_required_stake() + 5_u64;
assert_ok!(AdminUtils::sudo_set_nominator_min_required_stake(
<<Test as Config>::RuntimeOrigin>::root(),
to_be_set
Expand Down
3 changes: 3 additions & 0 deletions pallets/collective/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ repository = "https://github.com/opentensor/subtensor"
description = "Collective system: Members of a set of account IDs can make their collective feelings known through dispatched calls from one of two specialized origins."
readme = "README.md"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

Expand Down
2 changes: 1 addition & 1 deletion pallets/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ benchmarks_instance_pallet! {
verify {
// All proposals exist and the last proposal has just been updated.
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
let voting = Collective::<T, I>::voting(&last_hash).ok_or("Proposal Missing")?;
let voting = Collective::<T, I>::voting(last_hash).ok_or("Proposal Missing")?;
assert_eq!(voting.ayes.len(), (m - 3) as usize);
assert_eq!(voting.nays.len(), 1);
}
Expand Down
Loading