diff --git a/.github/workflows/check-rust.yml b/.github/workflows/check-rust.yml index 5b0d1519f..1716bd454 100644 --- a/.github/workflows/check-rust.yml +++ b/.github/workflows/check-rust.yml @@ -71,7 +71,7 @@ jobs: strategy: matrix: rust-branch: - - nightly-2024-03-05 + - stable rust-target: - x86_64-unknown-linux-gnu # - x86_64-apple-darwin @@ -119,55 +119,7 @@ jobs: 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 Shared Rust Cache - uses: Swatinem/rust-cache@v2.2.1 - with: - key: ${{ matrix.os }}-${{ env.RUST_BIN_DIR }} - - - name: cargo clippy --workspace --all-targets --all-features -- -D warnings - run: cargo clippy --workspace --all-targets --all-features -- -D warnings - - cargo-clippy-all-features: - name: cargo clippy --all-features - runs-on: SubtensorCI - strategy: - matrix: - rust-branch: - - nightly-2024-03-05 + - stable rust-target: - x86_64-unknown-linux-gnu # - x86_64-apple-darwin @@ -208,7 +160,6 @@ jobs: - name: cargo clippy --workspace --all-targets --all-features -- -D warnings run: cargo clippy --workspace --all-targets --all-features -- -D warnings - # runs cargo test --workspace cargo-test: name: cargo test @@ -216,7 +167,7 @@ jobs: strategy: matrix: rust-branch: - - nightly-2024-03-05 + - stable rust-target: - x86_64-unknown-linux-gnu # - x86_64-apple-darwin @@ -265,7 +216,7 @@ jobs: strategy: matrix: rust-branch: - - nightly-2024-03-05 + - stable rust-target: - x86_64-unknown-linux-gnu # - x86_64-apple-darwin @@ -314,7 +265,7 @@ jobs: strategy: matrix: rust-branch: - - nightly-2024-03-05 + - stable rust-target: - x86_64-unknown-linux-gnu # - x86_64-apple-darwin diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 511fb74c3..54f82447f 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -42,7 +42,7 @@ pub struct FullDeps { /// Grandpa block import setup. pub grandpa: GrandpaDeps, /// Backend used by the node. - pub backend: Arc, + pub _backend: Arc, } /// Instantiate all full RPC extensions. @@ -74,7 +74,7 @@ where pool, deny_unsafe, grandpa, - backend: _, + _backend: _, } = deps; // Custom RPC methods for Paratensor diff --git a/node/src/service.rs b/node/src/service.rs index 284edb52a..9a19ae354 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -266,7 +266,7 @@ pub fn new_full(config: Configuration) -> Result { subscription_executor: subscription_executor.clone(), finality_provider: finality_proof_provider.clone(), }, - backend: rpc_backend.clone(), + _backend: rpc_backend.clone(), }; crate::rpc::create_full(deps).map_err(Into::into) }, diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 61c29efff..47799f30d 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -7,7 +7,6 @@ pub use weights::WeightInfo; use sp_runtime::DispatchError; use sp_runtime::{traits::Member, RuntimeAppPublic}; -#[cfg(feature = "runtime-benchmarks")] mod benchmarking; #[deny(missing_docs)] diff --git a/pallets/commitments/src/lib.rs b/pallets/commitments/src/lib.rs index 6e252ecea..dec9177d2 100644 --- a/pallets/commitments/src/lib.rs +++ b/pallets/commitments/src/lib.rs @@ -1,11 +1,9 @@ #![cfg_attr(not(feature = "std"), no_std)] +mod benchmarking; #[cfg(test)] mod tests; -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - pub mod types; pub mod weights; @@ -234,7 +232,7 @@ where pub fn get_priority_vanilla() -> u64 { // Return high priority so that every extrinsic except set_weights function will // have a higher priority than the set_weights call - u64::max_value() + u64::MAX } } diff --git a/pallets/registry/src/lib.rs b/pallets/registry/src/lib.rs index 026c03260..e32b1fc5f 100644 --- a/pallets/registry/src/lib.rs +++ b/pallets/registry/src/lib.rs @@ -3,7 +3,6 @@ #[cfg(test)] mod tests; -#[cfg(feature = "runtime-benchmarks")] mod benchmarking; pub mod types; pub mod weights; diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 61eb17f4a..b590781f5 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -29,7 +29,6 @@ use sp_std::marker::PhantomData; // ============================ // ==== Benchmark Imports ===== // ============================ -#[cfg(feature = "runtime-benchmarks")] mod benchmarks; // ========================= @@ -2063,7 +2062,7 @@ pub mod pallet { let current_block_number: u64 = Self::get_current_block_as_u64(); let default_priority: u64 = current_block_number - Self::get_last_update_for_uid(netuid, uid); - return default_priority + u32::max_value() as u64; + return default_priority + u32::MAX as u64; } 0 } @@ -2141,7 +2140,7 @@ where pub fn get_priority_vanilla() -> u64 { // Return high priority so that every extrinsic except set_weights function will // have a higher priority than the set_weights call - u64::max_value() + u64::MAX } pub fn get_priority_set_weights(who: &T::AccountId, netuid: u16) -> u64 { @@ -2219,9 +2218,9 @@ where Err(InvalidTransaction::Call.into()) } } - Some(Call::set_root_weights { netuid, .. }) => { - if Self::check_weights_min_stake(who) { - let priority: u64 = Self::get_priority_set_weights(who, *netuid); + Some(Call::set_root_weights { netuid, hotkey, .. }) => { + if Self::check_weights_min_stake(hotkey) { + let priority: u64 = Self::get_priority_set_weights(hotkey, *netuid); Ok(ValidTransaction { priority, longevity: 1, diff --git a/pallets/subtensor/src/root.rs b/pallets/subtensor/src/root.rs index 42c783c3b..a09957924 100644 --- a/pallets/subtensor/src/root.rs +++ b/pallets/subtensor/src/root.rs @@ -1009,12 +1009,12 @@ impl Pallet { NetworkRegisteredAt::::remove(netuid); // --- 8. Remove incentive mechanism memory. - let _ = Uids::::clear_prefix(netuid, u32::max_value(), None); - let _ = Keys::::clear_prefix(netuid, u32::max_value(), None); - let _ = Bonds::::clear_prefix(netuid, u32::max_value(), None); + let _ = Uids::::clear_prefix(netuid, u32::MAX, None); + let _ = Keys::::clear_prefix(netuid, u32::MAX, None); + let _ = Bonds::::clear_prefix(netuid, u32::MAX, None); // --- 8. Removes the weights for this subnet (do not remove). - let _ = Weights::::clear_prefix(netuid, u32::max_value(), None); + let _ = Weights::::clear_prefix(netuid, u32::MAX, None); // --- 9. Iterate over stored weights and fill the matrix. for (uid_i, weights_i) in diff --git a/pallets/subtensor/src/weights.rs b/pallets/subtensor/src/weights.rs index 72c811f80..548bc30af 100644 --- a/pallets/subtensor/src/weights.rs +++ b/pallets/subtensor/src/weights.rs @@ -405,7 +405,7 @@ impl Pallet { return weights; } weights.iter_mut().for_each(|x| { - *x = (*x as u64 * u16::max_value() as u64 / sum) as u16; + *x = (*x as u64 * u16::MAX as u64 / sum) as u16; }); weights } diff --git a/pallets/subtensor/tests/block_step.rs b/pallets/subtensor/tests/block_step.rs index eb97fe692..5df173906 100644 --- a/pallets/subtensor/tests/block_step.rs +++ b/pallets/subtensor/tests/block_step.rs @@ -869,8 +869,9 @@ fn test_emission_based_on_registration_status() { n as usize ); + let block: u64 = 0; // drain the emission tuples for the subnet with registration on - SubtensorModule::drain_emission(next_block as u64); + SubtensorModule::drain_emission(block); // Turn on registration for the subnet with registration off SubtensorModule::set_network_registration_allowed(netuid_off, true); SubtensorModule::set_network_registration_allowed(netuid_on, false); diff --git a/pallets/subtensor/tests/epoch.rs b/pallets/subtensor/tests/epoch.rs index 0bfd11ba4..fe247fd32 100644 --- a/pallets/subtensor/tests/epoch.rs +++ b/pallets/subtensor/tests/epoch.rs @@ -38,7 +38,7 @@ fn normalize_weights(mut weights: Vec) -> Vec { return weights; } weights.iter_mut().for_each(|x| { - *x = (*x as u64 * u16::max_value() as u64 / sum) as u16; + *x = (*x as u64 * u16::MAX as u64 / sum) as u16; }); weights } diff --git a/pallets/subtensor/tests/weights.rs b/pallets/subtensor/tests/weights.rs index bb7f11908..5cd3bf7c2 100644 --- a/pallets/subtensor/tests/weights.rs +++ b/pallets/subtensor/tests/weights.rs @@ -1,13 +1,14 @@ mod mock; use frame_support::{ assert_err, assert_ok, - dispatch::{DispatchClass, DispatchResult, GetDispatchInfo, Pays}, + dispatch::{DispatchClass, DispatchInfo, DispatchResult, GetDispatchInfo, Pays}, + pallet_prelude::{InvalidTransaction, TransactionValidityError}, }; use mock::*; -use pallet_subtensor::Error; +use pallet_subtensor::{Error, Owner}; use sp_core::{H256, U256}; use sp_runtime::{ - traits::{BlakeTwo256, Hash}, + traits::{BlakeTwo256, DispatchInfoOf, Hash, SignedExtension}, DispatchError, }; use substrate_fixed::types::I32F32; @@ -37,6 +38,103 @@ fn test_set_weights_dispatch_info_ok() { assert_eq!(dispatch_info.pays_fee, Pays::No); }); } +#[test] +#[cfg(not(tarpaulin))] +fn test_set_rootweights_dispatch_info_ok() { + new_test_ext(0).execute_with(|| { + let dests = vec![1, 1]; + let weights = vec![1, 1]; + let netuid: u16 = 1; + let version_key: u64 = 0; + let hotkey: U256 = U256::from(1); // Add the hotkey field + let call = RuntimeCall::SubtensorModule(SubtensorCall::set_root_weights { + netuid, + dests, + weights, + version_key, + hotkey, // Include the hotkey field + }); + let dispatch_info = call.get_dispatch_info(); + + assert_eq!(dispatch_info.class, DispatchClass::Normal); + assert_eq!(dispatch_info.pays_fee, Pays::No); + }); +} + +#[test] +fn test_set_rootweights_validate() { + // Testing the signed extension validate function + // correctly filters this transaction. + + new_test_ext(0).execute_with(|| { + let dests = vec![1, 1]; + let weights = vec![1, 1]; + let netuid: u16 = 1; + let version_key: u64 = 0; + let coldkey = U256::from(0); + let hotkey: U256 = U256::from(1); // Add the hotkey field + assert_ne!(hotkey, coldkey); // Ensure hotkey is NOT the same as coldkey !!! + + let who = coldkey; // The coldkey signs this transaction + + let call = RuntimeCall::SubtensorModule(SubtensorCall::set_root_weights { + netuid, + dests, + weights, + version_key, + hotkey, // Include the hotkey field + }); + + // Create netuid + add_network(netuid, 0, 0); + // Register the hotkey + SubtensorModule::append_neuron(netuid, &hotkey, 0); + Owner::::insert(hotkey, coldkey); + + let min_stake = 500_000_000_000; + // Set the minimum stake + SubtensorModule::set_weights_min_stake(min_stake); + + // Verify stake is less than minimum + assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); + let info: DispatchInfo = + DispatchInfoOf::<::RuntimeCall>::default(); + + let extension = pallet_subtensor::SubtensorSignedExtension::::new(); + // Submit to the signed extension validate function + let result_no_stake = extension.validate(&who, &call.clone(), &info, 10); + // Should fail + assert_err!( + // Should get an invalid transaction error + result_no_stake, + TransactionValidityError::Invalid(InvalidTransaction::Call,) + ); + + // Increase the stake to be equal to the minimum + SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); + + // Verify stake is equal to minimum + assert_eq!( + SubtensorModule::get_total_stake_for_hotkey(&hotkey), + min_stake + ); + + // Submit to the signed extension validate function + let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); + // Now the call should pass + assert_ok!(result_min_stake); + + // Try with more stake than minimum + SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 1); + + // Verify stake is more than minimum + assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) > min_stake); + + let result_more_stake = extension.validate(&who, &call.clone(), &info, 10); + // The call should still pass + assert_ok!(result_more_stake); + }); +} #[test] fn test_commit_weights_dispatch_info_ok() { @@ -62,6 +160,82 @@ fn test_commit_weights_dispatch_info_ok() { }); } +#[test] +fn test_commit_weights_validate() { + // Testing the signed extension validate function + // correctly filters this transaction. + + new_test_ext(0).execute_with(|| { + let dests = vec![1, 1]; + let weights = vec![1, 1]; + let netuid: u16 = 1; + let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; + let version_key: u64 = 0; + let coldkey = U256::from(0); + let hotkey: U256 = U256::from(1); // Add the hotkey field + assert_ne!(hotkey, coldkey); // Ensure hotkey is NOT the same as coldkey !!! + + let who = hotkey; // The hotkey signs this transaction + + let commit_hash: H256 = + BlakeTwo256::hash_of(&(hotkey, netuid, dests, weights, salt, version_key)); + + let call = RuntimeCall::SubtensorModule(SubtensorCall::commit_weights { + netuid, + commit_hash, + }); + + // Create netuid + add_network(netuid, 0, 0); + // Register the hotkey + SubtensorModule::append_neuron(netuid, &hotkey, 0); + Owner::::insert(hotkey, coldkey); + + let min_stake = 500_000_000_000; + // Set the minimum stake + SubtensorModule::set_weights_min_stake(min_stake); + + // Verify stake is less than minimum + assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); + let info: DispatchInfo = + DispatchInfoOf::<::RuntimeCall>::default(); + + let extension = pallet_subtensor::SubtensorSignedExtension::::new(); + // Submit to the signed extension validate function + let result_no_stake = extension.validate(&who, &call.clone(), &info, 10); + // Should fail + assert_err!( + // Should get an invalid transaction error + result_no_stake, + TransactionValidityError::Invalid(InvalidTransaction::Call,) + ); + + // Increase the stake to be equal to the minimum + SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); + + // Verify stake is equal to minimum + assert_eq!( + SubtensorModule::get_total_stake_for_hotkey(&hotkey), + min_stake + ); + + // Submit to the signed extension validate function + let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); + // Now the call should pass + assert_ok!(result_min_stake); + + // Try with more stake than minimum + SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 1); + + // Verify stake is more than minimum + assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) > min_stake); + + let result_more_stake = extension.validate(&who, &call.clone(), &info, 10); + // The call should still pass + assert_ok!(result_more_stake); + }); +} + #[test] fn test_reveal_weights_dispatch_info_ok() { new_test_ext(0).execute_with(|| { @@ -85,6 +259,82 @@ fn test_reveal_weights_dispatch_info_ok() { }); } +#[test] +fn test_reveal_weights_validate() { + // Testing the signed extension validate function + // correctly filters this transaction. + + new_test_ext(0).execute_with(|| { + let dests = vec![1, 1]; + let weights = vec![1, 1]; + let netuid: u16 = 1; + let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; + let version_key: u64 = 0; + let coldkey = U256::from(0); + let hotkey: U256 = U256::from(1); // Add the hotkey field + assert_ne!(hotkey, coldkey); // Ensure hotkey is NOT the same as coldkey !!! + + let who = hotkey; // The hotkey signs this transaction + + let call = RuntimeCall::SubtensorModule(SubtensorCall::reveal_weights { + netuid, + uids: dests, + values: weights, + salt, + version_key, + }); + + // Create netuid + add_network(netuid, 0, 0); + // Register the hotkey + SubtensorModule::append_neuron(netuid, &hotkey, 0); + Owner::::insert(hotkey, coldkey); + + let min_stake = 500_000_000_000; + // Set the minimum stake + SubtensorModule::set_weights_min_stake(min_stake); + + // Verify stake is less than minimum + assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); + let info: DispatchInfo = + DispatchInfoOf::<::RuntimeCall>::default(); + + let extension = pallet_subtensor::SubtensorSignedExtension::::new(); + // Submit to the signed extension validate function + let result_no_stake = extension.validate(&who, &call.clone(), &info, 10); + // Should fail + assert_err!( + // Should get an invalid transaction error + result_no_stake, + TransactionValidityError::Invalid(InvalidTransaction::Call,) + ); + + // Increase the stake to be equal to the minimum + SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); + + // Verify stake is equal to minimum + assert_eq!( + SubtensorModule::get_total_stake_for_hotkey(&hotkey), + min_stake + ); + + // Submit to the signed extension validate function + let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); + // Now the call should pass + assert_ok!(result_min_stake); + + // Try with more stake than minimum + SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 1); + + // Verify stake is more than minimum + assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) > min_stake); + + let result_more_stake = extension.validate(&who, &call.clone(), &info, 10); + // The call should still pass + assert_ok!(result_more_stake); + }); +} + #[test] fn test_set_weights_is_root_error() { new_test_ext(0).execute_with(|| { diff --git a/runtime/src/check_nonce.rs b/runtime/src/check_nonce.rs index e6e992ccf..d9948f9b6 100644 --- a/runtime/src/check_nonce.rs +++ b/runtime/src/check_nonce.rs @@ -120,7 +120,7 @@ where priority: 0, requires, provides, - longevity: TransactionLongevity::max_value(), + longevity: TransactionLongevity::MAX, propagate: true, }) } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index f9f8d599f..2364008fd 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -135,7 +135,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 151, + spec_version: 152, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/scripts/localnet.sh b/scripts/localnet.sh index ab564871b..65ca5c0a9 100755 --- a/scripts/localnet.sh +++ b/scripts/localnet.sh @@ -6,9 +6,24 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" # The base directory of the subtensor project BASE_DIR="$SCRIPT_DIR/.." -: "${CHAIN:=local}" -: "${BUILD_BINARY:=1}" -: "${FEATURES:="pow-faucet runtime-benchmarks fast-blocks"}" +# get parameters +# Get the value of fast_blocks from the first argument +fast_blocks=${1:-"True"} + +# Check the value of fast_blocks +if [ "$fast_blocks" == "False" ]; then + # Block of code to execute if fast_blocks is False + echo "fast_blocks is Off" + : "${CHAIN:=local}" + : "${BUILD_BINARY:=1}" + : "${FEATURES:="pow-faucet runtime-benchmarks"}" +else + # Block of code to execute if fast_blocks is not False + echo "fast_blocks is On" + : "${CHAIN:=local}" + : "${BUILD_BINARY:=1}" + : "${FEATURES:="pow-faucet runtime-benchmarks fast-blocks"}" +fi SPEC_PATH="${SCRIPT_DIR}/specs/" FULL_PATH="$SPEC_PATH$CHAIN.json"