-
Notifications
You must be signed in to change notification settings - Fork 721
/
ChainFilter.hs
54 lines (44 loc) · 1.67 KB
/
ChainFilter.hs
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
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wno-deprecations -Wno-orphans #-}
{- HLINT ignore "Use head" -}
module Cardano.Analysis.ChainFilter (module Cardano.Analysis.ChainFilter) where
import Cardano.Prelude hiding (head)
import Data.Aeson
import Cardano.Slotting.Slot (EpochNo (..), SlotNo (..))
-- | Conditions for chain subsetting
data ChainFilter
= CBlock BlockCond
| CSlot SlotCond
deriving (FromJSON, Generic, NFData, Show, ToJSON)
-- | Block classification -- primary for validity as subjects of analysis.
data BlockCond
= BUnitaryChainDelta -- ^ All timings account for
-- processing of a single block.
| BFullnessGEq Double -- ^ Block fullness is above fraction.
| BFullnessLEq Double -- ^ Block fullness is below fraction.
| BSizeGEq Word64
| BSizeLEq Word64
deriving (FromJSON, Generic, NFData, Show, ToJSON)
deriving instance NFData EpochNo
data SlotCond
= SlotGEq SlotNo
| SlotLEq SlotNo
| EpochGEq EpochNo
| EpochLEq EpochNo
| SlotHasLeaders
deriving (FromJSON, Generic, NFData, Show, ToJSON)
cfIsSlotCond, cfIsBlockCond :: ChainFilter -> Bool
cfIsSlotCond = \case { CSlot{} -> True; _ -> False; }
cfIsBlockCond = \case { CBlock{} -> True; _ -> False; }
catSlotFilters :: [ChainFilter] -> [SlotCond]
catSlotFilters = go [] where
go :: [SlotCond] -> [ChainFilter] -> [SlotCond]
go acc = \case
[] -> reverse acc
CSlot c:rest -> go (c:acc) rest
_:rest -> go acc rest