@@ -8,6 +8,8 @@ use frame_benchmarking::{account, benchmarks, whitelisted_caller};
88use frame_support:: assert_ok;
99use frame_system:: RawOrigin ;
1010pub use pallet:: * ;
11+ use sp_core:: H256 ;
12+ use sp_runtime:: traits:: { BlakeTwo256 , Hash } ;
1113use sp_std:: vec;
1214
1315benchmarks ! {
@@ -333,4 +335,91 @@ benchmarks! {
333335 assert_ok!( Subtensor :: <T >:: add_stake( RawOrigin :: Signed ( coldkey) . into( ) , old_hotkey. clone( ) , 1_000_000_000 ) ) ;
334336 }
335337 } : _( RawOrigin :: Signed ( coldkey) , old_hotkey, new_hotkey)
338+
339+ commit_weights {
340+ let tempo: u16 = 1 ;
341+ let netuid: u16 = 1 ;
342+ let version_key: u64 = 0 ;
343+ let uids: Vec <u16 > = vec![ 0 ] ;
344+ let weight_values: Vec <u16 > = vec![ 10 ] ;
345+ let hotkey: T :: AccountId = account( "hot" , 0 , 1 ) ;
346+ let coldkey: T :: AccountId = account( "cold" , 0 , 2 ) ;
347+ let start_nonce = 300000 ;
348+
349+ let commit_hash: H256 = BlakeTwo256 :: hash_of( & (
350+ hotkey. clone( ) ,
351+ netuid,
352+ uids. clone( ) ,
353+ weight_values. clone( ) ,
354+ version_key,
355+ ) ) ;
356+
357+ Subtensor :: <T >:: init_new_network( netuid, tempo) ;
358+
359+ let block_number: u64 = Subtensor :: <T >:: get_current_block_as_u64( ) ;
360+ let ( nonce, work) : ( u64 , Vec <u8 >) = Subtensor :: <T >:: create_work_for_block_number(
361+ netuid,
362+ block_number,
363+ start_nonce,
364+ & hotkey,
365+ ) ;
366+ let result = Subtensor :: <T >:: register(
367+ <T as frame_system:: Config >:: RuntimeOrigin :: from( RawOrigin :: Signed ( hotkey. clone( ) ) ) ,
368+ netuid,
369+ block_number,
370+ nonce,
371+ work,
372+ hotkey. clone( ) ,
373+ coldkey,
374+ ) ;
375+ Subtensor :: <T >:: set_validator_permit_for_uid( netuid, 0 , true ) ;
376+
377+ } : commit_weights( RawOrigin :: Signed ( hotkey. clone( ) ) , netuid, commit_hash)
378+
379+ reveal_weights {
380+ let tempo: u16 = 0 ;
381+ let netuid: u16 = 1 ;
382+ let version_key: u64 = 0 ;
383+ let uids: Vec <u16 > = vec![ 0 ] ;
384+ let weight_values: Vec <u16 > = vec![ 10 ] ;
385+ let hotkey: T :: AccountId = account( "hot" , 0 , 1 ) ;
386+ let coldkey: T :: AccountId = account( "cold" , 1 , 2 ) ;
387+ let hotkey2: T :: AccountId = account( "hot2" , 2 , 3 ) ;
388+ let coldkey2: T :: AccountId = account( "cold2" , 3 , 4 ) ;
389+
390+ Subtensor :: <T >:: init_new_network( netuid, tempo) ;
391+ Subtensor :: <T >:: set_network_registration_allowed( netuid, true ) ;
392+ Subtensor :: <T >:: set_network_pow_registration_allowed( netuid, true ) ;
393+
394+ let block_number: u64 = Subtensor :: <T >:: get_current_block_as_u64( ) ;
395+ let ( nonce, work) : ( u64 , Vec <u8 >) = Subtensor :: <T >:: create_work_for_block_number(
396+ netuid,
397+ block_number,
398+ 3 ,
399+ & hotkey,
400+ ) ;
401+
402+ let _ = Subtensor :: <T >:: register(
403+ <T as frame_system:: Config >:: RuntimeOrigin :: from( RawOrigin :: Signed ( hotkey. clone( ) ) ) ,
404+ netuid,
405+ block_number,
406+ nonce,
407+ work. clone( ) ,
408+ hotkey. clone( ) ,
409+ coldkey. clone( ) ,
410+ ) ;
411+
412+ Subtensor :: <T >:: set_validator_permit_for_uid( netuid, 0 , true ) ;
413+ Subtensor :: <T >:: set_weight_commit_interval( 0 ) ;
414+
415+ let commit_hash: H256 = BlakeTwo256 :: hash_of( & (
416+ hotkey. clone( ) ,
417+ netuid,
418+ uids. clone( ) ,
419+ weight_values. clone( ) ,
420+ version_key,
421+ ) ) ;
422+ let _ = Subtensor :: <T >:: commit_weights( <T as frame_system:: Config >:: RuntimeOrigin :: from( RawOrigin :: Signed ( hotkey. clone( ) ) ) , netuid, commit_hash) ;
423+
424+ } : reveal_weights( RawOrigin :: Signed ( hotkey. clone( ) ) , netuid, uids, weight_values, version_key)
336425}
0 commit comments