Skip to content

Commit

Permalink
Tweaks for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed May 30, 2024
1 parent e13fa89 commit d0cb395
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 54 deletions.
47 changes: 23 additions & 24 deletions pallets/core/src/modules/accumulator/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::{
common::state_change::ToStateChange,
common::{state_change::ToStateChange, IntermediateError},
did::{Did, DidSignature, UncheckedDidKey},
util::{Action, IncId},
};
Expand Down Expand Up @@ -69,10 +69,10 @@ crate::bench_with_all_pairs! {
label: Some(vec![1; MAX_LABEL as usize].try_into().unwrap()),
},
nonce: 1u8.into()
}).modify::<T, _, _, _, _>(|action, counter| Pallet::<T>::add_params_(action.action, counter, AccumulatorOwner(did.into()))).unwrap();
}).modify::<T, _, _, _, _>(|action, counter| Pallet::<T>::add_params_(action.action, counter, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

let rem_params = RemoveAccumulatorParams {
params_ref: (AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
params_ref: AccumParametersStorageKey(AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
nonce: 1u8.into()
};

Expand Down Expand Up @@ -105,13 +105,13 @@ crate::bench_with_all_pairs! {
label: Some(vec![1; MAX_LABEL as usize].try_into().unwrap()),
},
nonce: 1u8.into()
},).modify::<T, _, _, _, _>(|action, counter| Pallet::<T>::add_params_(action.action, counter, AccumulatorOwner(did.into()))).unwrap();
},).modify::<T, _, _, _, _>(|action, counter| Pallet::<T>::add_params_(action.action, counter, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

let public_key = AccumulatorPublicKey {
curve_type: CurveType::Bls12381,
bytes: vec![3; b as usize].try_into().unwrap(),
/// The params used to generate the public key (`P_tilde` comes from params)
params_ref: Some((AccumulatorOwner(did.into()), IncId::from(1u8)))
params_ref: Some(AccumParametersStorageKey(AccumulatorOwner(did.into()), IncId::from(1u8)))
};

let add_key = AddAccumulatorPublicKey {
Expand Down Expand Up @@ -147,7 +147,7 @@ crate::bench_with_all_pairs! {
nonce: 1u8.into()
}).modify::<T, _, _, _, _>(
|ActionWithNonceWrapper { action, .. }, accumulator| {
Pallet::<T>::add_params_(action, accumulator, AccumulatorOwner(did.into()))
Pallet::<T>::add_params_(action, accumulator, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)
},
).unwrap();

Expand All @@ -159,17 +159,17 @@ crate::bench_with_all_pairs! {
curve_type: CurveType::Bls12381,
bytes: vec![3; MAX_KEY as usize].try_into().unwrap(),
/// The params used to generate the public key (`P_tilde` comes from params)
params_ref: Some((AccumulatorOwner(did.into()), IncId::from(1u8)))
params_ref: Some(AccumParametersStorageKey(AccumulatorOwner(did.into()), IncId::from(1u8)))
},
nonce: 1u8.into()
}).modify::<T, _, _, _, _>(
|ActionWithNonceWrapper { action, .. }, accumulator| {
Pallet::<T>::add_public_key_(action, accumulator, AccumulatorOwner(did.into()))
Pallet::<T>::add_public_key_(action, accumulator, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)
}
).unwrap();

let rem_key = RemoveAccumulatorPublicKey {
key_ref: (AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
key_ref: AccumPublicKeyStorageKey(AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
nonce: 1u8.into()
};

Expand All @@ -191,7 +191,7 @@ crate::bench_with_all_pairs! {
let public = pair.public();
let accumulator = Accumulator::Positive(AccumulatorCommon {
accumulated: vec![3; b as usize].try_into().unwrap(),
key_ref: (AccumulatorOwner(did.into()), 1u8.into()),
key_ref: AccumPublicKeyStorageKey(AccumulatorOwner(did.into()), 1u8.into()),
});

crate::did::Pallet::<T>::new_onchain_(
Expand All @@ -211,7 +211,7 @@ crate::bench_with_all_pairs! {
nonce: 1u8.into()
}).modify::<T, _, _, _, _>(
|ActionWithNonceWrapper { action, .. }, accumulator| {
Pallet::<T>::add_params_(action, accumulator, AccumulatorOwner(did.into()))
Pallet::<T>::add_params_(action, accumulator, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)
},
).unwrap();

Expand All @@ -223,12 +223,12 @@ crate::bench_with_all_pairs! {
curve_type: CurveType::Bls12381,
bytes: vec![3; MAX_KEY as usize].try_into().unwrap(),
/// The params used to generate the public key (`P_tilde` comes from params)
params_ref: Some((AccumulatorOwner(did.into()), IncId::from(1u8)))
params_ref: Some(AccumParametersStorageKey(AccumulatorOwner(did.into()), IncId::from(1u8)))
},
nonce: 1u8.into()
}).modify::<T, _, _, _, _>(
|ActionWithNonceWrapper { action, .. }, accumulator| {
Pallet::<T>::add_public_key_(action, accumulator, AccumulatorOwner(did.into()))
Pallet::<T>::add_public_key_(action, accumulator, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)
}
).unwrap();

Expand Down Expand Up @@ -261,7 +261,7 @@ crate::bench_with_all_pairs! {
let public = pair.public();
let accumulator = Accumulator::Positive(AccumulatorCommon {
accumulated: vec![3; MAX_ACC as usize].try_into().unwrap(),
key_ref: (AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
key_ref: AccumPublicKeyStorageKey(AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
});

crate::did::Pallet::<T>::new_onchain_(
Expand All @@ -283,7 +283,7 @@ crate::bench_with_all_pairs! {
},
nonce: 1u8.into()
}
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_params_(action.action, counters, AccumulatorOwner(did.into()))).unwrap();
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_params_(action.action, counters, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();


ActionWithNonceWrapper::<T, _, _>::new(
Expand All @@ -294,17 +294,17 @@ crate::bench_with_all_pairs! {
curve_type: CurveType::Bls12381,
bytes: vec![3; MAX_KEY as usize].try_into().unwrap(),
/// The params used to generate the public key (`P_tilde` comes from params)
params_ref: Some((AccumulatorOwner(did.into()), IncId::from(1u8)))
params_ref: Some(AccumParametersStorageKey(AccumulatorOwner(did.into()), IncId::from(1u8)))
},
nonce: 1u8.into()
}
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_public_key_(action.action, counters, AccumulatorOwner(did.into()))).unwrap();
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_public_key_(action.action, counters, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

AddAccumulator {
id: acc_id,
accumulator,
nonce: 1u8.into()
}.modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_accumulator_(action, counters, AccumulatorOwner(did.into()))).unwrap();
}.modify_removable::<T, _, _, _, _>(|action, acc| Pallet::<T>::add_accumulator_(action, acc, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

let new_accumulated = vec![3; a as usize];
let up_acc = UpdateAccumulator {
Expand All @@ -331,7 +331,7 @@ crate::bench_with_all_pairs! {

let accumulator = Accumulator::Positive(AccumulatorCommon {
accumulated: vec![3; MAX_ACC as usize].try_into().unwrap(),
key_ref: (AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
key_ref: AccumPublicKeyStorageKey(AccumulatorOwner(did.into()), 1u8.try_into().unwrap()),
});

crate::did::Pallet::<T>::new_onchain_(
Expand All @@ -342,7 +342,6 @@ crate::bench_with_all_pairs! {

let acc_id: AccumulatorId = AccumulatorId([2; 32]);


ActionWithNonceWrapper::<T, _, _>::new(
1u8.into(),
AccumulatorOwner(did.into()),
Expand All @@ -354,7 +353,7 @@ crate::bench_with_all_pairs! {
},
nonce: 1u8.into()
}
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_params_(action.action, counters, AccumulatorOwner(did.into()))).unwrap();
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_params_(action.action, counters, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();


ActionWithNonceWrapper::<T, _, _>::new(
Expand All @@ -365,17 +364,17 @@ crate::bench_with_all_pairs! {
curve_type: CurveType::Bls12381,
bytes: vec![3; MAX_KEY as usize].try_into().unwrap(),
/// The params used to generate the public key (`P_tilde` comes from params)
params_ref: Some((AccumulatorOwner(did.into()), IncId::from(1u8)))
params_ref: Some(AccumParametersStorageKey(AccumulatorOwner(did.into()), IncId::from(1u8)))
},
nonce: 1u8.into()
}
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_public_key_(action.action, counters, AccumulatorOwner(did.into()))).unwrap();
).modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_public_key_(action.action, counters, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

AddAccumulator {
id: acc_id,
accumulator,
nonce: 1u8.into()
}.modify::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_accumulator_(action, counters, AccumulatorOwner(did.into()))).unwrap();
}.modify_removable::<T, _, _, _, _>(|action, counters| Pallet::<T>::add_accumulator_(action, counters, AccumulatorOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

let remove_acc = RemoveAccumulator {
id: acc_id,
Expand Down
1 change: 0 additions & 1 deletion pallets/core/src/modules/accumulator/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ impl<T: Config> Pallet<T> {
*accumulator.accumulator.owner_did() == signer,
Error::<T>::NotAccumulatorOwner
);
Accumulators::<T>::remove(id);

deposit_indexed_event!(AccumulatorRemoved(id));
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion pallets/core/src/modules/blob/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ crate::bench_with_all_pairs! {
let did = Did([1; Did::BYTE_SIZE]);

did::Pallet::<T>::new_onchain_(did, vec![UncheckedDidKey::new_with_all_relationships(public)], Default::default()).unwrap();
let id = Default::default();
let id = BlobId(Default::default());

let blob = Blob {
id,
Expand Down
8 changes: 4 additions & 4 deletions pallets/core/src/modules/offchain_signatures/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::{
common::{CurveType, ToStateChange},
common::{CurveType, IntermediateError, ToStateChange},
did::{Did, DidSignature, UncheckedDidKey},
util::{Action, BoundedBytes, IncId},
};
Expand Down Expand Up @@ -71,7 +71,7 @@ crate::bench_with_all_pairs! {
).into(),
nonce: 1u8.into()
},
).modify::<T, _, _, _, _>(|action, entity| super::Pallet::<T>::add_params_(action.action, entity, SignatureParamsOwner(did.into()))).unwrap();
).modify::<T, _, _, _, _>(|action, entity| super::Pallet::<T>::add_params_(action.action, entity, SignatureParamsOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

let rem_params = RemoveOffchainSignatureParams {
params_ref: (SignatureParamsOwner(did.into()), 1u8.into()),
Expand Down Expand Up @@ -111,7 +111,7 @@ crate::bench_with_all_pairs! {
).into(),
nonce: 1u8.into()
},
).modify::<T, _, _, _, _>(|action, entity| super::Pallet::<T>::add_params_(action.action, entity, SignatureParamsOwner(did.into()))).unwrap();
).modify::<T, _, _, _, _>(|action, entity| super::Pallet::<T>::add_params_(action.action, entity, SignatureParamsOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

let key: OffchainPublicKey<T> = BBSPlusPublicKey::new(
BoundedBytes::try_from(vec![0; b as usize]).unwrap(),
Expand Down Expand Up @@ -154,7 +154,7 @@ crate::bench_with_all_pairs! {
).into(),
nonce: 1u8.into()
},
).modify::<T, _, _, _, _>(|action, entity| super::Pallet::<T>::add_params_(action.action, entity, SignatureParamsOwner(did.into()))).unwrap();
).modify::<T, _, _, _, _>(|action, entity| super::Pallet::<T>::add_params_(action.action, entity, SignatureParamsOwner(did.into())).map_err(IntermediateError::<T>::from)).unwrap();

Pallet::<T>::add_public_key_(
AddOffchainSignaturePublicKey {
Expand Down
6 changes: 3 additions & 3 deletions pallets/core/src/modules/revoke/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ crate::bench_with_all_pairs! {
let sig = pair.sign(&revoke.to_state_change().encode());
let signature = DidSignature::new(did, 1u32, sig).into();

super::Pallet::<T>::new_registry_(AddRegistry { id: reg_id, new_registry: RevocationRegistry { policy: Policy::one_of([DidOrDidMethodKey::from(did)]).unwrap(), add_only: false } }).unwrap();
AddRegistry { id: reg_id, new_registry: RevocationRegistry { policy: Policy::one_of([DidOrDidMethodKey::from(did)]).unwrap(), add_only: false } }.modify_removable(super::Pallet::<T>::new_registry_).unwrap();
}: revoke(RawOrigin::Signed(caller), revoke_raw, vec![SignatureWithNonce::new(signature, 1u32.into())])
verify {
assert!(revoke_ids
Expand All @@ -77,7 +77,7 @@ crate::bench_with_all_pairs! {
let reg_id = RevocationRegistryId([2u8; 32]);
let revoke_ids: BTreeSet<_> = (0..r).map(|i| U256::from(i).into()).map(RevokeId).collect();

super::Pallet::<T>::new_registry_(AddRegistry { id: reg_id, new_registry: RevocationRegistry { policy: Policy::one_of([DidOrDidMethodKey::from(did)]).unwrap(), add_only: false } }).unwrap();
AddRegistry { id: reg_id, new_registry: RevocationRegistry { policy: Policy::one_of([DidOrDidMethodKey::from(did)]).unwrap(), add_only: false } }.modify_removable(super::Pallet::<T>::new_registry_).unwrap();

crate::revoke::Pallet::<T>::revoke_(
RevokeRaw {
Expand Down Expand Up @@ -130,7 +130,7 @@ crate::bench_with_all_pairs! {
Default::default(),
).unwrap();

super::Pallet::<T>::new_registry_(add_reg).unwrap();
add_reg.modify_removable(super::Pallet::<T>::new_registry_).unwrap();

crate::revoke::Pallet::<T>::revoke_(
RevokeRaw {
Expand Down
8 changes: 4 additions & 4 deletions pallets/core/src/modules/status_list_credential/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ crate::bench_with_all_pairs! {
status_list_credential: StatusListCredential::<T>::RevocationList2020Credential(BoundedBytes((0..r).map(|v| v as u8).try_collect().unwrap())),
policy: Policy::one_of((0..MAX_POLICY_CONTROLLERS).map(|i| U256::from(i).into()).map(Did)).unwrap()
};
super::Pallet::<T>::create_(id, credential).unwrap();
AddStatusListCredential { id, credential }.modify_removable(super::Pallet::<T>::create_).unwrap();

let credential = StatusListCredential::<T>::StatusList2021Credential(BoundedBytes((0..r).map(|v| v as u8).try_collect().unwrap()));
let update_credential_raw = UpdateStatusListCredentialRaw {
Expand All @@ -51,7 +51,7 @@ crate::bench_with_all_pairs! {

let sig = pair.sign(&update.to_state_change().encode());
let signature = DidSignature::new(did, 1u32, sig).into();
}: update(RawOrigin::Signed(caller), update.into_data(), vec![DidSignatureWithNonce::new(signature, 1u32.into())])
}: update(RawOrigin::Signed(caller), update.into_data(), vec![SignatureWithNonce::new(signature, 1u32.into())])
verify {
assert_eq!(StatusListCredentials::get(id).unwrap(), StatusListCredentialWithPolicy {
status_list_credential: StatusListCredential::<T>::StatusList2021Credential(BoundedBytes((0..r).map(|v| v as u8).try_collect().unwrap())),
Expand All @@ -76,7 +76,7 @@ crate::bench_with_all_pairs! {
status_list_credential: StatusListCredential::<T>::RevocationList2020Credential(BoundedBytes((0..MAX_CREDENTIAL_SIZE).map(|v| v as u8).try_collect().unwrap())),
policy: Policy::one_of((0..MAX_POLICY_CONTROLLERS).map(|i| U256::from(i).into()).map(Did)).unwrap()
};
super::Pallet::<T>::create_(id, credential).unwrap();
AddStatusListCredential { id, credential }.modify_removable(super::Pallet::<T>::create_).unwrap();

let remove_credential_raw = RemoveStatusListCredentialRaw {
/// Unique identifier of the underlying `StatusListCredential`
Expand All @@ -87,7 +87,7 @@ crate::bench_with_all_pairs! {

let sig = pair.sign(&remove.to_state_change().encode());
let signature = DidSignature::new(did, 1u32, sig).into();
}: remove(RawOrigin::Signed(caller), remove.into_data(), vec![DidSignatureWithNonce::new(signature, 1u32.into())])
}: remove(RawOrigin::Signed(caller), remove.into_data(), vec![SignatureWithNonce::new(signature, 1u32.into())])
verify {
assert_eq!(StatusListCredentials::<T>::get(id), None);
};
Expand Down
Loading

0 comments on commit d0cb395

Please sign in to comment.