-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Equivocations slashing #3314
Equivocations slashing #3314
Changes from all commits
4f24928
9f1cad1
3fc6eaa
89e623b
0e1d398
d5c9cd1
45e5907
b93118f
051001a
2dae936
5c3a249
aaa8159
06ee813
a807dae
32cba20
39f7ed0
c5579b3
ecd8d81
cfe194d
4cb0bfe
7ede025
a56a7b4
da2cc83
0e2047a
61c6c22
c94f253
f7a8711
7b14a37
cea7edc
da01b46
e25b43a
55aeff5
0c8b03f
382ffa3
ac05b4f
ea68a83
fae60b9
6af9ffc
f2f91ab
9c91502
fdbc3bd
c101666
2d1d103
b7989c9
21c1131
a60252e
0db09ad
e9029f8
e40e448
63f08a0
fdb9d15
108869c
39cdeb6
67b0a50
763d32d
9c43140
c65854c
77c23dc
4384e6c
7d94eaf
97d4f5c
b8f65a8
fe75ebe
2ff220b
00a8506
eb790f2
bdf5177
2d0881a
8b4cd8e
b90e397
b9fa71b
6eb6cab
9e7e8ce
f23b2f3
2de1c86
6420e80
591fa51
0c4760f
48a3366
4bc4e6c
eb1de19
b015094
04ac719
1facbf8
57bc7a2
0b57b0d
12baeda
a88c5ac
53b2c64
2b81cc2
2c30785
fa1d88e
192e811
455dcac
3c46391
7257ca9
542de32
e02ef2f
08366c0
3f398c4
fe3094c
9b4263c
ce5e8ed
758a1ec
d58208b
4feb6e3
dd58c06
0c65697
6ddad41
246b5b1
cf31399
907ceaa
af31771
a9c58c5
ee582c4
d9a869f
5bcedda
0d34076
dd3f533
cdc43f2
106d2f0
c62f64c
98a7d52
9c6e323
4a8e88b
7b2dcde
a7e959e
f0108ac
1b01ad4
916af40
1bbd700
26efab0
d5ae058
405f995
231d1bd
41bd05a
e753bc6
b28d05c
96a9ffe
a51ef4b
5a2efb9
fa95730
f29ddec
b5084fc
9919e29
95a01d6
6158fdb
35c2e87
efc7248
870a7bd
ad3797f
0f998dd
6c5e5d9
4d59551
fc927d1
f3a2d68
f8236f5
46015f8
97bde5b
782e46d
ab32ead
de9fccc
10741ec
9f82296
940bef6
f9b82db
b7f44fc
dcf04c9
ce31bf1
50da947
a99d228
369f8f4
2d0fe68
7fd484d
6d2b7f8
03734e8
2803ed3
7781bc9
dbd49d7
967ca96
ae41ebc
6bc58a8
bbc837b
9430a2d
7ae6fb8
fadd9e7
2a7601e
3112203
94ae5f6
c74f722
40eb793
c2b83df
98265a5
e7be080
0ff99e7
8d345e4
799496d
4f95ff5
4f51e27
68468e4
6e5068b
ea6b4fa
3ed3e26
cf17c79
fb3002e
2ded0a7
8530934
4dde8a2
e3cbd31
9348769
8fe54c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,15 @@ | |
|
||
//! Private implementation details of BABE digests. | ||
|
||
#[cfg(feature = "std")] | ||
use super::AuthoritySignature; | ||
#[cfg(feature = "std")] | ||
use super::{BABE_ENGINE_ID, Epoch}; | ||
#[cfg(not(feature = "std"))] | ||
use super::{VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH}; | ||
use super::{AuthorityIndex, BabeBlockWeight, SlotNumber}; | ||
#[cfg(feature = "std")] | ||
use sr_primitives::{DigestItem, generic::OpaqueDigestItemId}; | ||
use sr_primitives::traits::{Header, DigestItemForHeader}; | ||
use codec::{Decode, Encode, Codec}; | ||
#[cfg(feature = "std")] | ||
use std::fmt::Debug; | ||
use codec::{Decode, Encode}; | ||
#[cfg(feature = "std")] | ||
use codec::{Codec, Input, Error}; | ||
use codec::{Input, Error}; | ||
#[cfg(feature = "std")] | ||
use schnorrkel::{ | ||
SignatureError, errors::MultiSignatureStage, | ||
|
@@ -93,6 +88,30 @@ impl BabePreDigest { | |
} | ||
} | ||
|
||
/// Get the slot. | ||
pub fn get_slot<H: Header>(header: &H) -> Result<SlotNumber, &str> | ||
where DigestItemForHeader<H>: CompatibleDigestItem, | ||
{ | ||
find_pre_digest::<H, RawBabePreDigest>(header) | ||
.map(|raw_pre_digest| raw_pre_digest.slot_number()) | ||
} | ||
|
||
/// Extract the BABE pre digest from the given header. Pre-runtime digests are | ||
/// mandatory, the function will return `Err` if none is found. | ||
pub fn find_pre_digest<H: Header, D: Codec>(header: &H) -> Result<D, &str> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's strange to return a |
||
where DigestItemForHeader<H>: CompatibleDigestItem, | ||
{ | ||
let mut pre_digest: Option<_> = None; | ||
for log in header.digest().logs() { | ||
match (log.as_babe_pre_digest(), pre_digest.is_some()) { | ||
(Some(_), true) => Err("Multiple BABE pre-runtime digests, rejecting!")?, | ||
(None, _) => {}, | ||
(s, false) => pre_digest = s, | ||
} | ||
} | ||
pre_digest.ok_or_else(|| "No BABE pre-runtime digest found") | ||
} | ||
|
||
/// The prefix used by BABE for its VRF keys. | ||
pub const BABE_VRF_PREFIX: &'static [u8] = b"substrate-babe-vrf"; | ||
|
||
|
@@ -197,43 +216,41 @@ impl Decode for BabePreDigest { | |
Ok(pre_digest) | ||
} | ||
} | ||
|
||
// TODO [slashing] This should use concrete types. | ||
/// A digest item which is usable with BABE consensus. | ||
#[cfg(feature = "std")] | ||
pub trait CompatibleDigestItem: Sized { | ||
/// Construct a digest item which contains a BABE pre-digest. | ||
fn babe_pre_digest(seal: BabePreDigest) -> Self; | ||
fn babe_pre_digest<D: Codec>(seal: D) -> Self; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change needed? The runtime should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it should be a better way to do it. But it also using a non raw pre digest. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this really feels wrong. |
||
|
||
/// If this item is an BABE pre-digest, return it. | ||
fn as_babe_pre_digest(&self) -> Option<BabePreDigest>; | ||
fn as_babe_pre_digest<D: Codec>(&self) -> Option<D>; | ||
|
||
/// Construct a digest item which contains a BABE seal. | ||
fn babe_seal(signature: AuthoritySignature) -> Self; | ||
fn babe_seal<S: Codec>(signature: S) -> Self; | ||
|
||
/// If this item is a BABE signature, return the signature. | ||
fn as_babe_seal(&self) -> Option<AuthoritySignature>; | ||
fn as_babe_seal<S: Codec>(&self) -> Option<S>; | ||
|
||
/// If this item is a BABE epoch, return it. | ||
fn as_babe_epoch(&self) -> Option<Epoch>; | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl<Hash> CompatibleDigestItem for DigestItem<Hash> where | ||
Hash: Debug + Send + Sync + Eq + Clone + Codec + 'static | ||
Hash: Send + Sync + Eq + Clone + Codec + 'static | ||
{ | ||
fn babe_pre_digest(digest: BabePreDigest) -> Self { | ||
fn babe_pre_digest<D: Codec>(digest: D) -> Self { | ||
DigestItem::PreRuntime(BABE_ENGINE_ID, digest.encode()) | ||
} | ||
|
||
fn as_babe_pre_digest(&self) -> Option<BabePreDigest> { | ||
fn as_babe_pre_digest<D: Codec>(&self) -> Option<D> { | ||
self.try_to(OpaqueDigestItemId::PreRuntime(&BABE_ENGINE_ID)) | ||
} | ||
|
||
fn babe_seal(signature: AuthoritySignature) -> Self { | ||
fn babe_seal<S: Codec>(signature: S) -> Self { | ||
DigestItem::Seal(BABE_ENGINE_ID, signature.encode()) | ||
} | ||
|
||
fn as_babe_seal(&self) -> Option<AuthoritySignature> { | ||
fn as_babe_seal<S: Codec>(&self) -> Option<S> { | ||
self.try_to(OpaqueDigestItemId::Seal(&BABE_ENGINE_ID)) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation and function naming needs real improvement