-
Notifications
You must be signed in to change notification settings - Fork 313
[Feature] Configurable Tempo & Owner-Triggered Epochs #2638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evgeny-s
wants to merge
13
commits into
devnet-ready
Choose a base branch
from
feature/dynamic-tempo
base: devnet-ready
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d30a76f
Dynamic tempo implementation
evgeny-s 42b3e29
clippy + fmt
evgeny-s c6567e2
clean up
evgeny-s ad7ba80
Renamed function + updated comment
evgeny-s df184e3
wrap set tempo + cycle reset with a helper function
evgeny-s b2e4658
tests
evgeny-s 02f43ee
clippy
evgeny-s 40f2773
Merge branch 'devnet-ready' into feature/dynamic-tempo
evgeny-s c3fa417
fixed test from devnet
evgeny-s dca9f44
Merge branch 'devnet-ready' into feature/dynamic-tempo
evgeny-s 73d1ab4
- disable dynamic tempo for subnets with CR enabled.
evgeny-s 1ba4a3d
- update migration - do not clamp tempos
evgeny-s 215f13b
fix migration test
evgeny-s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ pub mod root; | |
| pub mod run_coinbase; | ||
| pub mod subnet_emissions; | ||
| pub mod tao; | ||
| pub mod tempo_control; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| use super::*; | ||
| use crate::Error; | ||
| use frame_support::pallet_prelude::DispatchResult; | ||
| use sp_runtime::DispatchError; | ||
| use subtensor_runtime_common::NetUid; | ||
|
|
||
| use crate::system::pallet_prelude::OriginFor; | ||
| use crate::utils::rate_limiting::{Hyperparameter, TransactionType}; | ||
|
|
||
| impl<T: Config> Pallet<T> { | ||
| /// Owner-side `set_tempo` implementation. | ||
| pub fn do_set_tempo(origin: OriginFor<T>, netuid: NetUid, tempo: u16) -> DispatchResult { | ||
| let who = Self::ensure_subnet_owner(origin, netuid)?; | ||
|
|
||
| // Block dynamic tempo for any CR-enabled subnet | ||
| ensure!( | ||
| !Self::get_commit_reveal_weights_enabled(netuid), | ||
| Error::<T>::DynamicTempoBlockedByCommitReveal | ||
| ); | ||
|
|
||
| ensure!( | ||
| (MIN_TEMPO..=MAX_TEMPO).contains(&tempo), | ||
| Error::<T>::TempoOutOfBounds | ||
| ); | ||
|
|
||
| Self::ensure_admin_window_open(netuid)?; | ||
|
|
||
| let tx = TransactionType::TempoUpdate; | ||
| ensure!( | ||
| tx.passes_rate_limit_on_subnet::<T>(&who, netuid), | ||
| Error::<T>::TxRateLimitExceeded | ||
| ); | ||
|
|
||
| let now = Self::get_current_block_as_u64(); | ||
|
|
||
| Self::apply_tempo_with_cycle_reset(netuid, tempo); | ||
|
|
||
| tx.set_last_block_on_subnet::<T>(&who, netuid, now); | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Owner-side `set_activity_cutoff_factor` implementation. | ||
| pub fn do_set_activity_cutoff_factor( | ||
| origin: OriginFor<T>, | ||
| netuid: NetUid, | ||
| factor_milli: u32, | ||
| ) -> DispatchResult { | ||
| let who = Self::ensure_subnet_owner(origin, netuid)?; | ||
|
|
||
| ensure!( | ||
| (MIN_ACTIVITY_CUTOFF_FACTOR_MILLI..=MAX_ACTIVITY_CUTOFF_FACTOR_MILLI) | ||
| .contains(&factor_milli), | ||
| Error::<T>::ActivityCutoffFactorMilliOutOfBounds | ||
| ); | ||
|
|
||
| Self::ensure_admin_window_open(netuid)?; | ||
|
|
||
| let tx = TransactionType::OwnerHyperparamUpdate(Hyperparameter::ActivityCutoffFactorMilli); | ||
| ensure!( | ||
| tx.passes_rate_limit_on_subnet::<T>(&who, netuid), | ||
| Error::<T>::TxRateLimitExceeded | ||
| ); | ||
|
|
||
| let now = Self::get_current_block_as_u64(); | ||
|
|
||
| Self::set_activity_cutoff_factor_milli(netuid, factor_milli); | ||
| tx.set_last_block_on_subnet::<T>(&who, netuid, now); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Owner-side `trigger_epoch` implementation. | ||
| /// Schedules the triggered epoch to fire after `AdminFreezeWindow` blocks; that | ||
| /// countdown engages the freeze window for the subnet via `is_in_admin_freeze_window`. | ||
| pub fn do_trigger_epoch(origin: OriginFor<T>, netuid: NetUid) -> Result<(), DispatchError> { | ||
| let who = Self::ensure_subnet_owner(origin, netuid)?; | ||
|
|
||
| // Block for any CR-enabled subnet | ||
| ensure!( | ||
| !Self::get_commit_reveal_weights_enabled(netuid), | ||
| Error::<T>::DynamicTempoBlockedByCommitReveal | ||
| ); | ||
|
|
||
| // No `ensure_admin_window_open` here: trigger *defines* the next epoch. | ||
| ensure!( | ||
| PendingEpochAt::<T>::get(netuid) == 0, | ||
| Error::<T>::EpochTriggerAlreadyPending | ||
| ); | ||
|
|
||
| let tx = TransactionType::OwnerHyperparamUpdate(Hyperparameter::TriggerEpoch); | ||
| ensure!( | ||
| tx.passes_rate_limit_on_subnet::<T>(&who, netuid), | ||
| Error::<T>::TxRateLimitExceeded | ||
| ); | ||
|
|
||
| let now = Self::get_current_block_as_u64(); | ||
| let window = AdminFreezeWindow::<T>::get() as u64; | ||
| let fires_at = now.saturating_add(window); | ||
|
|
||
| PendingEpochAt::<T>::insert(netuid, fires_at); | ||
| tx.set_last_block_on_subnet::<T>(&who, netuid, now); | ||
|
|
||
| Self::deposit_event(Event::EpochTriggered { | ||
| netuid, | ||
| by: who, | ||
| fires_at, | ||
| }); | ||
| Ok(()) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that if tempo is set to 0, manual trigger or max cap of MAX_TEMPO will not work. Is this by design?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the previous implementation meant that if tempo is 0, we don't run tempo on this subnet.
We don't have this case in Mainnet, but we support it. There is still a possibility to set the tempo to 0 by the root.
So we support the same semantics.