Skip to content

Commit

Permalink
peer-selection: removed counters cached
Browse files Browse the repository at this point in the history
Since `PeerSelectionCounters` are stored in a `TVar` we don't need to
cache them in `PeerSelectionState`.
  • Loading branch information
coot committed Apr 16, 2024
1 parent 8e863da commit 7d30e1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
19 changes: 9 additions & 10 deletions ouroboros-network/src/Ouroboros/Network/PeerSelection/Governor.hs
Expand Up @@ -37,7 +37,6 @@ module Ouroboros.Network.PeerSelection.Governor
, ChurnMode (..)
) where

import Data.Cache
import Data.Foldable (traverse_)
import Data.Hashable
import Data.Void (Void)
Expand Down Expand Up @@ -556,23 +555,23 @@ peerSelectionGovernorLoop tracer
now <- getMonotonicTime
let Decision { decisionTrace, decisionJobs, decisionState } =
timedDecision now
!newCounters = peerSelectionStateToCounters decisionState

atomically $ do
mbCounters <- atomically $ do
-- Update counters
withCacheA (countersCache decisionState)
newCounters
(writeTVar countersVar)
counters <- readTVar countersVar
let !counters' = peerSelectionStateToCounters decisionState
if counters' /= counters
then writeTVar countersVar counters'
>> return (Just counters')
else return Nothing

-- Trace counters
traceWithCache countersTracer
(countersCache decisionState)
newCounters
traverse_ (traceWith countersTracer) mbCounters

traverse_ (traceWith tracer) decisionTrace

mapM_ (JobPool.forkJob jobPool) decisionJobs
loop (decisionState { countersCache = Cache newCounters }) dbgUpdateAt'
loop decisionState dbgUpdateAt'

evalGuardedDecisions :: Time
-> PeerSelectionState peeraddr peerconn
Expand Down
Expand Up @@ -50,7 +50,6 @@ module Ouroboros.Network.PeerSelection.Governor.Types
, BootstrapPeersCriticalTimeoutError (..)
) where

import Data.Cache (Cache (..))
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Maybe (fromMaybe)
Expand Down Expand Up @@ -441,11 +440,6 @@ data PeerSelectionState peeraddr peerconn = PeerSelectionState {
-- | Rng for fuzzy delay
fuzzRng :: !StdGen,

-- | 'PeerSelectionCounters' counters cache. Allows to only trace
-- values when necessary.
--
countersCache :: !(Cache PeerSelectionCounters),

-- | Current ledger state judgement
--
ledgerStateJudgement :: !LedgerStateJudgement,
Expand Down Expand Up @@ -914,7 +908,6 @@ emptyPeerSelectionState rng =
inProgressDemoteHot = Set.empty,
inProgressDemoteToCold = Set.empty,
fuzzRng = rng,
countersCache = Cache emptyPeerSelectionCounters,
ledgerStateJudgement = TooOld,
bootstrapPeersFlag = DontUseBootstrapPeers,
hasOnlyBootstrapPeers = False,
Expand Down

0 comments on commit 7d30e1a

Please sign in to comment.