From 630f7dfd2d1e673f9efb2eb23bb107480f9e831d Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 28 Aug 2025 23:46:52 +0800 Subject: [PATCH 01/10] not support commit reveal v3 --- pallets/subtensor/src/benchmarks.rs | 36 --------------- pallets/subtensor/src/macros/dispatches.rs | 44 ------------------- .../subtensor/src/transaction_extension.rs | 14 ------ 3 files changed, 94 deletions(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 5cdb47685..0329638e3 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -1599,40 +1599,4 @@ mod pallet_benchmarks { assert_eq!(TokenSymbol::::get(netuid), new_symbol); } - - #[benchmark] - fn commit_timelocked_weights() { - let hotkey: T::AccountId = whitelisted_caller(); - let netuid = NetUid::from(1); - let vec_commit: Vec = vec![0; MAX_CRV3_COMMIT_SIZE_BYTES as usize]; - let commit: BoundedVec<_, _> = vec_commit.try_into().unwrap(); - let round: u64 = 0; - - Subtensor::::init_new_network(netuid, 1); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - SubtokenEnabled::::insert(netuid, true); - - let reg_fee = Subtensor::::get_burn(netuid); - Subtensor::::add_balance_to_coldkey_account( - &hotkey, - reg_fee.saturating_mul(2.into()).into(), - ); - - assert_ok!(Subtensor::::burned_register( - RawOrigin::Signed(hotkey.clone()).into(), - netuid, - hotkey.clone() - )); - - Subtensor::::set_commit_reveal_weights_enabled(netuid, true); - - #[extrinsic_call] - _( - RawOrigin::Signed(hotkey.clone()), - netuid, - commit.clone(), - round, - Subtensor::::get_commit_reveal_weights_version(), - ); - } } diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index aed0c150d..2f7587db9 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -2175,49 +2175,5 @@ mod dispatches { Self::deposit_event(Event::SymbolUpdated { netuid, symbol }); Ok(()) } - - /// ---- Used to commit timelock encrypted commit-reveal weight values to later be revealed. - /// - /// # Args: - /// * `origin`: (`::RuntimeOrigin`): - /// - The committing hotkey. - /// - /// * `netuid` (`u16`): - /// - The u16 network identifier. - /// - /// * `commit` (`Vec`): - /// - The encrypted compressed commit. - /// The steps for this are: - /// 1. Instantiate [`WeightsTlockPayload`] - /// 2. Serialize it using the `parity_scale_codec::Encode` trait - /// 3. Encrypt it following the steps (here)[https://github.com/ideal-lab5/tle/blob/f8e6019f0fb02c380ebfa6b30efb61786dede07b/timelock/src/tlock.rs#L283-L336] - /// to produce a [`TLECiphertext`] type. - /// 4. Serialize and compress using the `ark-serialize` `CanonicalSerialize` trait. - /// - /// * reveal_round (`u64`): - /// - The drand reveal round which will be avaliable during epoch `n+1` from the current - /// epoch. - /// - /// * commit_reveal_version (`u16`): - /// - The client (bittensor-drand) version - #[pallet::call_index(113)] - #[pallet::weight((Weight::from_parts(64_530_000, 0) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] - pub fn commit_timelocked_weights( - origin: T::RuntimeOrigin, - netuid: NetUid, - commit: BoundedVec>, - reveal_round: u64, - commit_reveal_version: u16, - ) -> DispatchResult { - Self::do_commit_timelocked_weights( - origin, - netuid, - commit, - reveal_round, - commit_reveal_version, - ) - } } } diff --git a/pallets/subtensor/src/transaction_extension.rs b/pallets/subtensor/src/transaction_extension.rs index 99749032a..7a955ccc3 100644 --- a/pallets/subtensor/src/transaction_extension.rs +++ b/pallets/subtensor/src/transaction_extension.rs @@ -244,20 +244,6 @@ where Err(CustomTransactionError::StakeAmountTooLow.into()) } } - Some(Call::commit_timelocked_weights { - netuid, - reveal_round, - .. - }) => { - if Self::check_weights_min_stake(who, *netuid) { - if *reveal_round < pallet_drand::LastStoredRound::::get() { - return Err(CustomTransactionError::InvalidRevealRound.into()); - } - Ok((Default::default(), Some(who.clone()), origin)) - } else { - Err(CustomTransactionError::StakeAmountTooLow.into()) - } - } Some(Call::register { netuid, .. } | Call::burned_register { netuid, .. }) => { let registrations_this_interval = Pallet::::get_registrations_this_interval(*netuid); From 5e2094a0fb7b9c0770dea1e0dfda936e21dae057 Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 28 Aug 2025 23:48:34 +0800 Subject: [PATCH 02/10] bump version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 60687d3a3..00cc24b41 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 306, + spec_version: 307, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From e570914a65f946f27e04bfea0d646ffaa7431ee0 Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 28 Aug 2025 23:52:57 +0800 Subject: [PATCH 03/10] remove correct function --- pallets/subtensor/src/benchmarks.rs | 68 ++++++++------- pallets/subtensor/src/macros/dispatches.rs | 86 ++++++++++--------- .../subtensor/src/transaction_extension.rs | 2 +- 3 files changed, 81 insertions(+), 75 deletions(-) diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 0329638e3..fa7913f58 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -1092,38 +1092,6 @@ mod pallet_benchmarks { ); } - #[benchmark] - fn commit_crv3_weights() { - let hotkey: T::AccountId = whitelisted_caller(); - let netuid = NetUid::from(1); - let vec_commit: Vec = vec![0; MAX_CRV3_COMMIT_SIZE_BYTES as usize]; - let commit: BoundedVec<_, _> = vec_commit.try_into().unwrap(); - let round: u64 = 0; - - Subtensor::::init_new_network(netuid, 1); - Subtensor::::set_network_pow_registration_allowed(netuid, true); - SubtokenEnabled::::insert(netuid, true); - - let reg_fee = Subtensor::::get_burn(netuid); - Subtensor::::add_balance_to_coldkey_account(&hotkey, reg_fee.to_u64().saturating_mul(2)); - - assert_ok!(Subtensor::::burned_register( - RawOrigin::Signed(hotkey.clone()).into(), - netuid, - hotkey.clone() - )); - - Subtensor::::set_commit_reveal_weights_enabled(netuid, true); - - #[extrinsic_call] - _( - RawOrigin::Signed(hotkey.clone()), - netuid, - commit.clone(), - round, - ); - } - #[benchmark] fn decrease_take() { let coldkey: T::AccountId = whitelisted_caller(); @@ -1599,4 +1567,40 @@ mod pallet_benchmarks { assert_eq!(TokenSymbol::::get(netuid), new_symbol); } + + #[benchmark] + fn commit_timelocked_weights() { + let hotkey: T::AccountId = whitelisted_caller(); + let netuid = NetUid::from(1); + let vec_commit: Vec = vec![0; MAX_CRV3_COMMIT_SIZE_BYTES as usize]; + let commit: BoundedVec<_, _> = vec_commit.try_into().unwrap(); + let round: u64 = 0; + + Subtensor::::init_new_network(netuid, 1); + Subtensor::::set_network_pow_registration_allowed(netuid, true); + SubtokenEnabled::::insert(netuid, true); + + let reg_fee = Subtensor::::get_burn(netuid); + Subtensor::::add_balance_to_coldkey_account( + &hotkey, + reg_fee.saturating_mul(2.into()).into(), + ); + + assert_ok!(Subtensor::::burned_register( + RawOrigin::Signed(hotkey.clone()).into(), + netuid, + hotkey.clone() + )); + + Subtensor::::set_commit_reveal_weights_enabled(netuid, true); + + #[extrinsic_call] + _( + RawOrigin::Signed(hotkey.clone()), + netuid, + commit.clone(), + round, + Subtensor::::get_commit_reveal_weights_version(), + ); + } } diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 2f7587db9..7b559e45e 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -249,48 +249,6 @@ mod dispatches { Self::do_reveal_weights(origin, netuid, uids, values, salt, version_key) } - /// ---- Used to commit encrypted commit-reveal v3 weight values to later be revealed. - /// - /// # Args: - /// * `origin`: (`::RuntimeOrigin`): - /// - The committing hotkey. - /// - /// * `netuid` (`u16`): - /// - The u16 network identifier. - /// - /// * `commit` (`Vec`): - /// - The encrypted compressed commit. - /// The steps for this are: - /// 1. Instantiate [`WeightsTlockPayload`] - /// 2. Serialize it using the `parity_scale_codec::Encode` trait - /// 3. Encrypt it following the steps (here)[https://github.com/ideal-lab5/tle/blob/f8e6019f0fb02c380ebfa6b30efb61786dede07b/timelock/src/tlock.rs#L283-L336] - /// to produce a [`TLECiphertext`] type. - /// 4. Serialize and compress using the `ark-serialize` `CanonicalSerialize` trait. - /// - /// * reveal_round (`u64`): - /// - The drand reveal round which will be avaliable during epoch `n+1` from the current - /// epoch. - /// - /// # Raises: - /// * `CommitRevealV3Disabled`: - /// - Attempting to commit when the commit-reveal mechanism is disabled. - /// - /// * `TooManyUnrevealedCommits`: - /// - Attempting to commit when the user has more than the allowed limit of unrevealed commits. - /// - #[pallet::call_index(99)] - #[pallet::weight((Weight::from_parts(77_750_000, 0) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] - pub fn commit_crv3_weights( - origin: T::RuntimeOrigin, - netuid: NetUid, - commit: BoundedVec>, - reveal_round: u64, - ) -> DispatchResult { - Self::do_commit_timelocked_weights(origin, netuid, commit, reveal_round, 4) - } - /// ---- The implementation for batch revealing committed weights. /// /// # Args: @@ -2175,5 +2133,49 @@ mod dispatches { Self::deposit_event(Event::SymbolUpdated { netuid, symbol }); Ok(()) } + + /// ---- Used to commit timelock encrypted commit-reveal weight values to later be revealed. + /// + /// # Args: + /// * `origin`: (`::RuntimeOrigin`): + /// - The committing hotkey. + /// + /// * `netuid` (`u16`): + /// - The u16 network identifier. + /// + /// * `commit` (`Vec`): + /// - The encrypted compressed commit. + /// The steps for this are: + /// 1. Instantiate [`WeightsTlockPayload`] + /// 2. Serialize it using the `parity_scale_codec::Encode` trait + /// 3. Encrypt it following the steps (here)[https://github.com/ideal-lab5/tle/blob/f8e6019f0fb02c380ebfa6b30efb61786dede07b/timelock/src/tlock.rs#L283-L336] + /// to produce a [`TLECiphertext`] type. + /// 4. Serialize and compress using the `ark-serialize` `CanonicalSerialize` trait. + /// + /// * reveal_round (`u64`): + /// - The drand reveal round which will be avaliable during epoch `n+1` from the current + /// epoch. + /// + /// * commit_reveal_version (`u16`): + /// - The client (bittensor-drand) version + #[pallet::call_index(113)] + #[pallet::weight((Weight::from_parts(64_530_000, 0) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] + pub fn commit_timelocked_weights( + origin: T::RuntimeOrigin, + netuid: NetUid, + commit: BoundedVec>, + reveal_round: u64, + commit_reveal_version: u16, + ) -> DispatchResult { + Self::do_commit_timelocked_weights( + origin, + netuid, + commit, + reveal_round, + commit_reveal_version, + ) + } } } diff --git a/pallets/subtensor/src/transaction_extension.rs b/pallets/subtensor/src/transaction_extension.rs index 7a955ccc3..ccf7bbad2 100644 --- a/pallets/subtensor/src/transaction_extension.rs +++ b/pallets/subtensor/src/transaction_extension.rs @@ -230,7 +230,7 @@ where Err(CustomTransactionError::StakeAmountTooLow.into()) } } - Some(Call::commit_crv3_weights { + Some(Call::commit_timelocked_weights { netuid, reveal_round, .. From aeb5852bfbbe9fcbd648f6d85006f1229063fa82 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 28 Aug 2025 18:02:04 +0000 Subject: [PATCH 04/10] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 7b559e45e..d6767af8c 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -120,9 +120,9 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(80)] - #[pallet::weight((Weight::from_parts(95_160_000, 0) - .saturating_add(T::DbWeight::get().reads(14)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] + #[pallet::weight((Weight::from_parts(19_170_000, 0) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( origin: OriginFor, netuids: Vec>, From fee24593ee4c764937dd579f046bd3a80d56fd7f Mon Sep 17 00:00:00 2001 From: open-junius Date: Tue, 2 Sep 2025 20:32:55 +0800 Subject: [PATCH 05/10] bump version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 00cc24b41..679e5e55b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 307, + spec_version: 308, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 251ad7088341845cb05ca72d36e2b495dbf07a84 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 2 Sep 2025 14:39:35 +0000 Subject: [PATCH 06/10] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 38d6d959a..1a0802431 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -120,9 +120,9 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(80)] - #[pallet::weight((Weight::from_parts(19_330_000, 0) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))] + #[pallet::weight((Weight::from_parts(94_660_000, 0) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( origin: OriginFor, netuids: Vec>, @@ -2159,7 +2159,7 @@ mod dispatches { /// * commit_reveal_version (`u16`): /// - The client (bittensor-drand) version #[pallet::call_index(113)] - #[pallet::weight((Weight::from_parts(64_530_000, 0) + #[pallet::weight((Weight::from_parts(83_450_000, 0) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_timelocked_weights( From 60fdadf6bb146ce235f231732b14c3992646ba43 Mon Sep 17 00:00:00 2001 From: open-junius Date: Wed, 3 Sep 2025 20:27:59 +0800 Subject: [PATCH 07/10] bump version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index f0dce12ca..55dd9fb11 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 308, + spec_version: 309, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 633ddea1fc637c1a858edbbb79b529cd714e3563 Mon Sep 17 00:00:00 2001 From: open-junius Date: Thu, 4 Sep 2025 09:04:19 +0800 Subject: [PATCH 08/10] bump version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index cc9c02eca..644a85ebc 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 309, + spec_version: 310, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From fc5ef70a4a22d1df79b16dbe53339e6027480fba Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 4 Sep 2025 03:00:22 +0000 Subject: [PATCH 09/10] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 695d9ff52..66a218d7c 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -1989,7 +1989,7 @@ mod dispatches { /// * commit_reveal_version (`u16`): /// - The client (bittensor-drand) version #[pallet::call_index(113)] - #[pallet::weight((Weight::from_parts(83_450_000, 0) + #[pallet::weight((Weight::from_parts(65_020_000, 0) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] pub fn commit_timelocked_weights( From bdde256c257dbf3f257054549901ac9637a4be39 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 4 Sep 2025 17:24:26 +0000 Subject: [PATCH 10/10] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 31ee31d56..618244487 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -761,7 +761,7 @@ mod dispatches { /// Attempt to adjust the senate membership to include a hotkey #[pallet::call_index(63)] - #[pallet::weight((Weight::from_parts(60_720_000, 0) + #[pallet::weight((Weight::from_parts(75_430_000, 0) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)), DispatchClass::Normal, Pays::Yes))] pub fn adjust_senate(origin: OriginFor, hotkey: T::AccountId) -> DispatchResult {