Skip to content

Commit

Permalink
fixing benchmarks if genesis is pure defaults (#368)
Browse files Browse the repository at this point in the history
* fixing benchmarks if genesis is pure defaults

* bump crate versions to publish

* trying to pin stable for crates.io

* another fix in ceremonies benchmakrs

* lockfile

* fmt +stable

* clippy

* fix tests
  • Loading branch information
brenzi authored Feb 7, 2024
1 parent f6e15ec commit 6f5a51c
Show file tree
Hide file tree
Showing 42 changed files with 272 additions and 223 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

20 changes: 5 additions & 15 deletions balances-tx-payment/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use encointer_balances_tx_payment_rpc_runtime_api::{
BalancesTxPaymentApi as BalancesTxPaymentApiRuntimeApi, Error,
};
use jsonrpsee::{
core::{Error as JsonRpseeError, RpcResult},
core::RpcResult,
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
types::error::{CallError, ErrorObject},
};
pub use pallet_transaction_payment::RuntimeDispatchInfo;
use pallet_transaction_payment::{FeeDetails, InclusionFee};
Expand Down Expand Up @@ -107,16 +107,6 @@ where
))
})?;

let try_into_rpc_balance = |value: AssetBalance| {
value.try_into().map_err(|_| {
JsonRpseeError::Call(CallError::Custom(ErrorObject::owned(
ErrorCode::InvalidParams.code(),
format!("{value} doesn't fit in NumberOrHex representation"),
None::<()>,
)))
})
};

Ok(FeeDetails {
inclusion_fee: if let Some(inclusion_fee) = fee_details.inclusion_fee {
let base_fee = api
Expand Down Expand Up @@ -147,9 +137,9 @@ where
})?;

Some(InclusionFee {
base_fee: try_into_rpc_balance(base_fee)?,
len_fee: try_into_rpc_balance(len_fee)?,
adjusted_weight_fee: try_into_rpc_balance(adjusted_weight_fee)?,
base_fee: base_fee.into(),
len_fee: len_fee.into(),
adjusted_weight_fee: adjusted_weight_fee.into(),
})
} else {
None
Expand Down
14 changes: 7 additions & 7 deletions balances/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
_provenance: Provenance,
) -> DepositConsequence {
if !<TotalIssuance<T>>::contains_key(asset) {
return DepositConsequence::UnknownAsset
return DepositConsequence::UnknownAsset;
};

let total_issuance = Pallet::<T>::total_issuance_entry(asset).principal;

let balance_amount = balance_type(amount);
if total_issuance.checked_add(balance_amount).is_none() {
return DepositConsequence::Overflow
return DepositConsequence::Overflow;
}

let balance = Pallet::<T>::balance(asset, who);

if balance.checked_add(balance_amount).is_none() {
return DepositConsequence::Overflow
return DepositConsequence::Overflow;
}

DepositConsequence::Success
Expand All @@ -98,22 +98,22 @@ impl<T: Config> fungibles::Inspect<T::AccountId> for Pallet<T> {
use WithdrawConsequence::*;

if !<TotalIssuance<T>>::contains_key(asset) {
return UnknownAsset
return UnknownAsset;
};

let total_issuance = Pallet::<T>::total_issuance_entry(asset);
if fungible(total_issuance.principal).checked_sub(amount).is_none() {
return Underflow
return Underflow;
}

if amount.is_zero() {
return Success
return Success;
}

let balance = fungible(Pallet::<T>::balance(asset, who));

if balance.checked_sub(amount).is_none() {
return WithdrawConsequence::BalanceLow
return WithdrawConsequence::BalanceLow;
}
WithdrawConsequence::Success
}
Expand Down
6 changes: 3 additions & 3 deletions balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<T: Config> Pallet<T> {
// Early exist if no-op.
if amount == 0u128 {
Self::deposit_event(Event::Transferred(cid, source, dest, amount));
return Ok(amount)
return Ok(amount);
}

ensure!(Balance::<T>::contains_key(cid, &source), Error::<T>::NoAccount);
Expand All @@ -289,7 +289,7 @@ impl<T: Config> Pallet<T> {

if source == dest {
<Balance<T>>::insert(cid, &source, entry_from);
return Ok(amount)
return Ok(amount);
}

if !Balance::<T>::contains_key(cid, &dest) {
Expand Down Expand Up @@ -352,7 +352,7 @@ impl<T: Config> Pallet<T> {
ensure!(res >= 0, Error::<T>::BalanceTooLow);
res
} else {
return Err(Error::<T>::BalanceTooLow.into())
return Err(Error::<T>::BalanceTooLow.into());
};
entry_tot.principal -= amount;
//FIXME: delete account if it falls below existential deposit
Expand Down
4 changes: 2 additions & 2 deletions bazaar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-encointer-bazaar"
version = "3.0.2"
version = "3.0.3"
authors = ["Encointer Association <[email protected]>"]
edition = "2021"
description = "Bazaar pallet for the Encointer blockchain runtime"
Expand All @@ -16,7 +16,7 @@ log = { version = "0.4.20", default-features = false }
scale-info = { version = "2.10.0", default-features = false }

# local deps
encointer-communities = { package = "pallet-encointer-communities", path = "../communities", default-features = false, version = "3.0.2" }
encointer-communities = { package = "pallet-encointer-communities", path = "../communities", default-features = false, version = "3.0.3" }
encointer-primitives = { path = "../primitives", default-features = false, features = ["serde_derive"], version = "3.0.2" }

# substrate deps
Expand Down
4 changes: 4 additions & 0 deletions bazaar/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ fn create_community<T: Config>() -> CommunityIdentifier {

let bs = vec![alice.clone(), bob.clone(), charlie.clone()];
let community_meta: CommunityMetadata = CommunityMetadata::default();

encointer_communities::Pallet::<T>::set_min_solar_trip_time_s(RawOrigin::Root.into(), 1).ok();
encointer_communities::Pallet::<T>::set_max_speed_mps(RawOrigin::Root.into(), 83).ok();

encointer_communities::Pallet::<T>::new_community(
RawOrigin::Root.into(),
location,
Expand Down
6 changes: 3 additions & 3 deletions ceremonies/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-encointer-ceremonies"
version = "3.0.2"
version = "3.0.4"
authors = ["Encointer Association <[email protected]>"]
edition = "2021"
description = "Ceremonies pallet for the Encointer blockchain runtime"
Expand All @@ -18,10 +18,10 @@ scale-info = { version = "2.10.0", default-features = false }
# local deps
encointer-balances = { package = "pallet-encointer-balances", path = "../balances", default-features = false, version = "3.0.2" }
encointer-ceremonies-assignment = { path = "assignment", default-features = false, version = "3.0.2" }
encointer-communities = { package = "pallet-encointer-communities", path = "../communities", default-features = false, version = "3.0.2" }
encointer-communities = { package = "pallet-encointer-communities", path = "../communities", default-features = false, version = "3.0.3" }
encointer-meetup-validation = { path = "meetup-validation", default-features = false, version = "3.0.2" }
encointer-primitives = { path = "../primitives", default-features = false, features = ["serde_derive"], version = "3.0.2" }
encointer-scheduler = { package = "pallet-encointer-scheduler", path = "../scheduler", default-features = false, version = "3.0.2" }
encointer-scheduler = { package = "pallet-encointer-scheduler", path = "../scheduler", default-features = false, version = "3.0.3" }

# substrate deps
frame-support = { default-features = false, version = "25.0.0" }
Expand Down
14 changes: 7 additions & 7 deletions ceremonies/assignment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn generate_assignment_function_params<Hashing: Hash>(
AssignmentParams { m: m as u64, s1: s1 as u64, s2: s2 as u64 },
num_meetups,
) {
break
break;
} else {
skip_count += 1; // safe; skip_count <= 200;
}
Expand All @@ -65,7 +65,7 @@ fn validate_equal_mapping(
meetup_count: u64,
) -> bool {
if num_participants < 2 {
return true
return true;
}

let mut meetup_index_count: Vec<u64> = vec![0; meetup_count as usize];
Expand All @@ -80,7 +80,7 @@ fn validate_equal_mapping(

meetup_index_count[meetup_index] += 1; // safe; <= num_participants
if meetup_index_count[meetup_index] > meetup_index_count_max {
return false
return false;
}
}
true
Expand All @@ -97,14 +97,14 @@ pub fn assignment_fn_inverse(
participant_count: u64,
) -> Option<Vec<ParticipantIndexType>> {
if assignment_count == 0 {
return Some(vec![])
return Some(vec![]);
}

let mut max_index = assignment_params.m.saturating_sub(meetup_index) / assignment_count;
let mut result: Vec<ParticipantIndexType> = Vec::with_capacity(max_index as usize);
// ceil
if (assignment_params.m.saturating_sub(meetup_index) as i64).rem_euclid(assignment_count as i64) !=
0
if (assignment_params.m.saturating_sub(meetup_index) as i64).rem_euclid(assignment_count as i64)
!= 0
{
max_index += 1; //safe; m prime below num_participants
}
Expand All @@ -118,7 +118,7 @@ pub fn assignment_fn_inverse(
};

if t3 >= participant_count {
continue
continue;
}

result.push(t3);
Expand Down
26 changes: 13 additions & 13 deletions ceremonies/assignment/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,64 +40,64 @@ pub fn is_coprime(a: u64, b: u64) -> bool {

pub fn is_prime(n: u64) -> bool {
if n <= 3 {
return n > 1
return n > 1;
}
if n % 2 == 0 || n % 3 == 0 {
return false
return false;
}
if n < 25 {
return true
return true;
}
let mut i: u64 = 5;
let mut j: u64 = 25;
while j <= n {
let i_plus_two = i.checked_add(2u64).expect("i^2 does not overflow, so i + 2 is safe; qed");
if n % i == 0u64 || n % (i_plus_two) == 0u64 {
return false
return false;
}
i = i.checked_add(6u64).expect("i^2 does not overflow, so i + 6 is safe; qed");

if let Some(i_squared) = i.checked_pow(2) {
j = i_squared;
} else {
// if i overflows we can be sure that j <= n does not hold
break
break;
}
}
true
}

pub fn get_greatest_common_denominator(a: u64, b: u64) -> u64 {
if a == 0 || b == 0 {
return 0
return 0;
}

if a == b {
return a
return a;
}

if a > b {
return get_greatest_common_denominator(a.checked_sub(b).expect("a > b; qed"), b)
return get_greatest_common_denominator(a.checked_sub(b).expect("a > b; qed"), b);
}

get_greatest_common_denominator(a, b.checked_sub(a).expect("b <= a; qed"))
}

pub fn find_prime_below(mut n: u64) -> u64 {
if n <= 2 {
return 2u64
return 2u64;
}
if n % 2 == 0 {
n = n.checked_sub(1).expect("n > 2; qed");
}
while n > 0 {
if is_prime(n) {
return n
return n;
}
if let Some(n_minus_two) = n.checked_sub(2) {
n = n_minus_two;
} else {
break
break;
}
}
2u64
Expand All @@ -108,11 +108,11 @@ pub fn find_random_coprime_below<H: Hash>(
random_source: &mut RandomNumberGenerator<H>,
) -> u64 {
if upper_bound <= 1 {
return 0
return 0;
}

if upper_bound == 2 {
return 1
return 1;
}

(1..upper_bound)
Expand Down
Loading

0 comments on commit 6f5a51c

Please sign in to comment.