Skip to content

Commit daf8a1b

Browse files
committed
allow num_ns configuration
1 parent 24b1831 commit daf8a1b

19 files changed

Lines changed: 80 additions & 34 deletions

File tree

crates/hotshot-builder/legacy/src/service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ mod test {
35823582
BlockInfo {
35833583
block_payload: payload,
35843584
metadata: TestMetadata {
3585-
num_transactions: 1,
3585+
num_transactions: 1, ..Default::default()
35863586
},
35873587
vid_trigger: Arc::new(async_lock::RwLock::new(Some(vid_trigger_sender))),
35883588
offered_fee: 100,
@@ -3820,7 +3820,7 @@ mod test {
38203820
let da_proposal = DaProposal2::<TestTypes> {
38213821
encoded_transactions: Arc::new([1, 2, 3, 4, 5, 6]),
38223822
metadata: TestMetadata {
3823-
num_transactions: 1,
3823+
num_transactions: 1, ..Default::default()
38243824
}, // arbitrary
38253825
view_number,
38263826
epoch,
@@ -3879,7 +3879,7 @@ mod test {
38793879
let da_proposal = DaProposal2::<TestTypes> {
38803880
encoded_transactions: Arc::new([1, 2, 3, 4, 5, 6]),
38813881
metadata: TestMetadata {
3882-
num_transactions: 1,
3882+
num_transactions: 1, ..Default::default()
38833883
}, // arbitrary
38843884
view_number,
38853885
epoch,
@@ -3929,7 +3929,7 @@ mod test {
39293929
let da_proposal = DaProposal2::<TestTypes> {
39303930
encoded_transactions: Arc::new([1, 2, 3, 4, 5, 6]),
39313931
metadata: TestMetadata {
3932-
num_transactions: 1,
3932+
num_transactions: 1, ..Default::default()
39333933
}, // arbitrary
39343934
view_number,
39353935
epoch,

crates/hotshot-builder/legacy/src/testing/basic_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ mod tests {
151151
timestamp: 0,
152152
timestamp_millis: 0,
153153
metadata: TestMetadata {
154-
num_transactions: 0,
154+
num_transactions: 0, ..Default::default()
155155
},
156156
random: 1, // arbitrary
157157
version: TEST_VERSIONS.test.base,
@@ -266,7 +266,7 @@ mod tests {
266266
let da_proposal = DaProposal2 {
267267
encoded_transactions: encoded_transactions.clone().into(),
268268
metadata: TestMetadata {
269-
num_transactions: encoded_transactions.len() as u64,
269+
num_transactions: encoded_transactions.len() as u64, ..Default::default()
270270
},
271271
view_number: ViewNumber::new(round as u64),
272272
epoch: None, // TODO: check if this is okay

crates/hotshot-builder/legacy/src/testing/finalization_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ async fn progress_round_with_transactions(
273273
.expect("should sign encoded transactions hash successfully");
274274

275275
let metadata = TestMetadata {
276-
num_transactions: transactions.len() as u64,
276+
num_transactions: transactions.len() as u64, ..Default::default()
277277
};
278278

279279
da_proposal_sender

crates/hotshot-builder/legacy/src/testing/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub async fn calc_proposal_msg(
124124
let num_transactions = transactions.len() as u64;
125125
let encoded_transactions = TestTransaction::encode(&transactions);
126126
let block_payload = TestBlockPayload { transactions };
127-
let metadata = TestMetadata { num_transactions };
127+
let metadata = TestMetadata { num_transactions, ..Default::default() };
128128
let block_vid_commitment = vid_commitment(
129129
&encoded_transactions,
130130
&metadata.encode(),
@@ -146,7 +146,7 @@ pub async fn calc_proposal_msg(
146146
let da_proposal = DaProposal2 {
147147
encoded_transactions: encoded_transactions.clone().into(),
148148
metadata: TestMetadata {
149-
num_transactions: encoded_transactions.len() as u64,
149+
num_transactions: encoded_transactions.len() as u64, ..Default::default()
150150
},
151151
view_number: ViewNumber::new(round as u64),
152152
epoch: None,

crates/hotshot-builder/refactored/src/testing/basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async fn test_pruning() {
199199
&Default::default(),
200200
TestBlockPayload::genesis(),
201201
&TestMetadata {
202-
num_transactions: 0,
202+
num_transactions: 0, ..Default::default()
203203
},
204204
TEST_VERSIONS.test.base,
205205
),

crates/hotshot-builder/shared/src/testing/consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl SimulatedChainState {
5454
let num_transactions = transactions.len() as u64;
5555
let encoded_transactions = TestTransaction::encode(&transactions);
5656
let block_payload = TestBlockPayload { transactions };
57-
let metadata = TestMetadata { num_transactions };
57+
let metadata = TestMetadata { num_transactions, ..Default::default() };
5858
let block_vid_commitment = vid_commitment(
5959
&encoded_transactions,
6060
&metadata.encode(),

crates/hotshot/example-types/src/block_types.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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}}}")]
176177
pub 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

180192
impl 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
}

crates/hotshot/new-protocol/bench/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ pub struct NodeConfig {
3838
#[arg(long, default_value_t = 0)]
3939
pub block_size: usize,
4040

41+
/// Number of namespaces to split each block payload into. AvidmGf2Scheme's
42+
/// `ns_disperse` and `recover` parallelize per-namespace via rayon, so
43+
/// increasing this should reduce dispersal/recovery latency up to the
44+
/// machine's core count. Default 1 = legacy single-namespace behaviour.
45+
#[arg(long, default_value_t = 1)]
46+
pub namespaces: u32,
47+
4148
/// Period between CPU + network sampler ticks (milliseconds). 50ms is the
4249
/// default; lower values give finer resolution at the cost of more
4350
/// /proc reads per second.

crates/hotshot/new-protocol/bench/src/node.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ async fn run_instrumented(mut coordinator: BenchCoordinator, cfg: &NodeConfig) -
311311
if let ConsensusOutput::RequestBlockAndHeader(ref req) = output
312312
&& cfg.block_size > 0
313313
{
314-
let block = build_test_block(cfg.block_size, cfg.total_nodes);
314+
let block = build_test_block(cfg.block_size, cfg.total_nodes, cfg.namespaces);
315315
let parent_leaf = req.parent_proposal.clone().into();
316316
let version = bench_upgrade_lock().version_infallible(req.view);
317317
let header = TestBlockHeader::new::<TestTypes>(
@@ -371,20 +371,26 @@ struct TestBlock {
371371
builder_commitment: hotshot_types::utils::BuilderCommitment,
372372
}
373373

374-
fn build_test_block(size: usize, num_nodes: usize) -> TestBlock {
374+
fn build_test_block(size: usize, num_nodes: usize, n_namespaces: u32) -> TestBlock {
375375
use hotshot_types::traits::EncodeBytes;
376376

377377
let tx = TestTransaction::new(vec![0u8; size]);
378378
let block = TestBlockPayload {
379379
transactions: vec![tx],
380380
};
381+
let encoded = block.encode();
382+
383+
// `TestMetadata` itself emits the namespace table when `num_transactions
384+
// > 1` AND `payload_byte_len > 0`. The bench sets both so AvidM dispersal
385+
// splits the payload into N evenly-sized namespaces and parallelizes
386+
// per-namespace via rayon (same wire format as production `NsTable`).
387+
let n = n_namespaces.max(1);
381388
let metadata = TestMetadata {
382-
num_transactions: 1,
389+
num_transactions: n as u64,
390+
payload_byte_len: if n > 1 { encoded.len() as u64 } else { 0 },
383391
};
384-
// Use the actual committee size so the commitment matches what
385-
// VidDisperse::calculate_vid_disperse will produce.
386392
let payload_commitment = hotshot_types::data::vid_commitment(
387-
&block.encode(),
393+
&encoded,
388394
&metadata.encode(),
389395
num_nodes,
390396
versions::NEW_PROTOCOL_VERSION,

crates/hotshot/new-protocol/bench/tests/smoke.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn node_config(
4040
.into_owned(),
4141
block_size,
4242
sampler_tick_ms: 50,
43+
namespaces: 1,
4344
}
4445
}
4546

0 commit comments

Comments
 (0)