From f0f1cb1d05de79079dd06dc1080776812a399bfc Mon Sep 17 00:00:00 2001 From: YourUsername Date: Wed, 13 Mar 2024 22:14:51 +0000 Subject: [PATCH 1/3] wip: working on tests --- README.md | 327 +++++---------------- pallets/subspace/tests/delegate_staking.rs | 24 -- pallets/subspace/tests/mock.rs | 5 + pallets/subspace/tests/staking.rs | 31 +- pallets/subspace/tests/step.rs | 9 +- pallets/subspace/tests/weights.rs | 103 ++++++- 6 files changed, 185 insertions(+), 314 deletions(-) diff --git a/README.md b/README.md index dc8288879..c07b50a46 100644 --- a/README.md +++ b/README.md @@ -1,293 +1,114 @@ -# Create your own Subspace +# Subspace -# **Subspace** [![Discord Chat](https://img.shields.io/discord/308323056592486420.svg)](https://discord.gg/commune) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) - - -This repository contains Commune's substrate-chain. Subspace contains the trusted logic which: - -1. Runs Commune's consensus mechanism -1. Advertises module information, IPs, etc -1. and facilitates value transfer via TAO. - - +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![Build Status](https://img.shields.io/travis/com/paritytech/substrate/master?label=stable)](https://travis-ci.com/paritytech/substrate) +[![Coverage Status](https://img.shields.io/codecov/c/gh/paritytech/substrate?label=coverage)](https://codecov.io/gh/paritytech/substrate) + +Subspace is a FRAME-based [Substrate](https://substrate.io/) blockchain node that provides the foundation for [Commune's](https://commune.network/) decentralized cloud platform. It serves as the trusted base layer responsible for consensus, module advertising, and peer discovery. + +## Table of Contents +- [Overview](#overview) +- [System Requirements](#system-requirements) +- [Installation](#installation) +- [Usage](#usage) + - [Build](#build) + - [Run](#run) + - [Test](#test) +- [Architecture](#architecture) +- [Contributing](#contributing) +- [License](#license) +- [Acknowledgements](#acknowledgements) + +## Overview +Subspace is built using [Substrate](https://substrate.io/), a framework for developing scalable and upgradeable blockchains. It provides the core functionality and security needed for Commune's platform: +1. Implements Commune's consensus mechanism +2. Advertises cluster modules and their IP addresses +3. Enables peer discovery for nodes to connect with each other ## System Requirements +- Supported OSs: Linux, MacOS +- Supported Architectures: x86_64 +- Memory: ~ 286MB +- Disk: ~500MB +- Network: Public IPv4 address, TCP ports 9944, 30333 open -* The binaries in ./bin/release are x86_64 binaries to be used with the Linux kernel. -* Subspace needs ~286 MiB to run. -* Architectures other than x86_64 are currently not supported. -* OSs other than Linux and MacOS are currently not supported. - - -## Architectures -Subspace support the following architectures: +## Installation -## Linux x86_64 -Requirements: -* Linux kernel 2.6.32+, -* glibc 2.11+ -A fresh FRAME-based [Substrate](https://www.substrate.io/) node, ready for hacking :rocket: +1. Complete the [basic Rust setup instructions](./docs/rust-setup.md). -## MacOS x86_64 -Requirements: -* MacOS 10.7+ (Lion+) - -## Network requirements -* Subspace needs access to the public internet -* Subspace runs on ipv4 -* Subspace listens on the following ports: -1) 9944 - Websocket. This port is used by commune. It only accepts connections from localhost. Make sure this port is firewalled off from the public domain. -2) 9933 - RPC. This port is opened, but not used. -3) 30333 - p2p socket. This port accepts connections from other subspace nodes. Make sure your firewall(s) allow incoming traffic to this port. -* It is assumed your default outgoing traffic policy is ACCEPT. If not, make sure outbound traffic to port 30333 is allowed. - - - -### Installation -First, complete the [basic Rust setup instructions](./docs/rust-setup.md). - -### Run - -Use Rust's native `cargo` command to build and launch the template node: - -```sh -cargo run --release -- --dev +2. Clone this repository: +```bash +git clone https://github.com/commune-network/subspace.git +cd subspace/ ``` -### Build - -The `cargo run` command will perform an initial build. Use the following command to build the node -without launching it: +## Usage -```sh +### Build +To build the node without launching it, run: +```bash cargo build --release ``` -### Embedded Docs - -Once the project has been built, the following command can be used to explore all parameters and -subcommands: - -```sh -./target/release/node-subspace -h +### Run +To run a single development node with ephemeral storage: +```bash +./target/release/node-subspace --dev ``` +This will start a Subspace node with a clean state. The node's state will be discarded on exit. -## Run - -The provided `cargo run` command will launch a epochrary node and its state will be discarded after -you terminate the process. After the project has been built, there are other ways to launch the -node. - -### Single-Node Development Chain - -This command will start the single-node development chain with non-persistent state: - +To retain the node's state between runs, specify a base path: ```bash -./target/release/subspace --dev +mkdir my-chain-state/ +./target/release/node-subspace --dev --base-path ./my-chain-state/ ``` -Purge the development chain's state: - +Other useful commands: ```bash +# Purge chain state ./target/release/subspace purge-chain --dev -``` -Start the development chain with detailed logging: - -```bash +# Detailed logging RUST_BACKTRACE=1 ./target/release/subspace-ldebug --dev -``` - -Running debug with logs. -```bash -SKIP_WASM_BUILD=1 RUST_LOG=runtime=debug -- --nocapture -``` - -Running individual tests -```bash -SKIP_WASM_BUILD=1 RUST_LOG=runtime=debug cargo test -- --nocapture -``` -Running code coverage -```bash -SKIP_WASM_BUILD=1 RUST_LOG=runtime=debug cargo tarpaulin --skip-clean +# Explore parameters and subcommands +./target/release/node-subspace -h ``` -> Note; above requires `cargo-tarpaulin` is installed to the host, eg. `cargo install cargo-tarpaulin` - - -> Development chain means that the state of our chain will be in a tmp folder while the nodes are -> running. Also, **alice** account will be authority and sudo account as declared in the -> [genesis state](https://github.com/substrate-developer-hub/substrate-node-template/blob/main/node/src/chain_spec.rs#L49). -> At the same time the following accounts will be pre-funded: -> - Alice -> - Bob -> - Alice//stash -> - Bob//stash - -In case of being interested in maintaining the chain' state between runs a base path must be added -so the db can be stored in the provided folder instead of a epochral one. We could use this folder -to store different chain databases, as a different folder will be created per different chain that -is ran. The following commands shows how to use a newly created folder as our db base path. +### Test +To run all tests: ```bash -// Create a folder to use as the db base path -$ mkdir my-chain-state - -// Use of that folder to store the chain state -$ ./target/release/node-template --dev --base-path ./my-chain-state/ - -// Check the folder structure created inside the base path after running the chain -$ ls ./my-chain-state -chains -$ ls ./my-chain-state/chains/ -dev -$ ls ./my-chain-state/chains/dev -db keystore network +cargo test --all ``` -### Connect with Polkadot-JS Apps Front-end - -Once the node template is running locally, you can connect it with **Polkadot-JS Apps** front-end -to interact with your chain. [Click -here](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944) connecting the Apps to your -local node template. - -### Multi-Node Local Testnet - -If you want to see the multi-node consensus algorithm in action, refer to our -[Simulate a network tutorial](https://docs.substrate.io/tutorials/get-started/simulate-network/). - -## Template Structure - -A Substrate project such as this consists of a number of components that are spread across a few -directories. - -### Node - -A blockchain node is an application that allows users to participate in a blockchain network. -Substrate-based blockchain nodes expose a number of capabilities: - -- Networking: Substrate nodes use the [`libp2p`](https://libp2p.io/) networking stack to allow the - nodes in the network to communicate with one another. -- Consensus: Blockchains must have a way to come to - [consensus](https://docs.substrate.io/main-docs/fundamentals/consensus/) on the state of the - network. Substrate makes it possible to supply custom consensus engines and also ships with - several consensus mechanisms that have been built on top of - [Web3 Foundation research](https://research.web3.foundation/en/latest/polkadot/NPoS/index.html). -- RPC Server: A remote procedure call (RPC) server is used to interact with Substrate nodes. - -There are several files in the `node` directory - take special note of the following: - -- [`chain_spec.rs`](./node/src/chain_spec.rs): A - [chain specification](https://docs.substrate.io/main-docs/build/chain-spec/) is a - source code file that defines a Substrate chain's initial (genesis) state. Chain specifications - are useful for development and testing, and critical when architecting the launch of a - production chain. Take note of the `development_config` and `testnet_genesis` functions, which - are used to define the genesis state for the local development chain configuration. These - functions identify some - [well-known accounts](https://docs.substrate.io/reference/command-line-tools/subkey/) - and use them to configure the blockchain's initial state. -- [`service.rs`](./node/src/service.rs): This file defines the node implementation. Take note of - the libraries that this file imports and the names of the functions it invokes. In particular, - there are references to consensus-related topics, such as the - [block finalization and forks](https://docs.substrate.io/main-docs/fundamentals/consensus/#finalization-and-forks) - and other [consensus mechanisms](https://docs.substrate.io/main-docs/fundamentals/consensus/#default-consensus-models) - such as Aura for block authoring and GRANDPA for finality. - -After the node has been [built](#build), refer to the embedded documentation to learn more about the -capabilities and configuration parameters that it exposes: - -```shell -./target/release/node-template --help -``` - -### Runtime - -In Substrate, the terms -"runtime" and "state transition function" -are analogous - they refer to the core logic of the blockchain that is responsible for validating -blocks and executing the state changes they define. The Substrate project in this repository uses -[FRAME](https://docs.substrate.io/main-docs/fundamentals/runtime-intro/#frame) to construct a -blockchain runtime. FRAME allows runtime developers to declare domain-specific logic in modules -called "pallets". At the heart of FRAME is a helpful -[macro language](https://docs.substrate.io/reference/frame-macros/) that makes it easy to -create pallets and flexibly compose them to create blockchains that can address -[a variety of needs](https://substrate.io/ecosystem/projects/). - -Review the [FRAME runtime implementation](./runtime/src/lib.rs) included in this template and note -the following: - -- This file configures several pallets to include in the runtime. Each pallet configuration is - defined by a code block that begins with `impl $PALLET_NAME::Config for Runtime`. -- The pallets are composed into a single runtime by way of the - [`construct_runtime!`](https://crates.parity.io/frame_support/macro.construct_runtime.html) - macro, which is part of the core - FRAME Support [system](https://docs.substrate.io/reference/frame-pallets/#system-pallets) library. - -### Pallets - -The runtime in this project is constructed using many FRAME pallets that ship with the -[core Substrate repository](https://github.com/paritytech/substrate/tree/master/frame) and a -template pallet that is [defined in the `pallets`](./pallets/template/src/lib.rs) directory. - -A FRAME pallet is compromised of a number of blockchain primitives: - -- Storage: FRAME defines a rich set of powerful - [storage abstractions](https://docs.substrate.io/main-docs/build/runtime-storage/) that makes - it easy to use Substrate's efficient key-value database to manage the evolving state of a - blockchain. -- Dispatchables: FRAME pallets define special types of functions that can be invoked (dispatched) - from outside of the runtime in order to update its state. -- Events: Substrate uses [events and errors](https://docs.substrate.io/main-docs/build/events-errors/) - to notify users of important changes in the runtime. -- Errors: When a dispatchable fails, it returns an error. -- Config: The `Config` configuration interface is used to define the types and parameters upon - which a FRAME pallet depends. - -### Run in Docker - -First, install [Docker](https://docs.docker.com/get-docker/) and -[Docker Compose](https://docs.docker.com/compose/install/). - -Then run the following command to start a single node development chain. - +To run specific tests: ```bash -./scripts/docker_run.sh +cargo test -p pallet-subspace --test test_voting ``` -This command will firstly compile your code, and then start a local development network. You can -also replace the default command -(`cargo build --release && ./target/release/node-template --dev --ws-external`) -by appending your own. A few useful ones are as follow. - +To run tests with detailed logs: ```bash -# Run Substrate node without re-compiling -./scripts/docker_run.sh ./target/release/node-template --dev --ws-external - -# Purge the local dev chain -./scripts/docker_run.sh ./target/release/node-template purge-chain --dev - -# Check whether the code is compilable -./scripts/docker_run.sh cargo check +SKIP_WASM_BUILD=1 RUST_LOG=runtime=debug cargo test -- --nocapture ``` +## Architecture +Subspace leverages the modular and extensible architecture of Substrate. It uses FRAME pallets to encapsulate domain-specific logic such as consensus, storage, and p2p networking. -## 6. License -IDGAF Copyright © 2023 Yomama - -Lower Bound is MIT Liscence -Upper Bound is Infinite -Fuck shit up, dont blame me if things go south, use code as is, peace. - - +Notable components: +- `/node`: Implementation of the Subspace node including networking, consensus, and RPC +- `/runtime`: The core blockchain logic responsible for validating and executing state transitions +- `/pallets`: Custom FRAME pallets with Commune-specific logic +## Contributing +We welcome contributions to Subspace! Feel free to submit issues, fork the repository and send pull requests. -## 7. Acknowledgments -**parralax** +Please make sure your code follows the house coding style and passes all tests before submitting. See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines. +Join our [Discord community](https://discord.gg/commune) to discuss the project, ask questions and meet other contributors. -TEST FNS +## License +Subspace is licensed under the [MIT License](LICENSE). -cargo test -p pallet-subspace --test test_voting \ No newline at end of file +## Acknowledgments +Special thanks to the teams at [Parity Technologies](https://www.parity.io/) and [Web3 Foundation](https://web3.foundation/) for their work on Substrate and FRAME. \ No newline at end of file diff --git a/pallets/subspace/tests/delegate_staking.rs b/pallets/subspace/tests/delegate_staking.rs index 7cebdbac9..2fbb2b4ec 100644 --- a/pallets/subspace/tests/delegate_staking.rs +++ b/pallets/subspace/tests/delegate_staking.rs @@ -8,30 +8,6 @@ use substrate_fixed::types::I64F64; // /*********************************************************** // staking::add_stake() tests // ************************************************************/ -// #[test] -// fn test_stake_overflow() { -// new_test_ext().execute_with(|| { - -// let token_amount : u64 = 1_000_000_000; -// let balance : u64 = 10 * token_amount; -// let netuid : u16 = 0; - -// for i in [0,1].iter() { -// let delta : u64 = 1 * token_amount; -// let stake : u64 = balance + delta*(*i); -// let key : U256 = U256::from(*i); -// add_balance(key, balance); -// let result =register_module(netuid, key, stake); -// println!("RESULT: {:?}", result); - -// println!("STAKE {}", SubspaceModule::get_stake(netuid, &key)); -// assert_eq!(SubspaceModule::get_stake(netuid, &key), balance); -// assert_eq!(SubspaceModule::get_balance(&key), 0); -// } - -// }); -// } - #[test] fn test_ownership_ratio() { new_test_ext().execute_with(|| { diff --git a/pallets/subspace/tests/mock.rs b/pallets/subspace/tests/mock.rs index 8360495c4..422fec9d2 100644 --- a/pallets/subspace/tests/mock.rs +++ b/pallets/subspace/tests/mock.rs @@ -12,6 +12,7 @@ use sp_runtime::{ }; type Block = frame_system::mocking::MockBlock; +const TOKEN_DECIMALS: u32 = 9; // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( @@ -285,3 +286,7 @@ pub fn add_stake_and_balance(netuid: u16, key: U256, amount: u64) { assert_ok!(result); } + +pub fn to_nano(x: u64) -> u64 { + x * 10u64.pow(TOKEN_DECIMALS) +} diff --git a/pallets/subspace/tests/staking.rs b/pallets/subspace/tests/staking.rs index c0ef27b31..d9683e85f 100644 --- a/pallets/subspace/tests/staking.rs +++ b/pallets/subspace/tests/staking.rs @@ -4,41 +4,15 @@ use frame_support::assert_ok; use mock::*; use sp_core::U256; use substrate_fixed::types::I64F64; - // /*********************************************************** // staking::add_stake() tests // ************************************************************/ -// #[test] -// fn test_stake_overflow() { -// new_test_ext().execute_with(|| { - -// let token_amount : u64 = 1_000_000_000; -// let balance : u64 = 10 * token_amount; -// let netuid : u16 = 0; - -// for i in [0,1].iter() { -// let delta : u64 = 1 * token_amount; -// let stake : u64 = balance + delta*(*i); -// let key : U256 = U256::from(*i); -// add_balance(key, balance); -// let result =register_module(netuid, key, stake); -// println!("RESULT: {:?}", result); - -// println!("STAKE {}", SubspaceModule::get_stake(netuid, &key)); -// assert_eq!(SubspaceModule::get_stake(netuid, &key), balance); -// assert_eq!(SubspaceModule::get_balance(&key), 0); -// } - -// }); -// } - #[test] fn test_stake() { new_test_ext().execute_with(|| { let max_uids: u16 = 10; - let token_amount: u64 = 1_000_000_000; let netuids: [u16; 4] = core::array::from_fn(|i| i as u16); - let amount_staked_vector: Vec = netuids.iter().map(|_| 10 * token_amount).collect(); + let amount_staked_vector: Vec = netuids.iter().map(|_| to_nano(10)).collect(); let mut total_stake: u64 = 0; let mut subnet_stake: u64 = 0; @@ -225,9 +199,8 @@ fn test_transfer_stake() { fn test_delegate_stake() { new_test_ext().execute_with(|| { let max_uids: u16 = 10; - let token_amount: u64 = 1_000_000_000; let netuids: Vec = [0, 1, 2, 3].to_vec(); - let amount_staked_vector: Vec = netuids.iter().map(|_i| 10 * token_amount).collect(); + let amount_staked_vector: Vec = netuids.iter().map(|_i| to_nano(10)).collect(); let mut total_stake: u64 = 0; let mut subnet_stake: u64 = 0; diff --git a/pallets/subspace/tests/step.rs b/pallets/subspace/tests/step.rs index a1231af14..309ecfb37 100644 --- a/pallets/subspace/tests/step.rs +++ b/pallets/subspace/tests/step.rs @@ -934,10 +934,9 @@ fn test_dynamic_burn() { // - adjustment alpha = 0 // - min_burn = 2 $COMAI // - max_burn = 250 $COMAI - let token_amount = 100_000_000; let mut params = SubspaceModule::global_params(); - params.min_burn = 2 * token_amount; - params.max_burn = 250 * token_amount; + params.min_burn = to_nano(2); + params.max_burn = to_nano(250); params.adjustment_alpha = 0; params.target_registrations_interval = 200; params.target_registrations_per_interval = 100; @@ -981,7 +980,7 @@ fn test_dynamic_burn() { // burn is now at 11 instead of 2 assert!( - SubspaceModule::get_burn() == 11 * token_amount, + SubspaceModule::get_burn() == to_nano(11), "current burn {:?}", SubspaceModule::get_burn() ); @@ -995,7 +994,7 @@ fn test_dynamic_burn() { // make sure the burn correctly decreased base on demand assert!( - SubspaceModule::get_burn() == 825000000, + SubspaceModule::get_burn() == 8250000000, "current burn: {:?}", SubspaceModule::get_burn() ); diff --git a/pallets/subspace/tests/weights.rs b/pallets/subspace/tests/weights.rs index 07ab6cf8f..92caa9902 100644 --- a/pallets/subspace/tests/weights.rs +++ b/pallets/subspace/tests/weights.rs @@ -1,7 +1,7 @@ mod mock; -use frame_support::assert_ok; +use frame_support::{assert_err, assert_ok}; -use pallet_subspace::Error; +use pallet_subspace::{Error, GlobalParams}; use sp_core::U256; use sp_runtime::DispatchError; @@ -270,7 +270,6 @@ fn test_check_len_uids_within_allowed_within_network_pool() { }); } -/// Check _falsey_ path #[test] fn test_check_len_uids_within_allowed_not_within_network_pool() { new_test_ext().execute_with(|| { @@ -299,3 +298,101 @@ fn test_check_len_uids_within_allowed_not_within_network_pool() { ); }); } + +#[test] +fn test_min_weight_stake() { + new_test_ext().execute_with(|| { + let mut global_params: GlobalParams = SubspaceModule::global_params(); + global_params.min_weight_stake = to_nano(20); + SubspaceModule::set_global_params(global_params); + + let netuid: u16 = 0; + let module_count: u16 = 16; + let voter_idx: u16 = 0; + + // registers the modules + for i in 0..module_count { + assert_ok!(register_module(netuid, U256::from(i), to_nano(10))); + } + + let uids: Vec = (0..module_count).filter(|&uid| uid != voter_idx).collect(); + let weights = vec![1; uids.len()]; + + assert_err!( + SubspaceModule::set_weights( + get_origin(U256::from(voter_idx)), + netuid, + uids.clone(), + weights.clone(), + ), + Error::::NotEnoughtStakePerWeight + ); + + increase_stake(netuid, U256::from(voter_idx), to_nano(400)); + + assert_ok!(SubspaceModule::set_weights( + get_origin(U256::from(voter_idx)), + netuid, + uids, + weights, + )); + }); +} + +#[test] +fn test_weight_age() { + new_test_ext().execute_with(|| { + const NETUID: u16 = 0; + const MODULE_COUNT: u16 = 16; + const TEMPO: u64 = 100; + const VOTER_IDX: u16 = 0; + + let mut subnet_params = SubspaceModule::subnet_params(NETUID); + subnet_params.tempo = TEMPO as u16; + subnet_params.max_weight_age = TEMPO; + SubspaceModule::set_subnet_params(NETUID, subnet_params); + + (0..MODULE_COUNT).for_each(|i| { + assert_ok!(register_module(NETUID, U256::from(i), to_nano(10))); + }); + + let uids: Vec = (0..MODULE_COUNT).filter(|&uid| uid != VOTER_IDX).collect(); + let weights = vec![1; uids.len()]; + + assert_ok!(SubspaceModule::set_weights( + get_origin(U256::from(VOTER_IDX)), + NETUID, + uids.clone(), + weights, + )); + + let stakes_before: Vec = uids + .iter() + .map(|uid| SubspaceModule::get_total_stake_to(NETUID, &U256::from(*uid))) + .collect(); + + step_block((TEMPO as u16) * 10); + + let stakes_after: Vec = uids + .iter() + .map(|uid| SubspaceModule::get_total_stake_to(NETUID, &U256::from(*uid))) + .collect(); + + assert!( + stakes_before.iter().sum::() < stakes_after.iter().sum::(), + "Total stake should increase after weight aging" + ); + + step_block((TEMPO as u16) * 10); + + let stakes_after_v2: Vec = uids + .iter() + .map(|uid: &u16| SubspaceModule::get_total_stake_to(NETUID, &U256::from(*uid))) + .collect(); + + assert_eq!( + stakes_after, stakes_after_v2, + "Stake values should remain the same after maximum weight age" + ); + }); +} \ No newline at end of file From 756208dd484cc26cd5b98c50ff603e956518bcc7 Mon Sep 17 00:00:00 2001 From: YourUsername Date: Thu, 14 Mar 2024 13:58:33 +0000 Subject: [PATCH 2/3] added weight age test --- pallets/subspace/tests/weights.rs | 80 ++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/pallets/subspace/tests/weights.rs b/pallets/subspace/tests/weights.rs index 92caa9902..e6e12f4e7 100644 --- a/pallets/subspace/tests/weights.rs +++ b/pallets/subspace/tests/weights.rs @@ -316,7 +316,7 @@ fn test_min_weight_stake() { } let uids: Vec = (0..module_count).filter(|&uid| uid != voter_idx).collect(); - let weights = vec![1; uids.len()]; + let weights = vec![1; uids.len()]; assert_err!( SubspaceModule::set_weights( @@ -345,54 +345,78 @@ fn test_weight_age() { const NETUID: u16 = 0; const MODULE_COUNT: u16 = 16; const TEMPO: u64 = 100; - const VOTER_IDX: u16 = 0; - - let mut subnet_params = SubspaceModule::subnet_params(NETUID); - subnet_params.tempo = TEMPO as u16; - subnet_params.max_weight_age = TEMPO; - SubspaceModule::set_subnet_params(NETUID, subnet_params); + const PASSIVE_VOTER: u16 = 0; + const ACTIVE_VOTER: u16 = 1; + // Register modules (0..MODULE_COUNT).for_each(|i| { assert_ok!(register_module(NETUID, U256::from(i), to_nano(10))); }); - let uids: Vec = (0..MODULE_COUNT).filter(|&uid| uid != VOTER_IDX).collect(); + let uids: Vec = (0..MODULE_COUNT) + .filter(|&uid| uid != PASSIVE_VOTER && uid != ACTIVE_VOTER) + .collect(); let weights = vec![1; uids.len()]; + // Set subnet parameters + let mut subnet_params = SubspaceModule::subnet_params(NETUID); + subnet_params.tempo = TEMPO as u16; + subnet_params.max_weight_age = TEMPO; + SubspaceModule::set_subnet_params(NETUID, subnet_params); + + // Set weights for passive and active voters assert_ok!(SubspaceModule::set_weights( - get_origin(U256::from(VOTER_IDX)), + get_origin(U256::from(PASSIVE_VOTER)), NETUID, uids.clone(), - weights, + weights.clone(), + )); + assert_ok!(SubspaceModule::set_weights( + get_origin(U256::from(ACTIVE_VOTER)), + NETUID, + uids.clone(), + weights.clone(), )); - let stakes_before: Vec = uids - .iter() - .map(|uid| SubspaceModule::get_total_stake_to(NETUID, &U256::from(*uid))) - .collect(); + let passive_stake_before = + SubspaceModule::get_total_stake_to(NETUID, &U256::from(PASSIVE_VOTER)); + let active_stake_before = + SubspaceModule::get_total_stake_to(NETUID, &U256::from(ACTIVE_VOTER)); - step_block((TEMPO as u16) * 10); + step_block(TEMPO as u16); - let stakes_after: Vec = uids - .iter() - .map(|uid| SubspaceModule::get_total_stake_to(NETUID, &U256::from(*uid))) - .collect(); + let passive_stake_after = + SubspaceModule::get_total_stake_to(NETUID, &U256::from(PASSIVE_VOTER)); + let active_stake_after = + SubspaceModule::get_total_stake_to(NETUID, &U256::from(ACTIVE_VOTER)); assert!( - stakes_before.iter().sum::() < stakes_after.iter().sum::(), - "Total stake should increase after weight aging" + passive_stake_before < passive_stake_after || active_stake_before < active_stake_after, + "Stake should be increasing" ); - step_block((TEMPO as u16) * 10); + // Set weights again for active voter + assert_ok!(SubspaceModule::set_weights( + get_origin(U256::from(ACTIVE_VOTER)), + NETUID, + uids, + weights, + )); + + step_block(TEMPO as u16); - let stakes_after_v2: Vec = uids - .iter() - .map(|uid: &u16| SubspaceModule::get_total_stake_to(NETUID, &U256::from(*uid))) - .collect(); + let passive_stake_after_v2 = + SubspaceModule::get_total_stake_to(NETUID, &U256::from(PASSIVE_VOTER)); + let active_stake_after_v2 = + SubspaceModule::get_total_stake_to(NETUID, &U256::from(ACTIVE_VOTER)); assert_eq!( - stakes_after, stakes_after_v2, + passive_stake_after, passive_stake_after_v2, "Stake values should remain the same after maximum weight age" ); + assert!( + active_stake_after < active_stake_after_v2, + "Stake should be increasing" + ); }); -} \ No newline at end of file +} From fe2471a225793c718d587a6b790d48045133d7c3 Mon Sep 17 00:00:00 2001 From: YourUsername Date: Thu, 14 Mar 2024 14:07:13 +0000 Subject: [PATCH 3/3] added better docs --- CONTRIBUTING.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 6 +++--- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..f71940bcc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,53 @@ +# Contributing to CommuneAI + +Thank you for your interest in contributing to CommuneAI! We welcome contributions from the community to help improve and enhance the project. + +## Table of Contents +- [Code of Conduct](#code-of-conduct) +- [Getting Started](#getting-started) +- [How to Contribute](#how-to-contribute) + - [Reporting Bugs](#reporting-bugs) + - [Suggesting Enhancements](#suggesting-enhancements) + - [Pull Requests](#pull-requests) +- [Style Guidelines](#style-guidelines) +- [License](#license) + +## Getting Started +To get started with contributing to CommuneAI, follow these steps: +1. Fork the repository on GitHub. +2. Clone your forked repository to your local machine. +3. Create a new branch for your contribution. +4. Make your desired changes and additions. +5. Test your changes to ensure they work as intended. +6. Commit your changes with a descriptive commit message. +7. Push your changes to your forked repository. +8. Open a pull request on the original repository, describing your changes in detail. + +## How to Contribute + +### Reporting Bugs +If you encounter a bug while using [Project Name], please create a new issue on the GitHub repository. When reporting a bug, please provide the following information: +- A clear and descriptive title for the issue. +- Steps to reproduce the bug. +- Expected behavior and actual behavior. +- Any relevant error messages or screenshots. + +### Suggesting Enhancements +If you have an idea for an enhancement or new feature for [Project Name], please create a new issue on the GitHub repository. When suggesting an enhancement, please provide the following information: +- A clear and descriptive title for the issue. +- A detailed description of the proposed enhancement. +- Any relevant examples or use cases. + +### Pull Requests +We welcome pull requests for bug fixes, enhancements, and new features. When submitting a pull request, please ensure that: +- Your code follows the project's [style guidelines](#style-guidelines). +- Your changes are well-documented and include relevant comments. +- Your pull request includes a clear and descriptive title and description. +- Your pull request is based on the latest version of the main branch. + +## Style Guidelines +Please follow these style guidelines when contributing to CommuneAI: +- Use meaningful variable and function names. +- Follow the existing code style and formatting conventions. +- Write clear and concise comments to explain complex or non-obvious code. +- Include relevant documentation updates when adding new features or making significant changes. diff --git a/README.md b/README.md index c07b50a46..035a33102 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Subspace -[![Discord Chat](https://img.shields.io/discord/308323056592486420.svg)](https://discord.gg/commune) +[![Discord Chat](https://img.shields.io/discord/308323056592486420.svg)](discord.gg/communeai) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://img.shields.io/travis/com/paritytech/substrate/master?label=stable)](https://travis-ci.com/paritytech/substrate) [![Coverage Status](https://img.shields.io/codecov/c/gh/paritytech/substrate?label=coverage)](https://codecov.io/gh/paritytech/substrate) -Subspace is a FRAME-based [Substrate](https://substrate.io/) blockchain node that provides the foundation for [Commune's](https://commune.network/) decentralized cloud platform. It serves as the trusted base layer responsible for consensus, module advertising, and peer discovery. +Subspace is a FRAME-based [Substrate](https://substrate.io/) blockchain node that provides the foundation for [Commune's](https://www.communeai.org/) network. It serves as the trusted base layer responsible for consensus, module advertising, and peer discovery. ## Table of Contents - [Overview](#overview) @@ -105,7 +105,7 @@ We welcome contributions to Subspace! Feel free to submit issues, fork the repos Please make sure your code follows the house coding style and passes all tests before submitting. See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines. -Join our [Discord community](https://discord.gg/commune) to discuss the project, ask questions and meet other contributors. +Join our [Discord community](discord.gg/communeai) to discuss the project, ask questions and meet other contributors. ## License Subspace is licensed under the [MIT License](LICENSE).