Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. // srml/support
  2.  
  3. /// Something which can compute and check proofs of
  4. /// a historical key owner and return full identification data of that
  5. /// key owner.
  6. pub trait KeyOwnerProofSystem<Key> {
  7. /// The proof of membership itself.
  8. type Proof: Codec;
  9. /// The full identification of a key owner.
  10. type FullIdentification: Codec;
  11.  
  12. /// Prove membership of a key owner in the current block-state.
  13. ///
  14. /// This should typically only be called off-chain, since it may be
  15. /// computationally heavy.
  16. ///
  17. /// Returns `Some` iff the key owner referred to by the given `key` is a
  18. /// member of the current set.
  19. fn prove(key: Key) -> Option<Self::Proof>;
  20.  
  21. /// Check a proof of membership on-chain. Return `Some` iff the proof is
  22. /// valid and recent enough to check.
  23. fn check_proof(key: Key, proof: Self::Proof) -> Option<Self::FullIdentification>;
  24. }
  25.  
  26. /// A generic trait for reporting slashing violations.
  27. pub trait Slash<Hash, Identification> {
  28. fn slash(misbehavior_footprint: Hash, who: Identification);
  29. }
  30.  
  31. /// A generic trait for enacting slashes.
  32. pub trait DoSlash<Identification> {
  33. fn do_slash(severity: Severity, identification: Identification);
  34. }
  35.  
  36. // IN THE CONSENSUS MODULE. THIS IS REALLY CLOSE TO THE REAL CODE WE'D WRITE.
  37.  
  38. struct EquivocationProof<P> {
  39. header_a: Header,
  40. header_b: Header,
  41. author: Sr25519Public,
  42. membership_proof: P,
  43. }
  44.  
  45. trait Trait: system::Trait {
  46. type KeyOwner: KeyOwnerProofSystem<Sr25519Public>;
  47. type EquivocationSlash: Slash<Self::Hash, Self::KeyOwner::FullIdentification>;
  48. }
  49.  
  50. struct Babe<T: Trait>;
  51.  
  52. impl<T: Trait> Babe<T> {
  53. fn report_equivocation(proof: EquivocationProof<T::KeyOwner::Proof>) {
  54. let identification = T::KeyOwner::check_proof(
  55. proof.author.clone(),
  56. proof.membership_proof
  57. ).expect("fuck");
  58.  
  59. if slot(&proof.header_a) == slot(&proof.header_b)
  60. && check_signature(&proof.header_a, &proof.author)
  61. && check_signature(&proof.header_b, &proof.author)
  62. {
  63. // time to slash.
  64. let footprint = T::Hashing::hash((proof.author, slot(&proof.header_a)).encode());
  65.  
  66. } else {
  67. panic!("fuck")
  68. }
  69. }
  70. }
  71.  
  72. // rolling_misconduct, ABSTRACTING SO WE DON'T HAVE TO DEAL WITH THIS LOGIC
  73. // IN MORE THAN ONE PLACE
  74.  
  75. struct RollingMisconduct<T> {
  76. reports: Vec<BlockReports>, // in storage...something more optimized. this is just to prove a point
  77. }
  78.  
  79. impl<T> RollingMisconduct<T> {
  80. fn on_initialize() {
  81. self.reports.push(empty());
  82. }
  83.  
  84. fn on_finalize() {
  85. if self.reports.len() > MIN {
  86. let overflow = self.reports.len() - MIN;
  87. self.reports.drain(..overflow);
  88. }
  89. }
  90.  
  91. // note a misbehavior of `kind` and return the number of times it's happened
  92. // (including now) in the rolling window.
  93. fn note_misbehavior(kind: Code) -> usize {
  94.  
  95. }
  96. }
  97.  
  98. // staking
  99.  
  100. // EXPOSURE IS ONLY NON-GENERIC HERE
  101. impl<T: Trait> DoSlash<(T::AccountId, Exposure<T>)> for StakingSlasher {
  102. fn do_slash(severity: Severity, (who, exposure): (T::AccountId, Exposure<T>)) {
  103. // severity is probably a Fraction.
  104. }
  105. }
  106.  
  107. // slash_deduplicator
  108.  
  109. // tracks all misbehavior reported during the bonding duration and makes sure
  110. // duplicates are excluded.
  111. struct SlashDeduplicator<T> {
  112. // all in storage.
  113. Map<EraIndex, Vec<T::Hash>>,
  114. Map<Hash, ()>,
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement