@@ -172,7 +172,7 @@ pub mod pallet {
172172 u16 ,
173173 Twox64Concat ,
174174 T :: AccountId ,
175- RevealedData < BalanceOf < T > , T :: MaxFields , BlockNumberFor < T > > ,
175+ Vec < ( Vec < u8 > , u64 ) > , // Reveals<(Data, RevealBlock)>
176176 OptionQuery ,
177177 > ;
178178
@@ -221,11 +221,13 @@ pub mod pallet {
221221
222222 let cur_block = <frame_system:: Pallet < T > >:: block_number ( ) ;
223223
224+ let min_used_space: u64 = 100 ;
224225 let required_space: u64 = info
225226 . fields
226227 . iter ( )
227228 . map ( |field| field. len_for_rate_limit ( ) )
228- . sum ( ) ;
229+ . sum :: < u64 > ( )
230+ . max ( min_used_space) ;
229231
230232 let mut usage = UsedSpaceOf :: < T > :: get ( netuid, & who) . unwrap_or_default ( ) ;
231233 let cur_block_u64 = cur_block. saturated_into :: < u64 > ( ) ;
@@ -478,7 +480,6 @@ where
478480
479481impl < T : Config > Pallet < T > {
480482 pub fn reveal_timelocked_commitments ( ) -> DispatchResult {
481- let current_block = <frame_system:: Pallet < T > >:: block_number ( ) ;
482483 let index = TimelockedIndex :: < T > :: get ( ) ;
483484 for ( netuid, who) in index. clone ( ) {
484485 let Some ( mut registration) = <CommitmentOf < T > >:: get ( netuid, & who) else {
@@ -528,10 +529,7 @@ impl<T: Config> Pallet<T> {
528529 . ok ( ) ;
529530
530531 let Some ( sig) = sig else {
531- remain_fields. push ( Data :: TimelockEncrypted {
532- encrypted,
533- reveal_round,
534- } ) ;
532+ log:: warn!( "No sig after deserialization" ) ;
535533 continue ;
536534 } ;
537535
@@ -547,10 +545,7 @@ impl<T: Config> Pallet<T> {
547545 . ok ( ) ;
548546
549547 let Some ( commit) = commit else {
550- remain_fields. push ( Data :: TimelockEncrypted {
551- encrypted,
552- reveal_round,
553- } ) ;
548+ log:: warn!( "No commit after deserialization" ) ;
554549 continue ;
555550 } ;
556551
@@ -563,61 +558,41 @@ impl<T: Config> Pallet<T> {
563558 . unwrap_or_default ( ) ;
564559
565560 if decrypted_bytes. is_empty ( ) {
566- remain_fields. push ( Data :: TimelockEncrypted {
567- encrypted,
568- reveal_round,
569- } ) ;
561+ log:: warn!( "Bytes were decrypted for {:?} but they are empty" , who) ;
570562 continue ;
571563 }
572564
573- let mut reader = & decrypted_bytes[ ..] ;
574- let revealed_info: CommitmentInfo < T :: MaxFields > =
575- match Decode :: decode ( & mut reader) {
576- Ok ( info) => info,
577- Err ( e) => {
578- log:: warn!(
579- "Failed to decode decrypted data for {:?}: {:?}" ,
580- who,
581- e
582- ) ;
583- remain_fields. push ( Data :: TimelockEncrypted {
584- encrypted,
585- reveal_round,
586- } ) ;
587- continue ;
588- }
589- } ;
590-
591- revealed_fields. push ( revealed_info) ;
565+ revealed_fields. push ( decrypted_bytes) ;
592566 }
593567
594568 other => remain_fields. push ( other) ,
595569 }
596570 }
597571
598572 if !revealed_fields. is_empty ( ) {
599- let mut all_revealed_data = Vec :: new ( ) ;
600- for info in revealed_fields {
601- all_revealed_data. extend ( info. fields . into_inner ( ) ) ;
602- }
573+ let mut existing_reveals =
574+ RevealedCommitments :: < T > :: get ( netuid, & who) . unwrap_or_default ( ) ;
603575
604- let bounded_revealed = BoundedVec :: try_from ( all_revealed_data )
605- . map_err ( |_| "Could not build BoundedVec for revealed fields" ) ? ;
576+ let current_block = <frame_system :: Pallet < T > > :: block_number ( ) ;
577+ let block_u64 = current_block . saturated_into :: < u64 > ( ) ;
606578
607- let combined_revealed_info = CommitmentInfo {
608- fields : bounded_revealed ,
609- } ;
579+ // Push newly revealed items onto the tail of existing_reveals and emit the event
580+ for revealed_bytes in revealed_fields {
581+ existing_reveals . push ( ( revealed_bytes , block_u64 ) ) ;
610582
611- let revealed_data = RevealedData {
612- info : combined_revealed_info,
613- revealed_block : current_block,
614- deposit : registration. deposit ,
615- } ;
616- <RevealedCommitments < T > >:: insert ( netuid, & who, revealed_data) ;
617- Self :: deposit_event ( Event :: CommitmentRevealed {
618- netuid,
619- who : who. clone ( ) ,
620- } ) ;
583+ Self :: deposit_event ( Event :: CommitmentRevealed {
584+ netuid,
585+ who : who. clone ( ) ,
586+ } ) ;
587+ }
588+
589+ const MAX_REVEALS : usize = 10 ;
590+ if existing_reveals. len ( ) > MAX_REVEALS {
591+ let remove_count = existing_reveals. len ( ) . saturating_sub ( MAX_REVEALS ) ;
592+ existing_reveals. drain ( 0 ..remove_count) ;
593+ }
594+
595+ RevealedCommitments :: < T > :: insert ( netuid, & who, existing_reveals) ;
621596 }
622597
623598 registration. info . fields = BoundedVec :: try_from ( remain_fields)
0 commit comments