@@ -170,16 +170,44 @@ impl<TYPES: NodeType> TestableBlock<TYPES> for TestBlockPayload {
170170}
171171
172172#[ derive(
173- Debug , Display , Clone , Copy , Serialize , Deserialize , PartialEq , Eq , PartialOrd , Ord , Hash ,
173+ Debug , Display , Clone , Copy , Default , Serialize , Deserialize ,
174+ PartialEq , Eq , PartialOrd , Ord , Hash ,
174175) ]
175176#[ display( "{{num_transactions:{num_transactions}}}" ) ]
176177pub struct TestMetadata {
177178 pub num_transactions : u64 ,
179+ /// Total encoded-payload byte length. When this is `> 0` and
180+ /// `num_transactions > 1`, `EncodeBytes::encode` emits a well-formed
181+ /// namespace table (in the wire format consumed by
182+ /// `hotshot_types::data::ns_table::parse_ns_table`) that splits the
183+ /// payload into `num_transactions` evenly-sized namespaces. The AvidM
184+ /// dispersal pipeline then parallelizes per-namespace via rayon.
185+ ///
186+ /// Default `0` preserves the legacy single-namespace behaviour for
187+ /// every existing call site that doesn't opt in.
188+ #[ serde( default ) ]
189+ pub payload_byte_len : u64 ,
178190}
179191
180192impl EncodeBytes for TestMetadata {
181193 fn encode ( & self ) -> Arc < [ u8 ] > {
182- Arc :: new ( [ ] )
194+ let n_ns = self . num_transactions ;
195+ let total = self . payload_byte_len as usize ;
196+ if n_ns <= 1 || total == 0 {
197+ return Arc :: new ( [ ] ) ;
198+ }
199+ // Wire format consumed by `parse_ns_table`:
200+ // [u32_le num_nss] [u32_le ns_id | u32_le ns_end_offset] × num_nss
201+ let n = n_ns as usize ;
202+ let chunk = total / n;
203+ let mut buf = Vec :: with_capacity ( 4 + n * 8 ) ;
204+ buf. extend_from_slice ( & ( n_ns as u32 ) . to_le_bytes ( ) ) ;
205+ for i in 0 ..n {
206+ let end = if i + 1 == n { total } else { ( i + 1 ) * chunk } ;
207+ buf. extend_from_slice ( & ( i as u32 ) . to_le_bytes ( ) ) ; // ns_id
208+ buf. extend_from_slice ( & ( end as u32 ) . to_le_bytes ( ) ) ; // ns_end_offset
209+ }
210+ buf. into ( )
183211 }
184212}
185213
@@ -205,6 +233,7 @@ impl<TYPES: NodeType> BlockPayload<TYPES> for TestBlockPayload {
205233 let txns_vec: Vec < TestTransaction > = transactions. into_iter ( ) . collect ( ) ;
206234 let metadata = TestMetadata {
207235 num_transactions : txns_vec. len ( ) as u64 ,
236+ ..Default :: default ( )
208237 } ;
209238 Ok ( (
210239 Self {
@@ -240,6 +269,7 @@ impl<TYPES: NodeType> BlockPayload<TYPES> for TestBlockPayload {
240269 Self :: genesis ( ) ,
241270 TestMetadata {
242271 num_transactions : 0 ,
272+ ..Default :: default ( )
243273 } ,
244274 )
245275 }
0 commit comments