From cf756524713d47000efc1a38838a7664497e0fe9 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Wed, 4 Sep 2024 21:01:32 +0400 Subject: [PATCH 1/4] feat: bumps testnet total issuance --- Cargo.toml | 1 + justfile | 4 ++ node/Cargo.toml | 1 + pallets/subtensor/Cargo.toml | 9 ++-- pallets/subtensor/src/lib.rs | 14 +++++- runtime/Cargo.toml | 1 + runtime/src/lib.rs | 2 +- scripts/localnet.sh | 98 +++++++++++++++++++----------------- 8 files changed, 79 insertions(+), 51 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9a7968b90..d390177bea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -176,3 +176,4 @@ runtime-benchmarks = [ "node-subtensor-runtime/runtime-benchmarks", ] metadata-hash = ["node-subtensor-runtime/metadata-hash"] +testnet = [] diff --git a/justfile b/justfile index f99f3913ab..d20ae9afb8 100644 --- a/justfile +++ b/justfile @@ -52,3 +52,7 @@ lint: production: @echo "Running cargo build with metadata-hash generation..." cargo +{{RUSTV}} build --profile production --features="runtime-benchmarks metadata-hash" + +testnet: + @echo "Running cargo build with testnet config..." + cargo +{{RUSTV}} build --profile production --features="runtime-benchmarks metadata-hash testnet" diff --git a/node/Cargo.toml b/node/Cargo.toml index 3c5c91b927..2e85897a42 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -107,3 +107,4 @@ try-runtime = [ ] metadata-hash = ["node-subtensor-runtime/metadata-hash"] +testnet = [] diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 3023d1e0dc..ab50e89f23 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -45,7 +45,9 @@ hex = { workspace = true } pallet-collective = { version = "4.0.0-dev", default-features = false, path = "../collective" } pallet-membership = { workspace = true } hex-literal = { workspace = true } -num-traits = { version = "0.2.19", default-features = false, features = ["libm"] } +num-traits = { version = "0.2.19", default-features = false, features = [ + "libm", +] } [dev-dependencies] pallet-balances = { workspace = true, features = ["std"] } @@ -89,7 +91,7 @@ std = [ "serde_with/std", "substrate-fixed/std", "num-traits/std", - "serde_json/std" + "serde_json/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -113,6 +115,7 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-utility/try-runtime", "sp-runtime/try-runtime", - "pallet-collective/try-runtime" + "pallet-collective/try-runtime", ] pow-faucet = [] +testnet = [] diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 2985736c81..855704c0ec 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -187,10 +187,18 @@ pub mod pallet { /// ============================ #[pallet::type_value] - /// Total Rao in circulation. + /// Total TAO Cap. pub fn TotalSupply() -> u64 { - 21_000_000_000_000_000 + #[cfg(feature = "testnet")] + { + 15_000_000_000_000_000_000 + } + #[cfg(not(feature = "testnet"))] + { + 21_000_000_000_000_000 + } } + #[pallet::type_value] /// Default Delegate Take. pub fn DefaultDelegateTake() -> u16 { @@ -665,6 +673,8 @@ pub mod pallet { /// separate accounting. #[pallet::storage] // --- ITEM ( total_issuance ) pub type TotalIssuance = StorageValue<_, u64, ValueQuery, DefaultTotalIssuance>; + #[pallet::storage] // --- ITEM ( total_supply ) + pub type TotalTaoSupplyCap = StorageValue<_, u64, ValueQuery, TotalSupply>; #[pallet::storage] // --- ITEM ( total_stake ) pub type TotalStake = StorageValue<_, u64, ValueQuery>; #[pallet::storage] // --- ITEM ( default_delegate_take ) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 8a2886eb10..6c5bf28c11 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -207,3 +207,4 @@ try-runtime = [ "pallet-registry/try-runtime", ] metadata-hash = ["substrate-wasm-builder/metadata-hash"] +testnet = [] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index ca8f839114..5ffb0863ac 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -142,7 +142,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: 195, + spec_version: 196, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/scripts/localnet.sh b/scripts/localnet.sh index 850a314d88..e0e366a6ac 100755 --- a/scripts/localnet.sh +++ b/scripts/localnet.sh @@ -15,41 +15,49 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" # The base directory of the subtensor project BASE_DIR="$SCRIPT_DIR/.." -# get parameters -# Get the value of fast_blocks from the first argument +# Get parameters fast_blocks=${1:-"True"} +testnet=${2:-"Fale"} + +# Initialize FEATURES +FEATURES="pow-faucet runtime-benchmarks" # 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"}" +if [ "$fast_blocks" == "True" ]; then + echo "fast_blocks is On" + FEATURES+=" fast-blocks" +else + echo "fast_blocks is Off" +fi + +# Check the value of testnet +if [ "$testnet" == "True" ]; then + echo "testnet is On" + FEATURES+=" testnet" 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"}" + echo "testnet is Off" fi +: "${CHAIN:=local}" +: "${BUILD_BINARY:=1}" + SPEC_PATH="${SCRIPT_DIR}/specs/" FULL_PATH="$SPEC_PATH$CHAIN.json" + # Kill any existing nodes which may have not exited correctly after a previous # run. pkill -9 'node-subtensor' if [ ! -d "$SPEC_PATH" ]; then - echo "*** Creating directory ${SPEC_PATH}..." - mkdir $SPEC_PATH + echo "*** Creating directory ${SPEC_PATH}..." + mkdir $SPEC_PATH fi if [[ $BUILD_BINARY == "1" ]]; then - echo "*** Building substrate binary..." - cargo build --workspace --profile=release --features "$FEATURES" --manifest-path "$BASE_DIR/Cargo.toml" - echo "*** Binary compiled" + echo "*** Building substrate binary..." + cargo build --workspace --profile=release --features "$FEATURES" --manifest-path "$BASE_DIR/Cargo.toml" + echo "*** Binary compiled" fi echo "*** Building chainspec..." @@ -57,44 +65,44 @@ echo "*** Building chainspec..." echo "*** Chainspec built and output to file" if [ $NO_PURGE -eq 1 ]; then - echo "*** Purging previous state skipped..." + echo "*** Purging previous state skipped..." else - echo "*** Purging previous state..." - "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/bob --chain="$FULL_PATH" >/dev/null 2>&1 - "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/alice --chain="$FULL_PATH" >/dev/null 2>&1 - echo "*** Previous chainstate purged" + echo "*** Purging previous state..." + "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/bob --chain="$FULL_PATH" >/dev/null 2>&1 + "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/alice --chain="$FULL_PATH" >/dev/null 2>&1 + echo "*** Previous chainstate purged" fi echo "*** Starting localnet nodes..." alice_start=( - "$BASE_DIR/target/release/node-subtensor" - --base-path /tmp/alice - --chain="$FULL_PATH" - --alice - --port 30334 - --rpc-port 9946 - --validator - --rpc-cors=all - --allow-private-ipv4 - --discover-local + "$BASE_DIR/target/release/node-subtensor" + --base-path /tmp/alice + --chain="$FULL_PATH" + --alice + --port 30334 + --rpc-port 9946 + --validator + --rpc-cors=all + --allow-private-ipv4 + --discover-local ) bob_start=( - "$BASE_DIR"/target/release/node-subtensor - --base-path /tmp/bob - --chain="$FULL_PATH" - --bob - --port 30335 - --rpc-port 9945 - --validator - --allow-private-ipv4 - --discover-local + "$BASE_DIR"/target/release/node-subtensor + --base-path /tmp/bob + --chain="$FULL_PATH" + --bob + --port 30335 + --rpc-port 9945 + --validator + --allow-private-ipv4 + --discover-local ) trap 'pkill -P $$' EXIT SIGINT SIGTERM ( - ("${alice_start[@]}" 2>&1) & - ("${bob_start[@]}" 2>&1) - wait + ("${alice_start[@]}" 2>&1) & + ("${bob_start[@]}" 2>&1) + wait ) From ffd8ed3ca19ce93b8837ad06a2eb3005797ba6c7 Mon Sep 17 00:00:00 2001 From: distributedstatemachine <112424909+distributedstatemachine@users.noreply.github.com> Date: Thu, 5 Sep 2024 17:06:30 +0400 Subject: [PATCH 2/4] Revert "hotfix: bumps testnet total issuance" --- Cargo.toml | 1 - justfile | 4 -- node/Cargo.toml | 1 - pallets/subtensor/Cargo.toml | 9 ++-- pallets/subtensor/src/lib.rs | 14 +----- runtime/Cargo.toml | 1 - runtime/src/lib.rs | 2 +- scripts/localnet.sh | 98 +++++++++++++++++------------------- 8 files changed, 51 insertions(+), 79 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d390177bea..f9a7968b90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -176,4 +176,3 @@ runtime-benchmarks = [ "node-subtensor-runtime/runtime-benchmarks", ] metadata-hash = ["node-subtensor-runtime/metadata-hash"] -testnet = [] diff --git a/justfile b/justfile index d20ae9afb8..f99f3913ab 100644 --- a/justfile +++ b/justfile @@ -52,7 +52,3 @@ lint: production: @echo "Running cargo build with metadata-hash generation..." cargo +{{RUSTV}} build --profile production --features="runtime-benchmarks metadata-hash" - -testnet: - @echo "Running cargo build with testnet config..." - cargo +{{RUSTV}} build --profile production --features="runtime-benchmarks metadata-hash testnet" diff --git a/node/Cargo.toml b/node/Cargo.toml index 2e85897a42..3c5c91b927 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -107,4 +107,3 @@ try-runtime = [ ] metadata-hash = ["node-subtensor-runtime/metadata-hash"] -testnet = [] diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index ab50e89f23..3023d1e0dc 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -45,9 +45,7 @@ hex = { workspace = true } pallet-collective = { version = "4.0.0-dev", default-features = false, path = "../collective" } pallet-membership = { workspace = true } hex-literal = { workspace = true } -num-traits = { version = "0.2.19", default-features = false, features = [ - "libm", -] } +num-traits = { version = "0.2.19", default-features = false, features = ["libm"] } [dev-dependencies] pallet-balances = { workspace = true, features = ["std"] } @@ -91,7 +89,7 @@ std = [ "serde_with/std", "substrate-fixed/std", "num-traits/std", - "serde_json/std", + "serde_json/std" ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -115,7 +113,6 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-utility/try-runtime", "sp-runtime/try-runtime", - "pallet-collective/try-runtime", + "pallet-collective/try-runtime" ] pow-faucet = [] -testnet = [] diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 855704c0ec..2985736c81 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -187,18 +187,10 @@ pub mod pallet { /// ============================ #[pallet::type_value] - /// Total TAO Cap. + /// Total Rao in circulation. pub fn TotalSupply() -> u64 { - #[cfg(feature = "testnet")] - { - 15_000_000_000_000_000_000 - } - #[cfg(not(feature = "testnet"))] - { - 21_000_000_000_000_000 - } + 21_000_000_000_000_000 } - #[pallet::type_value] /// Default Delegate Take. pub fn DefaultDelegateTake() -> u16 { @@ -673,8 +665,6 @@ pub mod pallet { /// separate accounting. #[pallet::storage] // --- ITEM ( total_issuance ) pub type TotalIssuance = StorageValue<_, u64, ValueQuery, DefaultTotalIssuance>; - #[pallet::storage] // --- ITEM ( total_supply ) - pub type TotalTaoSupplyCap = StorageValue<_, u64, ValueQuery, TotalSupply>; #[pallet::storage] // --- ITEM ( total_stake ) pub type TotalStake = StorageValue<_, u64, ValueQuery>; #[pallet::storage] // --- ITEM ( default_delegate_take ) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 6c5bf28c11..8a2886eb10 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -207,4 +207,3 @@ try-runtime = [ "pallet-registry/try-runtime", ] metadata-hash = ["substrate-wasm-builder/metadata-hash"] -testnet = [] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5ffb0863ac..ca8f839114 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -142,7 +142,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: 196, + spec_version: 195, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/scripts/localnet.sh b/scripts/localnet.sh index e0e366a6ac..850a314d88 100755 --- a/scripts/localnet.sh +++ b/scripts/localnet.sh @@ -15,49 +15,41 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" # The base directory of the subtensor project BASE_DIR="$SCRIPT_DIR/.." -# Get parameters +# get parameters +# Get the value of fast_blocks from the first argument fast_blocks=${1:-"True"} -testnet=${2:-"Fale"} - -# Initialize FEATURES -FEATURES="pow-faucet runtime-benchmarks" # Check the value of fast_blocks -if [ "$fast_blocks" == "True" ]; then - echo "fast_blocks is On" - FEATURES+=" fast-blocks" -else - echo "fast_blocks is Off" -fi - -# Check the value of testnet -if [ "$testnet" == "True" ]; then - echo "testnet is On" - FEATURES+=" testnet" +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 - echo "testnet is Off" + # 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 -: "${CHAIN:=local}" -: "${BUILD_BINARY:=1}" - SPEC_PATH="${SCRIPT_DIR}/specs/" FULL_PATH="$SPEC_PATH$CHAIN.json" - # Kill any existing nodes which may have not exited correctly after a previous # run. pkill -9 'node-subtensor' if [ ! -d "$SPEC_PATH" ]; then - echo "*** Creating directory ${SPEC_PATH}..." - mkdir $SPEC_PATH + echo "*** Creating directory ${SPEC_PATH}..." + mkdir $SPEC_PATH fi if [[ $BUILD_BINARY == "1" ]]; then - echo "*** Building substrate binary..." - cargo build --workspace --profile=release --features "$FEATURES" --manifest-path "$BASE_DIR/Cargo.toml" - echo "*** Binary compiled" + echo "*** Building substrate binary..." + cargo build --workspace --profile=release --features "$FEATURES" --manifest-path "$BASE_DIR/Cargo.toml" + echo "*** Binary compiled" fi echo "*** Building chainspec..." @@ -65,44 +57,44 @@ echo "*** Building chainspec..." echo "*** Chainspec built and output to file" if [ $NO_PURGE -eq 1 ]; then - echo "*** Purging previous state skipped..." + echo "*** Purging previous state skipped..." else - echo "*** Purging previous state..." - "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/bob --chain="$FULL_PATH" >/dev/null 2>&1 - "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/alice --chain="$FULL_PATH" >/dev/null 2>&1 - echo "*** Previous chainstate purged" + echo "*** Purging previous state..." + "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/bob --chain="$FULL_PATH" >/dev/null 2>&1 + "$BASE_DIR/target/release/node-subtensor" purge-chain -y --base-path /tmp/alice --chain="$FULL_PATH" >/dev/null 2>&1 + echo "*** Previous chainstate purged" fi echo "*** Starting localnet nodes..." alice_start=( - "$BASE_DIR/target/release/node-subtensor" - --base-path /tmp/alice - --chain="$FULL_PATH" - --alice - --port 30334 - --rpc-port 9946 - --validator - --rpc-cors=all - --allow-private-ipv4 - --discover-local + "$BASE_DIR/target/release/node-subtensor" + --base-path /tmp/alice + --chain="$FULL_PATH" + --alice + --port 30334 + --rpc-port 9946 + --validator + --rpc-cors=all + --allow-private-ipv4 + --discover-local ) bob_start=( - "$BASE_DIR"/target/release/node-subtensor - --base-path /tmp/bob - --chain="$FULL_PATH" - --bob - --port 30335 - --rpc-port 9945 - --validator - --allow-private-ipv4 - --discover-local + "$BASE_DIR"/target/release/node-subtensor + --base-path /tmp/bob + --chain="$FULL_PATH" + --bob + --port 30335 + --rpc-port 9945 + --validator + --allow-private-ipv4 + --discover-local ) trap 'pkill -P $$' EXIT SIGINT SIGTERM ( - ("${alice_start[@]}" 2>&1) & - ("${bob_start[@]}" 2>&1) - wait + ("${alice_start[@]}" 2>&1) & + ("${bob_start[@]}" 2>&1) + wait ) From ca42a0f875ea14ba22df9d49504a21d0172a8947 Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Thu, 5 Sep 2024 17:27:51 +0400 Subject: [PATCH 3/4] fix: metagraph stake info --- pallets/subtensor/src/rpc_info/neuron_info.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pallets/subtensor/src/rpc_info/neuron_info.rs b/pallets/subtensor/src/rpc_info/neuron_info.rs index cadd4b6e35..be367a5669 100644 --- a/pallets/subtensor/src/rpc_info/neuron_info.rs +++ b/pallets/subtensor/src/rpc_info/neuron_info.rs @@ -1,6 +1,5 @@ use super::*; use frame_support::pallet_prelude::{Decode, Encode}; -use frame_support::storage::IterableStorageDoubleMap; extern crate alloc; use codec::Compact; @@ -179,12 +178,10 @@ impl Pallet { let last_update = Self::get_last_update_for_uid(netuid, uid); let validator_permit = Self::get_validator_permit_for_uid(netuid, uid); - let stake: Vec<(T::AccountId, Compact)> = - as IterableStorageDoubleMap>::iter_prefix( - hotkey.clone(), - ) - .map(|(coldkey, stake)| (coldkey, stake.into())) - .collect(); + let stake: Vec<(T::AccountId, Compact)> = vec![( + coldkey.clone(), + Self::get_stake_for_hotkey_on_subnet(&hotkey, netuid).into(), + )]; let neuron = NeuronInfoLite { hotkey: hotkey.clone(), From 8dd149cabd66e3903b3df3dd673d847a253a651c Mon Sep 17 00:00:00 2001 From: Samuel Dare Date: Thu, 5 Sep 2024 18:25:51 +0400 Subject: [PATCH 4/4] chore: bump spec version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index ca8f839114..5ffb0863ac 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -142,7 +142,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: 195, + spec_version: 196, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,