mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 11:57:56 +00:00
Fix over/under flow risk in OnDilution (#2548)
* fix over/under flow risk in OnDilution * bump impl
This commit is contained in:
committed by
Gavin Wood
parent
e5627e2480
commit
580432d822
@@ -59,7 +59,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
impl_name: create_runtime_str!("substrate-node"),
|
||||
authoring_version: 10,
|
||||
spec_version: 78,
|
||||
impl_version: 78,
|
||||
impl_version: 79,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
|
||||
@@ -64,7 +64,9 @@ use serde::{Serialize, Deserialize};
|
||||
use rstd::prelude::*;
|
||||
use srml_support::{StorageValue, StorageMap, decl_module, decl_storage, decl_event, ensure};
|
||||
use srml_support::traits::{Currency, ReservableCurrency, OnDilution, OnUnbalanced, Imbalance};
|
||||
use runtime_primitives::{Permill, traits::{Zero, EnsureOrigin, StaticLookup}};
|
||||
use runtime_primitives::{Permill,
|
||||
traits::{Zero, EnsureOrigin, StaticLookup, Saturating, CheckedSub, CheckedMul}
|
||||
};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use system::ensure_signed;
|
||||
|
||||
@@ -291,8 +293,12 @@ impl<T: Trait> OnDilution<BalanceOf<T>> for Module<T> {
|
||||
// pre dilution and post-dilution.
|
||||
if !minted.is_zero() && !portion.is_zero() {
|
||||
let total_issuance = T::Currency::total_issuance();
|
||||
let funding = (total_issuance - portion) / portion * minted;
|
||||
<Pot<T>>::mutate(|x| *x += funding);
|
||||
if let Some(funding) = total_issuance.checked_sub(&portion) {
|
||||
let funding = funding / portion;
|
||||
if let Some(funding) = funding.checked_mul(&minted) {
|
||||
<Pot<T>>::mutate(|x| *x = x.saturating_add(funding));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user