Skip to content

Commit 20a60ff

Browse files
committed
Merge branch 'feat/settable-max-mech-count' of github.com:opentensor/subtensor into feat/settable-max-mech-count
2 parents 55444a7 + 3832d59 commit 20a60ff

File tree

21 files changed

+1178
-328
lines changed

21 files changed

+1178
-328
lines changed

.github/workflows/check-bittensor-e2e-tests.yml.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,27 @@ jobs:
130130
- name: Set up Docker Buildx
131131
uses: docker/setup-buildx-action@v3
132132

133+
- name: Move Docker data-root to /mnt/data
134+
run: |
135+
sudo systemctl stop docker
136+
sudo mkdir -p /mnt/data/docker
137+
sudo chown -R runner:runner /mnt/data
138+
sudo chmod -R 777 /mnt/data
139+
echo '{"data-root": "/mnt/data/docker"}' | sudo tee /etc/docker/daemon.json
140+
sudo systemctl start docker
141+
docker info | grep "Docker Root Dir"
142+
133143
- name: Build Docker Image
134144
run: docker build -f Dockerfile-localnet -t localnet .
135145

136146
- name: Save Docker Image as Tar
137-
run: docker save -o subtensor-localnet.tar localnet
147+
run: docker save -o /mnt/data/subtensor-localnet.tar localnet
138148

139149
- name: Upload Docker Image as Artifact
140150
uses: actions/upload-artifact@v4
141151
with:
142152
name: subtensor-localnet
143-
path: subtensor-localnet.tar
153+
path: /mnt/data/subtensor-localnet.tar
144154

145155
# main btcli job
146156
run-btcli-e2e-tests:
@@ -181,7 +191,7 @@ jobs:
181191
- name: Install uv
182192
uses: astral-sh/setup-uv@v5
183193
with:
184-
enable-cache: 'false'
194+
enable-cache: "false"
185195

186196
- name: Create Python virtual environment
187197
working-directory: ${{ github.workspace }}
@@ -275,7 +285,7 @@ jobs:
275285
- name: Install uv
276286
uses: astral-sh/setup-uv@v5
277287
with:
278-
enable-cache: 'false'
288+
enable-cache: "false"
279289

280290
- name: Create Python virtual environment
281291
working-directory: ${{ github.workspace }}

evm-tests/test/staking.precompile.reward.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe("Test neuron precompile reward", () => {
7474

7575
let index = 0;
7676
while (index < 60) {
77-
const pending = await api.query.SubtensorModule.ValidatorEmission.getValue(netuid);
77+
const pending = await api.query.SubtensorModule.PendingValidatorEmission.getValue(netuid);
7878
if (pending > 0) {
7979
console.log("pending amount is ", pending);
8080
break;

pallets/admin-utils/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ pub mod pallet {
538538
);
539539
// Prevent chain bloat: Require max UIDs to be limited
540540
let mechanism_count = pallet_subtensor::MechanismCountCurrent::<T>::get(netuid);
541-
pallet_subtensor::Pallet::<T>::check_max_uids_vs_mechanism_count(
541+
pallet_subtensor::Pallet::<T>::ensure_max_uids_over_all_mechanisms(
542542
max_allowed_uids,
543543
mechanism_count.into(),
544544
)?;

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use pallet_subtensor::{
1010
TargetRegistrationsPerInterval, Tempo, WeightsVersionKeyRateLimit, *,
1111
};
1212
// use pallet_subtensor::{migrations, Event};
13-
use pallet_subtensor::{Event, utils::rate_limiting::TransactionType};
13+
use pallet_subtensor::{
14+
Event, subnets::mechanism::MAX_MECHANISM_COUNT_PER_SUBNET,
15+
utils::rate_limiting::TransactionType,
16+
};
1417
use sp_consensus_grandpa::AuthorityId as GrandpaId;
1518
use sp_core::{Get, Pair, U256, ed25519};
1619
use substrate_fixed::types::I96F32;
@@ -540,10 +543,10 @@ fn test_sudo_set_max_allowed_uids() {
540543
Error::<Test>::MaxAllowedUidsGreaterThanDefaultMaxAllowedUids
541544
);
542545

543-
// Chain bloat check against mechanism count
544-
// Set MechanismCountCurrent to exceed 256 / DefaultMaxAllowedUids (16)
546+
// Trying to set max allowed uids that would cause max_allowed_uids * mechanism_count > 256
547+
MaxAllowedUids::<Test>::insert(netuid, 8);
545548
MechanismCountCurrent::<Test>::insert(netuid, MechId::from(32));
546-
let large_max_uids = 16_u16;
549+
let large_max_uids = 16;
547550
assert_noop!(
548551
AdminUtils::sudo_set_max_allowed_uids(
549552
<<Test as Config>::RuntimeOrigin>::root(),
@@ -2888,3 +2891,32 @@ fn test_sudo_set_min_allowed_uids() {
28882891
);
28892892
});
28902893
}
2894+
2895+
#[test]
2896+
fn test_sudo_set_max_mechanism_count() {
2897+
new_test_ext().execute_with(|| {
2898+
// Normal case
2899+
assert_ok!(AdminUtils::sudo_set_max_mechanism_count(
2900+
<<Test as Config>::RuntimeOrigin>::root(),
2901+
MechId::from(10)
2902+
));
2903+
2904+
// Zero fails
2905+
assert_noop!(
2906+
AdminUtils::sudo_set_max_mechanism_count(
2907+
<<Test as Config>::RuntimeOrigin>::root(),
2908+
MechId::from(0)
2909+
),
2910+
pallet_subtensor::Error::<Test>::InvalidValue
2911+
);
2912+
2913+
// Over max bound fails
2914+
assert_noop!(
2915+
AdminUtils::sudo_set_max_mechanism_count(
2916+
<<Test as Config>::RuntimeOrigin>::root(),
2917+
MechId::from(MAX_MECHANISM_COUNT_PER_SUBNET + 1)
2918+
),
2919+
pallet_subtensor::Error::<Test>::InvalidValue
2920+
);
2921+
});
2922+
}

pallets/subtensor/src/coinbase/block_step.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
1818
.to_u64(),
1919
);
2020
log::debug!("Block emission: {block_emission:?}");
21-
// --- 3. Run emission through network.
21+
22+
// --- 3. Reveal matured weights.
23+
Self::reveal_crv3_commits();
24+
// --- 4. Run emission through network.
2225
Self::run_coinbase(block_emission);
23-
// --- 4. Set pending children on the epoch; but only after the coinbase has been run.
26+
// --- 5. Update moving prices AFTER using them for emissions.
27+
Self::update_moving_prices();
28+
// --- 6. Set pending children on the epoch; but only after the coinbase has been run.
2429
Self::try_set_pending_children(block_number);
25-
// --- 5. Run auto-claim root divs.
30+
// --- 7. Run auto-claim root divs.
2631
Self::run_auto_claim_root_divs(last_block_hash);
27-
// --- 6. Populate root coldkey maps.
32+
// --- 8. Populate root coldkey maps.
2833
Self::populate_root_coldkey_staking_maps();
2934

3035
// Return ok.
@@ -261,4 +266,24 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
261266
return next_value.saturating_to_num::<u64>().into();
262267
}
263268
}
269+
270+
pub fn update_moving_prices() {
271+
let subnets_to_emit_to: Vec<NetUid> =
272+
Self::get_subnets_to_emit_to(&Self::get_all_subnet_netuids());
273+
// Only update price EMA for subnets that we emit to.
274+
for netuid_i in subnets_to_emit_to.iter() {
275+
// Update moving prices after using them above.
276+
Self::update_moving_price(*netuid_i);
277+
}
278+
}
279+
280+
pub fn reveal_crv3_commits() {
281+
let netuids: Vec<NetUid> = Self::get_all_subnet_netuids();
282+
for netuid in netuids.into_iter().filter(|netuid| *netuid != NetUid::ROOT) {
283+
// Reveal matured weights.
284+
if let Err(e) = Self::reveal_crv3_commits_for_subnet(netuid) {
285+
log::warn!("Failed to reveal commits for subnet {netuid} due to error: {e:?}");
286+
};
287+
}
288+
}
264289
}

pallets/subtensor/src/coinbase/reveal_commits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct LegacyWeightsTlockPayload {
3636

3737
impl<T: Config> Pallet<T> {
3838
/// The `reveal_crv3_commits` function is run at the very beginning of epoch `n`,
39-
pub fn reveal_crv3_commits(netuid: NetUid) -> dispatch::DispatchResult {
39+
pub fn reveal_crv3_commits_for_subnet(netuid: NetUid) -> dispatch::DispatchResult {
4040
let reveal_period = Self::get_reveal_period(netuid);
4141
let cur_block = Self::get_current_block_as_u64();
4242
let cur_epoch = Self::get_epoch_index(netuid, cur_block);

0 commit comments

Comments
 (0)