Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to acquire tip by LocalStateQuery protocol client. #2875

Merged
merged 6 commits into from
Jan 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import Ouroboros.Consensus.Storage.FS.API (HasFS, SomeHasFS (..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy
(defaultDiskPolicy)
import qualified Ouroboros.Consensus.Storage.LedgerDB.InMemory as LgrDB
(ledgerDbPast, ledgerDbWithAnchor)
(ledgerDbPast, ledgerDbTip, ledgerDbWithAnchor)

import Test.QuickCheck hiding (Result)
import Test.Tasty
Expand Down Expand Up @@ -75,14 +75,17 @@ prop_localStateQueryServer
:: SecurityParam
-> BlockTree
-> Permutation
-> Positive (Small Int)
-> Property
prop_localStateQueryServer k bt p = checkOutcome k chain actualOutcome
prop_localStateQueryServer k bt p (Positive (Small n)) = checkOutcome k chain actualOutcome
where
chain :: Chain TestBlock
chain = treePreferredChain bt

points :: [Point TestBlock]
points = blockPoint <$> permute p (treeToBlocks bt)
points :: [Maybe (Point TestBlock)]
points = permute p $
replicate n Nothing
++ (Just . blockPoint <$> (treeToBlocks bt))

actualOutcome = runSimOrThrow $ do
let client = mkClient points
Expand All @@ -109,7 +112,7 @@ prop_localStateQueryServer k bt p = checkOutcome k chain actualOutcome
checkOutcome
:: SecurityParam
-> Chain TestBlock
-> [(Point TestBlock, Either AcquireFailure (Point TestBlock))]
-> [(Maybe (Point TestBlock), Either AcquireFailure (Point TestBlock))]
-> Property
checkOutcome k chain = conjoin . map (uncurry checkResult)
where
Expand All @@ -118,10 +121,10 @@ checkOutcome k chain = conjoin . map (uncurry checkResult)
Chain.drop (fromIntegral (maxRollbacks k)) chain

checkResult
:: Point TestBlock
:: Maybe (Point TestBlock)
-> Either AcquireFailure (Point TestBlock)
-> Property
checkResult pt = \case
checkResult (Just pt) = \case
Right result
-> tabulate "Acquired" ["Success"] $ result === pt
Left AcquireFailurePointNotOnChain
Expand All @@ -140,16 +143,19 @@ checkOutcome k chain = conjoin . map (uncurry checkResult)
(property False)
| otherwise
-> tabulate "Acquired" ["AcquireFailurePointTooOld"] $ property True
checkResult Nothing = \case
Right _result -> tabulate "Acquired" ["Success"] True
Left failure -> counterexample ("acuire tip point resulted in " ++ show failure) False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"acuire" -> "acquired"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this in another pr.


mkClient
:: Monad m
=> [Point TestBlock]
=> [Maybe (Point TestBlock)]
-> LocalStateQueryClient
TestBlock
(Point TestBlock)
(Query TestBlock)
m
[(Point TestBlock, Either AcquireFailure (Point TestBlock))]
[(Maybe (Point TestBlock), Either AcquireFailure (Point TestBlock))]
mkClient points = localStateQueryClient [(pt, QueryLedgerTip) | pt <- points]

mkServer
Expand All @@ -162,6 +168,7 @@ mkServer k chain = do
return $
localStateQueryServer
cfg
(castPoint . LgrDB.ledgerDbTip <$> LgrDB.getCurrent lgrDB)
(\pt -> LgrDB.ledgerDbPast pt <$> LgrDB.getCurrent lgrDB)
getImmutablePoint
where
Expand Down