Skip to content

Commit

Permalink
Renaming ReallyCold to Cold and Cold to Cooling
Browse files Browse the repository at this point in the history
  • Loading branch information
bolt12 committed Oct 11, 2023
1 parent 3052c1f commit e0d61a9
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 79 deletions.
32 changes: 16 additions & 16 deletions ouroboros-network/sim-tests/Test/Ouroboros/Network/PeerSelection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,10 @@ envEventCredits (TraceEnvSetTargets PeerSelectionTargets {
+ targetNumberOfEstablishedPeers
+ targetNumberOfActivePeers)

envEventCredits (TraceEnvPeersDemote Noop _) = 10
envEventCredits (TraceEnvPeersDemote ToWarm _) = 30
envEventCredits (TraceEnvPeersDemote ToCold _) = 30
envEventCredits (TraceEnvPeersDemote ToReallyCold _) = 30
envEventCredits (TraceEnvPeersDemote Noop _) = 10
envEventCredits (TraceEnvPeersDemote ToWarm _) = 30
envEventCredits (TraceEnvPeersDemote ToCooling _) = 30
envEventCredits (TraceEnvPeersDemote ToCold _) = 30

envEventCredits TraceEnvPeersStatus{} = 0
-- These events are visible in the environment but are the result of actions
Expand Down Expand Up @@ -1992,12 +1992,12 @@ prop_governor_target_established_below env =
| Set.null failures -> Nothing
| otherwise -> Just failures
where
failures = Map.keysSet (Map.filter (==PeerCold) . fmap fst $ status)
failures = Map.keysSet (Map.filter (==PeerCooling) . fmap fst $ status)
TraceDemoteLocalAsynchronous status
| Set.null failures -> Nothing
| otherwise -> Just failures
where
failures = Map.keysSet (Map.filter (==PeerCold) . fmap fst $ status)
failures = Map.keysSet (Map.filter (==PeerCooling) . fmap fst $ status)
TracePromoteWarmFailed _ _ peer _ ->
Just (Set.singleton peer)
_ -> Nothing
Expand Down Expand Up @@ -2090,12 +2090,12 @@ prop_governor_target_established_big_ledger_peers_below env =
| Set.null failures -> Nothing
| otherwise -> Just failures
where
failures = Map.keysSet (Map.filter (==PeerCold) . fmap fst $ status)
failures = Map.keysSet (Map.filter (==PeerCooling) . fmap fst $ status)
TraceDemoteLocalAsynchronous status
| Set.null failures -> Nothing
| otherwise -> Just failures
where
failures = Map.keysSet (Map.filter (==PeerCold) . fmap fst $ status)
failures = Map.keysSet (Map.filter (==PeerCooling) . fmap fst $ status)
TracePromoteWarmFailed _ _ peer _ ->
Just (Set.singleton peer)
_ -> Nothing
Expand Down Expand Up @@ -2609,12 +2609,12 @@ prop_governor_target_established_local env =
| Set.null failures -> Nothing
| otherwise -> Just failures
where
failures = Map.keysSet (Map.filter (==PeerCold) . fmap fst $ status)
failures = Map.keysSet (Map.filter (==PeerCooling) . fmap fst $ status)
TraceDemoteLocalAsynchronous status
| Set.null failures -> Nothing
| otherwise -> Just failures
where
failures = Map.keysSet (Map.filter (==PeerCold) . fmap fst $ status)
failures = Map.keysSet (Map.filter (==PeerCooling) . fmap fst $ status)
TracePromoteWarmFailed _ _ peer _ ->
Just (Set.singleton peer)
_ -> Nothing
Expand Down Expand Up @@ -2938,7 +2938,7 @@ prop_issue_3550 = prop_governor_target_established_below $
[ (PeerAddr 4,[],GovernorScripts {peerShareScript = Script (Just ([],PeerShareTimeSlow) :| []), connectionScript = Script ((Noop,NoDelay) :| [])}),
(PeerAddr 14,[],GovernorScripts {peerShareScript = Script (Nothing :| []), connectionScript = Script ((Noop,NoDelay) :| [])}),
(PeerAddr 16,[],GovernorScripts {peerShareScript = Script (Nothing :| []), connectionScript = Script ((Noop,NoDelay) :| [])}),
(PeerAddr 29,[],GovernorScripts {peerShareScript = Script (Nothing :| []), connectionScript = Script ((ToWarm,NoDelay) :| [(ToCold,NoDelay),(Noop,NoDelay)])})
(PeerAddr 29,[],GovernorScripts {peerShareScript = Script (Nothing :| []), connectionScript = Script ((ToWarm,NoDelay) :| [(ToCooling,NoDelay),(Noop,NoDelay)])})
],
localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 16,DoAdvertisePeer)]),(1,1,Map.fromList [(PeerAddr 4,DoAdvertisePeer)])],
publicRootPeers = Map.fromList
Expand Down Expand Up @@ -2976,7 +2976,7 @@ prop_issue_3515 = prop_governor_nolivelock $
peerGraph = PeerGraph
[(PeerAddr 10,[],GovernorScripts {
peerShareScript = Script (Nothing :| []),
connectionScript = Script ((ToCold,NoDelay) :| [(Noop,NoDelay)])
connectionScript = Script ((ToCooling,NoDelay) :| [(Noop,NoDelay)])
})],
localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 10,DoAdvertisePeer)])],
publicRootPeers = Map.fromList [],
Expand Down Expand Up @@ -3008,7 +3008,7 @@ prop_issue_3494 = prop_governor_nofail $
GovernorMockEnvironment {
peerGraph = PeerGraph [(PeerAddr 64,[],GovernorScripts {
peerShareScript = Script (Nothing :| []),
connectionScript = Script ((ToCold,NoDelay) :| [(Noop,NoDelay)])
connectionScript = Script ((ToCooling,NoDelay) :| [(Noop,NoDelay)])
})],
localRootPeers = LocalRootPeers.fromGroups [(1,1,Map.fromList [(PeerAddr 64,DoAdvertisePeer)])],
publicRootPeers = Map.fromList [],
Expand Down Expand Up @@ -3038,11 +3038,11 @@ prop_issue_3233 = prop_governor_nolivelock $
peerGraph = PeerGraph
[(PeerAddr 4,[],GovernorScripts {
peerShareScript = Script (Nothing :| []),
connectionScript = Script ((ToCold,NoDelay)
:| [(ToCold,NoDelay),
connectionScript = Script ((ToCooling,NoDelay)
:| [(ToCooling,NoDelay),
(Noop,NoDelay),
(ToWarm,NoDelay),
(ToCold,NoDelay),
(ToCooling,NoDelay),
(Noop,NoDelay)
])
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,23 +414,23 @@ mockPeerSelectionActions' tracer
PeerHot -> writeTVar v PeerWarm
>> return False
PeerWarm -> return False
PeerCold -> return False
PeerReallyCold -> return True
ToCold -> do
PeerCooling -> return False
PeerCold -> return True
ToCooling -> do
threadDelay (interpretScriptDelay delay)
atomically $ do
s <- readTVar v
case s of
PeerCold -> return False
_ -> writeTVar v PeerCold
PeerCooling -> return False
_ -> writeTVar v PeerCooling
>> return False
ToReallyCold -> do
ToCold -> do
threadDelay (interpretScriptDelay delay)
atomically $ do
s <- readTVar v
case s of
PeerReallyCold -> return True
_ -> writeTVar v PeerReallyCold
PeerCold -> return True
_ -> writeTVar v PeerCooling
>> return True

traceWith tracer (TraceEnvPeersDemote demotion peeraddr)
Expand All @@ -448,8 +448,8 @@ mockPeerSelectionActions' tracer
atomically $ do
status <- readTVar conn
case status of
PeerHot -> error "activatePeerConnection of hot peer"
PeerWarm -> writeTVar conn PeerHot
PeerHot -> error "activatePeerConnection of hot peer"
PeerWarm -> writeTVar conn PeerHot
--TODO: check it's just a race condition and not just wrong:
--
-- We throw 'ActivationError' for the following reason:
Expand All @@ -459,34 +459,34 @@ mockPeerSelectionActions' tracer
-- errored. Otherwise 'jobPromoteWarmPeer' will try to update the
-- state as if the transition went fine which will violate
-- 'invariantPeerSelectionState'.
PeerCold -> throwIO ActivationError
PeerReallyCold -> throwIO ActivationError
PeerCooling -> throwIO ActivationError
PeerCold -> throwIO ActivationError

deactivatePeerConnection :: PeerConn m -> m ()
deactivatePeerConnection (PeerConn peeraddr _ conn) = do
traceWith tracer (TraceEnvDeactivatePeer peeraddr)
atomically $ do
status <- readTVar conn
case status of
PeerHot -> writeTVar conn PeerWarm
PeerHot -> writeTVar conn PeerWarm
--TODO: check it's just a race condition and not just wrong:
PeerWarm -> return ()
PeerWarm -> return ()
-- See the note in 'activatePeerConnection' why we throw an exception
-- here.
PeerCold -> throwIO DeactivationError
PeerReallyCold -> throwIO DeactivationError
PeerCooling -> throwIO DeactivationError
PeerCold -> throwIO DeactivationError

closePeerConnection :: PeerConn m -> m ()
closePeerConnection (PeerConn peeraddr _ conn) = do
traceWith tracer (TraceEnvCloseConn peeraddr)
atomically $ do
status <- readTVar conn
case status of
PeerHot -> writeTVar conn PeerReallyCold
PeerHot -> writeTVar conn PeerCold
--TODO: check it's just a race condition and not just wrong:
PeerWarm -> writeTVar conn PeerReallyCold
PeerCold -> writeTVar conn PeerReallyCold
PeerReallyCold -> return ()
PeerWarm -> writeTVar conn PeerCold
PeerCooling -> writeTVar conn PeerCold
PeerCold -> return ()
conns <- readTVar connsVar
let !conns' = Map.delete peeraddr conns
writeTVar connsVar conns'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ interpretPeerShareTime PeerShareTimeTimeout = 25
type ConnectionScript = TimedScript AsyncDemotion

data AsyncDemotion = ToWarm
| ToCooling
| ToCold
| ToReallyCold
| Noop
deriving (Eq, Show)

Expand Down Expand Up @@ -204,14 +204,14 @@ simpleGraphRep (graph, vertexInfo, lookupVertex) =

instance Arbitrary AsyncDemotion where
arbitrary = frequency [ (2, pure ToWarm)
, (2, pure ToCooling)
, (2, pure ToCold)
, (2, pure ToReallyCold)
, (6, pure Noop)
]
shrink ToWarm = [ToCold, Noop]
shrink ToCold = [ToReallyCold, Noop]
shrink ToReallyCold = [Noop]
shrink Noop = []
shrink ToWarm = [ToCooling, Noop]
shrink ToCooling = [ToCold, Noop]
shrink ToCold = [Noop]
shrink Noop = []


instance Arbitrary GovernorScripts where
Expand Down
4 changes: 2 additions & 2 deletions ouroboros-network/sim-tests/Test/Ouroboros/Network/Testnet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1961,11 +1961,11 @@ prop_diffusion_async_demotions defaultBearerInfo diffScript =
DiffusionPeerSelectionTrace (TraceDemoteBigLedgerPeersAsynchronous status) ->
Just $ Left (Just failures)
where
failures = Map.keysSet (Map.filter ((==PeerCold) . fst) status)
failures = Map.keysSet (Map.filter ((==PeerCooling) . fst) status)
DiffusionPeerSelectionTrace (TraceDemoteLocalAsynchronous status) ->
Just $ Left (Just failures)
where
failures = Map.keysSet (Map.filter ((==PeerCold) . fst) status)
failures = Map.keysSet (Map.filter ((==PeerCooling) . fst) status)
DiffusionPeerSelectionTrace (TraceDemoteHotFailed _ _ peeraddr _) ->
Just $ Left (Just failures)
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ connections :: forall m peeraddr peerconn.
-> PeerSelectionActions peeraddr peerconn m
-> PeerSelectionState peeraddr peerconn
-> Guarded (STM m) (TimedDecision m peeraddr peerconn)
connections coldPeersCacheTVar
connections coolingPeersCacheTVar
PeerSelectionActions{
peerStateActions = PeerStateActions {monitorPeerConnection}
}
Expand All @@ -153,15 +153,15 @@ connections coldPeersCacheTVar
} =
Guarded Nothing $ do
-- Get previously cooling peers
coolingPeers <- readTVar coldPeersCacheTVar
coolingPeers <- readTVar coolingPeersCacheTVar
monitorStatus <- traverse monitorPeerConnection
(EstablishedPeers.toMap establishedPeers)
-- filter previously cooling peers from the demotion sets
let demotions = asynchronousDemotions coolingPeers monitorStatus
`Map.withoutKeys` coolingPeers
check (not (Map.null demotions))
let (demotedToWarm, demotedToCold) = Map.partition ((==PeerWarm) . fst) demotions
demotedToReallyCold = Map.filter ((==PeerReallyCold) . fst) demotedToCold
let (demotedToWarm, demotedToCoolingOrCold) = Map.partition ((==PeerWarm) . fst) demotions
demotedToCold = Map.filter ((==PeerCold) . fst) demotedToCoolingOrCold
-- fuzz reconnect delays
(aFuzz, fuzzRng') = randomR (-5, 5 :: Double) fuzzRng
(rFuzz, fuzzRng'') = randomR (-2, 2 :: Double) fuzzRng'
Expand All @@ -170,16 +170,16 @@ connections coldPeersCacheTVar
PeerWarm -> ( peerState
, (\x -> (x + realToFrac aFuzz) `max` 0) <$> reconnectDelay
)
PeerCold -> ( peerState
PeerCooling -> ( peerState
, (\x -> (x + realToFrac rFuzz) `max` 0) <$> reconnectDelay
)
PeerReallyCold -> a
PeerCold -> a
) <$> demotions
-- update cache by removing the ones that were demoted to really cold
-- and adding the ones demoted to cold.
modifyTVar coldPeersCacheTVar
( (Set.\\ Map.keysSet demotedToReallyCold)
. (<> Map.keysSet demotedToCold)
modifyTVar coolingPeersCacheTVar
( (Set.\\ Map.keysSet demotedToCold)
. (<> Map.keysSet demotedToCoolingOrCold)
)
return $ \now ->
let -- Remove all asynchronous demotions from 'activePeers'
Expand All @@ -200,19 +200,19 @@ connections coldPeersCacheTVar
demotedToWarm
)
. EstablishedPeers.deletePeers
(Map.keysSet demotedToReallyCold)
(Map.keysSet demotedToCold)
$ establishedPeers

-- Asynchronous transition to cold peer can only be
-- a result of a failure.
knownPeers' = KnownPeers.setConnectTimes
( (\(_, a) -> ExitPolicy.reconnectDelay (fromMaybe 0 a) `addTime` now)
<$> demotedToReallyCold
<$> demotedToCold
)
. Set.foldr'
((snd .) . KnownPeers.incrementFailCount)
(knownPeers st)
$ Map.keysSet demotedToReallyCold
$ Map.keysSet demotedToCold
(localDemotions, nonLocalDemotions) =
Map.partitionWithKey
(\peer _ -> peer `LocalRootPeers.member` localRootPeers)
Expand Down Expand Up @@ -245,7 +245,7 @@ connections coldPeersCacheTVar
-- reason we need to adjust 'inProgressPromoteWarm'.
inProgressPromoteWarm
= inProgressPromoteWarm
Set.\\ Map.keysSet demotedToReallyCold,
Set.\\ Map.keysSet demotedToCold,

-- Note that we do not need to adjust
-- inProgressDemoteWarm or inProgressDemoteHot
Expand Down Expand Up @@ -280,23 +280,23 @@ connections coldPeersCacheTVar

-- a warm -> cold transition has occurred if it is now cold, and it was
-- warm, but not in the set we were deliberately demoting synchronously
asyncDemotion previouslyColdPeers peeraddr (PeerCold, returnCommand)
asyncDemotion previouslyColdPeers peeraddr (PeerCooling, returnCommand)
| peeraddr `EstablishedPeers.member` establishedPeers
, peeraddr `Set.notMember` activePeers
, peeraddr `Set.notMember` inProgressDemoteWarm
, peeraddr `Set.notMember` previouslyColdPeers = Just (PeerCold, returnCommand)
, peeraddr `Set.notMember` previouslyColdPeers = Just (PeerCooling, returnCommand)

-- a hot -> cold transition has occurred if it is now cold, and it was hot
asyncDemotion previouslyColdPeers peeraddr (PeerCold, returnCommand)
asyncDemotion previouslyColdPeers peeraddr (PeerCooling, returnCommand)
| peeraddr `Set.member` activePeers
, peeraddr `Set.notMember` inProgressDemoteHot
, peeraddr `Set.notMember` previouslyColdPeers = Just (PeerCold, returnCommand)
, peeraddr `Set.notMember` previouslyColdPeers = Just (PeerCooling, returnCommand)

-- a cold -> really cold transition has occurred if it is now really cold, and it was cold
asyncDemotion _ peeraddr (PeerReallyCold, returnCommand)
asyncDemotion _ peeraddr (PeerCold, returnCommand)
| peeraddr `EstablishedPeers.member` establishedPeers || peeraddr `Set.member` activePeers
, peeraddr `Set.notMember` inProgressDemoteWarm
, peeraddr `Set.notMember` inProgressDemoteHot = Just (PeerReallyCold, returnCommand)
, peeraddr `Set.notMember` inProgressDemoteHot = Just (PeerCold, returnCommand)

asyncDemotion _ _ _ = Nothing

Expand Down
Loading

0 comments on commit e0d61a9

Please sign in to comment.