forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EvilValidatorsPerSession and fix other nits (paritytech#710)
* Add EvilValidatorsPerSession and fix other nits * Split out slash.rs in staking
- Loading branch information
1 parent
f79977f
commit 7965f6b
Showing
7 changed files
with
76 additions
and
47 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file modified
BIN
+1.11 KB
(100%)
runtime/wasm/target/wasm32-unknown-unknown/release/chainx_runtime.compact.wasm
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use super::*; | ||
use rstd::result; | ||
use xsupport::info; | ||
|
||
impl<T: Trait> Module<T> { | ||
/// Slash the double signer and return the slashed balance. | ||
/// | ||
/// TODO extract the similar slashing logic in shifter.rs. | ||
pub fn slash_double_signer(who: &T::AccountId) -> result::Result<T::Balance, &'static str> { | ||
if !Self::is_intention(who) { | ||
return Err("Cannot slash if the reported double signer is not an intention"); | ||
} | ||
|
||
// Slash the whole jackpot of double signer. | ||
let council = xaccounts::Module::<T>::council_account(); | ||
let jackpot = Self::jackpot_accountid_for(who); | ||
|
||
let slashed = <xassets::Module<T>>::pcx_free_balance(&jackpot); | ||
let _ = <xassets::Module<T>>::pcx_move_free_balance(&jackpot, &council, slashed); | ||
info!( | ||
"[slash_double_signer] {:?} is slashed: {:?}", | ||
who!(who), | ||
slashed | ||
); | ||
|
||
// Force the double signer to be inactive. | ||
<xaccounts::IntentionPropertiesOf<T>>::mutate(who, |props| { | ||
props.is_active = false; | ||
props.last_inactive_since = <system::Module<T>>::block_number(); | ||
info!("[slash_double_signer] force {:?} to be inactive", who!(who)); | ||
}); | ||
|
||
// Note the double signer so that he could be removed from the current validator set on new session. | ||
<EvilValidatorsPerSession<T>>::mutate(|evil_validators| { | ||
if !evil_validators.contains(&who) { | ||
evil_validators.push(who.clone()) | ||
} | ||
}); | ||
|
||
Ok(slashed) | ||
} | ||
} |