Skip to content

Commit

Permalink
Merge pull request #1072 from opentensor/devnet-ready
Browse files Browse the repository at this point in the history
devnet deploy 12-6-2024 CR3 debug
  • Loading branch information
unconst authored Dec 6, 2024
2 parents 55e754b + dec011f commit af330be
Show file tree
Hide file tree
Showing 32 changed files with 1,594 additions and 609 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/check-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build Docker Image

on:
pull_request:

jobs:
build:
runs-on: SubtensorCI

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build Docker Image
run: docker build .
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Publish Docker Image
on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: read
Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BASE_IMAGE=ubuntu:20.04
ARG BASE_IMAGE=ubuntu:24.04

FROM $BASE_IMAGE AS builder
SHELL ["/bin/bash", "-c"]
Expand All @@ -15,7 +15,7 @@ LABEL ai.opentensor.image.authors="operations@opentensor.ai" \
# Set up Rust environment
ENV RUST_BACKTRACE=1
RUN apt-get update && \
apt-get install -y curl build-essential protobuf-compiler clang git && \
apt-get install -y curl build-essential protobuf-compiler clang git pkg-config libssl-dev && \
rm -rf /var/lib/apt/lists/*

RUN set -o pipefail && curl https://sh.rustup.rs -sSf | sh -s -- -y
Expand Down
63 changes: 36 additions & 27 deletions chainspecs/plain_spec_devnet.json

Large diffs are not rendered by default.

144 changes: 91 additions & 53 deletions chainspecs/raw_spec_devnet.json

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions node/src/chain_spec/devnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,23 @@ pub fn devnet_config() -> Result<ChainSpec, String> {
// Keys for debug
authority_keys_from_ss58(
"5D5ABUyMsdmJdH7xrsz9vREq5eGXr5pXhHxix2dENQR62dEo",
"5H3qMjQjoeZxZ98jzDmoCwbz2sugd5fDN1wrr8Phf49zemKL",
"5DLBJuPvyPYit5h5ZaYiF8NvCweXCozUs6pLx3fng1mdVcbw",
),
authority_keys_from_ss58(
"5GbRc5sNDdhcPAU9suV2g9P5zyK1hjAQ9JHeeadY1mb8kXoM",
"5GbkysfaCjK3cprKPhi3CUwaB5xWpBwcfrkzs6FmqHxej8HZ",
"5ELAzpniRUzAtvydVLmfs5ogbjzoBVxfn6XrN91ahBeDukoY",
),
authority_keys_from_ss58(
"5CoVWwBwXz2ndEChGcS46VfSTb3RMUZzZzAYdBKo263zDhEz",
"5HTLp4BvPp99iXtd8YTBZA1sMfzo8pd4mZzBJf7HYdCn2boU",
"5EHVLDoMqjWrBnUrNtj8FAb1sFFg97vydLGydH8vz7BGs9Qf",
),
authority_keys_from_ss58(
"5EekcbqupwbgWqF8hWGY4Pczsxp9sbarjDehqk7bdyLhDCwC",
"5GAemcU4Pzyfe8DwLwDFx3aWzyg3FuqYUCCw2h4sdDZhyFvE",
"5CdFyer8NZ4m8QXAHkgZ7zQ8oM8U6N5XrMSDzcMWdDjbAwUg",
),
authority_keys_from_ss58(
"5GgdEQyS5DZzUwKuyucEPEZLxFKGmasUFm1mqM3sx1MRC5RV",
"5EibpMomXmgekxcfs25SzFBpGWUsG9Lc8ALNjXN3TYH5Tube",
),
authority_keys_from_ss58(
"5Ek5JLCGk2PuoT1fS23GXiWYUT98HVUBERFQBu5g57sNf44x",
"5Gyrc6b2mx1Af6zWJYHdx3gwgtXgZvD9YkcG9uTUPYry4V2a",
"5FYgXyYc59s9c161swNEf4VEGezLd3q5ca6rSYWuJPjbBNKf",
),
],
// Sudo account
Expand Down
4 changes: 3 additions & 1 deletion pallets/admin-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ log = { workspace = true }
pallet-subtensor = { version = "4.0.0-dev", default-features = false, path = "../subtensor" }
sp-weights = { workspace = true }
substrate-fixed = { workspace = true }
pallet-evm-chain-id = { workspace = true }
pallet-drand = { workspace = true, default-features = false }


[dev-dependencies]
sp-core = { workspace = true }
sp-io = { workspace = true }
Expand All @@ -52,6 +52,7 @@ std = [
"pallet-subtensor/std",
"sp-consensus-aura/std",
"pallet-balances/std",
"pallet-evm-chain-id/std",
"pallet-scheduler/std",
"sp-runtime/std",
"sp-tracing/std",
Expand All @@ -77,6 +78,7 @@ try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-balances/try-runtime",
"pallet-evm-chain-id/try-runtime",
"pallet-scheduler/try-runtime",
"sp-runtime/try-runtime",
"pallet-subtensor/try-runtime",
Expand Down
32 changes: 29 additions & 3 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_support::traits::tokens::Balance;
use frame_system::pallet_prelude::*;
use pallet_evm_chain_id::{self, ChainId};
use sp_runtime::BoundedVec;

/// The main data structure of the module.
Expand All @@ -29,7 +30,11 @@ pub mod pallet {

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
pub trait Config: frame_system::Config + pallet_subtensor::pallet::Config {
pub trait Config:
frame_system::Config
+ pallet_subtensor::pallet::Config
+ pallet_evm_chain_id::pallet::Config
{
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

Expand Down Expand Up @@ -885,9 +890,9 @@ pub mod pallet {
/// The extrinsic will call the Subtensor pallet to set the weights min stake.
#[pallet::call_index(42)]
#[pallet::weight((0, DispatchClass::Operational, Pays::No))]
pub fn sudo_set_weights_min_stake(origin: OriginFor<T>, min_stake: u64) -> DispatchResult {
pub fn sudo_set_stake_threshold(origin: OriginFor<T>, min_stake: u64) -> DispatchResult {
ensure_root(origin)?;
pallet_subtensor::Pallet::<T>::set_weights_min_stake(min_stake);
pallet_subtensor::Pallet::<T>::set_stake_threshold(min_stake);
Ok(())
}

Expand Down Expand Up @@ -1212,6 +1217,27 @@ pub mod pallet {
);
Ok(())
}

/// Sets the EVM ChainID.
///
/// # Arguments
/// * `origin` - The origin of the call, which must be the subnet owner or the root account.
/// * `chainId` - The u64 chain ID
///
/// # Errors
/// * `BadOrigin` - If the caller is neither the subnet owner nor the root account.
///
/// # Weight
/// Weight is handled by the `#[pallet::weight]` attribute.
#[pallet::call_index(58)]
#[pallet::weight(<T as Config>::WeightInfo::sudo_set_evm_chain_id())]
pub fn sudo_set_evm_chain_id(origin: OriginFor<T>, chain_id: u64) -> DispatchResult {
// Ensure the call is made by the root account
ensure_root(origin)?;

ChainId::<T>::set(chain_id);
Ok(())
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ frame_support::construct_runtime!(
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>} = 4,
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 5,
Drand: pallet_drand::{Pallet, Call, Storage, Event<T>} = 6,
EVMChainId: pallet_evm_chain_id = 7,
}
);

Expand Down Expand Up @@ -277,6 +278,7 @@ impl pallet_scheduler::Config for Test {
type Preimages = ();
}

impl pallet_evm_chain_id::Config for Test {}
impl pallet_drand::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_drand::weights::SubstrateWeight<Test>;
Expand Down
45 changes: 39 additions & 6 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,23 +682,23 @@ fn test_sudo_set_max_allowed_validators() {
}

#[test]
fn test_sudo_set_weights_min_stake() {
fn test_sudo_set_stake_threshold() {
new_test_ext().execute_with(|| {
let to_be_set: u64 = 10;
let init_value: u64 = SubtensorModule::get_weights_min_stake();
let init_value: u64 = SubtensorModule::get_stake_threshold();
assert_eq!(
AdminUtils::sudo_set_weights_min_stake(
AdminUtils::sudo_set_stake_threshold(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
to_be_set
),
Err(DispatchError::BadOrigin)
);
assert_eq!(SubtensorModule::get_weights_min_stake(), init_value);
assert_ok!(AdminUtils::sudo_set_weights_min_stake(
assert_eq!(SubtensorModule::get_stake_threshold(), init_value);
assert_ok!(AdminUtils::sudo_set_stake_threshold(
<<Test as Config>::RuntimeOrigin>::root(),
to_be_set
));
assert_eq!(SubtensorModule::get_weights_min_stake(), to_be_set);
assert_eq!(SubtensorModule::get_stake_threshold(), to_be_set);
});
}

Expand Down Expand Up @@ -1433,3 +1433,36 @@ fn sudo_set_commit_reveal_weights_interval() {
assert_eq!(SubtensorModule::get_reveal_period(netuid), to_be_set);
});
}

#[test]
fn test_sudo_root_sets_evm_chain_id() {
new_test_ext().execute_with(|| {
let chain_id: u64 = 945;
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);

assert_ok!(AdminUtils::sudo_set_evm_chain_id(
<<Test as Config>::RuntimeOrigin>::root(),
chain_id
));

assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), chain_id);
});
}

#[test]
fn test_sudo_non_root_cannot_set_evm_chain_id() {
new_test_ext().execute_with(|| {
let chain_id: u64 = 945;
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);

assert_eq!(
AdminUtils::sudo_set_evm_chain_id(
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
chain_id
),
Err(DispatchError::BadOrigin)
);

assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);
});
}
9 changes: 9 additions & 0 deletions pallets/admin-utils/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub trait WeightInfo {
fn sudo_set_tempo() -> Weight;
fn sudo_set_commit_reveal_weights_interval() -> Weight;
fn sudo_set_commit_reveal_weights_enabled() -> Weight;
fn sudo_set_evm_chain_id() -> Weight;
}

/// Weights for `pallet_admin_utils` using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -431,6 +432,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
fn sudo_set_evm_chain_id() -> Weight {
Weight::from_parts(20_200_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests.
Expand Down Expand Up @@ -805,4 +810,8 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
fn sudo_set_evm_chain_id() -> Weight {
Weight::from_parts(20_200_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
17 changes: 15 additions & 2 deletions pallets/drand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,13 @@ impl<T: Config> Pallet<T> {
let mut last_stored_round = LastStoredRound::<T>::get();
let latest_pulse_body = Self::fetch_drand_latest().map_err(|_| "Failed to query drand")?;
let latest_unbounded_pulse: DrandResponseBody = serde_json::from_str(&latest_pulse_body)
.map_err(|_| "Drand: Failed to serialize response body to pulse")?;
.map_err(|_| {
log::warn!(
"Drand: Response that failed to deserialize: {}",
latest_pulse_body
);
"Drand: Failed to serialize response body to pulse"
})?;
let latest_pulse = latest_unbounded_pulse
.try_into_pulse()
.map_err(|_| "Drand: Received pulse contains invalid data")?;
Expand All @@ -417,7 +423,14 @@ impl<T: Config> Pallet<T> {
let pulse_body = Self::fetch_drand_by_round(round)
.map_err(|_| "Drand: Failed to query drand for round")?;
let unbounded_pulse: DrandResponseBody = serde_json::from_str(&pulse_body)
.map_err(|_| "Drand: Failed to serialize response body to pulse")?;
.map_err(|_| {
log::warn!(
"Drand: Response that failed to deserialize for round {}: {}",
round,
pulse_body
);
"Drand: Failed to serialize response body to pulse"
})?;
let pulse = unbounded_pulse
.try_into_pulse()
.map_err(|_| "Drand: Received pulse contains invalid data")?;
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ impl<T: Config> Pallet<T> {

// Check to see if the hotkey has enough stake to set weights.
ensure!(
Self::get_total_stake_for_hotkey(&hotkey) >= Self::get_weights_min_stake(),
Self::get_total_stake_for_hotkey(&hotkey) >= Self::get_stake_threshold(),
Error::<T>::NotEnoughStakeToSetWeights
);

Expand Down
3 changes: 3 additions & 0 deletions pallets/subtensor/src/coinbase/run_coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ impl<T: Config> Pallet<T> {
);
log::debug!("Accumulated emissions on hotkey {:?} for netuid {:?}: mining {:?}, validator {:?}", hotkey, *netuid, mining_emission, validator_emission);
}

// 4.5 Apply pending childkeys of this subnet for the next epoch
Self::do_set_pending_children(*netuid);
} else {
// No epoch, increase blocks since last step and continue
Self::set_blocks_since_last_step(
Expand Down
Loading

0 comments on commit af330be

Please sign in to comment.