@@ -33,7 +33,7 @@ import Data.Set qualified as Set
3333import Data.Function (on )
3434import Data.Hashable
3535import Data.List as List (foldl' , groupBy , sortBy , transpose )
36- import Data.Maybe (mapMaybe )
36+ import Data.Maybe (fromMaybe , mapMaybe )
3737import Data.Set (Set )
3838
3939import Control.Exception (assert )
@@ -473,8 +473,11 @@ empty fetch range, but this is ok since we never request empty ranges.
473473--
474474-- A 'ChainSuffix' must be non-empty, as an empty suffix, i.e. the candidate
475475-- chain is equal to the current chain, would not be a plausible candidate.
476- newtype ChainSuffix header =
477- ChainSuffix { getChainSuffix :: AnchoredFragment header }
476+ data ChainSuffix header = ChainSuffix {
477+ getChainSuffix :: ! (AnchoredFragment header )
478+ , -- | TODO
479+ getChainSuffixAfterImmutableTip :: ! (AnchoredFragment header )
480+ }
478481
479482{-
480483We define the /chain suffix/ as the suffix of the candidate chain up until (but
@@ -511,25 +514,27 @@ interested in this candidate at all.
511514-- current chain.
512515--
513516chainForkSuffix
514- :: (HasHeader header , HasHeader block ,
515- HeaderHash header ~ HeaderHash block )
516- => AnchoredFragment block -- ^ Current chain.
517- -> AnchoredFragment header -- ^ Candidate chain
517+ :: HasHeader header
518+ => AnchoredFragment header
519+ -> AnchoredFragment header
518520 -> Maybe (ChainSuffix header )
519521chainForkSuffix current candidate =
520522 case AF. intersect current candidate of
521523 Nothing -> Nothing
522- Just (_ , _, _, candidateSuffix) ->
524+ Just (currentPrefix , _, _, candidateSuffix) ->
523525 -- If the suffix is empty, it means the candidate chain was equal to
524526 -- the current chain and didn't fork off. Such a candidate chain is
525527 -- not a plausible candidate, so it must have been filtered out.
526528 assert (not (AF. null candidateSuffix)) $
527- Just (ChainSuffix candidateSuffix)
529+ Just (ChainSuffix candidateSuffix candidateSuffixAfterImmTip)
530+ where
531+ candidateSuffixAfterImmTip =
532+ fromMaybe (error " unreachable TODO" ) (AF. join currentPrefix candidateSuffix)
533+
528534
529535selectForkSuffixes
530- :: (HasHeader header , HasHeader block ,
531- HeaderHash header ~ HeaderHash block )
532- => AnchoredFragment block
536+ :: HasHeader header
537+ => AnchoredFragment header
533538 -> [(FetchDecision (AnchoredFragment header ), peerinfo )]
534539 -> [(FetchDecision (ChainSuffix header ), peerinfo )]
535540selectForkSuffixes current chains =
@@ -743,7 +748,7 @@ prioritisePeerChains FetchModeDeadline salt compareCandidateChains blockFetchSiz
743748 (equatingPair
744749 -- compare on probability band first, then preferred chain
745750 (==)
746- (equateCandidateChains `on` getChainSuffix )
751+ (equateCandidateChains `on` getChainSuffixAfterImmutableTip )
747752 `on`
748753 (\ (band, chain, _fragments) -> (band, chain)))))
749754 . sortBy (descendingOrder
@@ -752,7 +757,7 @@ prioritisePeerChains FetchModeDeadline salt compareCandidateChains blockFetchSiz
752757 (comparingPair
753758 -- compare on probability band first, then preferred chain
754759 compare
755- (compareCandidateChains `on` getChainSuffix )
760+ (compareCandidateChains `on` getChainSuffixAfterImmutableTip )
756761 `on`
757762 (\ (band, chain, _fragments) -> (band, chain))))))
758763 . map annotateProbabilityBand
@@ -776,7 +781,7 @@ prioritisePeerChains FetchModeDeadline salt compareCandidateChains blockFetchSiz
776781 | EQ <- compareCandidateChains chain1 chain2 = True
777782 | otherwise = False
778783
779- chainHeadPoint (_,ChainSuffix c,_) = AF. headPoint c
784+ chainHeadPoint (_,ChainSuffix c _ ,_) = AF. headPoint c
780785
781786prioritisePeerChains FetchModeBulkSync salt compareCandidateChains blockFetchSize =
782787 map (\ (decision, peer) ->
0 commit comments