Skip to content

Commit

Permalink
Rename reader to follower
Browse files Browse the repository at this point in the history
Fixes #2833
  • Loading branch information
EncodePanda committed Jan 14, 2021
1 parent bf8579c commit 736843e
Show file tree
Hide file tree
Showing 14 changed files with 572 additions and 572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
module Test.Ouroboros.Storage.ChainDB.Model (
Model -- opaque
, IteratorId
, CPS.ReaderId
, CPS.FollowerId
-- * Construction
, empty
, addBlock
Expand Down Expand Up @@ -53,11 +53,11 @@ module Test.Ouroboros.Storage.ChainDB.Model (
, stream
, iteratorNext
, iteratorClose
-- * Readers
, newReader
, readerInstruction
, readerForward
, readerClose
-- * Followers
, newFollower
, followerInstruction
, followerForward
, followerClose
-- * ModelSupportsBlock
, ModelSupportsBlock
-- * Exported for testing purposes
Expand Down Expand Up @@ -537,35 +537,35 @@ iteratorClose :: IteratorId -> Model blk -> Model blk
iteratorClose itrId m = m { iterators = Map.insert itrId [] (iterators m) }

{-------------------------------------------------------------------------------
Readers
Followers
-------------------------------------------------------------------------------}

readerExists :: CPS.ReaderId -> Model blk -> Bool
readerExists rdrId = CPS.readerExists rdrId . cps
followerExists :: CPS.FollowerId -> Model blk -> Bool
followerExists rdrId = CPS.followerExists rdrId . cps

checkIfReaderExists :: CPS.ReaderId -> Model blk
checkIfFollowerExists :: CPS.FollowerId -> Model blk
-> a
-> Either (ChainDbError blk) a
checkIfReaderExists rdrId m a
| readerExists rdrId m
checkIfFollowerExists rdrId m a
| followerExists rdrId m
= Right a
| otherwise
= Left ClosedReaderError
= Left ClosedFollowerError

newReader :: HasHeader blk => Model blk -> (CPS.ReaderId, Model blk)
newReader m = (rdrId, m { cps = cps' })
newFollower :: HasHeader blk => Model blk -> (CPS.FollowerId, Model blk)
newFollower m = (rdrId, m { cps = cps' })
where
(cps', rdrId) = CPS.initReader GenesisPoint (cps m)
(cps', rdrId) = CPS.initFollower GenesisPoint (cps m)

readerInstruction
followerInstruction
:: forall blk b. ModelSupportsBlock blk
=> CPS.ReaderId
=> CPS.FollowerId
-> BlockComponent blk b
-> Model blk
-> Either (ChainDbError blk)
(Maybe (ChainUpdate blk b), Model blk)
readerInstruction rdrId blockComponent m = checkIfReaderExists rdrId m $
rewrap $ CPS.readerInstruction rdrId (cps m)
followerInstruction rdrId blockComponent m = checkIfFollowerExists rdrId m $
rewrap $ CPS.followerInstruction rdrId (cps m)
where
toB :: blk -> b
toB blk = getBlockComponent blk blockComponent
Expand All @@ -576,25 +576,25 @@ readerInstruction rdrId blockComponent m = checkIfReaderExists rdrId m $
rewrap Nothing = (Nothing, m)
rewrap (Just (upd, cps')) = (Just (toB <$> upd), m { cps = cps' })

readerForward :: HasHeader blk
=> CPS.ReaderId
followerForward :: HasHeader blk
=> CPS.FollowerId
-> [Point blk]
-> Model blk
-> Either (ChainDbError blk)
(Maybe (Point blk), Model blk)
readerForward rdrId points m = checkIfReaderExists rdrId m $
followerForward rdrId points m = checkIfFollowerExists rdrId m $
case CPS.findFirstPoint points (cps m) of
Nothing -> (Nothing, m)
Just ipoint -> (Just ipoint, m { cps = cps' })
where
cps' = CPS.updateReader rdrId ipoint (cps m)
cps' = CPS.updateFollower rdrId ipoint (cps m)

readerClose :: CPS.ReaderId
followerClose :: CPS.FollowerId
-> Model blk
-> Model blk
readerClose rdrId m
| readerExists rdrId m
= m { cps = CPS.deleteReader rdrId (cps m) }
followerClose rdrId m
| followerExists rdrId m
= m { cps = CPS.deleteFollower rdrId (cps m) }
| otherwise
= m

Expand Down Expand Up @@ -944,7 +944,7 @@ copyToImmutableDB secParam m = m {
closeDB :: Model blk -> Model blk
closeDB m@Model{..} = m {
isOpen = False
, cps = cps { CPS.chainReaders = Map.empty }
, cps = cps { CPS.chainFollowers = Map.empty }
, iterators = Map.empty
}

Expand Down
Loading

0 comments on commit 736843e

Please sign in to comment.