Skip to content

Commit

Permalink
implement proposal type petition (#400)
Browse files Browse the repository at this point in the history
* implement proposal type petition

* fmt

* fixes

* add petion test

* clippy

* clippy

* benchmark petition as biggest proposal

* petitions don't supeseed others in the queue.

* fmt

* align CI with runtimes repo

* fix CI

* fmt again

* fmt again
  • Loading branch information
brenzi authored Aug 26, 2024
1 parent f8437f5 commit 557aea1
Show file tree
Hide file tree
Showing 47 changed files with 422 additions and 257 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
os: [ ubuntu-latest ]
check: [ cargo build --release,
cargo test --all --features runtime-benchmarks --features try-runtime,
cargo +nightly fmt --all -- --check,
cargo +nightly-2024-04-14 fmt --all -- --check,
cargo clippy --all-features -- -D warnings
]
steps:
Expand All @@ -36,7 +36,8 @@ jobs:
run: sudo apt-get install protobuf-compiler

- name: Install nightly toolchain
run: rustup toolchain install nightly --profile minimal --component rustfmt
# align nightly version with https://github.com/polkadot-fellows/runtimes/blob/7157d41176bebf128aa2e29e72ed184844446b19/.github/env#L2C22-L2C32
run: rustup toolchain install nightly-2024-04-14 --profile minimal --component rustfmt

- name: Setup Rust toolchain
run: rustup show
Expand Down
7 changes: 6 additions & 1 deletion rustfmt.toml → .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# align with https://github.com/polkadot-fellows/runtimes/blob/main/.rustfmt.toml
# Basic
edition = "2021"
hard_tabs = true
max_width = 100
use_small_heuristics = "Max"
Expand All @@ -17,4 +19,7 @@ match_arm_blocks = false
match_block_trailing_comma = true
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
use_field_init_shorthand = true
# Format comments
comment_width = 100
wrap_comments = true
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
13 changes: 7 additions & 6 deletions balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const LOG: &str = "encointer";
/// ```
/// This needs to be negated in the formula!
// FIXME: how to define negative hex literal?
//pub const DemurrageRate: BalanceType = BalanceType::from_bits(0x0000000000000000000001E3F0A8A973_i128);
//pub const DemurrageRate: BalanceType =
// BalanceType::from_bits(0x0000000000000000000001E3F0A8A973_i128);
pub use pallet::*;

mod impl_fungibles;
Expand Down Expand Up @@ -133,8 +134,8 @@ pub mod pallet {
///
/// [CC]: 1 Unit of Community Currency
/// NI: Nominal Income. Unit = [CC]
/// FCF: Fee Conversion Factor. Unit = [1/ KKSM] <- Kilo-KSM to be able to adjust fee factor in both ways.
/// CB: Balance in Community Currency [CC]
/// FCF: Fee Conversion Factor. Unit = [1/ KKSM] <- Kilo-KSM to be able to adjust fee factor
/// in both ways. CB: Balance in Community Currency [CC]
///
/// The following equation should hold for fee design:
/// KSM * FCF * NI = CB -> FCF = CB / (NI * KSM)
Expand Down Expand Up @@ -278,7 +279,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 +290,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 +353,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
6 changes: 4 additions & 2 deletions balances/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ limitations under the License.
// --wasm-execution=compiled
// --heap-pages=4096
// --output=runtime/src/weights/pallet_encointer_balances.rs
// --template=/Users/pigu/Dropbox/DATA/Documents/solidbit/kunden/encointer/code/repos/encointer-node/scripts/frame-weight-template-full-info.hbs
// --template=/Users/pigu/Dropbox/DATA/Documents/solidbit/kunden/encointer/code/repos/
// encointer-node/scripts/frame-weight-template-full-info.hbs

#![allow(unused_parens)]
#![allow(unused_imports)]
Expand All @@ -54,7 +55,8 @@ pub trait WeightInfo {
fn set_fee_conversion_factor() -> Weight;
}

/// Weights for pallet_encointer_balances using the Encointer solo chain node and recommended hardware.
/// Weights for pallet_encointer_balances using the Encointer solo chain node and recommended
/// hardware.
pub struct EncointerWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for EncointerWeight<T> {
fn transfer() -> Weight {
Expand Down
1 change: 0 additions & 1 deletion bazaar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
//! provides functionality for
//! - creating new bazaar entries (shop and articles)
//! - removing existing entries (shop and articles)
//!

#![cfg_attr(not(feature = "std"), no_std)]

Expand Down
3 changes: 2 additions & 1 deletion bazaar/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ pub trait WeightInfo {
fn delete_offering() -> Weight;
}

/// Weights for pallet_encointer_bazaar using the Encointer solo chain node and recommended hardware.
/// Weights for pallet_encointer_bazaar using the Encointer solo chain node and recommended
/// hardware.
pub struct EncointerWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for EncointerWeight<T> {
fn create_business() -> Weight {
Expand Down
13 changes: 7 additions & 6 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,7 +97,7 @@ 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;
Expand All @@ -118,7 +118,7 @@ pub fn assignment_fn_inverse(
};

if t3 >= participant_count {
continue
continue;
}

result.push(t3);
Expand Down Expand Up @@ -264,7 +264,8 @@ mod tests {
assignment_params = AssignmentParams { m, s1, s2 };
check_assignment(num_participants, assignment_params, n);

// in the case where there is only one participant, m will be 2 because it is the smallest prime number
// in the case where there is only one participant, m will be 2 because it is the smallest
// prime number
s1 = 1u64;
s2 = 1u64;
n = 1u64;
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 557aea1

Please sign in to comment.