Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nodes/rust/duniter-v2s
  • llaq/lc-core-substrate
  • pini-gh/duniter-v2s
  • vincentux/duniter-v2s
  • mildred/duniter-v2s
  • d0p1/duniter-v2s
  • bgallois/duniter-v2s
  • Nicolas80/duniter-v2s
8 results
Show changes
Commits on Source (2)
Showing
with 743 additions and 20 deletions
......@@ -185,6 +185,21 @@ build_release_tag:
IMAGE_TAG: "$CI_COMMIT_TAG"
PODMAN_BUILD_OPTIONS: "--platform linux/amd64"
run_benchmarks:
stage: tests
extends: .docker_build
rules:
- if: $CI_COMMIT_REF_NAME =~ /^wip*$/
when: manual
- if: $CI_COMMIT_TAG
when: never
- if: '$CI_MERGE_REQUEST_ID || $CI_COMMIT_BRANCH == "master"'
- when: manual
variables:
IMAGE_NAME: "duniter/duniter-v2s-test"
IMAGE_TAG: "debug-sha-$CI_COMMIT_SHORT_SHA"
PODMAN_BUILD_OPTIONS: "--target build --build-arg benchmarks=1"
tests:
stage: tests
image: rust:1-bullseye
......
......@@ -3008,6 +3008,7 @@ dependencies = [
"pallet-quota",
"pallet-scheduler",
"pallet-session",
"pallet-session-benchmarking",
"pallet-sudo",
"pallet-timestamp",
"pallet-transaction-payment",
......@@ -5770,18 +5771,24 @@ dependencies = [
name = "pallet-distance"
version = "1.0.0"
dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"getrandom 0.2.8",
"pallet-authority-members",
"pallet-authorship",
"pallet-balances",
"pallet-identity",
"pallet-membership",
"pallet-session",
"parity-scale-codec",
"scale-info",
"sp-consensus-babe",
"sp-core",
"sp-distance",
"sp-inherents",
"sp-io",
"sp-keystore",
"sp-runtime",
"sp-std 5.0.0",
]
......
......@@ -33,6 +33,11 @@ RUN if [ "$debug" = 0 ]; then \
echo "TARGET_FOLDER=debug" >>/root/dynenv; \
fi
ARG benchmarks=0
RUN if [ "$benchmarks" != 0 ]; then \
echo "BENCH_OPTIONS=--features\ runtime-benchmarks" >>/root/dynenv; \
fi
# Configure cross-build environment if need be
RUN set -x && \
if [ "$TARGETPLATFORM" != "$BUILDPLATFORM" ]; then \
......@@ -48,7 +53,7 @@ ARG chain="gdev"
RUN set -x && \
cat /root/dynenv && \
. /root/dynenv && \
cargo build --locked $CARGO_OPTIONS --no-default-features --features $chain --target "$RUST_ARCH_TRIPLET" && \
cargo build --locked $CARGO_OPTIONS --no-default-features $BENCH_OPTIONS --features $chain --target "$RUST_ARCH_TRIPLET" && \
mkdir -p build && \
mv target/$RUST_ARCH_TRIPLET/$TARGET_FOLDER/duniter build/
......@@ -56,11 +61,17 @@ RUN set -x && \
ARG cucumber=0
RUN if [ "$cucumber" != 0 ] && [ "$TARGETPLATFORM" = "$BUILDPLATFORM" ]; then \
cargo ta && \
cargo test --workspace --exclude duniter-end2end-tests --exclude duniter-live-tests --features runtime-benchmarks \
cd target/debug/deps/ && \
rm cucumber_tests-*.d && \
mv cucumber_tests* ../../../build/duniter-cucumber; \
fi
# Run runtime benchmarks
RUN if [ "$benchmarks" != 0 ]; then \
build/duniter benchmark pallet --chain dev --execution=wasm --wasm-execution=compiled --pallet "*" --extrinsic "*" --steps 2 --repeat 1; \
fi
# ------------------------------------------------------------------------------
# Final Stage
# ------------------------------------------------------------------------------
......
......@@ -56,6 +56,7 @@ benchmarks_instance_pallet! {
Pallet::<T, I>::del_cert(RawOrigin::Root.into(), issuer, receiver)?;
let issuer_cert: u32 = StorageIdtyCertMeta::<T, I>::get(issuer).issued_count;
let receiver_cert: u32 = StorageIdtyCertMeta::<T, I>::get(receiver).received_count;
frame_system::pallet::Pallet::<T>::set_block_number(T::CertPeriod::get());
}: _<T::RuntimeOrigin>(caller_origin, issuer, receiver)
verify {
assert_has_event::<T, I>(Event::<T, I>::NewCert{ issuer: issuer, issuer_issued_count: issuer_cert + 1, receiver: receiver, receiver_received_count: receiver_cert + 1 }.into());
......
......@@ -11,15 +11,23 @@ version = '1.0.0'
[features]
default = ['std']
runtime-benchmarks = [
'frame-benchmarking/runtime-benchmarks',
'pallet-balances',
'pallet-identity/runtime-benchmarks',
'sp-consensus-babe',
]
std = [
'codec/std',
'frame-support/std',
'frame-benchmarking/std',
'pallet-authority-members/std',
'pallet-authorship/std',
'pallet-identity/std',
'pallet-membership/std',
'pallet-session/std',
'sp-core/std',
'sp-consensus-babe/std',
'sp-distance/std',
'sp-runtime/std',
'sp-std/std',
......@@ -31,18 +39,28 @@ pallet-authority-members = { path = "../authority-members", default-features = f
pallet-identity = { path = "../identity", default-features = false }
pallet-membership = { path = "../membership", default-features = false }
sp-distance = { path = "../../primitives/distance", default-features = false }
sp-consensus-babe = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false, optional = true }
getrandom = { version = "0.2", features = ["js"] }
# substrate
scale-info = { version = "2.1.1", default-features = false, features = [
"derive",
] }
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', optional = true, default-features = false }
[dependencies.codec]
default-features = false
features = ['derive']
package = 'parity-scale-codec'
version = '3.1.5'
[dependencies.frame-benchmarking]
default-features = false
git = 'https://github.com/duniter/substrate'
optional = true
branch = 'duniter-substrate-v0.9.42'
[dependencies.frame-support]
default-features = false
git = 'https://github.com/duniter/substrate'
......@@ -87,3 +105,8 @@ branch = 'duniter-substrate-v0.9.42'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
[dev-dependencies]
pallet-balances = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
sp-io = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
sp-keystore = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
// Copyright 2021-2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use codec::Encode;
use frame_benchmarking::{benchmarks, vec};
use frame_support::traits::{Currency, OnFinalize};
use frame_system::RawOrigin;
use pallet_balances::Pallet as Balances;
use sp_runtime::traits::{Bounded, One};
use sp_runtime::Perbill;
use crate::Pallet;
fn populate_pool<T: Config>(i: u32) -> Result<(), &'static str> {
EvaluationPool0::<T>::mutate(|current_pool| -> Result<(), &'static str> {
for j in 0..i {
current_pool
.evaluations
.try_push((j.into(), median::MedianAcc::new()))
.map_err(|_| Error::<T>::QueueFull)?;
}
Ok(())
})
}
benchmarks! {
where_clause {
where
T: pallet_balances::Config, T::Balance: From<u64>,
T::BlockNumber: From<u32>,
}
request_distance_evaluation {
let idty = T::IdtyIndex::one();
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key;
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
let _ = <Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value());
}: _<T::RuntimeOrigin>(caller_origin.clone())
verify {
assert!(IdentityDistanceStatus::<T>::get(&idty) == Some((caller, DistanceStatus::Pending)), "Request not added");
}
update_evaluation {
let digest_data = sp_consensus_babe::digests::PreDigest::SecondaryPlain(
sp_consensus_babe::digests::SecondaryPlainPreDigest { authority_index: 0u32, slot: Default::default() });
// A BABE digest item is needed to check authorship
let digest = sp_runtime::DigestItem::PreRuntime(*b"BABE", digest_data.encode());
let _ = <frame_system::Pallet<T>>::deposit_log(digest);
let idty = T::IdtyIndex::one();
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key;
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
let i in 1 .. MAX_EVALUATIONS_PER_SESSION => populate_pool::<T>(i)?;
}: _<T::RuntimeOrigin>(RawOrigin::None.into(), ComputationResult{distances: vec![Perbill::one(); i as usize]})
force_update_evaluation {
let idty = T::IdtyIndex::one();
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key;
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
let i in 1 .. MAX_EVALUATIONS_PER_SESSION => populate_pool::<T>(i)?;
}: _<T::RuntimeOrigin>(RawOrigin::Root.into(), caller, ComputationResult{distances: vec![Perbill::one(); i as usize]})
force_set_distance_status {
let idty = T::IdtyIndex::one();
let caller: T::AccountId = pallet_identity::Identities::<T>::get(idty).unwrap().owner_key;
let status = Some((caller.clone(), DistanceStatus::Valid));
}: _<T::RuntimeOrigin>(RawOrigin::Root.into(), idty, status)
verify {
assert!(IdentityDistanceStatus::<T>::get(&idty) == Some((caller, DistanceStatus::Valid)), "Status not set");
}
on_finalize {
DidUpdate::<T>::set(true);
}: { Pallet::<T>::on_finalize(Default::default()); }
verify {
assert!(!DidUpdate::<T>::get());
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}
......@@ -21,10 +21,16 @@ mod traits;
mod types;
mod weights;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
#[cfg(test)]
mod mock;
pub use pallet::*;
pub use traits::*;
pub use types::*;
// pub use weights::WeightInfo;
pub use weights::WeightInfo;
use frame_support::traits::StorageVersion;
use pallet_authority_members::SessionIndex;
......@@ -39,7 +45,7 @@ pub const MAX_EVALUATIONS_PER_SESSION: u32 = 600;
/// Maximum number of evaluators in a session
pub const MAX_EVALUATORS_PER_SESSION: u32 = 100;
#[frame_support::pallet(dev_mode)] // dev mode while waiting for benchmarks
#[frame_support::pallet()]
pub mod pallet {
use super::*;
use frame_support::{pallet_prelude::*, traits::ReservableCurrency};
......@@ -50,7 +56,6 @@ pub mod pallet {
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
#[pallet::pallet]
// #[pallet::generate_store(pub(super) trait Store)] // deprecated
#[pallet::storage_version(STORAGE_VERSION)]
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);
......@@ -73,7 +78,7 @@ pub mod pallet {
/// Number of session to keep a positive evaluation result
type ResultExpiration: Get<u32>;
// /// Type representing the weight of this pallet
// type WeightInfo: WeightInfo;
type WeightInfo: WeightInfo;
}
// STORAGE //
......@@ -177,8 +182,7 @@ pub mod pallet {
/// dummy `on_initialize` to return the weight used in `on_finalize`.
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
// weight of `on_finalize`
//T::WeightInfo::on_finalize()// TODO uncomment when benchmarking
Weight::zero()
<T as pallet::Config>::WeightInfo::on_finalize()
}
/// # <weight>
......@@ -196,8 +200,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// Request an identity to be evaluated
#[pallet::call_index(0)]
#[pallet::weight(0)]
// #[pallet::weight(T::WeightInfo::request_distance_evaluation())]
#[pallet::weight(<T as pallet::Config>::WeightInfo::request_distance_evaluation())]
pub fn request_distance_evaluation(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
......@@ -215,8 +218,7 @@ pub mod pallet {
/// (Inherent) Push an evaluation result to the pool
#[pallet::call_index(1)]
#[pallet::weight(0)]
// #[pallet::weight(T::WeightInfo::update_evaluation())]
#[pallet::weight(<T as pallet::Config>::WeightInfo::update_evaluation(MAX_EVALUATIONS_PER_SESSION))]
pub fn update_evaluation(
origin: OriginFor<T>,
computation_result: ComputationResult,
......@@ -236,8 +238,7 @@ pub mod pallet {
/// Push an evaluation result to the pool
#[pallet::call_index(2)]
#[pallet::weight(0)]
// #[pallet::weight(T::WeightInfo::force_update_evaluation())]
#[pallet::weight(<T as pallet::Config>::WeightInfo::force_update_evaluation(MAX_EVALUATIONS_PER_SESSION))]
pub fn force_update_evaluation(
origin: OriginFor<T>,
evaluator: <T as frame_system::Config>::AccountId,
......@@ -256,8 +257,7 @@ pub mod pallet {
/// when the evaluation completes.
/// * `status.1` is the status of the evaluation.
#[pallet::call_index(3)]
#[pallet::weight(0)]
// #[pallet::weight(T::WeightInfo::force_set_distance_status())]
#[pallet::weight(<T as pallet::Config>::WeightInfo::force_set_distance_status())]
pub fn force_set_distance_status(
origin: OriginFor<T>,
identity: <T as pallet_identity::Config>::IdtyIndex,
......
// Copyright 2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
use super::*;
use crate::{self as pallet_distance};
use core::marker::PhantomData;
use frame_support::{
parameter_types,
traits::{Everything, GenesisBuild},
};
use frame_system as system;
use pallet_balances::AccountData;
use pallet_session::ShouldEndSession;
use sp_core::{ConstU32, H256};
use sp_runtime::{
impl_opaque_keys,
key_types::DUMMY,
testing::{Header, TestSignature, UintAuthorityId},
traits::{BlakeTwo256, ConvertInto, IdentityLookup, IsMember, OpaqueKeys},
KeyTypeId, Perbill,
};
type Balance = u64;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
pub type AccountId = u64;
impl_opaque_keys! {
pub struct MockSessionKeys {
pub dummy: UintAuthorityId,
}
}
impl From<UintAuthorityId> for MockSessionKeys {
fn from(dummy: UintAuthorityId) -> Self {
Self { dummy }
}
}
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Config<T>, Event},
Authorship: pallet_authorship::{Pallet, Storage},
AuthorityMembers: pallet_authority_members::{Pallet, Call, Storage, Config<T>, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Identity: pallet_identity::{Pallet, Call, Storage, Config<T>, Event<T>},
Distance: pallet_distance::{Pallet, Call, Storage},
}
);
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 42;
}
impl system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}
pub struct TestSessionHandler;
impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
const KEY_TYPE_IDS: &'static [KeyTypeId] = &[DUMMY];
fn on_new_session<Ks: OpaqueKeys>(
_changed: bool,
_validators: &[(AccountId, Ks)],
_queued_validators: &[(AccountId, Ks)],
) {
}
fn on_disabled(_validator_index: u32) {}
fn on_genesis_session<Ks: OpaqueKeys>(_validators: &[(AccountId, Ks)]) {}
}
const SESSION_LENGTH: u64 = 5;
pub struct TestShouldEndSession;
impl ShouldEndSession<u64> for TestShouldEndSession {
fn should_end_session(now: u64) -> bool {
now % SESSION_LENGTH == 0
}
}
impl pallet_session::Config for Test {
type RuntimeEvent = RuntimeEvent;
type ValidatorId = AccountId;
type ValidatorIdOf = ConvertInto;
type ShouldEndSession = TestShouldEndSession;
type NextSessionRotation = ();
type SessionManager = AuthorityMembers;
type SessionHandler = TestSessionHandler;
type Keys = MockSessionKeys;
type WeightInfo = ();
}
pub struct FullIdentificationOfImpl;
impl sp_runtime::traits::Convert<AccountId, Option<()>> for FullIdentificationOfImpl {
fn convert(_: AccountId) -> Option<()> {
Some(())
}
}
impl pallet_session::historical::Config for Test {
type FullIdentification = ();
type FullIdentificationOf = FullIdentificationOfImpl;
}
pub struct ConstantAuthor<T>(PhantomData<T>);
impl<T: From<u64>> frame_support::traits::FindAuthor<T> for ConstantAuthor<T> {
fn find_author<'a, I>(_: I) -> Option<T>
where
I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>,
{
Some(1u64.into())
}
}
impl pallet_authorship::Config for Test {
type FindAuthor = ConstantAuthor<Self::AccountId>;
type EventHandler = ();
}
pub struct TestIsSmithMember;
impl IsMember<u32> for TestIsSmithMember {
fn is_member(member_id: &u32) -> bool {
member_id % 3 == 0
}
}
pub struct IdentityIndexOf<T: pallet_identity::Config>(PhantomData<T>);
impl<T: pallet_identity::Config> sp_runtime::traits::Convert<T::AccountId, Option<T::IdtyIndex>>
for IdentityIndexOf<T>
{
fn convert(account_id: T::AccountId) -> Option<T::IdtyIndex> {
pallet_identity::Pallet::<T>::identity_index_of(account_id)
}
}
impl pallet_authority_members::Config for Test {
type KeysWrapper = MockSessionKeys;
type IsMember = TestIsSmithMember;
type MaxAuthorities = ConstU32<4>;
type MemberId = u32;
type MemberIdOf = IdentityIndexOf<Self>;
type OnNewSession = ();
type OnRemovedMember = ();
type RemoveMemberOrigin = system::EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
parameter_types! {
pub const ExistentialDeposit: Balance = 10;
pub const MaxLocks: u32 = 50;
}
impl pallet_balances::Config for Test {
type Balance = Balance;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Test>;
type MaxLocks = MaxLocks;
type MaxReserves = ();
type ReserveIdentifier = [u8; 8];
type RuntimeEvent = RuntimeEvent;
type HoldIdentifier = ();
type FreezeIdentifier = ();
type MaxHolds = ConstU32<0>;
type MaxFreezes = ConstU32<0>;
}
parameter_types! {
pub const ChangeOwnerKeyPeriod: u64 = 10;
pub const ConfirmPeriod: u64 = 2;
pub const IdtyCreationPeriod: u64 = 3;
pub const MaxInactivityPeriod: u64 = 5;
pub const ValidationPeriod: u64 = 2;
}
pub struct IdtyNameValidatorTestImpl;
impl pallet_identity::traits::IdtyNameValidator for IdtyNameValidatorTestImpl {
fn validate(idty_name: &pallet_identity::IdtyName) -> bool {
idty_name.0.len() < 16
}
}
impl pallet_identity::Config for Test {
type ChangeOwnerKeyPeriod = ChangeOwnerKeyPeriod;
type ConfirmPeriod = ConfirmPeriod;
type CheckIdtyCallAllowed = ();
type IdtyCreationPeriod = IdtyCreationPeriod;
type IdtyData = ();
type IdtyNameValidator = IdtyNameValidatorTestImpl;
type IdtyIndex = u32;
type AccountLinker = ();
type IdtyRemovalOtherReason = ();
type Signer = UintAuthorityId;
type Signature = TestSignature;
type OnIdtyChange = ();
type RemoveIdentityConsumers = ();
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetupHandler = ();
}
parameter_types! {
pub const MinAccessibleReferees: Perbill = Perbill::from_percent(80);
}
impl pallet_distance::Config for Test {
type Currency = Balances;
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MinAccessibleReferees = MinAccessibleReferees;
type ResultExpiration = frame_support::traits::ConstU32<720>;
type WeightInfo = ();
}
// Build genesis storage according to the mock runtime.
#[allow(dead_code)] // ??? Clippy triggers dead code for new_test_ext while it is used during test benchmark
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
.unwrap();
pub const NAMES: [&str; 6] = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Ferdie"];
pallet_identity::GenesisConfig::<Test> {
identities: (1..=4)
.map(|i| pallet_identity::GenesisIdty {
index: i as u32,
name: pallet_identity::IdtyName::from(NAMES[i - 1]),
value: pallet_identity::IdtyValue {
data: (),
next_creatable_identity_on: 0,
owner_key: i as u64,
old_owner_key: None,
removable_on: 0,
status: pallet_identity::IdtyStatus::Validated,
},
})
.collect(),
}
.assimilate_storage(&mut t)
.unwrap();
sp_io::TestExternalities::new(t)
}
// Copyright 2021-2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(clippy::unnecessary_cast)]
use frame_support::weights::{constants::RocksDbWeight, Weight};
pub trait WeightInfo {
fn request_distance_evaluation() -> Weight;
fn update_evaluation(i: u32) -> Weight;
fn force_update_evaluation(i: u32) -> Weight;
fn force_set_distance_status() -> Weight;
fn on_finalize() -> Weight;
}
// Insecure weights implementation, use it for tests only!
impl WeightInfo for () {
/// Storage: Identity IdentityIndexOf (r:1 w:0)
/// Proof Skipped: Identity IdentityIndexOf (max_values: None, max_size: None, mode: Measured)
/// Storage: Distance IdentityDistanceStatus (r:1 w:1)
/// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured)
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance EvaluationPool2 (r:1 w:1)
/// Proof Skipped: Distance EvaluationPool2 (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(121), added: 2596, mode: MaxEncodedLen)
/// Storage: Distance DistanceStatusExpireOn (r:1 w:1)
/// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured)
fn request_distance_evaluation() -> Weight {
// Proof Size summary in bytes:
// Measured: `935`
// Estimated: `4400`
// Minimum execution time: 28_469_000 picoseconds.
Weight::from_parts(30_905_000, 0)
.saturating_add(Weight::from_parts(0, 4400))
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(4))
}
/// Storage: Distance DidUpdate (r:1 w:1)
/// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Authorship Author (r:1 w:1)
/// Proof: Authorship Author (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
/// Storage: System Digest (r:1 w:0)
/// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance EvaluationPool0 (r:1 w:1)
/// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `i` is `[1, 600]`.
fn update_evaluation(i: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `744 + i * (10 ±0)`
// Estimated: `2228 + i * (10 ±0)`
// Minimum execution time: 13_870_000 picoseconds.
Weight::from_parts(17_116_748, 0)
.saturating_add(Weight::from_parts(0, 2228))
// Standard Error: 684
.saturating_add(Weight::from_parts(128_989, 0).saturating_mul(i.into()))
.saturating_add(RocksDbWeight::get().reads(5))
.saturating_add(RocksDbWeight::get().writes(3))
.saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into()))
}
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance EvaluationPool0 (r:1 w:1)
/// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `i` is `[1, 600]`.
fn force_update_evaluation(i: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `612 + i * (10 ±0)`
// Estimated: `2096 + i * (10 ±0)`
// Minimum execution time: 8_392_000 picoseconds.
Weight::from_parts(10_825_908, 0)
.saturating_add(Weight::from_parts(0, 2096))
// Standard Error: 326
.saturating_add(Weight::from_parts(123_200, 0).saturating_mul(i.into()))
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into()))
}
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance DistanceStatusExpireOn (r:1 w:1)
/// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured)
/// Storage: Distance IdentityDistanceStatus (r:0 w:1)
/// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured)
fn force_set_distance_status() -> Weight {
// Proof Size summary in bytes:
// Measured: `586`
// Estimated: `4051`
// Minimum execution time: 8_099_000 picoseconds.
Weight::from_parts(8_786_000, 0)
.saturating_add(Weight::from_parts(0, 4051))
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(2))
}
/// Storage: Distance DidUpdate (r:1 w:1)
/// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured)
fn on_finalize() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `1655`
// Minimum execution time: 3_904_000 picoseconds.
Weight::from_parts(4_132_000, 0)
.saturating_add(Weight::from_parts(0, 1655))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
}
......@@ -11,7 +11,7 @@ version = '3.0.0'
[features]
default = ['std']
runtime-benchmarks = ['frame-benchmarking']
runtime-benchmarks = ['frame-benchmarking', 'pallet-membership/runtime-benchmarks', 'pallet-identity/runtime-benchmarks']
std = [
'codec/std',
'frame-support/std',
......
......@@ -87,7 +87,7 @@ fn create_dummy_identity<T: Config>(i: u32) -> Result<(), &'static str> {
<Identities<T>>::insert(idty_index, value);
IdentitiesRemovableOn::<T>::append(removable_on, (idty_index, IdtyStatus::Created));
IdentityIndexOf::<T>::insert(owner_key.clone(), idty_index);
<IdentitiesNames<T>>::insert(idty_name.clone(), ());
<IdentitiesNames<T>>::insert(idty_name.clone(), idty_index);
Ok(())
}
......
......@@ -247,8 +247,8 @@ macro_rules! pallets_config {
type WeightInfo = common_runtime::weights::pallet_authority_members::WeightInfo<Runtime>;
}
impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
type EventHandler = ImOnline;
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Babe>;
}
impl pallet_im_online::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
......@@ -518,6 +518,7 @@ macro_rules! pallets_config {
type EvaluationPrice = frame_support::traits::ConstU64<1000>;
type MinAccessibleReferees = MinAccessibleReferees;
type ResultExpiration = frame_support::traits::ConstU32<720>;
type WeightInfo = common_runtime::weights::pallet_distance::WeightInfo<Runtime>;
}
// SMITHS SUB-WOT //
......
......@@ -25,6 +25,7 @@ pub mod frame_system;
pub mod pallet_babe;
pub mod pallet_balances;
pub mod pallet_collective;
pub mod pallet_distance;
pub mod pallet_grandpa;
pub mod pallet_im_online;
pub mod pallet_multisig;
......
//! Autogenerated weights for `pallet_distance`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-11-02, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `bgallois-ms7d43`, CPU: `12th Gen Intel(R) Core(TM) i3-12100F`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("gdev-benchmark"), DB CACHE: 1024
// Executed Command:
// ./target/release/duniter
// benchmark
// pallet
// --chain
// gdev-benchmark
// --execution=wasm
// --wasm-execution=compiled
// --pallet
// pallet-distance
// --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output
// runtime/common/src/weights/
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]
use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;
/// Weight functions for `pallet_distance`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_distance::WeightInfo for WeightInfo<T> {
/// Storage: Identity IdentityIndexOf (r:1 w:0)
/// Proof Skipped: Identity IdentityIndexOf (max_values: None, max_size: None, mode: Measured)
/// Storage: Distance IdentityDistanceStatus (r:1 w:1)
/// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured)
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance EvaluationPool2 (r:1 w:1)
/// Proof Skipped: Distance EvaluationPool2 (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(121), added: 2596, mode: MaxEncodedLen)
/// Storage: Distance DistanceStatusExpireOn (r:1 w:1)
/// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured)
fn request_distance_evaluation() -> Weight {
// Proof Size summary in bytes:
// Measured: `935`
// Estimated: `4400`
// Minimum execution time: 28_469_000 picoseconds.
Weight::from_parts(30_905_000, 0)
.saturating_add(Weight::from_parts(0, 4400))
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}
/// Storage: Distance DidUpdate (r:1 w:1)
/// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Authorship Author (r:1 w:1)
/// Proof: Authorship Author (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
/// Storage: System Digest (r:1 w:0)
/// Proof Skipped: System Digest (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance EvaluationPool0 (r:1 w:1)
/// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `i` is `[1, 600]`.
fn update_evaluation(i: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `744 + i * (10 ±0)`
// Estimated: `2228 + i * (10 ±0)`
// Minimum execution time: 13_870_000 picoseconds.
Weight::from_parts(17_116_748, 0)
.saturating_add(Weight::from_parts(0, 2228))
// Standard Error: 684
.saturating_add(Weight::from_parts(128_989, 0).saturating_mul(i.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
.saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into()))
}
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance EvaluationPool0 (r:1 w:1)
/// Proof Skipped: Distance EvaluationPool0 (max_values: Some(1), max_size: None, mode: Measured)
/// The range of component `i` is `[1, 600]`.
fn force_update_evaluation(i: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `612 + i * (10 ±0)`
// Estimated: `2096 + i * (10 ±0)`
// Minimum execution time: 8_392_000 picoseconds.
Weight::from_parts(10_825_908, 0)
.saturating_add(Weight::from_parts(0, 2096))
// Standard Error: 326
.saturating_add(Weight::from_parts(123_200, 0).saturating_mul(i.into()))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 10).saturating_mul(i.into()))
}
/// Storage: Session CurrentIndex (r:1 w:0)
/// Proof Skipped: Session CurrentIndex (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Distance DistanceStatusExpireOn (r:1 w:1)
/// Proof Skipped: Distance DistanceStatusExpireOn (max_values: None, max_size: None, mode: Measured)
/// Storage: Distance IdentityDistanceStatus (r:0 w:1)
/// Proof Skipped: Distance IdentityDistanceStatus (max_values: None, max_size: None, mode: Measured)
fn force_set_distance_status() -> Weight {
// Proof Size summary in bytes:
// Measured: `586`
// Estimated: `4051`
// Minimum execution time: 8_099_000 picoseconds.
Weight::from_parts(8_786_000, 0)
.saturating_add(Weight::from_parts(0, 4051))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
/// Storage: Distance DidUpdate (r:1 w:1)
/// Proof Skipped: Distance DidUpdate (max_values: Some(1), max_size: None, mode: Measured)
fn on_finalize() -> Weight {
// Proof Size summary in bytes:
// Measured: `170`
// Estimated: `1655`
// Minimum execution time: 3_904_000 picoseconds.
Weight::from_parts(4_132_000, 0)
.saturating_add(Weight::from_parts(0, 1655))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
}
......@@ -16,16 +16,36 @@ targets = ['x86_64-unknown-linux-gnu']
[features]
default = ['std']
runtime-benchmarks = [
'frame-benchmarking',
'common-runtime/runtime-benchmarks',
'frame-benchmarking/runtime-benchmarks',
'frame-support/runtime-benchmarks',
'frame-system-benchmarking',
'frame-system/runtime-benchmarks',
'hex-literal',
'pallet-authority-members/runtime-benchmarks',
'pallet-babe/runtime-benchmarks',
'pallet-balances/runtime-benchmarks',
'pallet-certification/runtime-benchmarks',
'pallet-collective/runtime-benchmarks',
'pallet-duniter-test-parameters/runtime-benchmarks',
'pallet-duniter-account/runtime-benchmarks',
'pallet-duniter-wot/runtime-benchmarks',
'pallet-grandpa/runtime-benchmarks',
'pallet-identity/runtime-benchmarks',
'pallet-membership/runtime-benchmarks',
'pallet-provide-randomness/runtime-benchmarks',
'pallet-im-online/runtime-benchmarks',
'pallet-multisig/runtime-benchmarks',
'pallet-oneshot-account/runtime-benchmarks',
'pallet-preimage/runtime-benchmarks',
'pallet-session-benchmarking/runtime-benchmarks',
'pallet-proxy/runtime-benchmarks',
'pallet-scheduler/runtime-benchmarks',
'pallet-timestamp/runtime-benchmarks',
'pallet-treasury/runtime-benchmarks',
'pallet-universal-dividend/runtime-benchmarks',
'common-runtime/runtime-benchmarks',
'pallet-upgrade-origin/runtime-benchmarks',
'pallet-utility/runtime-benchmarks',
'sp-runtime/runtime-benchmarks',
]
std = [
......@@ -155,6 +175,7 @@ pallet-preimage = { git = 'https://github.com/duniter/substrate', branch = 'duni
pallet-proxy = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
pallet-scheduler = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
pallet-session = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
pallet-session-benchmarking = { path = '../../pallets/session-benchmarking', default-features = false }
pallet-sudo = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
pallet-timestamp = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
pallet-transaction-payment = { git = 'https://github.com/duniter/substrate', branch = 'duniter-substrate-v0.9.42', default-features = false }
......
......@@ -22,6 +22,10 @@
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
pub mod parameters;
pub use self::parameters::*;
......@@ -136,6 +140,7 @@ mod benches {
define_benchmarks!(
[pallet_certification, Cert]
[pallet_certification, SmithCert]
[pallet_distance, Distance]
[pallet_oneshot_account, OneshotAccount]
[pallet_universal_dividend, UniversalDividend]
[pallet_provide_randomness, ProvideRandomness]
......
......@@ -27,6 +27,7 @@ runtime-benchmarks = [
'pallet-balances/runtime-benchmarks',
'pallet-certification/runtime-benchmarks',
'pallet-collective/runtime-benchmarks',
'pallet-distance/runtime-benchmarks',
'pallet-duniter-test-parameters/runtime-benchmarks',
'pallet-duniter-account/runtime-benchmarks',
'pallet-quota/runtime-benchmarks',
......
......@@ -145,6 +145,7 @@ mod benches {
define_benchmarks!(
[pallet_certification, Cert]
[pallet_certification, SmithCert]
[pallet_distance, Distance]
[pallet_oneshot_account, OneshotAccount]
[pallet_universal_dividend, UniversalDividend]
[pallet_provide_randomness, ProvideRandomness]
......
......@@ -141,6 +141,7 @@ mod benches {
define_benchmarks!(
[pallet_certification, Cert]
[pallet_certification, SmithCert]
[pallet_distance, Distance]
[pallet_oneshot_account, OneshotAccount]
[pallet_universal_dividend, UniversalDividend]
[pallet_provide_randomness, ProvideRandomness]
......