Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // srml/support
- /// Something which can compute and check proofs of
- /// a historical key owner and return full identification data of that
- /// key owner.
- pub trait KeyOwnerProofSystem<Key> {
- /// The proof of membership itself.
- type Proof: Codec;
- /// The full identification of a key owner.
- type FullIdentification: Codec;
- /// Prove membership of a key owner in the current block-state.
- ///
- /// This should typically only be called off-chain, since it may be
- /// computationally heavy.
- ///
- /// Returns `Some` iff the key owner referred to by the given `key` is a
- /// member of the current set.
- fn prove(key: Key) -> Option<Self::Proof>;
- /// Check a proof of membership on-chain. Return `Some` iff the proof is
- /// valid and recent enough to check.
- fn check_proof(key: Key, proof: Self::Proof) -> Option<Self::FullIdentification>;
- }
- /// A generic trait for reporting slashing violations.
- pub trait Slash<Hash, Identification> {
- fn slash(misbehavior_footprint: Hash, who: Identification);
- }
- /// A generic trait for enacting slashes.
- pub trait DoSlash<Identification> {
- fn do_slash(severity: Severity, identification: Identification);
- }
- // IN THE CONSENSUS MODULE. THIS IS REALLY CLOSE TO THE REAL CODE WE'D WRITE.
- struct EquivocationProof<P> {
- header_a: Header,
- header_b: Header,
- author: Sr25519Public,
- membership_proof: P,
- }
- trait Trait: system::Trait {
- type KeyOwner: KeyOwnerProofSystem<Sr25519Public>;
- type EquivocationSlash: Slash<Self::Hash, Self::KeyOwner::FullIdentification>;
- }
- struct Babe<T: Trait>;
- impl<T: Trait> Babe<T> {
- fn report_equivocation(proof: EquivocationProof<T::KeyOwner::Proof>) {
- let identification = T::KeyOwner::check_proof(
- proof.author.clone(),
- proof.membership_proof
- ).expect("fuck");
- if slot(&proof.header_a) == slot(&proof.header_b)
- && check_signature(&proof.header_a, &proof.author)
- && check_signature(&proof.header_b, &proof.author)
- {
- // time to slash.
- let footprint = T::Hashing::hash((proof.author, slot(&proof.header_a)).encode());
- } else {
- panic!("fuck")
- }
- }
- }
- // rolling_misconduct, ABSTRACTING SO WE DON'T HAVE TO DEAL WITH THIS LOGIC
- // IN MORE THAN ONE PLACE
- struct RollingMisconduct<T> {
- reports: Vec<BlockReports>, // in storage...something more optimized. this is just to prove a point
- }
- impl<T> RollingMisconduct<T> {
- fn on_initialize() {
- self.reports.push(empty());
- }
- fn on_finalize() {
- if self.reports.len() > MIN {
- let overflow = self.reports.len() - MIN;
- self.reports.drain(..overflow);
- }
- }
- // note a misbehavior of `kind` and return the number of times it's happened
- // (including now) in the rolling window.
- fn note_misbehavior(kind: Code) -> usize {
- }
- }
- // staking
- // EXPOSURE IS ONLY NON-GENERIC HERE
- impl<T: Trait> DoSlash<(T::AccountId, Exposure<T>)> for StakingSlasher {
- fn do_slash(severity: Severity, (who, exposure): (T::AccountId, Exposure<T>)) {
- // severity is probably a Fraction.
- }
- }
- // slash_deduplicator
- // tracks all misbehavior reported during the bonding duration and makes sure
- // duplicates are excluded.
- struct SlashDeduplicator<T> {
- // all in storage.
- Map<EraIndex, Vec<T::Hash>>,
- Map<Hash, ()>,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement