@@ -33,7 +33,7 @@ import Data.Set qualified as Set
33
33
import Data.Function (on )
34
34
import Data.Hashable
35
35
import Data.List as List (foldl' , groupBy , sortBy , transpose )
36
- import Data.Maybe (mapMaybe )
36
+ import Data.Maybe (fromMaybe , mapMaybe )
37
37
import Data.Set (Set )
38
38
39
39
import Control.Exception (assert )
@@ -473,8 +473,11 @@ empty fetch range, but this is ok since we never request empty ranges.
473
473
--
474
474
-- A 'ChainSuffix' must be non-empty, as an empty suffix, i.e. the candidate
475
475
-- 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
+ }
478
481
479
482
{-
480
483
We define the /chain suffix/ as the suffix of the candidate chain up until (but
@@ -511,25 +514,27 @@ interested in this candidate at all.
511
514
-- current chain.
512
515
--
513
516
chainForkSuffix
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
518
520
-> Maybe (ChainSuffix header )
519
521
chainForkSuffix current candidate =
520
522
case AF. intersect current candidate of
521
523
Nothing -> Nothing
522
- Just (_ , _, _, candidateSuffix) ->
524
+ Just (currentPrefix , _, _, candidateSuffix) ->
523
525
-- If the suffix is empty, it means the candidate chain was equal to
524
526
-- the current chain and didn't fork off. Such a candidate chain is
525
527
-- not a plausible candidate, so it must have been filtered out.
526
528
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
+
528
534
529
535
selectForkSuffixes
530
- :: (HasHeader header , HasHeader block ,
531
- HeaderHash header ~ HeaderHash block )
532
- => AnchoredFragment block
536
+ :: HasHeader header
537
+ => AnchoredFragment header
533
538
-> [(FetchDecision (AnchoredFragment header ), peerinfo )]
534
539
-> [(FetchDecision (ChainSuffix header ), peerinfo )]
535
540
selectForkSuffixes current chains =
@@ -743,7 +748,7 @@ prioritisePeerChains FetchModeDeadline salt compareCandidateChains blockFetchSiz
743
748
(equatingPair
744
749
-- compare on probability band first, then preferred chain
745
750
(==)
746
- (equateCandidateChains `on` getChainSuffix )
751
+ (equateCandidateChains `on` getChainSuffixAfterImmutableTip )
747
752
`on`
748
753
(\ (band, chain, _fragments) -> (band, chain)))))
749
754
. sortBy (descendingOrder
@@ -752,7 +757,7 @@ prioritisePeerChains FetchModeDeadline salt compareCandidateChains blockFetchSiz
752
757
(comparingPair
753
758
-- compare on probability band first, then preferred chain
754
759
compare
755
- (compareCandidateChains `on` getChainSuffix )
760
+ (compareCandidateChains `on` getChainSuffixAfterImmutableTip )
756
761
`on`
757
762
(\ (band, chain, _fragments) -> (band, chain))))))
758
763
. map annotateProbabilityBand
@@ -776,7 +781,7 @@ prioritisePeerChains FetchModeDeadline salt compareCandidateChains blockFetchSiz
776
781
| EQ <- compareCandidateChains chain1 chain2 = True
777
782
| otherwise = False
778
783
779
- chainHeadPoint (_,ChainSuffix c,_) = AF. headPoint c
784
+ chainHeadPoint (_,ChainSuffix c _ ,_) = AF. headPoint c
780
785
781
786
prioritisePeerChains FetchModeBulkSync salt compareCandidateChains blockFetchSize =
782
787
map (\ (decision, peer) ->
0 commit comments