Skip to content

Commit

Permalink
scoring updates (#257)
Browse files Browse the repository at this point in the history
* score -> network-score and identifier integration
* extrinsic timestamp addition
* fix updating rating identifier status
  • Loading branch information
smohan-dw authored Dec 4, 2023
1 parent d3ed0a0 commit 75756d0
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 138 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pallets/network-score/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ sp-std = { git = "https://github.com/dhiway/substrate-sdk", branch = "release-v1
sp-core = { git = "https://github.com/dhiway/substrate-sdk", branch = "release-v1.3.0", default-features = false, optional = true }
sp-io = { git = "https://github.com/dhiway/substrate-sdk", branch = "release-v1.3.0", default-features = false, optional = true }
sp-keystore = { git = "https://github.com/dhiway/substrate-sdk", branch = "release-v1.3.0", default-features = false, optional = true }
timestamp = { package = "pallet-timestamp", git = "https://github.com/dhiway/substrate-sdk", default-features = false, branch = "release-v1.3.0" }


[features]
default = ['std']
Expand All @@ -72,6 +74,7 @@ std = [
"sp-io/std",
"sp-std/std",
"pallet-chain-space/std",
"timestamp/std",
"identifier/std",
]
try-runtime = [
Expand Down
40 changes: 22 additions & 18 deletions pallets/network-score/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ benchmarks! {
let entry = RatingInputEntryOf::<T> {
entity_uid: entity_uid.clone(),
provider_uid,
total_rating: 250u64,
total_encoded_rating: 250u64,
count_of_txn: 7u64,
entity_type: EntityTypeOf::Logistic,
rating_type: RatingTypeOf::Overall,
provider_did: did1.clone(),
};

let raw_space = [2u8; 256].to_vec();
Expand All @@ -77,12 +78,12 @@ benchmarks! {
let authorization_id: AuthorizationIdOf =
Ss58Identifier::to_authorization_id(&auth_digest.encode()[..]).unwrap();

let origin = <T as pallet::Config>::EnsureOrigin::generate_origin(caller, did1.clone());
let origin = <T as pallet::Config>::EnsureOrigin::generate_origin(caller.clone(), did1.clone());

let entry_digest = <T as frame_system::Config>::Hashing::hash(&entry.encode()[..]);

let id_digest = <T as frame_system::Config>::Hashing::hash(
&[&(entry_digest.clone()).encode()[..], &message_id.encode()[..], &space_id.encode()[..], &did1.encode()[..]].concat()[..]
&[&(entry_digest.clone()).encode()[..], &entity_uid.encode()[..], &message_id.encode()[..], &space_id.encode()[..], &did1.encode()[..]].concat()[..]
);
let identifier = Ss58Identifier::to_scoring_id(&id_digest.encode()[..]).unwrap();

Expand All @@ -93,10 +94,10 @@ benchmarks! {

}: _<T::RuntimeOrigin>(origin, entry, entry_digest, message_id, authorization_id)
verify {
assert_last_event::<T>(Event::RatingEntryAdded { identifier, entity: entity_uid}.into());
assert_last_event::<T>(Event::RatingEntryAdded { identifier, entity: entity_uid, provider: did1, creator: caller}.into());
}

amend_rating {
revoke_rating {
let l in 1 .. MAX_PAYLOAD_BYTE_LENGTH;

let caller: T::AccountId = account("caller", 0, SEED);
Expand All @@ -115,22 +116,23 @@ benchmarks! {
let entry = RatingInputEntryOf::<T> {
entity_uid: entity_uid.clone(),
provider_uid,
total_rating: 250u64,
total_encoded_rating: 250u64,
count_of_txn: 7u64,
entity_type: EntityTypeOf::Logistic,
rating_type: RatingTypeOf::Overall,
provider_did: did1.clone(),
};
let entry_digest = <T as frame_system::Config>::Hashing::hash(
&[&entry.encode()[..]].concat()[..],
);

let id_digest_add = <T as frame_system::Config>::Hashing::hash(
&[&(entry_digest.clone()).encode()[..], &message_id_add.encode()[..], &space_id.encode()[..], &did1.encode()[..]].concat()[..]
&[&(entry_digest.clone()).encode()[..], &entity_uid.encode()[..], &message_id_add.encode()[..], &space_id.encode()[..], &did1.encode()[..]].concat()[..]
);
let identifier_add = Ss58Identifier::to_scoring_id(&id_digest_add.encode()[..]).unwrap();

let id_digest = <T as frame_system::Config>::Hashing::hash(
&[&(entry_digest.clone()).encode()[..], &message_id_revoke.encode()[..], &space_id.encode()[..], &did1.encode()[..]].concat()[..]
&[&(entry_digest.clone()).encode()[..], &entity_uid.encode()[..], &message_id_revoke.encode()[..], &space_id.encode()[..], &did1.encode()[..]].concat()[..]
);
let identifier_revoke = Ss58Identifier::to_scoring_id(&id_digest.encode()[..]).unwrap();

Expand All @@ -140,7 +142,7 @@ benchmarks! {
let authorization_id: AuthorizationIdOf =
Ss58Identifier::to_authorization_id(&auth_digest.encode()[..]).unwrap();

let origin = <T as pallet::Config>::EnsureOrigin::generate_origin(caller, did1);
let origin = <T as pallet::Config>::EnsureOrigin::generate_origin(caller.clone(), did1.clone());
let chain_space_origin = RawOrigin::Root.into();

pallet_chain_space::Pallet::<T>::create(origin.clone(), space_digest )?;
Expand All @@ -149,7 +151,7 @@ benchmarks! {
let _ = Pallet::<T>::register_rating(origin.clone(), entry, entry_digest, message_id_add, authorization_id.clone());
}: _<T::RuntimeOrigin>(origin, identifier_add, message_id_revoke, entry_digest, authorization_id)
verify {
assert_last_event::<T>(Event::RatingEntryRevoked { identifier: identifier_revoke, entity: entity_uid}.into());
assert_last_event::<T>(Event::RatingEntryRevoked { identifier: identifier_revoke, entity: entity_uid, provider: did1, creator: caller}.into());
}

revise_rating {
Expand All @@ -173,10 +175,11 @@ benchmarks! {
let entry = RatingInputEntryOf::<T> {
entity_uid: entity_uid.clone(),
provider_uid: provider_uid.clone(),
total_rating: 250u64,
total_encoded_rating: 250u64,
count_of_txn: 7u64,
entity_type: EntityTypeOf::Logistic,
rating_type: RatingTypeOf::Overall,
provider_did: did.clone(),
};

let entry_digest = <T as frame_system::Config>::Hashing::hash(
Expand All @@ -186,27 +189,28 @@ benchmarks! {
let entry_revise = RatingInputEntryOf::<T> {
entity_uid: entity_uid.clone(),
provider_uid,
total_rating: 250u64,
total_encoded_rating: 250u64,
count_of_txn: 6u64,
entity_type: EntityTypeOf::Logistic,
rating_type: RatingTypeOf::Overall,
provider_did: did.clone(),
};
let entry_revise_digest = <T as frame_system::Config>::Hashing::hash(
&[&entry.encode()[..]].concat()[..],
);

let id_digest_add = <T as frame_system::Config>::Hashing::hash(
&[&(entry_digest.clone()).encode()[..], &message_id_add.encode()[..], &space_id.encode()[..], &did.encode()[..]].concat()[..]
&[&(entry_digest.clone()).encode()[..], &entity_uid.encode()[..], &message_id_add.encode()[..], &space_id.encode()[..], &did.encode()[..]].concat()[..]
);
let identifier_add = Ss58Identifier::to_scoring_id(&id_digest_add.encode()[..]).unwrap();

let id_digest = <T as frame_system::Config>::Hashing::hash(
&[&(entry_digest.clone()).encode()[..], &message_id_revoke.encode()[..], &space_id.encode()[..], &did.encode()[..]].concat()[..]
&[&(entry_digest.clone()).encode()[..], &entity_uid.encode()[..], &message_id_revoke.encode()[..], &space_id.encode()[..], &did.encode()[..]].concat()[..]
);
let identifier_revoke = Ss58Identifier::to_scoring_id(&id_digest.encode()[..]).unwrap();

let id_digest_revise = <T as frame_system::Config>::Hashing::hash(
&[&(entry_revise_digest.clone()).encode()[..], &message_id_revise.encode()[..], &space_id.encode()[..], &did.encode()[..]].concat()[..]
&[&(entry_revise_digest.clone()).encode()[..], &entity_uid.encode()[..], &message_id_revise.encode()[..], &space_id.encode()[..], &did.encode()[..]].concat()[..]
);
let identifier_revise = Ss58Identifier::to_scoring_id(&id_digest_revise.encode()[..]).unwrap();

Expand All @@ -216,17 +220,17 @@ benchmarks! {
let authorization_id: AuthorizationIdOf =
Ss58Identifier::to_authorization_id(&auth_digest.encode()[..]).unwrap();

let origin = <T as pallet::Config>::EnsureOrigin::generate_origin(caller, did);
let origin = <T as pallet::Config>::EnsureOrigin::generate_origin(caller.clone(), did.clone());
let chain_space_origin = RawOrigin::Root.into();

pallet_chain_space::Pallet::<T>::create(origin.clone(), space_digest )?;
pallet_chain_space::Pallet::<T>::approve(chain_space_origin, space_id, 10u64 ).expect("Approval should not fail.");

let _ = Pallet::<T>::register_rating(origin.clone(), entry, entry_digest, message_id_add, authorization_id.clone());
let _ = Pallet::<T>::amend_rating(origin.clone(), identifier_add, message_id_revoke, entry_digest, authorization_id.clone());
let _ = Pallet::<T>::revoke_rating(origin.clone(), identifier_add, message_id_revoke, entry_digest, authorization_id.clone());
}: _<T::RuntimeOrigin>(origin, entry_revise, entry_revise_digest, message_id_revise, identifier_revoke, authorization_id)
verify {
assert_last_event::<T>(Event::RatingEntryRevised { identifier: identifier_revise, entity: entity_uid}.into());
assert_last_event::<T>(Event::RatingEntryRevised { identifier: identifier_revise, entity: entity_uid, provider: did, creator: caller}.into());
}

impl_benchmark_test_suite! (Pallet, crate::mock::new_test_ext(), crate::mock::Test)
Expand Down
Loading

0 comments on commit 75756d0

Please sign in to comment.