Skip to content

Commit

Permalink
followsLoEFrag now trims fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols committed May 29, 2024
1 parent c6b1d22 commit 3957238
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NE
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (isJust, isNothing)
import Data.Maybe (isJust, isNothing, mapMaybe)
import Data.Maybe.Strict (StrictMaybe (..), strictMaybeToMaybe)
import Data.Set (Set)
import qualified Data.Set as Set
Expand Down Expand Up @@ -675,7 +675,7 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
return $ AF.fromOldestFirst curHead (hdr : hdrs)

let chainDiffs = NE.nonEmpty
$ filter (followsLoEFrag loeFrag curChainAndLedger)
$ mapMaybe (followsLoEFrag loeFrag curChainAndLedger)
$ map Diff.extend
$ NE.filter (preferAnchoredCandidate (bcfg chainSelEnv) curChain)
candidates
Expand Down Expand Up @@ -718,14 +718,17 @@ chainSelectionForBlock cdb@CDB{..} blockCache hdr punish = electric $ do
followsLoEFrag :: LoE (AnchoredFragment (Header blk))
-> ChainAndLedger blk
-> ChainDiff (Header blk)
-> Bool
followsLoEFrag LoEDisabled _ _ = True
-> Maybe (ChainDiff (Header blk))
followsLoEFrag LoEDisabled _ diff = Just diff
followsLoEFrag (LoEEnabled loe) curChain diff =
case Diff.apply (VF.validatedFragment curChain) diff of
Nothing -> False
Nothing -> Nothing
Just frag ->
AF.withinFragmentBounds (AF.headPoint loe) frag
|| AF.withinFragmentBounds (AF.headPoint frag) loe
if
AF.withinFragmentBounds (AF.headPoint loe) frag
|| AF.withinFragmentBounds (AF.headPoint frag) loe
then Just diff
else Nothing

-- | 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 @@ -751,7 +754,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 curChainAndLedger))
fmap (mapMaybe (followsLoEFrag loeFrag curChainAndLedger))

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

0 comments on commit 3957238

Please sign in to comment.