sc_consensus_babe/
migration.rs1use crate::{
20 AuthorityId, BabeAuthorityWeight, BabeConfiguration, BabeEpochConfiguration, Epoch,
21 NextEpochDescriptor, Randomness,
22};
23use codec::{Decode, Encode};
24use sc_consensus_epochs::Epoch as EpochT;
25use sp_consensus_slots::Slot;
26
27#[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)]
29pub struct EpochV0 {
30 pub epoch_index: u64,
32 pub start_slot: Slot,
34 pub duration: u64,
36 pub authorities: Vec<(AuthorityId, BabeAuthorityWeight)>,
38 pub randomness: Randomness,
40}
41
42impl EpochT for EpochV0 {
43 type NextEpochDescriptor = NextEpochDescriptor;
44 type Slot = Slot;
45
46 fn increment(&self, descriptor: NextEpochDescriptor) -> EpochV0 {
47 EpochV0 {
48 epoch_index: self.epoch_index + 1,
49 start_slot: self.start_slot + self.duration,
50 duration: self.duration,
51 authorities: descriptor.authorities,
52 randomness: descriptor.randomness,
53 }
54 }
55
56 fn start_slot(&self) -> Slot {
57 self.start_slot
58 }
59
60 fn end_slot(&self) -> Slot {
61 self.start_slot + self.duration
62 }
63}
64
65impl EpochV0 {
67 pub fn migrate(self, config: &BabeConfiguration) -> Epoch {
69 sp_consensus_babe::Epoch {
70 epoch_index: self.epoch_index,
71 start_slot: self.start_slot,
72 duration: self.duration,
73 authorities: self.authorities,
74 randomness: self.randomness,
75 config: BabeEpochConfiguration { c: config.c, allowed_slots: config.allowed_slots },
76 }
77 .into()
78 }
79}