Skip to content

Commit

Permalink
Merge pull request #552 from opentensor/feat/liquid_alpha_2
Browse files Browse the repository at this point in the history
feat: liquid alpha
  • Loading branch information
distributedstatemachine authored Jul 2, 2024
2 parents ce6793d + 87c8d5f commit 8cb6cb1
Show file tree
Hide file tree
Showing 25 changed files with 4,158 additions and 2,320 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/check-devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,18 @@ jobs:
echo "network spec_version: $spec_version"
if (( $(echo "$local_spec_version <= $spec_version" | bc -l) )); then echo "$local_spec_version ≯ $spec_version ❌"; exit 1; fi
echo "$local_spec_version > $spec_version ✅"
check-devnet-migrations:
name: check devnet migrations
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://dev.chain.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
16 changes: 15 additions & 1 deletion .github/workflows/check-finney.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Finney Deploy Check

on:
pull_request:
branches: [finney]
branches: [finney, main]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -37,3 +37,17 @@ jobs:
echo "network spec_version: $spec_version"
if (( $(echo "$local_spec_version <= $spec_version" | bc -l) )); then echo "$local_spec_version ≯ $spec_version ❌"; exit 1; fi
echo "$local_spec_version > $spec_version ✅"
check-finney-migrations:
name: check finney migrations
runs-on: SubtensorCI
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://entrypoint-finney.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
41 changes: 0 additions & 41 deletions .github/workflows/check-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,47 +339,6 @@ jobs:
- name: Check features
run: zepter run check

check-finney-migrations:
name: check finney migrations
runs-on: SubtensorCI
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://entrypoint-finney.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"

check-devnet-migrations:
name: check devnet migrations
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://dev.chain.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"

check-testnet-migrations:
name: check testnet migrations
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://test.chain.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
15 changes: 15 additions & 0 deletions .github/workflows/check-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,18 @@ jobs:
echo "network spec_version: $spec_version"
if (( $(echo "$local_spec_version <= $spec_version" | bc -l) )); then echo "$local_spec_version ≯ $spec_version ❌"; exit 1; fi
echo "$local_spec_version > $spec_version ✅"
check-testnet-migrations:
name: check testnet migrations
runs-on: ubuntu-22.04
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Run Try Runtime Checks
uses: "paritytech/[email protected]"
with:
runtime-package: "node-subtensor-runtime"
node-uri: "wss://test.chain.opentensor.ai:443"
checks: "pre-and-post"
extra-args: "--disable-spec-version-check --no-weight-warnings"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ specs/*.json
.idea

# Runtime upgrade snapshot
bt.snap
bt.snap

# localnet spec
scripts/specs/local.json
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ benchmarks:

clippy:
@echo "Running cargo clippy..."
cargo +{{RUSTV}} clippy --workspace --all-targets -- -D \
cargo +{{RUSTV}} clippy --workspace --all-targets -- \
-D clippy::todo \
-D clippy::unimplemented

clippy-fix:
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- -A \
-A clippy::todo \
-A clippy::unimplemented
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
cargo +{{RUSTV}} clippy --fix --allow-dirty --workspace --all-targets -- \
-A clippy::todo \
-A clippy::unimplemented \
-A clippy::indexing_slicing
fix:
@echo "Running cargo fix..."
cargo +{{RUSTV}} fix --workspace
git diff --exit-code || (echo "There are local changes after running 'cargo fix --workspace' ❌" && exit 1)
git diff --exit-code || (echo "There are local changes after running 'cargo fix --workspace' ❌" && exit 1)

lint:
@echo "Running cargo fmt..."
just fmt
@echo "Running cargo clippy with automatic fixes on potentially dirty code..."
just clippy-fix
@echo "Running cargo clippy..."
just clippy

4 changes: 3 additions & 1 deletion pallets/admin-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sp-runtime = { workspace = true }
log = { workspace = true }
pallet-subtensor = { version = "4.0.0-dev", default-features = false, path = "../subtensor" }
sp-weights = { workspace = true }
substrate-fixed = { workspace = true }


[dev-dependencies]
Expand All @@ -53,7 +54,8 @@ std = [
"sp-weights/std",
"log/std",
"sp-core/std",
"sp-io/std"
"sp-io/std",
"substrate-fixed/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
46 changes: 46 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,45 @@ pub mod pallet {
log::info!("ToggleSetWeightsCommitReveal( netuid: {:?} ) ", netuid);
Ok(())
}

/// Enables or disables Liquid Alpha for a given subnet.
///
/// # Parameters
/// - `origin`: The origin of the call, which must be the root account or subnet owner.
/// - `netuid`: The unique identifier for the subnet.
/// - `enabled`: A boolean flag to enable or disable Liquid Alpha.
///
/// # Weight
/// This function has a fixed weight of 0 and is classified as an operational transaction that does not incur any fees.
#[pallet::call_index(50)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_liquid_alpha_enabled(
origin: OriginFor<T>,
netuid: u16,
enabled: bool,
) -> DispatchResult {
T::Subtensor::ensure_subnet_owner_or_root(origin, netuid)?;
T::Subtensor::set_liquid_alpha_enabled(netuid, enabled);
log::info!(
"LiquidAlphaEnableToggled( netuid: {:?}, Enabled: {:?} ) ",
netuid,
enabled
);
Ok(())
}

/// Sets values for liquid alpha
#[pallet::call_index(51)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_alpha_values(
origin: OriginFor<T>,
netuid: u16,
alpha_low: u16,
alpha_high: u16,
) -> DispatchResult {
T::Subtensor::ensure_subnet_owner_or_root(origin.clone(), netuid)?;
T::Subtensor::do_set_alpha_values(origin, netuid, alpha_low, alpha_high)
}
}
}

Expand Down Expand Up @@ -1091,4 +1130,11 @@ pub trait SubtensorInterface<AccountId, Balance, RuntimeOrigin> {
fn set_target_stakes_per_interval(target_stakes_per_interval: u64);
fn set_commit_reveal_weights_interval(netuid: u16, interval: u64);
fn set_commit_reveal_weights_enabled(netuid: u16, enabled: bool);
fn set_liquid_alpha_enabled(netuid: u16, enabled: bool);
fn do_set_alpha_values(
origin: RuntimeOrigin,
netuid: u16,
alpha_low: u16,
alpha_high: u16,
) -> Result<(), DispatchError>;
}
21 changes: 19 additions & 2 deletions pallets/admin-utils/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ frame_support::construct_runtime!(
System: frame_system,
Balances: pallet_balances,
AdminUtils: pallet_admin_utils,
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>},
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>},
}
);

Expand Down Expand Up @@ -110,7 +110,9 @@ parameter_types! {
pub const InitialSubnetLimit: u16 = 10; // Max 10 subnets.
pub const InitialNetworkRateLimit: u64 = 0;
pub const InitialTargetStakesPerInterval: u16 = 1;

pub const InitialAlphaHigh: u16 = 58982; // Represents 0.9 as per the production default
pub const InitialAlphaLow: u16 = 45875; // Represents 0.7 as per the production default
pub const InitialLiquidAlphaOn: bool = false; // Default value for LiquidAlphaOn
}

impl pallet_subtensor::Config for Test {
Expand Down Expand Up @@ -162,6 +164,9 @@ impl pallet_subtensor::Config for Test {
type InitialSubnetLimit = InitialSubnetLimit;
type InitialNetworkRateLimit = InitialNetworkRateLimit;
type InitialTargetStakesPerInterval = InitialTargetStakesPerInterval;
type AlphaHigh = InitialAlphaHigh;
type AlphaLow = InitialAlphaLow;
type LiquidAlphaOn = InitialLiquidAlphaOn;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
Expand Down Expand Up @@ -464,6 +469,18 @@ impl pallet_admin_utils::SubtensorInterface<AccountId, Balance, RuntimeOrigin> f
fn set_commit_reveal_weights_enabled(netuid: u16, enabled: bool) {
SubtensorModule::set_commit_reveal_weights_enabled(netuid, enabled);
}

fn set_liquid_alpha_enabled(netuid: u16, enabled: bool) {
SubtensorModule::set_liquid_alpha_enabled(netuid, enabled);
}
fn do_set_alpha_values(
origin: RuntimeOrigin,
netuid: u16,
alpha_low: u16,
alpha_high: u16,
) -> Result<(), DispatchError> {
SubtensorModule::do_set_alpha_values(origin, netuid, alpha_low, alpha_high)
}
}

impl pallet_admin_utils::Config for Test {
Expand Down
Loading

0 comments on commit 8cb6cb1

Please sign in to comment.