Skip to content

Commit d042eab

Browse files
committed
chore: worst case scenario benchmark
1 parent a18d697 commit d042eab

File tree

3 files changed

+41
-62
lines changed

3 files changed

+41
-62
lines changed

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build-testnet:
1111
# Development
1212

1313
check: fmt
14-
cargo clippy --tests
14+
cargo clippy --tests --features testnet,runtime-benchmarks
1515

1616
test: check
1717
SKIP_WASM_BUILD=1 cargo nextest run

pallets/emission0/src/benchmarking.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ mod benchmarks {
3030
<T::Governance>::force_set_whitelisted(&module_key2);
3131

3232
<T::Governance>::set_allocator(&module_key2);
33-
let _ =
34-
<T::Currency>::deposit_creating(&module_key2, <T::Torus>::min_validator_stake() * 2);
33+
let _ = <T::Currency>::deposit_creating(
34+
&module_key2,
35+
<T::Torus>::min_validator_stake().saturating_mul(2),
36+
);
3537

3638
<T::Torus>::force_set_stake(
3739
&module_key2,

pallets/permission0/src/benchmarking.rs

Lines changed: 36 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ mod benchmarks {
291291

292292
#[benchmark]
293293
fn update_namespace_permission() {
294-
use pallet_torus0_api::NamespacePathInner;
295294
use polkadot_sdk::sp_std::collections::btree_set::BTreeSet;
296295

297296
let alice: T::AccountId = account("alice", 0, 0);
@@ -311,21 +310,15 @@ mod benchmarks {
311310
.expect("failed to register namespace");
312311
}
313312

314-
let mut alice_paths_set: BTreeSet<NamespacePathInner> = BTreeSet::new();
315-
alice_paths_set.insert(b"agent.alice.network".to_vec().try_into().unwrap());
316-
alice_paths_set.insert(b"agent.alice.compute".to_vec().try_into().unwrap());
317-
let alice_paths_bounded: BoundedBTreeSet<
318-
NamespacePathInner,
319-
T::MaxNamespacesPerPermission,
320-
> = alice_paths_set
313+
let alice_paths_set = BTreeSet::from([
314+
b"agent.alice.network".to_vec().try_into().unwrap(),
315+
b"agent.alice.compute".to_vec().try_into().unwrap(),
316+
]);
317+
let alice_paths_bounded: BoundedBTreeSet<_, _> = alice_paths_set
321318
.try_into()
322319
.expect("failed to create bounded set");
323320

324-
let mut alice_paths: BoundedBTreeMap<
325-
Option<PermissionId>,
326-
BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>,
327-
T::MaxNamespacesPerPermission,
328-
> = BoundedBTreeMap::new();
321+
let mut alice_paths = BoundedBTreeMap::new();
329322
alice_paths
330323
.try_insert(None, alice_paths_bounded)
331324
.expect("failed to insert alice paths");
@@ -346,7 +339,6 @@ mod benchmarks {
346339

347340
#[benchmark]
348341
fn delegate_namespace_permission() {
349-
use pallet_torus0_api::NamespacePathInner;
350342
use polkadot_sdk::sp_std::collections::btree_set::BTreeSet;
351343

352344
let alice: T::AccountId = account("alice", 0, 0);
@@ -427,21 +419,18 @@ mod benchmarks {
427419
.expect("failed to register pollution namespace");
428420
}
429421

430-
let mut alice_bob_set: BTreeSet<NamespacePathInner> = BTreeSet::new();
431-
alice_bob_set.insert(b"agent.alice.compute".to_vec().try_into().unwrap());
432-
alice_bob_set.insert(b"agent.alice.network".to_vec().try_into().unwrap());
433-
alice_bob_set.insert(b"agent.alice.storage".to_vec().try_into().unwrap());
434-
alice_bob_set.insert(b"agent.alice.n".to_vec().try_into().unwrap());
435-
let alice_bob_set: BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission> =
436-
alice_bob_set
437-
.try_into()
438-
.expect("failed to create bounded set");
422+
let alice_bob_set = BTreeSet::from([
423+
b"agent.alice.compute".to_vec().try_into().unwrap(),
424+
b"agent.alice.network".to_vec().try_into().unwrap(),
425+
b"agent.alice.storage".to_vec().try_into().unwrap(),
426+
b"agent.alice.n".to_vec().try_into().unwrap(),
427+
b"agent.alice.n".to_vec().try_into().unwrap(),
428+
]);
429+
let alice_bob_set: BoundedBTreeSet<_, _> = alice_bob_set
430+
.try_into()
431+
.expect("failed to create bounded set");
439432

440-
let mut alice_paths: BoundedBTreeMap<
441-
Option<PermissionId>,
442-
BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>,
443-
T::MaxNamespacesPerPermission,
444-
> = BoundedBTreeMap::new();
433+
let mut alice_paths = BoundedBTreeMap::new();
445434
alice_paths
446435
.try_insert(None, alice_bob_set)
447436
.expect("failed to insert alice paths");
@@ -456,20 +445,16 @@ mod benchmarks {
456445
)
457446
.expect("failed to create alice->bob permission");
458447

459-
let mut bob_charlie_set: BTreeSet<NamespacePathInner> = BTreeSet::new();
460-
bob_charlie_set.insert(b"agent.alice.compute.gpu".to_vec().try_into().unwrap());
461-
bob_charlie_set.insert(b"agent.alice.network.subnet1".to_vec().try_into().unwrap());
462-
bob_charlie_set.insert(b"agent.alice.n".to_vec().try_into().unwrap());
463-
let bob_charlie_set: BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission> =
464-
bob_charlie_set
465-
.try_into()
466-
.expect("failed to create bounded set");
448+
let bob_charlie_set = BTreeSet::from([
449+
b"agent.alice.compute.gpu".to_vec().try_into().unwrap(),
450+
b"agent.alice.network.subnet1".to_vec().try_into().unwrap(),
451+
b"agent.alice.n".to_vec().try_into().unwrap(),
452+
]);
453+
let bob_charlie_set: BoundedBTreeSet<_, _> = bob_charlie_set
454+
.try_into()
455+
.expect("failed to create bounded set");
467456

468-
let mut bob_paths: BoundedBTreeMap<
469-
Option<PermissionId>,
470-
BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>,
471-
T::MaxNamespacesPerPermission,
472-
> = BoundedBTreeMap::new();
457+
let mut bob_paths = BoundedBTreeMap::new();
473458
bob_paths
474459
.try_insert(Some(alice_permission_id), bob_charlie_set)
475460
.expect("failed to insert bob paths");
@@ -485,18 +470,16 @@ mod benchmarks {
485470
.expect("failed to create bob->charlie permission");
486471

487472
for (i, path) in alice_n.iter().enumerate() {
488-
let acc: T::AccountId = account("acc", 100 + i as u32, 0);
473+
let acc: T::AccountId = account("acc", 100.saturating_add(i as u32), 0);
489474
let mut acc_name = "acc".to_string();
490475
acc_name.push_str(&i.to_string());
491476

492477
T::Torus::force_register_agent(&acc, acc_name.as_bytes().to_vec(), vec![], vec![])
493478
.expect("failed to register acc");
494479

495-
let mut set: BTreeSet<NamespacePathInner> = BTreeSet::new();
496-
set.insert(path.to_vec().try_into().unwrap());
480+
let set = BTreeSet::from([path.to_vec().try_into().unwrap()]);
497481
let set: BoundedBTreeSet<_, _> = set.try_into().expect("failed to create bounded set");
498-
499-
let mut paths: BoundedBTreeMap<_, _, _> = BoundedBTreeMap::new();
482+
let mut paths = BoundedBTreeMap::new();
500483
paths
501484
.try_insert(Some(bob_permission_id), set)
502485
.expect("failed to insert bob paths");
@@ -512,25 +495,19 @@ mod benchmarks {
512495
.expect("failed to create bob->charlie permission");
513496
}
514497

515-
let mut charlie_dave_set: BTreeSet<NamespacePathInner> = BTreeSet::new();
516-
charlie_dave_set.insert(b"agent.alice.compute.gpu.h100".to_vec().try_into().unwrap());
517-
charlie_dave_set.insert(
498+
let charlie_dave_set = BTreeSet::from([
499+
b"agent.alice.compute.gpu.h100".to_vec().try_into().unwrap(),
518500
b"agent.alice.network.subnet1.fast"
519501
.to_vec()
520502
.try_into()
521503
.unwrap(),
522-
);
504+
]);
523505

524-
let charlie_dave_set: BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission> =
525-
charlie_dave_set
526-
.try_into()
527-
.expect("failed to create bounded set");
506+
let charlie_dave_set: BoundedBTreeSet<_, _> = charlie_dave_set
507+
.try_into()
508+
.expect("failed to create bounded set");
528509

529-
let mut charlie_paths: BoundedBTreeMap<
530-
Option<PermissionId>,
531-
BoundedBTreeSet<NamespacePathInner, T::MaxNamespacesPerPermission>,
532-
T::MaxNamespacesPerPermission,
533-
> = BoundedBTreeMap::new();
510+
let mut charlie_paths = BoundedBTreeMap::new();
534511
charlie_paths
535512
.try_insert(Some(bob_permission_id), charlie_dave_set)
536513
.expect("failed to insert charlie paths");

0 commit comments

Comments
 (0)