Skip to content
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

Commit reveal 2 Improvements #893

Merged
merged 15 commits into from
Oct 31, 2024
4 changes: 2 additions & 2 deletions pallets/admin-utils/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ mod benchmarks {
}

#[benchmark]
fn sudo_set_commit_reveal_weights_periods() {
fn sudo_set_commit_reveal_weights_interval() {
pallet_subtensor::Pallet::<T>::init_new_network(
1u16, /*netuid*/
1u16, /*sudo_tempo*/
);

#[extrinsic_call]
_(RawOrigin::Root, 1u16/*netuid*/, 3u64/*interval*/)/*set_commit_reveal_weights_periods()*/;
_(RawOrigin::Root, 1u16/*netuid*/, 3u64/*interval*/)/*sudo_set_commit_reveal_weights_interval()*/;
}

#[benchmark]
Expand Down
14 changes: 7 additions & 7 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,12 +1187,12 @@ pub mod pallet {
///
/// # Weight
/// Weight is handled by the `#[pallet::weight]` attribute.
#[pallet::call_index(56)]
#[pallet::weight(T::WeightInfo::sudo_set_commit_reveal_weights_periods())]
pub fn sudo_set_commit_reveal_weights_periods(
#[pallet::call_index(57)]
#[pallet::weight(T::WeightInfo::sudo_set_commit_reveal_weights_interval())]
pub fn sudo_set_commit_reveal_weights_interval(
origin: OriginFor<T>,
netuid: u16,
periods: u64,
interval: u64,
) -> DispatchResult {
pallet_subtensor::Pallet::<T>::ensure_subnet_owner_or_root(origin, netuid)?;

Expand All @@ -1201,11 +1201,11 @@ pub mod pallet {
Error::<T>::SubnetDoesNotExist
);

pallet_subtensor::Pallet::<T>::set_reveal_period(netuid, periods);
pallet_subtensor::Pallet::<T>::set_reveal_period(netuid, interval);
log::debug!(
"SetWeightCommitPeriods( netuid: {:?}, periods: {:?} ) ",
"SetWeightCommitInterval( netuid: {:?}, interval: {:?} ) ",
netuid,
periods
interval
);
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/admin-utils/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub trait WeightInfo {
fn sudo_set_min_burn() -> Weight;
fn sudo_set_network_registration_allowed() -> Weight;
fn sudo_set_tempo() -> Weight;
fn sudo_set_commit_reveal_weights_periods() -> Weight;
fn sudo_set_commit_reveal_weights_interval() -> Weight;
fn sudo_set_commit_reveal_weights_enabled() -> Weight;
}

Expand Down Expand Up @@ -413,7 +413,7 @@ 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_commit_reveal_weights_periods() -> Weight {
fn sudo_set_commit_reveal_weights_interval() -> Weight {
// Proof Size summary in bytes:
// Measured: `456`
// Estimated: `3921`
Expand Down Expand Up @@ -781,7 +781,7 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
fn sudo_set_commit_reveal_weights_periods() -> Weight {
fn sudo_set_commit_reveal_weights_interval() -> Weight {
// -- Extrinsic Time --
// Model:
// Time ~= 19.38
Expand Down
4 changes: 2 additions & 2 deletions pallets/admin-utils/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1414,15 +1414,15 @@ fn test_sudo_set_dissolve_network_schedule_duration() {
}

#[test]
fn sudo_set_commit_reveal_weights_periods() {
fn sudo_set_commit_reveal_weights_interval() {
new_test_ext().execute_with(|| {
let netuid: u16 = 1;
add_network(netuid, 10);

let to_be_set = 55;
let init_value = SubtensorModule::get_reveal_period(netuid);

assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_periods(
assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
to_be_set
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ pub mod pallet {
0
}
#[pallet::type_value]
/// Default minimum stake for weights.
/// Default Reveal Period Epochs
pub fn DefaultRevealPeriodEpochs<T: Config>() -> u64 {
1
}
Expand Down Expand Up @@ -1251,14 +1251,14 @@ pub mod pallet {
/// ITEM( weights_min_stake )
pub type WeightsMinStake<T> = StorageValue<_, u64, ValueQuery, DefaultWeightsMinStake<T>>;
#[pallet::storage]
/// --- MAP (netuid, who) --> VecDeque<(hash, commit_block)> | Stores a queue of commits for an account on a given netuid.
/// --- MAP (netuid, who) --> VecDeque<(hash, commit_block, first_reveal_block, last_reveal_block)> | Stores a queue of commits for an account on a given netuid.
pub type WeightCommits<T: Config> = StorageDoubleMap<
_,
Twox64Concat,
u16,
Twox64Concat,
T::AccountId,
VecDeque<(H256, u64)>,
VecDeque<(H256, u64, u64, u64)>,
OptionQuery,
>;
#[pallet::storage]
Expand Down
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,7 @@ mod errors {
RevealTooEarly,
/// Attempted to batch reveal weights with mismatched vector input lenghts.
InputLengthsUnequal,
/// A transactor exceeded the rate limit for setting weights.
CommittingWeightsTooFast,
}
}
20 changes: 20 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,25 @@ mod events {
ColdkeySwapScheduleDurationSet(BlockNumberFor<T>),
/// The duration of dissolve network has been set
DissolveNetworkScheduleDurationSet(BlockNumberFor<T>),
/// Weights have been successfully committed.
///
/// - **who**: The account ID of the user committing the weights.
/// - **netuid**: The network identifier.
/// - **commit_hash**: The hash representing the committed weights.
WeightsCommitted(T::AccountId, u16, H256),

/// Weights have been successfully revealed.
///
/// - **who**: The account ID of the user revealing the weights.
/// - **netuid**: The network identifier.
/// - **commit_hash**: The hash of the revealed weights.
WeightsRevealed(T::AccountId, u16, H256),

/// Weights have been successfully batch revealed.
///
/// - **who**: The account ID of the user revealing the weights.
/// - **netuid**: The network identifier.
/// - **revealed_hashes**: A vector of hashes representing each revealed weight set.
WeightsBatchRevealed(T::AccountId, u16, Vec<H256>),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use scale_info::prelude::string::String;
use sp_io::{hashing::twox_128, storage::clear_prefix, KillStorageResult};

pub fn migrate_commit_reveal_2<T: Config>() -> Weight {
let migration_name = b"migrate_commit_reveal_2".to_vec();
let migration_name = b"migrate_commit_reveal_2_v2".to_vec();
let mut weight = T::DbWeight::get().reads(1);

if HasMigrationRun::<T>::get(&migration_name) {
Expand Down
6 changes: 3 additions & 3 deletions pallets/subtensor/src/rpc_info/subnet_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct SubnetInfov2<T: Config> {
identity: Option<SubnetIdentity>,
}

#[freeze_struct("4ceb81dfe8a8f96d")]
#[freeze_struct("55b472510f10e76a")]
#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
pub struct SubnetHyperparams {
rho: Compact<u16>,
Expand All @@ -76,7 +76,7 @@ pub struct SubnetHyperparams {
max_validators: Compact<u16>,
adjustment_alpha: Compact<u64>,
difficulty: Compact<u64>,
commit_reveal_periods: Compact<u64>,
commit_reveal_weights_interval: Compact<u64>,
commit_reveal_weights_enabled: bool,
alpha_high: Compact<u16>,
alpha_low: Compact<u16>,
Expand Down Expand Up @@ -280,7 +280,7 @@ impl<T: Config> Pallet<T> {
max_validators: max_validators.into(),
adjustment_alpha: adjustment_alpha.into(),
difficulty: difficulty.into(),
commit_reveal_periods: commit_reveal_periods.into(),
commit_reveal_weights_interval: commit_reveal_periods.into(),
commit_reveal_weights_enabled,
alpha_high: alpha_high.into(),
alpha_low: alpha_low.into(),
Expand Down
Loading
Loading