Skip to content

Commit

Permalink
Eliminate record wildcards as requested in #434
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Dec 4, 2023
1 parent 6832f8a commit 975a64f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ mkTrunk btTrunk = BlockTree { btTrunk, btBranches = [] }
-- FIXME: we should enforce that the new branch' suffix does not contain any
-- block in common with an existingbranch.
addBranch :: AF.HasHeader blk => AF.AnchoredFragment blk -> BlockTree blk -> Maybe (BlockTree blk)
addBranch branch BlockTree{..} = do
(_, btbPrefix, _, btbSuffix) <- AF.intersect btTrunk branch
addBranch branch bt = do
(_, btbPrefix, _, btbSuffix) <- AF.intersect (btTrunk bt) branch
-- NOTE: We could use the monadic bind for @Maybe@ here but we would rather
-- catch bugs quicker.
let btbFull = fromJust $ AF.join btbPrefix btbSuffix
pure $ BlockTree { btTrunk, btBranches = BlockTreeBranch { .. } : btBranches }
pure $ bt { btBranches = BlockTreeBranch { .. } : btBranches bt }

-- | Same as @addBranch@ but assumes that the precondition holds.
addBranch' :: AF.HasHeader blk => AF.AnchoredFragment blk -> BlockTree blk -> BlockTree blk
Expand All @@ -90,7 +90,7 @@ addBranch' branch blockTree =

-- | Return all the full fragments from the root of the tree.
allFragments :: BlockTree blk -> [AF.AnchoredFragment blk]
allFragments BlockTree{..} = btTrunk : map btbFull btBranches
allFragments bt = btTrunk bt : map btbFull (btBranches bt)

-- | Look for a point in the block tree and return a fragment going from the
-- root of the tree to the point in question.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ classifiers GenesisTest {gtBlockTree, gtSecurityParam = SecurityParam k, gtGenes
existsSelectableAdversary =
any isSelectable branches

isSelectable BlockTreeBranch{..} = AF.length btbSuffix > fromIntegral k
isSelectable bt = AF.length (btbSuffix bt) > fromIntegral k

SlotNo goodTipSlot = withOrigin 0 id (headSlot goodChain)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ genChainsAndSchedule numAdversaries scheduleType =
prop_longRangeAttack :: QC.Gen QC.Property
prop_longRangeAttack = do
(genesisTest, schedule) <- genChainsAndSchedule 1 FastAdversary
let Classifiers {..} = classifiers genesisTest
let cls = classifiers genesisTest

pure $ withMaxSuccess 10 $ runSimOrThrow $
runTest genesisTest schedule $ \fragment ->
classify genesisWindowAfterIntersection "Full genesis window after intersection"
$ existsSelectableAdversary ==> not $ isHonestTestFragH fragment
classify (genesisWindowAfterIntersection cls) "Full genesis window after intersection"
$ existsSelectableAdversary cls ==> not $ isHonestTestFragH fragment
-- TODO
-- $ not existsSelectableAdversary ==> immutableTipBeforeFork fragment
-- $ not (existsSelectableAdversary cls) ==> immutableTipBeforeFork fragment
where
isHonestTestFragH :: TestFragH -> Bool
isHonestTestFragH frag = case headAnchor frag of
Expand Down

0 comments on commit 975a64f

Please sign in to comment.