-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathmod.rs
More file actions
78 lines (64 loc) · 1.81 KB
/
mod.rs
File metadata and controls
78 lines (64 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::hash::{Hash, Hasher};
use aleph_primitives::BlockNumber;
use sp_runtime::traits::{CheckedSub, Header as SubstrateHeader, One};
use crate::{
sync::{BlockIdentifier, Header, Justification as JustificationT},
AlephJustification,
};
mod chain_status;
mod finalizer;
mod status_notifier;
mod verification;
pub use verification::SessionVerifier;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BlockId<H: SubstrateHeader<Number = BlockNumber>> {
hash: H::Hash,
number: H::Number,
}
/// An identifier uniquely specifying a block and its height.
impl<SH: SubstrateHeader<Number = BlockNumber>> Hash for BlockId<SH> {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
self.hash.hash(state);
self.number.hash(state);
}
}
impl<H: SubstrateHeader<Number = BlockNumber>> BlockIdentifier for BlockId<H> {
fn number(&self) -> u32 {
self.number
}
}
impl<H: SubstrateHeader<Number = BlockNumber>> Header for H {
type Identifier = BlockId<H>;
fn id(&self) -> Self::Identifier {
BlockId {
hash: self.hash(),
number: *self.number(),
}
}
fn parent_id(&self) -> Option<Self::Identifier> {
let number = self.number().checked_sub(&One::one())?;
Some(BlockId {
hash: *self.parent_hash(),
number,
})
}
}
/// A justification, including the related header.
#[derive(Clone)]
pub struct Justification<H: SubstrateHeader<Number = BlockNumber>> {
header: H,
raw_justification: AlephJustification,
}
impl<H: SubstrateHeader<Number = BlockNumber>> JustificationT for Justification<H> {
type Header = H;
type Unverified = Self;
fn header(&self) -> &Self::Header {
&self.header
}
fn into_unverified(self) -> Self::Unverified {
self
}
}