Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

slashing interface #3015

Closed
wants to merge 25 commits into from
Closed

slashing interface #3015

wants to merge 25 commits into from

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Jul 4, 2019

What does this PR:

It tries to introduce a few traits (Misconduct, OnEndEra, OnSlashing) to introduce a generic interface to slash misbehavior(s)

Roughly those have the following functionality:

  • Misconduct: Trait that defines a type that handles severity level
  • OnEndEra: Misconduct that should be slashed in the end of era instead of rolling
  • OnSlashing: A trait to handles balance and concrete slashing, i.e, need to both call T::Currency::free_balance() and T::Currency::slash() based on severity_level estimated by the
    Assumed to implemented on top of a module that handles Currency a.ka BalanceOf<T>
    Misconduct

Example use case

pub struct StakingSlasher<T>(T);

impl<T: Trait> OnSlashing<T::AccountId, Exposure, Severity> for StakingSlasher<T>
where
	Severity: Into<BalanceOf<T>>,
	Exposure: Into<BalanceOf<T>>,
{....}

/// Misconduct type
pub struct MyMisconduct<T>(T);

impl<T: Trait> Misconduct for MyMisconduct<T> {
   type Severity = u64;

    fn as_misconduct_level(&self, _severity: Fraction<Self::Severity>) -> u8 {...}

    fn on_misconduct(&mut self, _misbehaved: &[Self::AccountId]) -> Fraction<Self::Severity> {..}
}

let misconduct = MyMisconduct(SomeModule);
let misbehaved = vec![FakeSlashRecipient::default()];
// will probably require type parameters..
let misconduct_level = rolling_data(&misbehaved, &mut misconduct);
// use severity_level to determine whether to kick out the validator or not

TODO (before merge)

  1. Use checked_operations on Fraction
  2. Add documentation (will not do before we have some sort of consensus)
  3. bump impl version
  4. How to deal with I'm online messages #2719

A possible solution to #2719 could be to change
pub fn end_of_era(end_of_era: &E) -> u8
// don't slash ignored based on some proof
pub fn end_of_era(end_of_era: &E, ignore: &[AccountId]) -> u8

Follow-up

Implement the concrete misconduct types

References

https://research.web3.foundation/en/latest/polkadot/slashing/

@parity-cla-bot
Copy link

It looks like @niklasad1 signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

1 similar comment
@parity-cla-bot
Copy link

It looks like @niklasad1 signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@niklasad1 niklasad1 added the A3-in_progress Pull request is in progress. No review needed at this stage. label Jul 4, 2019
@niklasad1 niklasad1 changed the title [WIP] slashing interface slashing interface Jul 8, 2019
@niklasad1 niklasad1 requested a review from rphmeier July 8, 2019 13:49
@niklasad1 niklasad1 added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jul 8, 2019

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs?

@niklasad1 niklasad1 added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Jul 9, 2019
@niklasad1
Copy link
Member Author

Closing, has issues

@niklasad1 niklasad1 closed this Jul 10, 2019
@niklasad1 niklasad1 deleted the na-slashing-interface branch November 28, 2019 14:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A3-in_progress Pull request is in progress. No review needed at this stage.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants