@@ -31,16 +31,19 @@ use sp_runtime::{
3131use sp_std:: { fmt:: Debug , iter:: once, prelude:: * } ;
3232use subtensor_macros:: freeze_struct;
3333
34- /// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater
35- /// than 32-bytes then it will be truncated when encoding.
36- ///
37- /// Can also be `None`.
34+ /// Represents stored data which can be:
35+ /// - `Raw`: a direct blob up to 128 bytes
36+ /// - `BigRaw`: a larger blob up to 512 bytes
37+ /// - A cryptographic hash (BlakeTwo256, Sha256, Keccak256, ShaThree256)
38+ /// - A timelock-encrypted blob with a reveal round
39+ /// - A reset flag (`ResetBondsFlag`)
40+ /// Can also be `None`.
3841#[ derive( Clone , Eq , PartialEq , RuntimeDebug , MaxEncodedLen ) ]
3942pub enum Data {
4043 /// No data here.
4144 None ,
42- /// The data is stored directly.
43- Raw ( BoundedVec < u8 , ConstU32 < 512 > > ) ,
45+ /// The data is stored directly (up to 128 bytes) .
46+ Raw ( BoundedVec < u8 , ConstU32 < 128 > > ) ,
4447 /// Only the Blake2 hash of the data is stored. The preimage of the hash may be retrieved
4548 /// through some hash-lookup service.
4649 BlakeTwo256 ( [ u8 ; 32 ] ) ,
@@ -60,6 +63,8 @@ pub enum Data {
6063 } ,
6164 /// Flag to trigger bonds reset for subnet
6265 ResetBondsFlag ,
66+ /// The data is stored directly (up to 512 bytes).
67+ BigRaw ( BoundedVec < u8 , ConstU32 < MAX_BIGRAW_COMMITMENT_SIZE_BYTES > > ) ,
6368}
6469
6570impl Data {
@@ -82,6 +87,7 @@ impl Data {
8287 | Data :: ShaThree256 ( arr) => arr. len ( ) as u64 ,
8388 Data :: TimelockEncrypted { encrypted, .. } => encrypted. len ( ) as u64 ,
8489 Data :: ResetBondsFlag => 0 ,
90+ Data :: BigRaw ( bytes) => bytes. len ( ) as u64 ,
8591 }
8692 }
8793}
@@ -112,6 +118,11 @@ impl Decode for Data {
112118 }
113119 }
114120 135 => Data :: ResetBondsFlag ,
121+ 136 => {
122+ let bigvec =
123+ BoundedVec :: < u8 , ConstU32 < MAX_BIGRAW_COMMITMENT_SIZE_BYTES > > :: decode ( input) ?;
124+ Data :: BigRaw ( bigvec)
125+ }
115126 _ => return Err ( codec:: Error :: from ( "invalid leading byte" ) ) ,
116127 } )
117128 }
@@ -141,6 +152,11 @@ impl Encode for Data {
141152 r
142153 }
143154 Data :: ResetBondsFlag => vec ! [ 135 ] ,
155+ Data :: BigRaw ( bigvec) => {
156+ let mut r = vec ! [ 136 ] ;
157+ r. extend_from_slice ( & bigvec. encode ( ) ) ;
158+ r
159+ }
144160 }
145161 }
146162}
@@ -327,7 +343,12 @@ impl TypeInfo for Data {
327343 . field ( |f| f. name ( "reveal_round" ) . ty :: < u64 > ( ) ) ,
328344 )
329345 } )
330- . variant ( "ResetBondsFlag" , |v| v. index ( 135 ) ) ;
346+ . variant ( "ResetBondsFlag" , |v| v. index ( 135 ) )
347+ . variant ( "BigRaw" , |v| {
348+ v. index ( 136 ) . fields ( Fields :: unnamed ( ) . field ( |f| {
349+ f. ty :: < BoundedVec < u8 , ConstU32 < MAX_BIGRAW_COMMITMENT_SIZE_BYTES > > > ( )
350+ } ) )
351+ } ) ;
331352
332353 Type :: builder ( )
333354 . path ( Path :: new ( "Data" , module_path ! ( ) ) )
@@ -354,6 +375,7 @@ pub struct CommitmentInfo<FieldLimit: Get<u32>> {
354375
355376/// Maximum size of the serialized timelock commitment in bytes
356377pub const MAX_TIMELOCK_COMMITMENT_SIZE_BYTES : u32 = 1024 ;
378+ pub const MAX_BIGRAW_COMMITMENT_SIZE_BYTES : u32 = 512 ;
357379
358380/// Contains the decrypted data of a revealed commitment.
359381#[ freeze_struct( "bf575857b57f9bef" ) ]
0 commit comments