Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d30a76f
Dynamic tempo implementation
evgeny-s May 6, 2026
42b3e29
clippy + fmt
evgeny-s May 6, 2026
c6567e2
clean up
evgeny-s May 6, 2026
ad7ba80
Renamed function + updated comment
evgeny-s May 7, 2026
df184e3
wrap set tempo + cycle reset with a helper function
evgeny-s May 7, 2026
b2e4658
tests
evgeny-s May 7, 2026
02f43ee
clippy
evgeny-s May 7, 2026
40f2773
Merge branch 'devnet-ready' into feature/dynamic-tempo
evgeny-s May 7, 2026
c3fa417
fixed test from devnet
evgeny-s May 7, 2026
dca9f44
Merge branch 'devnet-ready' into feature/dynamic-tempo
evgeny-s May 7, 2026
73d1ab4
- disable dynamic tempo for subnets with CR enabled.
evgeny-s May 8, 2026
1ba4a3d
- update migration - do not clamp tempos
evgeny-s May 8, 2026
215f13b
fix migration test
evgeny-s May 8, 2026
577d62b
Added benchmarks for new extrinsics
evgeny-s May 11, 2026
ff61eb3
Merge branch 'devnet-ready' into feature/dynamic-tempo
evgeny-s May 11, 2026
e15d749
fix for e2e test
evgeny-s May 11, 2026
7a1d7a3
- Increase timeout
evgeny-s May 11, 2026
4c06820
- updated name + timeout
evgeny-s May 12, 2026
82ae882
increase MAX_EPOCHS_PER_BLOCK for fast-runtime
evgeny-s May 12, 2026
bcfe012
Added runtime API to get the next epoch start block
evgeny-s May 13, 2026
34bcc41
Merge branch 'devnet-ready' into feature/dynamic-tempo
evgeny-s May 15, 2026
927be34
Merge branch 'devnet-ready' into feature/dynamic-tempo
evgeny-s May 21, 2026
b5b4184
- fix test after dev merge
evgeny-s May 21, 2026
1fc3e88
- Added stateful SubnetEpochIndex
evgeny-s May 22, 2026
4f97a5b
- clean previous tempo + 1 approach
evgeny-s May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions eco-tests/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ pub fn next_block_no_epoch(netuid: NetUid) -> u64 {
let high_tempo: u16 = u16::MAX - 1;
let old_tempo: u16 = SubtensorModule::get_tempo(netuid);

SubtensorModule::set_tempo(netuid, high_tempo);
SubtensorModule::set_tempo_unchecked(netuid, high_tempo);
let new_block = next_block();
SubtensorModule::set_tempo(netuid, old_tempo);
SubtensorModule::set_tempo_unchecked(netuid, old_tempo);

new_block
}
Expand All @@ -99,14 +99,14 @@ pub fn run_to_block_no_epoch(netuid: NetUid, n: u64) {
let high_tempo: u16 = u16::MAX - 1;
let old_tempo: u16 = SubtensorModule::get_tempo(netuid);

SubtensorModule::set_tempo(netuid, high_tempo);
SubtensorModule::set_tempo_unchecked(netuid, high_tempo);
run_to_block(n);
SubtensorModule::set_tempo(netuid, old_tempo);
SubtensorModule::set_tempo_unchecked(netuid, old_tempo);
}

pub fn step_epochs(count: u16, netuid: NetUid) {
for _ in 0..count {
let blocks_to_next_epoch = SubtensorModule::blocks_until_next_epoch(
let blocks_to_next_epoch = SubtensorModule::blocks_until_next_auto_epoch(
netuid,
SubtensorModule::get_tempo(netuid),
SubtensorModule::get_current_block_as_u64(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ pub mod pallet {
pallet_subtensor::Pallet::<T>::if_subnet_exist(netuid),
Error::<T>::SubnetDoesNotExist
);
pallet_subtensor::Pallet::<T>::set_tempo(netuid, tempo);
pallet_subtensor::Pallet::<T>::apply_tempo_with_cycle_reset(netuid, tempo);
log::debug!("TempoSet( netuid: {netuid:?} tempo: {tempo:?} ) ");
Ok(())
}
Expand Down
16 changes: 10 additions & 6 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2042,16 +2042,20 @@ fn test_sudo_set_admin_freeze_window_and_rate() {
fn test_freeze_window_blocks_root_and_owner() {
new_test_ext().execute_with(|| {
let netuid = NetUid::from(1);
let tempo = 10;
let tempo: u16 = 10;
// Create subnet with tempo 10
add_network(netuid, tempo);
// Set freeze window to 3 blocks
assert_ok!(AdminUtils::sudo_set_admin_freeze_window(
<<Test as Config>::RuntimeOrigin>::root(),
3
));
// Advance to a block where remaining < 3
run_to_block((tempo - 2).into());
// Pin the state-based scheduler so the next auto-epoch lands at
// `LastEpochBlock + tempo`. Freeze window covers blocks (next_auto - 3, next_auto].
pallet_subtensor::LastEpochBlock::<Test>::insert(netuid, 0);
let next_auto = tempo as u64;
// Advance to a block inside the freeze window (remaining < 3).
run_to_block(next_auto - 2);

// Root should be blocked during freeze window
assert_noop!(
Expand Down Expand Up @@ -2147,7 +2151,7 @@ fn test_owner_hyperparam_update_rate_limit_enforced() {
SubnetOwner::<Test>::insert(netuid, owner);

// Set tempo to 1 so owner hyperparam RL = 2 tempos = 2 blocks
SubtensorModule::set_tempo(netuid, 1);
SubtensorModule::set_tempo_unchecked(netuid, 1);
// Disable admin freeze window to avoid blocking on small tempo
assert_ok!(AdminUtils::sudo_set_admin_freeze_window(
<<Test as Config>::RuntimeOrigin>::root(),
Expand Down Expand Up @@ -2202,7 +2206,7 @@ fn test_hyperparam_rate_limit_enforced_by_tempo() {
SubnetOwner::<Test>::insert(netuid, owner);

// Set tempo to 1 so RL = 2 blocks
SubtensorModule::set_tempo(netuid, 1);
SubtensorModule::set_tempo_unchecked(netuid, 1);
// Disable admin freeze window to avoid blocking on small tempo
assert_ok!(AdminUtils::sudo_set_admin_freeze_window(
<<Test as Config>::RuntimeOrigin>::root(),
Expand Down Expand Up @@ -2250,7 +2254,7 @@ fn test_owner_hyperparam_rate_limit_independent_per_param() {
SubnetOwner::<Test>::insert(netuid, owner);

// Use small tempo to make RL short and deterministic (2 blocks when tempo=1)
SubtensorModule::set_tempo(netuid, 1);
SubtensorModule::set_tempo_unchecked(netuid, 1);
// Disable admin freeze window so it doesn't interfere with small tempo
assert_ok!(AdminUtils::sudo_set_admin_freeze_window(
<<Test as Config>::RuntimeOrigin>::root(),
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ sp_api::decl_runtime_apis! {
fn get_selective_mechagraph(netuid: NetUid, subid: MechId, metagraph_indexes: Vec<u16>) -> Option<SelectiveMetagraph<AccountId32>>;
fn get_subnet_to_prune() -> Option<NetUid>;
fn get_subnet_account_id(netuid: NetUid) -> Option<AccountId32>;
fn get_next_epoch_start_block(netuid: NetUid) -> Option<u64>;
}

pub trait StakeInfoRuntimeApi {
Expand Down
68 changes: 54 additions & 14 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,15 @@ mod pallet_benchmarks {
salt.clone(),
version_key,
));
let commit_block = Subtensor::<T>::get_current_block_as_u64();
assert_ok!(Subtensor::<T>::commit_weights(
RawOrigin::Signed(hotkey.clone()).into(),
netuid,
commit_hash,
));

let (first_reveal_block, _) = Subtensor::<T>::get_reveal_blocks(netuid, commit_block);
let reveal_block: BlockNumberFor<T> = first_reveal_block
.try_into()
.ok()
.expect("can't convert to block number");
frame_system::Pallet::<T>::set_block_number(reveal_block);
// Advance the epoch counter into the commit's reveal window.
let reveal_period = Subtensor::<T>::get_reveal_period(netuid);
SubnetEpochIndex::<T>::mutate(netuid, |e| *e = e.saturating_add(reveal_period));

#[extrinsic_call]
_(
Expand Down Expand Up @@ -676,7 +672,6 @@ mod pallet_benchmarks {
let mut salts_list = Vec::new();
let mut version_keys = Vec::new();

let commit_block = Subtensor::<T>::get_current_block_as_u64();
for i in 0..num_commits {
let uids = vec![0u16];
let values = vec![i as u16];
Expand Down Expand Up @@ -704,12 +699,9 @@ mod pallet_benchmarks {
version_keys.push(version_key_i);
}

let (first_reveal_block, _) = Subtensor::<T>::get_reveal_blocks(netuid, commit_block);
let reveal_block: BlockNumberFor<T> = first_reveal_block
.try_into()
.ok()
.expect("can't convert to block number");
frame_system::Pallet::<T>::set_block_number(reveal_block);
// Advance the epoch counter into the reveal window for these commits.
let reveal_period = Subtensor::<T>::get_reveal_period(netuid);
SubnetEpochIndex::<T>::mutate(netuid, |e| *e = e.saturating_add(reveal_period));

#[extrinsic_call]
_(
Expand Down Expand Up @@ -2148,6 +2140,54 @@ mod pallet_benchmarks {
);
}

#[benchmark]
fn set_tempo() {
let netuid = NetUid::from(1);
let coldkey: T::AccountId = account("Owner", 0, 1);

Subtensor::<T>::init_new_network(netuid, 1u16);
SubnetOwner::<T>::insert(netuid, coldkey.clone());
SubtokenEnabled::<T>::insert(netuid, true);
Subtensor::<T>::set_commit_reveal_weights_enabled(netuid, false);
Subtensor::<T>::set_admin_freeze_window(0);

#[extrinsic_call]
_(RawOrigin::Signed(coldkey.clone()), netuid, MIN_TEMPO);
}

#[benchmark]
fn set_activity_cutoff_factor() {
let netuid = NetUid::from(1);
let coldkey: T::AccountId = account("Owner", 0, 1);

Subtensor::<T>::init_new_network(netuid, 1u16);
SubnetOwner::<T>::insert(netuid, coldkey.clone());
SubtokenEnabled::<T>::insert(netuid, true);
Subtensor::<T>::set_admin_freeze_window(0);

#[extrinsic_call]
_(
RawOrigin::Signed(coldkey.clone()),
netuid,
INITIAL_ACTIVITY_CUTOFF_FACTOR_MILLI,
);
}

#[benchmark]
fn trigger_epoch() {
let netuid = NetUid::from(1);
let coldkey: T::AccountId = account("Owner", 0, 1);

Subtensor::<T>::init_new_network(netuid, 1u16);
SubnetOwner::<T>::insert(netuid, coldkey.clone());
SubtokenEnabled::<T>::insert(netuid, true);
Subtensor::<T>::set_commit_reveal_weights_enabled(netuid, false);
Subtensor::<T>::set_admin_freeze_window(0);

#[extrinsic_call]
_(RawOrigin::Signed(coldkey.clone()), netuid);
}

impl_benchmark_test_suite!(
Subtensor,
crate::tests::mock::new_test_ext(1),
Expand Down
6 changes: 4 additions & 2 deletions pallets/subtensor/src/coinbase/block_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ impl<T: Config + pallet_drand::Config> Pallet<T> {
}

fn try_set_pending_children(block_number: u64) {
// Called *after* `run_coinbase` has advanced `LastEpochBlock` for any
// subnet whose epoch slot fired this block — `should_run_epoch` is no
// longer true. Detect "epoch just fired" by `LastEpochBlock == block`.
for netuid in Self::get_all_subnet_netuids() {
if Self::should_run_epoch(netuid, block_number) {
// Set pending children on the epoch.
if LastEpochBlock::<T>::get(netuid) == block_number {
Self::do_set_pending_children(netuid);
}
}
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/coinbase/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod root;
pub mod run_coinbase;
pub mod subnet_emissions;
pub mod tao;
pub mod tempo_control;
5 changes: 3 additions & 2 deletions pallets/subtensor/src/coinbase/reveal_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ impl<T: Config> Pallet<T> {
/// The `reveal_crv3_commits` function is run at the very beginning of epoch `n`,
pub fn reveal_crv3_commits_for_subnet(netuid: NetUid) -> dispatch::DispatchResult {
let reveal_period = Self::get_reveal_period(netuid);
let cur_block = Self::get_current_block_as_u64();
let cur_epoch = Self::get_epoch_index(netuid, cur_block);
// If the subnet is deferred past this block the
// commits are taken once here and the later block(s) become no-ops.
let cur_epoch = Self::current_epoch_with_lookahead(netuid);
Comment on lines +41 to +43
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we reveal commits before knowing whether the subnet epoch will actually execute in this block. If MaxEpochsPerBlock has already been reached, the epoch can be deferred, leaving the revealed weights public before being used. That seems to weaken the commit-reveal property and may allow actors to react to revealed weights through other epoch-relevant state. Can we either reveal only on the successful execution path, or document/test why this gap is not exploitable?


// Weights revealed must have been committed during epoch `cur_epoch - reveal_period`.
let reveal_epoch = cur_epoch.saturating_sub(reveal_period);
Expand Down
4 changes: 4 additions & 0 deletions pallets/subtensor/src/coinbase/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ impl<T: Config> Pallet<T> {
MaxAllowedUids::<T>::remove(netuid);
ImmunityPeriod::<T>::remove(netuid);
ActivityCutoff::<T>::remove(netuid);
ActivityCutoffFactorMilli::<T>::remove(netuid);
LastEpochBlock::<T>::remove(netuid);
PendingEpochAt::<T>::remove(netuid);
SubnetEpochIndex::<T>::remove(netuid);
MinAllowedWeights::<T>::remove(netuid);
RegistrationsThisInterval::<T>::remove(netuid);
POWRegistrationsThisInterval::<T>::remove(netuid);
Expand Down
Loading
Loading