Skip to content

Commit af330be

Browse files
authored
Merge pull request #1072 from opentensor/devnet-ready
devnet deploy 12-6-2024 CR3 debug
2 parents 55e754b + dec011f commit af330be

32 files changed

+1594
-609
lines changed

.github/workflows/check-docker.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build Docker Image
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
build:
8+
runs-on: SubtensorCI
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Set up QEMU
15+
uses: docker/setup-qemu-action@v2
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
20+
- name: Build Docker Image
21+
run: docker build .

.github/workflows/docker.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Publish Docker Image
33
on:
44
release:
55
types: [published]
6+
workflow_dispatch:
67

78
permissions:
89
contents: read

Cargo.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG BASE_IMAGE=ubuntu:20.04
1+
ARG BASE_IMAGE=ubuntu:24.04
22

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

2121
RUN set -o pipefail && curl https://sh.rustup.rs -sSf | sh -s -- -y

chainspecs/plain_spec_devnet.json

+36-27
Large diffs are not rendered by default.

chainspecs/raw_spec_devnet.json

+91-53
Large diffs are not rendered by default.

node/src/chain_spec/devnet.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,23 @@ pub fn devnet_config() -> Result<ChainSpec, String> {
3030
// Keys for debug
3131
authority_keys_from_ss58(
3232
"5D5ABUyMsdmJdH7xrsz9vREq5eGXr5pXhHxix2dENQR62dEo",
33-
"5H3qMjQjoeZxZ98jzDmoCwbz2sugd5fDN1wrr8Phf49zemKL",
33+
"5DLBJuPvyPYit5h5ZaYiF8NvCweXCozUs6pLx3fng1mdVcbw",
3434
),
3535
authority_keys_from_ss58(
3636
"5GbRc5sNDdhcPAU9suV2g9P5zyK1hjAQ9JHeeadY1mb8kXoM",
37-
"5GbkysfaCjK3cprKPhi3CUwaB5xWpBwcfrkzs6FmqHxej8HZ",
37+
"5ELAzpniRUzAtvydVLmfs5ogbjzoBVxfn6XrN91ahBeDukoY",
3838
),
3939
authority_keys_from_ss58(
4040
"5CoVWwBwXz2ndEChGcS46VfSTb3RMUZzZzAYdBKo263zDhEz",
41-
"5HTLp4BvPp99iXtd8YTBZA1sMfzo8pd4mZzBJf7HYdCn2boU",
41+
"5EHVLDoMqjWrBnUrNtj8FAb1sFFg97vydLGydH8vz7BGs9Qf",
4242
),
4343
authority_keys_from_ss58(
4444
"5EekcbqupwbgWqF8hWGY4Pczsxp9sbarjDehqk7bdyLhDCwC",
45-
"5GAemcU4Pzyfe8DwLwDFx3aWzyg3FuqYUCCw2h4sdDZhyFvE",
45+
"5CdFyer8NZ4m8QXAHkgZ7zQ8oM8U6N5XrMSDzcMWdDjbAwUg",
4646
),
4747
authority_keys_from_ss58(
4848
"5GgdEQyS5DZzUwKuyucEPEZLxFKGmasUFm1mqM3sx1MRC5RV",
49-
"5EibpMomXmgekxcfs25SzFBpGWUsG9Lc8ALNjXN3TYH5Tube",
50-
),
51-
authority_keys_from_ss58(
52-
"5Ek5JLCGk2PuoT1fS23GXiWYUT98HVUBERFQBu5g57sNf44x",
53-
"5Gyrc6b2mx1Af6zWJYHdx3gwgtXgZvD9YkcG9uTUPYry4V2a",
49+
"5FYgXyYc59s9c161swNEf4VEGezLd3q5ca6rSYWuJPjbBNKf",
5450
),
5551
],
5652
// Sudo account

pallets/admin-utils/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ log = { workspace = true }
2929
pallet-subtensor = { version = "4.0.0-dev", default-features = false, path = "../subtensor" }
3030
sp-weights = { workspace = true }
3131
substrate-fixed = { workspace = true }
32+
pallet-evm-chain-id = { workspace = true }
3233
pallet-drand = { workspace = true, default-features = false }
3334

34-
3535
[dev-dependencies]
3636
sp-core = { workspace = true }
3737
sp-io = { workspace = true }
@@ -52,6 +52,7 @@ std = [
5252
"pallet-subtensor/std",
5353
"sp-consensus-aura/std",
5454
"pallet-balances/std",
55+
"pallet-evm-chain-id/std",
5556
"pallet-scheduler/std",
5657
"sp-runtime/std",
5758
"sp-tracing/std",
@@ -77,6 +78,7 @@ try-runtime = [
7778
"frame-support/try-runtime",
7879
"frame-system/try-runtime",
7980
"pallet-balances/try-runtime",
81+
"pallet-evm-chain-id/try-runtime",
8082
"pallet-scheduler/try-runtime",
8183
"sp-runtime/try-runtime",
8284
"pallet-subtensor/try-runtime",

pallets/admin-utils/src/lib.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod pallet {
2020
use frame_support::pallet_prelude::*;
2121
use frame_support::traits::tokens::Balance;
2222
use frame_system::pallet_prelude::*;
23+
use pallet_evm_chain_id::{self, ChainId};
2324
use sp_runtime::BoundedVec;
2425

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

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

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

@@ -1212,6 +1217,27 @@ pub mod pallet {
12121217
);
12131218
Ok(())
12141219
}
1220+
1221+
/// Sets the EVM ChainID.
1222+
///
1223+
/// # Arguments
1224+
/// * `origin` - The origin of the call, which must be the subnet owner or the root account.
1225+
/// * `chainId` - The u64 chain ID
1226+
///
1227+
/// # Errors
1228+
/// * `BadOrigin` - If the caller is neither the subnet owner nor the root account.
1229+
///
1230+
/// # Weight
1231+
/// Weight is handled by the `#[pallet::weight]` attribute.
1232+
#[pallet::call_index(58)]
1233+
#[pallet::weight(<T as Config>::WeightInfo::sudo_set_evm_chain_id())]
1234+
pub fn sudo_set_evm_chain_id(origin: OriginFor<T>, chain_id: u64) -> DispatchResult {
1235+
// Ensure the call is made by the root account
1236+
ensure_root(origin)?;
1237+
1238+
ChainId::<T>::set(chain_id);
1239+
Ok(())
1240+
}
12151241
}
12161242
}
12171243

pallets/admin-utils/src/tests/mock.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ frame_support::construct_runtime!(
2929
SubtensorModule: pallet_subtensor::{Pallet, Call, Storage, Event<T>, Error<T>} = 4,
3030
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 5,
3131
Drand: pallet_drand::{Pallet, Call, Storage, Event<T>} = 6,
32+
EVMChainId: pallet_evm_chain_id = 7,
3233
}
3334
);
3435

@@ -277,6 +278,7 @@ impl pallet_scheduler::Config for Test {
277278
type Preimages = ();
278279
}
279280

281+
impl pallet_evm_chain_id::Config for Test {}
280282
impl pallet_drand::Config for Test {
281283
type RuntimeEvent = RuntimeEvent;
282284
type WeightInfo = pallet_drand::weights::SubstrateWeight<Test>;

pallets/admin-utils/src/tests/mod.rs

+39-6
Original file line numberDiff line numberDiff line change
@@ -682,23 +682,23 @@ fn test_sudo_set_max_allowed_validators() {
682682
}
683683

684684
#[test]
685-
fn test_sudo_set_weights_min_stake() {
685+
fn test_sudo_set_stake_threshold() {
686686
new_test_ext().execute_with(|| {
687687
let to_be_set: u64 = 10;
688-
let init_value: u64 = SubtensorModule::get_weights_min_stake();
688+
let init_value: u64 = SubtensorModule::get_stake_threshold();
689689
assert_eq!(
690-
AdminUtils::sudo_set_weights_min_stake(
690+
AdminUtils::sudo_set_stake_threshold(
691691
<<Test as Config>::RuntimeOrigin>::signed(U256::from(1)),
692692
to_be_set
693693
),
694694
Err(DispatchError::BadOrigin)
695695
);
696-
assert_eq!(SubtensorModule::get_weights_min_stake(), init_value);
697-
assert_ok!(AdminUtils::sudo_set_weights_min_stake(
696+
assert_eq!(SubtensorModule::get_stake_threshold(), init_value);
697+
assert_ok!(AdminUtils::sudo_set_stake_threshold(
698698
<<Test as Config>::RuntimeOrigin>::root(),
699699
to_be_set
700700
));
701-
assert_eq!(SubtensorModule::get_weights_min_stake(), to_be_set);
701+
assert_eq!(SubtensorModule::get_stake_threshold(), to_be_set);
702702
});
703703
}
704704

@@ -1433,3 +1433,36 @@ fn sudo_set_commit_reveal_weights_interval() {
14331433
assert_eq!(SubtensorModule::get_reveal_period(netuid), to_be_set);
14341434
});
14351435
}
1436+
1437+
#[test]
1438+
fn test_sudo_root_sets_evm_chain_id() {
1439+
new_test_ext().execute_with(|| {
1440+
let chain_id: u64 = 945;
1441+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);
1442+
1443+
assert_ok!(AdminUtils::sudo_set_evm_chain_id(
1444+
<<Test as Config>::RuntimeOrigin>::root(),
1445+
chain_id
1446+
));
1447+
1448+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), chain_id);
1449+
});
1450+
}
1451+
1452+
#[test]
1453+
fn test_sudo_non_root_cannot_set_evm_chain_id() {
1454+
new_test_ext().execute_with(|| {
1455+
let chain_id: u64 = 945;
1456+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);
1457+
1458+
assert_eq!(
1459+
AdminUtils::sudo_set_evm_chain_id(
1460+
<<Test as Config>::RuntimeOrigin>::signed(U256::from(0)),
1461+
chain_id
1462+
),
1463+
Err(DispatchError::BadOrigin)
1464+
);
1465+
1466+
assert_eq!(pallet_evm_chain_id::ChainId::<Test>::get(), 0);
1467+
});
1468+
}

pallets/admin-utils/src/weights.rs

+9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub trait WeightInfo {
6262
fn sudo_set_tempo() -> Weight;
6363
fn sudo_set_commit_reveal_weights_interval() -> Weight;
6464
fn sudo_set_commit_reveal_weights_enabled() -> Weight;
65+
fn sudo_set_evm_chain_id() -> Weight;
6566
}
6667

6768
/// Weights for `pallet_admin_utils` using the Substrate node and recommended hardware.
@@ -431,6 +432,10 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
431432
.saturating_add(T::DbWeight::get().reads(1_u64))
432433
.saturating_add(T::DbWeight::get().writes(1_u64))
433434
}
435+
fn sudo_set_evm_chain_id() -> Weight {
436+
Weight::from_parts(20_200_000, 0)
437+
.saturating_add(RocksDbWeight::get().writes(1_u64))
438+
}
434439
}
435440

436441
// For backwards compatibility and tests.
@@ -805,4 +810,8 @@ impl WeightInfo for () {
805810
.saturating_add(RocksDbWeight::get().reads(1_u64))
806811
.saturating_add(RocksDbWeight::get().writes(1_u64))
807812
}
813+
fn sudo_set_evm_chain_id() -> Weight {
814+
Weight::from_parts(20_200_000, 0)
815+
.saturating_add(RocksDbWeight::get().writes(1_u64))
816+
}
808817
}

pallets/drand/src/lib.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,13 @@ impl<T: Config> Pallet<T> {
392392
let mut last_stored_round = LastStoredRound::<T>::get();
393393
let latest_pulse_body = Self::fetch_drand_latest().map_err(|_| "Failed to query drand")?;
394394
let latest_unbounded_pulse: DrandResponseBody = serde_json::from_str(&latest_pulse_body)
395-
.map_err(|_| "Drand: Failed to serialize response body to pulse")?;
395+
.map_err(|_| {
396+
log::warn!(
397+
"Drand: Response that failed to deserialize: {}",
398+
latest_pulse_body
399+
);
400+
"Drand: Failed to serialize response body to pulse"
401+
})?;
396402
let latest_pulse = latest_unbounded_pulse
397403
.try_into_pulse()
398404
.map_err(|_| "Drand: Received pulse contains invalid data")?;
@@ -417,7 +423,14 @@ impl<T: Config> Pallet<T> {
417423
let pulse_body = Self::fetch_drand_by_round(round)
418424
.map_err(|_| "Drand: Failed to query drand for round")?;
419425
let unbounded_pulse: DrandResponseBody = serde_json::from_str(&pulse_body)
420-
.map_err(|_| "Drand: Failed to serialize response body to pulse")?;
426+
.map_err(|_| {
427+
log::warn!(
428+
"Drand: Response that failed to deserialize for round {}: {}",
429+
round,
430+
pulse_body
431+
);
432+
"Drand: Failed to serialize response body to pulse"
433+
})?;
421434
let pulse = unbounded_pulse
422435
.try_into_pulse()
423436
.map_err(|_| "Drand: Received pulse contains invalid data")?;

pallets/subtensor/src/coinbase/root.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl<T: Config> Pallet<T> {
784784

785785
// Check to see if the hotkey has enough stake to set weights.
786786
ensure!(
787-
Self::get_total_stake_for_hotkey(&hotkey) >= Self::get_weights_min_stake(),
787+
Self::get_total_stake_for_hotkey(&hotkey) >= Self::get_stake_threshold(),
788788
Error::<T>::NotEnoughStakeToSetWeights
789789
);
790790

pallets/subtensor/src/coinbase/run_coinbase.rs

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ impl<T: Config> Pallet<T> {
166166
);
167167
log::debug!("Accumulated emissions on hotkey {:?} for netuid {:?}: mining {:?}, validator {:?}", hotkey, *netuid, mining_emission, validator_emission);
168168
}
169+
170+
// 4.5 Apply pending childkeys of this subnet for the next epoch
171+
Self::do_set_pending_children(*netuid);
169172
} else {
170173
// No epoch, increase blocks since last step and continue
171174
Self::set_blocks_since_last_step(

0 commit comments

Comments
 (0)