Skip to content

Commit

Permalink
Avoid going through OverlaySlots.
Browse files Browse the repository at this point in the history
This PR now collects the `OverlaySchedule` directly in `BBodyEnv`,
removing the need for overlaySlots and hopefully avoiding an expensive
call to `Map.keysSet`. It should be functionally equivalent to #1775
whilst allowing us to optimise further in making the overlay schedule
non-explicit.
  • Loading branch information
nc6 committed Aug 17, 2020
1 parent 2a9a243 commit 7a219b3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Shelley.Spec.Ledger.BlockChain
import Shelley.Spec.Ledger.Crypto
import Shelley.Spec.Ledger.Keys
import qualified Shelley.Spec.Ledger.LedgerState as LedgerState
import Shelley.Spec.Ledger.OverlaySchedule (overlaySlots)
import Shelley.Spec.Ledger.PParams (PParams)
import qualified Shelley.Spec.Ledger.STS.Bbody as STS
import qualified Shelley.Spec.Ledger.STS.Chain as STS
Expand Down Expand Up @@ -62,14 +61,14 @@ mkTickEnv = STS.TickEnv . LedgerState.getGKeys

mkBbodyEnv ::
ShelleyState crypto ->
STS.BbodyEnv
STS.BbodyEnv crypto
mkBbodyEnv
LedgerState.NewEpochState
{ LedgerState.nesOsched,
LedgerState.nesEs
} =
STS.BbodyEnv
{ STS.bbodySlots = overlaySlots nesOsched,
{ STS.bbodySlots = nesOsched,
STS.bbodyPp = LedgerState.esPp nesEs,
STS.bbodyAccount = LedgerState.esAccountState nesEs
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
module Shelley.Spec.Ledger.OverlaySchedule
( -- * Overlay schedule
OverlaySchedule,
OverlaySlots,
compactOverlaySchedule,
decompactOverlaySchedule,
emptyOverlaySchedule,
Expand All @@ -17,7 +16,6 @@ module Shelley.Spec.Ledger.OverlaySchedule
overlayScheduleHelper,
overlayScheduleIsEmpty,
overlayScheduleToMap,
overlaySlots,

-- * OBftSlot (for testing)
OBftSlot (..),
Expand Down Expand Up @@ -182,10 +180,5 @@ instance Crypto crypto => ToCBOR (OverlaySchedule crypto) where
instance Crypto crypto => FromCBOR (OverlaySchedule crypto) where
fromCBOR = decompactOverlaySchedule <$> fromCBOR

newtype OverlaySlots = OverlaySlots (Set SlotNo)

overlaySlots :: OverlaySchedule crypto -> OverlaySlots
overlaySlots (OverlaySchedule oSched) = OverlaySlots (Map.keysSet oSched)

isOverlaySlot :: SlotNo -> OverlaySlots -> Bool
isOverlaySlot slot (OverlaySlots oslots) = Set.member slot oslots
isOverlaySlot :: SlotNo -> OverlaySchedule c -> Bool
isOverlaySlot slot (OverlaySchedule oslots) = Map.member slot oslots
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
Expand Down Expand Up @@ -50,7 +51,7 @@ import Shelley.Spec.Ledger.LedgerState
LedgerState,
)
import Shelley.Spec.Ledger.OverlaySchedule
( OverlaySlots,
( OverlaySchedule,
isOverlaySlot,
)
import Shelley.Spec.Ledger.PParams (PParams)
Expand All @@ -63,8 +64,8 @@ data BbodyState crypto
= BbodyState (LedgerState crypto) (BlocksMade crypto)
deriving (Eq, Show)

data BbodyEnv = BbodyEnv
{ bbodySlots :: OverlaySlots,
data BbodyEnv crypto = BbodyEnv
{ bbodySlots :: OverlaySchedule crypto,
bbodyPp :: PParams,
bbodyAccount :: AccountState
}
Expand All @@ -83,7 +84,7 @@ instance
Signal (BBODY crypto) =
Block crypto

type Environment (BBODY crypto) = BbodyEnv
type Environment (BBODY crypto) = BbodyEnv crypto

type BaseM (BBODY crypto) = ShelleyBase

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ chainTransition =

BbodyState ls' bcur' <-
trans @(BBODY crypto) $
TRC (BbodyEnv (overlaySlots osched) pp' account, BbodyState ls bcur, block)
TRC (BbodyEnv osched pp' account, BbodyState ls bcur, block)

let nes'' = updateNES nes' bcur' ls'
bhb = bhbody bh
Expand Down

0 comments on commit 7a219b3

Please sign in to comment.