Allow council to slash treasury tip (#7753)

* wk2051 | D4 |Allow council to slash treasury tip | p1

* Update frame/tips/src/lib.rs

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>

* wk2051 | D5 |Allow council to slash treasury tip | p2

* wk2051 | D5 |Allow council to slash treasury tip | p3

* wk2051 | D5 |Allow council to slash treasury tip | p4

* wk2051 | D5 |Allow council to slash treasury tip | p5

* random change

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_tips --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/tips/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* fix typo

* Update frame/tips/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/tips/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/tips/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/tips/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/tips/src/tests.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* wk2052 | D1 | Allow council to slash treasury tip | p6

Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
RK
2020-12-30 00:07:19 +05:30
committed by GitHub
parent 8c795accc8
commit acf9d2145d
7 changed files with 133 additions and 63 deletions
+29 -27
View File
@@ -58,8 +58,6 @@ mod tests;
mod benchmarking;
pub mod weights;
use sp_std::if_std;
use sp_std::prelude::*;
use frame_support::{decl_module, decl_storage, decl_event, ensure, decl_error, Parameter};
use frame_support::traits::{
@@ -70,8 +68,7 @@ use frame_support::traits::{
use sp_runtime::{ Percent, RuntimeDebug, traits::{
Zero, AccountIdConversion, Hash, BadOrigin
}};
use frame_support::traits::{Contains, ContainsLengthBound};
use frame_support::traits::{Contains, ContainsLengthBound, OnUnbalanced, EnsureOrigin};
use codec::{Encode, Decode};
use frame_system::{self as system, ensure_signed};
pub use weights::WeightInfo;
@@ -170,6 +167,8 @@ decl_event!(
TipClosed(Hash, AccountId, Balance),
/// A tip suggestion has been retracted. \[tip_hash\]
TipRetracted(Hash),
/// A tip suggestion has been slashed. \[tip_hash, finder, deposit\]
TipSlashed(Hash, AccountId, Balance),
}
);
@@ -408,6 +407,32 @@ decl_module! {
Tips::<T>::remove(hash);
Self::payout_tip(hash, tip);
}
/// Remove and slash an already-open tip.
///
/// May only be called from `T::RejectOrigin`.
///
/// As a result, the finder is slashed and the deposits are lost.
///
/// Emits `TipSlashed` if successful.
///
/// # <weight>
/// `T` is charged as upper bound given by `ContainsLengthBound`.
/// The actual cost depends on the implementation of `T::Tippers`.
/// # </weight>
#[weight = <T as Config>::WeightInfo::slash_tip(T::Tippers::max_len() as u32)]
fn slash_tip(origin, hash: T::Hash) {
T::RejectOrigin::ensure_origin(origin)?;
let tip = Tips::<T>::take(hash).ok_or(Error::<T>::UnknownTip)?;
if !tip.deposit.is_zero() {
let imbalance = T::Currency::slash_reserved(&tip.finder, tip.deposit).0;
T::OnSlash::on_unbalanced(imbalance);
}
Reasons::<T>::remove(&tip.reason);
Self::deposit_event(RawEvent::TipSlashed(hash, tip.finder, tip.deposit));
}
}
}
@@ -523,10 +548,6 @@ impl<T: Config> Module<T> {
use frame_support::{Twox64Concat, migration::StorageKeyIterator};
if_std! {
println!("Inside migrate_retract_tip_for_tip_new()!");
}
for (hash, old_tip) in StorageKeyIterator::<
T::Hash,
OldOpenTip<T::AccountId, BalanceOf<T>, T::BlockNumber, T::Hash>,
@@ -534,25 +555,11 @@ impl<T: Config> Module<T> {
>::new(b"Treasury", b"Tips").drain()
{
if_std! {
println!("Inside loop migrate_retract_tip_for_tip_new()!");
}
let (finder, deposit, finders_fee) = match old_tip.finder {
Some((finder, deposit)) => {
if_std! {
// This code is only being compiled and executed when the `std` feature is enabled.
println!("OK case!");
println!("value is: {:#?},{:#?}", finder, deposit);
}
(finder, deposit, true)
},
None => {
if_std! {
// This code is only being compiled and executed when the `std` feature is enabled.
println!("None case!");
// println!("value is: {:#?},{:#?}", T::AccountId::default(), Zero::zero());
}
(T::AccountId::default(), Zero::zero(), false)
},
};
@@ -567,10 +574,5 @@ impl<T: Config> Module<T> {
};
Tips::<T>::insert(hash, new_tip)
}
if_std! {
println!("Exit migrate_retract_tip_for_tip_new()!");
}
}
}