Skip to content
Snippets Groups Projects
Commit 925f0938 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist: Committed by Éloïs
Browse files

opti(ud): mul instead of adds for creating UD

parent c98260f5
No related branches found
No related tags found
1 merge request!8opti(ud): mul instead of adds for creating UD
...@@ -202,15 +202,14 @@ pub mod pallet { ...@@ -202,15 +202,14 @@ pub mod pallet {
let total_weight: Weight = 0; let total_weight: Weight = 0;
let ud_amount = <CurrentUdStorage<T>>::try_get().expect("corrupted storage"); let ud_amount = <CurrentUdStorage<T>>::try_get().expect("corrupted storage");
let mut monetary_mass = <MonetaryMassStorage<T>>::try_get().expect("corrupted storage"); let monetary_mass = <MonetaryMassStorage<T>>::try_get().expect("corrupted storage");
for account_id in T::MembersIds::get() { for account_id in T::MembersIds::get() {
T::Currency::deposit_creating(&account_id, ud_amount); T::Currency::deposit_creating(&account_id, ud_amount);
monetary_mass += ud_amount;
Self::write_ud_history(n, account_id, ud_amount); Self::write_ud_history(n, account_id, ud_amount);
} }
<MonetaryMassStorage<T>>::put(monetary_mass); <MonetaryMassStorage<T>>::put(monetary_mass + (ud_amount * members_count));
Self::deposit_event(Event::NewUdCreated(ud_amount, members_count)); Self::deposit_event(Event::NewUdCreated(ud_amount, members_count));
total_weight total_weight
...@@ -271,7 +270,7 @@ pub mod pallet { ...@@ -271,7 +270,7 @@ pub mod pallet {
} }
// UD(t+1) = UD(t) + c² (M(t+1) / N(t+1)) / (dt/udFrequency) // UD(t+1) = UD(t) + c² (M(t+1) / N(t+1)) / (dt/udFrequency)
ud_t + c_square * monetary_mass / (members_count * count_uds_beetween_two_reevals) ud_t + (c_square * monetary_mass) / (members_count * count_uds_beetween_two_reevals)
} }
fn write_ud_history(n: T::BlockNumber, account_id: T::AccountId, ud_amount: BalanceOf<T>) { fn write_ud_history(n: T::BlockNumber, account_id: T::AccountId, ud_amount: BalanceOf<T>) {
let mut key = Vec::with_capacity(57); let mut key = Vec::with_capacity(57);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment