@@ -8,13 +8,13 @@ import Universum
8
8
import Pos.Chain.Delegation (ProxySKBlockInfo )
9
9
import Pos.Chain.Genesis (configGenesisWStakeholders )
10
10
import qualified Pos.Chain.Genesis as Genesis (Config (.. ))
11
- import Pos.Core (EpochIndex , FlatSlotId , LocalSlotIndex (.. ),
12
- SlotCount (.. ), SlotId (.. ), SlotLeaders , StakeholderId ,
13
- flattenEpochOrSlot , pcEpochSlots , slotIdSucc )
11
+ import Pos.Chain.Lrc (getEpochSlotLeaderScheduleObftPure ,
12
+ getSlotLeaderObftPure )
13
+ import Pos.Core (EpochIndex , SlotCount (.. ), SlotId (.. ), SlotLeaders ,
14
+ StakeholderId , pcEpochSlots )
14
15
import Pos.DB (MonadDBRead )
15
16
import Pos.DB.Delegation (getDlgTransPsk )
16
17
17
- import Data.List ((!!) )
18
18
import UnliftIO (MonadUnliftIO )
19
19
20
20
-- | This function selects the current slot leaders by obtaining the
@@ -32,32 +32,26 @@ getSlotLeaderObft genesisConfig si = do
32
32
stakeholders :: [StakeholderId ]
33
33
stakeholders = sort $ configGenesisWStakeholders genesisConfig
34
34
--
35
- flatSlotId :: FlatSlotId
36
- flatSlotId =
37
- flattenEpochOrSlot (pcEpochSlots (Genesis. configProtocolConstants
38
- genesisConfig))
39
- si
40
- --
41
- leaderIndex :: Int
42
- leaderIndex = (fromIntegral flatSlotId :: Int ) `mod` (length stakeholders)
35
+ epochSlotCount :: SlotCount
36
+ epochSlotCount =
37
+ pcEpochSlots (Genesis. configProtocolConstants genesisConfig)
43
38
--
44
39
currentSlotGenesisSId :: StakeholderId
45
- currentSlotGenesisSId = stakeholders !! leaderIndex
40
+ currentSlotGenesisSId =
41
+ case (nonEmpty stakeholders) of
42
+ Just s -> getSlotLeaderObftPure si epochSlotCount s
43
+ Nothing -> error " getSlotLeaderObft: Empty list of stakeholders"
46
44
47
45
-- | Generates the full slot leader schedule for an epoch (10*k slots long).
48
46
getEpochSlotLeaderScheduleObft
49
- :: (MonadDBRead m , MonadUnliftIO m )
50
- => Genesis. Config -> EpochIndex -> m SlotLeaders
51
- getEpochSlotLeaderScheduleObft genesisConfig ei = do
52
- leaders <-
53
- map fst
54
- <$> mapM (getSlotLeaderObft genesisConfig)
55
- (take (fromIntegral $ epochSlotCount)
56
- (iterate (slotIdSucc epochSlots) startSlotId))
57
- case nonEmpty leaders of
58
- Just l -> pure l
59
- Nothing -> error " getEpochSlotLeaderScheduleObft: Empty list of leaders"
47
+ :: Genesis. Config -> EpochIndex -> SlotLeaders
48
+ getEpochSlotLeaderScheduleObft genesisConfig ei =
49
+ case nonEmpty stakeholders of
50
+ Just s -> getEpochSlotLeaderScheduleObftPure ei epochSlotCount s
51
+ Nothing -> error " getEpochSlotLeaderScheduleObft: Empty list of stakeholders"
60
52
where
61
- startSlotId = SlotId ei (UnsafeLocalSlotIndex 0 )
62
- epochSlots = pcEpochSlots (Genesis. configProtocolConstants genesisConfig)
63
- epochSlotCount = getSlotCount $ epochSlots
53
+ -- We assume here that the genesis bootstrap stakeholders list
54
+ -- is nonempty
55
+ stakeholders :: [StakeholderId ]
56
+ stakeholders = sort $ configGenesisWStakeholders genesisConfig
57
+ epochSlotCount = pcEpochSlots (Genesis. configProtocolConstants genesisConfig)
0 commit comments