@@ -20,6 +20,7 @@ import Control.Monad.Class.MonadTime.SI
2020 )
2121import Data.Containers.ListUtils (nubOrd )
2222import Data.Foldable (toList )
23+ import Data.Function ((&) )
2324import Data.Functor ((<&>) )
2425import qualified Data.Map.Strict as Map
2526import Data.Maybe (catMaybes , mapMaybe )
@@ -125,9 +126,21 @@ duration PointSchedule{psSchedule, psMinEndTime} =
125126 maximum $ psMinEndTime : [t | sch <- toList psSchedule, (t, _) <- take 1 (reverse sch)]
126127
127128-- | Shrink a 'PeerSchedule' by removing ticks from it. The other ticks are kept
128- -- unchanged.
129- shrinkAdversarialPeer :: PeerSchedule blk -> [PeerSchedule blk ]
130- shrinkAdversarialPeer = shrinkList (const [] )
129+ -- unchanged. Preserve TP/HP/BP consistency, that is, at any time, TP >= HP and HP >= BP.
130+ shrinkAdversarialPeer :: Ord blk => PeerSchedule blk -> [PeerSchedule blk ]
131+ shrinkAdversarialPeer = (filter preservesConsistency) . shrinkList (const [] )
132+ where
133+ preservesConsistency sch =
134+ foldr
135+ ( \ (_t, p) (tp, hp, acc) ->
136+ case p of
137+ ScheduleTipPoint newTp -> (newTp, hp, acc)
138+ ScheduleHeaderPoint newHp -> (tp, newHp, acc && tp >= newHp)
139+ ScheduleBlockPoint newBp -> (tp, hp, acc && hp >= newBp)
140+ )
141+ (Slot. Origin , Slot. Origin , True )
142+ sch
143+ & (\ (_, _, x) -> x)
131144
132145-- | Shrink the 'others' field of a 'Peers' structure by attempting to remove
133146-- peers or by shrinking their values using the given shrinking function.
0 commit comments