@@ -68,6 +68,7 @@ pub mod pallet {
6868 traits:: { tokens:: fungible, UnfilteredDispatchable } ,
6969 } ;
7070 use frame_system:: pallet_prelude:: * ;
71+ use sp_core:: H256 ;
7172 use sp_runtime:: traits:: TrailingZeroInput ;
7273 use sp_std:: vec;
7374 use sp_std:: vec:: Vec ;
@@ -786,6 +787,27 @@ pub mod pallet {
786787 pub type AdjustmentAlpha < T : Config > =
787788 StorageMap < _ , Identity , u16 , u64 , ValueQuery , DefaultAdjustmentAlpha < T > > ;
788789
790+ // --- MAP (netuid, who) --> (hash, weight) | Returns the hash and weight committed by an account for a given netuid.
791+ #[ pallet:: storage]
792+ pub type WeightCommits < T : Config > = StorageDoubleMap <
793+ _ ,
794+ Twox64Concat ,
795+ u16 ,
796+ Twox64Concat ,
797+ T :: AccountId ,
798+ ( H256 , u64 ) ,
799+ OptionQuery ,
800+ > ;
801+
802+ #[ pallet:: type_value]
803+ pub fn DefaultWeightCommitRevealInterval < T : Config > ( ) -> u64 {
804+ 1000
805+ }
806+
807+ #[ pallet:: storage]
808+ pub type WeightCommitRevealInterval < T > =
809+ StorageValue < _ , u64 , ValueQuery , DefaultWeightCommitRevealInterval < T > > ;
810+
789811 // =======================================
790812 // ==== Subnetwork Consensus Storage ====
791813 // =======================================
@@ -1184,8 +1206,8 @@ pub mod pallet {
11841206 // - Attempting to set weights with max value exceeding limit.
11851207 #[ pallet:: call_index( 0 ) ]
11861208 #[ pallet:: weight( ( Weight :: from_parts( 10_151_000_000 , 0 )
1187- . saturating_add( T :: DbWeight :: get( ) . reads( 4104 ) )
1188- . saturating_add( T :: DbWeight :: get( ) . writes( 2 ) ) , DispatchClass :: Normal , Pays :: No ) ) ]
1209+ . saturating_add( T :: DbWeight :: get( ) . reads( 4104 ) )
1210+ . saturating_add( T :: DbWeight :: get( ) . writes( 2 ) ) , DispatchClass :: Normal , Pays :: No ) ) ]
11891211 pub fn set_weights (
11901212 origin : OriginFor < T > ,
11911213 netuid : u16 ,
@@ -1196,6 +1218,76 @@ pub mod pallet {
11961218 Self :: do_set_weights ( origin, netuid, dests, weights, version_key)
11971219 }
11981220
1221+ /// ---- Used to commit a hash of your weight values to later be revealed.
1222+ ///
1223+ /// # Args:
1224+ /// * `origin`: (`<T as frame_system::Config>::RuntimeOrigin`):
1225+ /// - The signature of the committing hotkey.
1226+ ///
1227+ /// * `netuid` (`u16`):
1228+ /// - The u16 network identifier.
1229+ ///
1230+ /// * `commit_hash` (`H256`):
1231+ /// - The hash representing the committed weights.
1232+ ///
1233+ /// # Raises:
1234+ /// * `CommitNotAllowed`:
1235+ /// - Attempting to commit when it is not allowed.
1236+ ///
1237+ #[ pallet:: call_index( 96 ) ]
1238+ #[ pallet:: weight( ( Weight :: from_parts( 46_000_000 , 0 )
1239+ . saturating_add( T :: DbWeight :: get( ) . reads( 1 ) )
1240+ . saturating_add( T :: DbWeight :: get( ) . writes( 1 ) ) , DispatchClass :: Normal , Pays :: No ) ) ]
1241+ pub fn commit_weights (
1242+ origin : T :: RuntimeOrigin ,
1243+ netuid : u16 ,
1244+ commit_hash : H256 ,
1245+ ) -> DispatchResult {
1246+ Self :: do_commit_weights ( origin, netuid, commit_hash)
1247+ }
1248+
1249+ /// ---- Used to reveal the weights for a previously committed hash.
1250+ ///
1251+ /// # Args:
1252+ /// * `origin`: (`<T as frame_system::Config>::RuntimeOrigin`):
1253+ /// - The signature of the revealing hotkey.
1254+ ///
1255+ /// * `netuid` (`u16`):
1256+ /// - The u16 network identifier.
1257+ ///
1258+ /// * `uids` (`Vec<u16>`):
1259+ /// - The uids for the weights being revealed.
1260+ ///
1261+ /// * `values` (`Vec<u16>`):
1262+ /// - The values of the weights being revealed.
1263+ ///
1264+ /// * `version_key` (`u64`):
1265+ /// - The network version key.
1266+ ///
1267+ /// # Raises:
1268+ /// * `NoCommitFound`:
1269+ /// - Attempting to reveal weights without an existing commit.
1270+ ///
1271+ /// * `InvalidRevealTempo`:
1272+ /// - Attempting to reveal weights outside the valid tempo.
1273+ ///
1274+ /// * `InvalidReveal`:
1275+ /// - The revealed hash does not match the committed hash.
1276+ ///
1277+ #[ pallet:: call_index( 97 ) ]
1278+ #[ pallet:: weight( ( Weight :: from_parts( 103_000_000 , 0 )
1279+ . saturating_add( T :: DbWeight :: get( ) . reads( 11 ) )
1280+ . saturating_add( T :: DbWeight :: get( ) . writes( 3 ) ) , DispatchClass :: Normal , Pays :: No ) ) ]
1281+ pub fn reveal_weights (
1282+ origin : T :: RuntimeOrigin ,
1283+ netuid : u16 ,
1284+ uids : Vec < u16 > ,
1285+ values : Vec < u16 > ,
1286+ version_key : u64 ,
1287+ ) -> DispatchResult {
1288+ Self :: do_reveal_weights ( origin, netuid, uids, values, version_key)
1289+ }
1290+
11991291 // # Args:
12001292 // * `origin`: (<T as frame_system::Config>Origin):
12011293 // - The caller, a hotkey who wishes to set their weights.
@@ -1756,7 +1848,7 @@ pub mod pallet {
17561848
17571849 #[ pallet:: call_index( 60 ) ]
17581850 #[ pallet:: weight( ( Weight :: from_parts( 91_000_000 , 0 )
1759- . saturating_add( T :: DbWeight :: get( ) . reads( 27 ) )
1851+ . saturating_add( T :: DbWeight :: get( ) . reads( 27 ) )
17601852 . saturating_add( T :: DbWeight :: get( ) . writes( 22 ) ) , DispatchClass :: Normal , Pays :: No ) ) ]
17611853 pub fn faucet (
17621854 origin : OriginFor < T > ,
@@ -1908,6 +2000,30 @@ where
19082000 _len : usize ,
19092001 ) -> TransactionValidity {
19102002 match call. is_sub_type ( ) {
2003+ Some ( Call :: commit_weights { netuid, .. } ) => {
2004+ if Self :: check_weights_min_stake ( who) {
2005+ let priority: u64 = Self :: get_priority_set_weights ( who, * netuid) ;
2006+ Ok ( ValidTransaction {
2007+ priority,
2008+ longevity : 1 ,
2009+ ..Default :: default ( )
2010+ } )
2011+ } else {
2012+ Err ( InvalidTransaction :: Call . into ( ) )
2013+ }
2014+ }
2015+ Some ( Call :: reveal_weights { netuid, .. } ) => {
2016+ if Self :: check_weights_min_stake ( who) {
2017+ let priority: u64 = Self :: get_priority_set_weights ( who, * netuid) ;
2018+ Ok ( ValidTransaction {
2019+ priority,
2020+ longevity : 1 ,
2021+ ..Default :: default ( )
2022+ } )
2023+ } else {
2024+ Err ( InvalidTransaction :: Call . into ( ) )
2025+ }
2026+ }
19112027 Some ( Call :: set_weights { netuid, .. } ) => {
19122028 if Self :: check_weights_min_stake ( who) {
19132029 let priority: u64 = Self :: get_priority_set_weights ( who, * netuid) ;
@@ -1986,6 +2102,14 @@ where
19862102 let transaction_fee = 0 ;
19872103 Ok ( ( CallType :: SetWeights , transaction_fee, who. clone ( ) ) )
19882104 }
2105+ Some ( Call :: commit_weights { .. } ) => {
2106+ let transaction_fee = 0 ;
2107+ Ok ( ( CallType :: SetWeights , transaction_fee, who. clone ( ) ) )
2108+ }
2109+ Some ( Call :: reveal_weights { .. } ) => {
2110+ let transaction_fee = 0 ;
2111+ Ok ( ( CallType :: SetWeights , transaction_fee, who. clone ( ) ) )
2112+ }
19892113 Some ( Call :: register { .. } ) => {
19902114 let transaction_fee = 0 ;
19912115 Ok ( ( CallType :: Register , transaction_fee, who. clone ( ) ) )
0 commit comments