Skip to content

Commit

Permalink
diffusion: removed extraActions
Browse files Browse the repository at this point in the history
They are passed as a closure, no need to leak them outside of `Cardano`
(or any other 3rd party integration).
  • Loading branch information
coot committed Feb 6, 2025
1 parent b3d5783 commit 987d6c9
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1265,10 +1265,10 @@ diffusionSimulation
interfaces
arguments
(ExtraState.empty consensusMode (NumberOfBigLedgerPeers 0))
(Cardano.cardanoExtraArgsToPeerSelectionActions cardanoExtraArgs)
ExtraSizes.empty
Cardano.cardanoPublicRootPeersAPI
(Cardano.cardanoPeerSelectionGovernorArgs
(Cardano.cardanoExtraArgsToPeerSelectionActions cardanoExtraArgs)
readUseLedgerPeers
peerSharing
( Cardano.updateOutboundConnectionsState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ data Arguments extraChurnArgs extraFlags m = Arguments
--
type ResolverException = SomeException

run :: forall extraState extraDebugState extraActions extraAPI
run :: forall extraState extraDebugState extraAPI
extraPeers extraFlags extraChurnArgs extraCounters
exception resolver resolverError m.
( Alternative (STM m)
Expand Down Expand Up @@ -202,14 +202,12 @@ run :: forall extraState extraDebugState extraActions extraAPI
-> Interfaces extraAPI m
-> Arguments extraChurnArgs extraFlags m
-> extraState
-> extraActions
-> extraCounters
-> PublicExtraPeersAPI extraPeers NtNAddr
-> (forall muxMode responderCtx ntnVersionData bytes a b .
PeerSelectionGovernorArgs
extraState
extraDebugState
extraActions
extraFlags
extraPeers
extraAPI
Expand Down Expand Up @@ -253,7 +251,7 @@ run :: forall extraState extraDebugState extraActions extraAPI
-> Tracer m (TraceLabelPeer NtNAddr (TraceFetchClientState BlockHeader))
-> m Void
run blockGeneratorArgs limits ni na
emptyExtraState extraActions emptyExtraCounters
emptyExtraState emptyExtraCounters
extraPeersAPI psArgs psToExtraCounters
toExtraPeers requestPublicRootPeers peerChurnGovernor
tracersExtra tracerBlockFetch =
Expand Down Expand Up @@ -456,7 +454,7 @@ run blockGeneratorArgs limits ni na
}

argsExtra :: Common.ArgumentsExtra
extraState extraDebugState extraActions
extraState extraDebugState
extraFlags extraPeers extraAPI
extraChurnArgs extraCounters exception
NtNAddr resolver resolverError m
Expand All @@ -474,7 +472,6 @@ run blockGeneratorArgs limits ni na
, Common.daEmptyExtraState = emptyExtraState
, Common.daEmptyExtraCounters = emptyExtraCounters
, Common.daExtraPeersAPI = extraPeersAPI
, Common.daExtraActions = extraActions
, Common.daExtraChurnArgs = aExtraChurnArgs na
, Common.daToExtraPeers = toExtraPeers
, Common.daRequestPublicRootPeers = Just requestPublicRootPeers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4011,6 +4011,10 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap

peerSelectionGovernorArgs =
Cardano.cardanoPeerSelectionGovernorArgs
Cardano.ExtraPeerSelectionActions {
genesisPeerTargets = targets,
readUseBootstrapPeers = readUseBootstrapPeers
}
(return DontUseLedgerPeers)
peerSharing
(Cardano.updateOutboundConnectionsState (lpExtraAPI (getLedgerStateCtx actions)))
Expand Down Expand Up @@ -4045,7 +4049,6 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
actions
:: PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions IO)
PeerTrustable
(Cardano.ExtraPeers SockAddr)
(Cardano.LedgerPeersConsensusInterface IO)
Expand Down Expand Up @@ -4083,10 +4086,6 @@ _governorFindingPublicRoots targetNumberOfRootPeers readDomains readUseBootstrap
},
peerSelectionTargets = targets,
readLedgerPeerSnapshot = pure Nothing,
extraActions = Cardano.ExtraPeerSelectionActions {
genesisPeerTargets = targets,
readUseBootstrapPeers = readUseBootstrapPeers
},
extraStateToExtraCounters = ExtraSizes.cardanoPeerSelectionStatetoCounters,
extraPeersAPI = ExtraPeers.cardanoPublicRootPeersAPI
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ governorAction mockEnv@GovernorMockEnvironment {
(useLedgerPeers mockEnv)
usbVar <- playTimedScript (contramap TraceEnvSetUseBootstrapPeers tracerMockEnv)
(useBootstrapPeers mockEnv)
let readUseBootstrapPeers = readTVar usbVar
-- todo: make NumberOfBigLedgerPeers come from quickcheck
debugStateVar <- StrictTVar.newTVarIO (emptyPeerSelectionState (mkStdGen 42) (ExtraState.empty consensusMode (NumberOfBigLedgerPeers 0)) ExtraPeers.empty)
countersVar <- StrictTVar.newTVarIO (emptyPeerSelectionCounters ExtraSizes.empty)
Expand All @@ -260,7 +261,7 @@ governorAction mockEnv@GovernorMockEnvironment {
(first fst <$> targets mockEnv)
mockPeerSelectionActions tracerMockEnv mockEnv
initialPeerTargets
(readTVar usbVar)
readUseBootstrapPeers
(readTVar lpVar)
(readTVar lsjVar)
(readTVar targetsVar)
Expand Down Expand Up @@ -293,6 +294,10 @@ governorAction mockEnv@GovernorMockEnvironment {

peerSelectionGovernorArgs =
Cardano.cardanoPeerSelectionGovernorArgs
Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets = snd initialPeerTargets,
Cardano.readUseBootstrapPeers = readUseBootstrapPeers
}
(readTVar lpVar)
(peerSharing actions)
(Cardano.updateOutboundConnectionsState (lpExtraAPI (getLedgerStateCtx actions)))
Expand Down Expand Up @@ -360,7 +365,6 @@ mockPeerSelectionActions :: forall m.
-> STM m PeerSelectionTargets
-> m (PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
PeerTrustable
(Cardano.ExtraPeers PeerAddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand Down Expand Up @@ -439,7 +443,6 @@ mockPeerSelectionActions' :: forall m.
-> TVar m OutboundConnectionsState
-> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
PeerTrustable
(Cardano.ExtraPeers PeerAddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand All @@ -453,7 +456,7 @@ mockPeerSelectionActions' tracer
publicRootPeers,
peerSharingFlag
}
(originalPeerTargets, peerTargets)
(originalPeerTargets, _peerTargets)
scripts
readTargets
readUseBootstrapPeers
Expand Down Expand Up @@ -498,10 +501,6 @@ mockPeerSelectionActions' tracer
readInboundPeers = pure Map.empty,
readLedgerPeerSnapshot = pure Nothing,
peerSelectionTargets = originalPeerTargets,
extraActions = Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets = peerTargets,
Cardano.readUseBootstrapPeers = readUseBootstrapPeers
},
extraPeersAPI = ExtraPeers.cardanoPublicRootPeersAPI,
extraStateToExtraCounters = Cardano.cardanoPeerSelectionStatetoCounters
}
Expand Down Expand Up @@ -828,7 +827,6 @@ traceAssociationMode
(IOSim s)
-> PeerSelectionActions
Cardano.ExtraState
extraActions
extraFlags
extraPeers
extraAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ governor_BOOTSTRAP_PEERS_TIMEOUT = 15 * 60
-- set of target peers.
targetPeers
:: (MonadSTM m, Ord peeraddr)
=> PeerSelectionActions
=> Cardano.ExtraPeerSelectionActions m
-> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
extraFlags
extraPeers
extraAPI
Expand All @@ -89,13 +89,14 @@ targetPeers
-> Guarded (STM m)
(TimedDecision m Cardano.ExtraState extraDebugState PeerTrustable
extraPeers peeraddr peerconn)
targetPeers PeerSelectionActions{ peerSelectionTargets,
readPeerSelectionTargets,
extraActions = Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets
},
extraPeersAPI
}
targetPeers Cardano.ExtraPeerSelectionActions {
Cardano.genesisPeerTargets
}
PeerSelectionActions {
peerSelectionTargets,
readPeerSelectionTargets,
extraPeersAPI
}
st@PeerSelectionState{
publicRootPeers,
localRootPeers,
Expand Down Expand Up @@ -182,11 +183,10 @@ targetPeers PeerSelectionActions{ peerSelectionTargets,
-- trusted, however we will keep a connection to it until the outbound
-- governor notices it and disconnects from it.
localRoots
:: forall extraDebugState extraActions extraAPI extraCounters peeraddr peerconn m.
:: forall extraDebugState extraAPI extraCounters peeraddr peerconn m.
(MonadSTM m, Ord peeraddr)
=> PeerSelectionActions
Cardano.ExtraState
extraActions
PeerTrustable
(Cardano.ExtraPeers peeraddr)
extraAPI
Expand Down Expand Up @@ -380,9 +380,10 @@ monitorBootstrapPeersFlag
:: ( MonadSTM m
, Ord peeraddr
)
=> PeerSelectionActions
=> Cardano.ExtraPeerSelectionActions m
-> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)

extraFlags
(Cardano.ExtraPeers peeraddr)
extraAPI
Expand All @@ -399,11 +400,8 @@ monitorBootstrapPeersFlag
-> Guarded (STM m)
(TimedDecision m Cardano.ExtraState extraDebugState extraFlags
(Cardano.ExtraPeers peeraddr) peeraddr peerconn)
monitorBootstrapPeersFlag PeerSelectionActions { extraActions = Cardano.ExtraPeerSelectionActions {
Cardano.readUseBootstrapPeers
}
, extraPeersAPI
}
monitorBootstrapPeersFlag Cardano.ExtraPeerSelectionActions { Cardano.readUseBootstrapPeers }
PeerSelectionActions { extraPeersAPI }
st@PeerSelectionState { knownPeers
, establishedPeers
, publicRootPeers
Expand Down Expand Up @@ -465,11 +463,10 @@ monitorBootstrapPeersFlag PeerSelectionActions { extraActions = Cardano.ExtraPee
--
monitorLedgerStateJudgement
:: ( MonadSTM m
, Ord peeraddr
)
, Ord peeraddr
)
=> PeerSelectionActions
Cardano.ExtraState
(Cardano.ExtraPeerSelectionActions m)
extraFlags
(Cardano.ExtraPeers peeraddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand Down Expand Up @@ -605,8 +602,8 @@ monitorLedgerStateJudgement PeerSelectionActions{
--
waitForSystemToQuiesce
:: ( MonadSTM m
, Ord peeraddr
)
, Ord peeraddr
)
=> PeerSelectionState
Cardano.ExtraState
PeerTrustable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,14 @@ cardanoPeerSelectionGovernorArgs
, Alternative (STM m)
, Ord peeraddr
)
=> STM m UseLedgerPeers
=> Cardano.ExtraPeerSelectionActions m
-> STM m UseLedgerPeers
-> PeerSharing
-> (OutboundConnectionsState -> STM m ())
-> PeerSelectionGovernorArgs
Cardano.ExtraState
extraDebugState
(Cardano.ExtraPeerSelectionActions m)

PeerTrustable
(Cardano.ExtraPeers peeraddr)
(Cardano.LedgerPeersConsensusInterface m)
Expand All @@ -201,7 +202,7 @@ cardanoPeerSelectionGovernorArgs
peerconn
BootstrapPeersCriticalTimeoutError
m
cardanoPeerSelectionGovernorArgs readUseLedgerPeers peerSharing updateOutboundConnectionsState =
cardanoPeerSelectionGovernorArgs extraActions readUseLedgerPeers peerSharing updateOutboundConnectionsState =
PeerSelectionGovernorArgs {
-- If by any chance the node takes more than 15 minutes to converge to a
-- clean state, we crash the node. This could happen in very rare
Expand All @@ -223,12 +224,12 @@ cardanoPeerSelectionGovernorArgs readUseLedgerPeers peerSharing updateOutboundCo
, extraDecisions =
ExtraGuardedDecisions {
preBlocking = \_ psa pst ->
monitorBootstrapPeersFlag psa pst
monitorBootstrapPeersFlag extraActions psa pst
<> monitorLedgerStateJudgement psa pst
<> waitForSystemToQuiesce pst
, postBlocking = mempty
, postNonBlocking = mempty
, customTargetsAction = Just $ \_ -> Cardano.targetPeers
, customTargetsAction = Just $ \_ -> Cardano.targetPeers extraActions
, customLocalRootsAction = Just $ \_ -> Cardano.localRoots
, enableProgressMakingActions = \st ->
not (requiresBootstrapPeers (Cardano.bootstrapPeersFlag st) (Cardano.ledgerStateJudgement st))
Expand Down
12 changes: 6 additions & 6 deletions ouroboros-network/src/Ouroboros/Network/Diffusion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ data ExtraTracers (p2p :: P2P) extraState extraDebugState extraFlags extraPeers
-- | Diffusion arguments which depend on p2p mode.
--
data ArgumentsExtra
(p2p :: P2P) extraArgs extraState extraDebugState extraActions extraAPI
(p2p :: P2P) extraArgs extraState extraDebugState extraAPI
extraPeers extraFlags extraChurnArgs extraCounters exception ntnAddr resolver resolverError m where
P2PArguments
:: Common.ArgumentsExtra extraState extraDebugState extraActions extraAPI
:: Common.ArgumentsExtra extraState extraDebugState extraAPI
extraPeers extraFlags extraChurnArgs
extraCounters exception ntnAddr resolver resolverError m
-> ArgumentsExtra 'P2P extraArgs extraState extraDebugState extraActions extraAPI
-> ArgumentsExtra 'P2P extraArgs extraState extraDebugState extraAPI
extraPeers extraFlags extraChurnArgs
extraCounters exception ntnAddr resolver resolverError m

NonP2PArguments
:: NonP2P.ArgumentsExtra
-> ArgumentsExtra 'NonP2P extraArgs extraState extraDebugState extraActions extraAPI
-> ArgumentsExtra 'NonP2P extraArgs extraState extraDebugState extraAPI
extraPeers extraFlags extraChurnArgs
extraCounters exception ntnAddr resolver resolverError m

Expand Down Expand Up @@ -115,7 +115,7 @@ data ApplicationsExtra (p2p :: P2P) ntnAddr m a where

-- | Run data diffusion in either 'P2P' or 'NonP2P' mode.
--
run :: forall (p2p :: P2P) extraArgs extraState extraDebugState extraActions extraFlags
run :: forall (p2p :: P2P) extraArgs extraState extraDebugState extraFlags
extraPeers extraAPI extraChurnArgs extraCounters exception a.
( Monoid extraPeers
, Eq extraCounters
Expand Down Expand Up @@ -143,7 +143,7 @@ run :: forall (p2p :: P2P) extraArgs extraState extraDebugState extraActions ext
IO
Socket RemoteAddress
LocalSocket LocalAddress
-> ArgumentsExtra p2p extraArgs extraState extraDebugState extraActions extraFlags
-> ArgumentsExtra p2p extraArgs extraState extraDebugState extraFlags
extraPeers extraAPI extraChurnArgs extraCounters exception
RemoteAddress Resolver IOException IO
-> Applications p2p RemoteAddress LocalAddress NodeToNodeVersionData NodeToClientVersionData extraAPI IO a
Expand Down
12 changes: 4 additions & 8 deletions ouroboros-network/src/Ouroboros/Network/Diffusion/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ nullTracersExtra =

-- | P2P Arguments Extras
--
data ArgumentsExtra extraState extraDebugState extraActions extraFlags extraPeers
data ArgumentsExtra extraState extraDebugState extraFlags extraPeers
extraAPI extraChurnArgs extraCounters exception
peeraddr resolver resolverError m = ArgumentsExtra {
-- | selection targets for the peer governor
Expand Down Expand Up @@ -432,7 +432,7 @@ data ArgumentsExtra extraState extraDebugState extraActions extraFlags extraPeer

, daPeerSelectionGovernorArgs
:: forall muxMode responderCtx ntnVersionData bytes a b .
PeerSelectionGovernorArgs extraState extraDebugState extraActions extraFlags extraPeers
PeerSelectionGovernorArgs extraState extraDebugState extraFlags extraPeers
extraAPI extraCounters
peeraddr (PeerConnectionHandle
muxMode responderCtx peeraddr
Expand Down Expand Up @@ -485,10 +485,6 @@ data ArgumentsExtra extraState extraDebugState extraActions extraFlags extraPeer
peeraddr
-> m Void

-- | Provide extraActions to be passed to peer selection actions
--
, daExtraActions :: extraActions

-- | Provide extraChurnArgs to be passed to churn governor
--
, daExtraChurnArgs :: extraChurnArgs
Expand Down Expand Up @@ -602,10 +598,10 @@ type NodeToNodePeerConnectionHandle (mode :: Mx.Mode) ntnAddr ntnVersionData m a
ByteString
m a b

type NodeToNodePeerSelectionActions extraState extraActions extraFlags extraPeers extraAPI extraCounters
type NodeToNodePeerSelectionActions extraState extraFlags extraPeers extraAPI extraCounters
(mode :: Mx.Mode) ntnAddr ntnVersionData m a b =
PeerSelectionActions
extraState extraActions extraFlags extraPeers extraAPI extraCounters
extraState extraFlags extraPeers extraAPI extraCounters
ntnAddr
(NodeToNodePeerConnectionHandle mode ntnAddr ntnVersionData m a b)
m
Expand Down
Loading

0 comments on commit 987d6c9

Please sign in to comment.