Skip to content

Commit

Permalink
Fix followsLoEFrag
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols committed May 29, 2024
1 parent 8c57176 commit 009dde5
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,8 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
return $ AF.fromOldestFirst curHead (hdr : hdrs)

let chainDiffs = NE.nonEmpty
$ filter (followsLoEFrag loeFrag curChainAndLedger)
$ map Diff.extend
$ filter (followsLoEFrag loeFrag)
$ NE.filter (preferAnchoredCandidate (bcfg chainSelEnv) curChain)
candidates
-- All candidates are longer than the current chain, so they will be
Expand Down Expand Up @@ -709,16 +709,23 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
curTip = castPoint $ AF.headPoint curChain
curHead = AF.headAnchor curChain

-- Either frag extends loe or loe extends frag
--
-- PRECONDITION: @AF.withinFragmentBounds (AF.anchorPoint frag) loe@
-- Either frag extends loe or loe extends frag. The fragment is represented
-- by the current chain and a diff with that current chain. It is tempting
-- to only consider the suffix of the diff, but that would be incorrect,
-- because the diff might not intersect with the LoE fragment, because the
-- diff suffix is anchored somewhere on the current chain and LoE frag's tip
-- might be older than that anchor.
followsLoEFrag :: LoE (AnchoredFragment (Header blk))
-> AnchoredFragment (Header blk)
-> ChainAndLedger blk
-> ChainDiff (Header blk)
-> Bool
followsLoEFrag LoEDisabled _ = True
followsLoEFrag (LoEEnabled loe) frag =
AF.withinFragmentBounds (AF.headPoint loe) frag
|| AF.withinFragmentBounds (AF.headPoint frag) loe
followsLoEFrag LoEDisabled _ _ = True
followsLoEFrag (LoEEnabled loe) curChain diff =
case Diff.apply (VF.validatedFragment curChain) diff of
Nothing -> False
Just frag ->
AF.withinFragmentBounds (AF.headPoint loe) frag
|| AF.withinFragmentBounds (AF.headPoint frag) loe

-- | We have found a 'ChainDiff' through the VolatileDB connecting the new
-- block to the current chain. We'll call the intersection/anchor @x@.
Expand All @@ -744,7 +751,7 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
-- times in case they're part of multiple forks that go through @b@.
let initCache = Map.singleton (headerHash hdr) hdr
chainDiffs <-
fmap (filter (followsLoEFrag loeFrag . Diff.getSuffix))
fmap (filter (followsLoEFrag loeFrag curChainAndLedger))

-- 4. Filter out candidates that are not preferred over the current
-- chain.
Expand Down

0 comments on commit 009dde5

Please sign in to comment.