diff --git a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/ChainSel.hs b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/ChainSel.hs index ca91af258d..fd4df5a2be 100644 --- a/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/ChainSel.hs +++ b/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Storage/ChainDB/Impl/ChainSel.hs @@ -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 @@ -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 @@ -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@. @@ -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.