-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reusable Diffusion - Make diffusion fully polymorphic #5016
base: main
Are you sure you want to change the base?
Changes from 1 commit
bae4f75
cb0da21
a382ed8
86f68f3
856abeb
f1b04ef
409b01d
6c4d16d
e9a9938
f4293b5
eef654f
cd3aa60
331ccac
5b0e2fa
9ef2b15
ecf1f10
5400a7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||
{-# LANGUAGE DeriveGeneric #-} | ||||||||||
{-# LANGUAGE DerivingStrategies #-} | ||||||||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||||||||||
|
||||||||||
module Cardano.Node.Types where | ||||||||||
|
||||||||||
import Data.Aeson (FromJSON) | ||||||||||
import GHC.Generics (Generic) | ||||||||||
import NoThunks.Class (NoThunks) | ||||||||||
|
||||||||||
-- | Wether the node is caught up or fell too far behind the chain | ||||||||||
data LedgerStateJudgement = YoungEnough | TooOld | ||||||||||
deriving (Eq, Show, Generic) | ||||||||||
|
||||||||||
instance NoThunks LedgerStateJudgement | ||||||||||
|
||||||||||
-- | Minimum number of hot big ledger peers in Genesis mode | ||||||||||
-- for trusted state to be signalled to Consensus. This number | ||||||||||
-- should be smaller than the `targetNumberOfActiveBigLedgerPeers` | ||||||||||
-- but greater than 1. In Genesis, we may demote a big ledger peer | ||||||||||
-- for underperformance, but not promote a replacement immediately | ||||||||||
-- to guard against adversaries which may want to slow down our | ||||||||||
-- progress. | ||||||||||
-- | ||||||||||
newtype MinBigLedgerPeersForTrustedState = | ||||||||||
MinBigLedgerPeersForTrustedState { getMinBigLedgerPeersForTrustedState :: Int } | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
the rest is explained in the haddock. |
||||||||||
deriving stock (Eq, Show) | ||||||||||
deriving newtype (FromJSON) | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Cardano.Node.ArgumentsExtra where | ||
|
||
import Cardano.Node.ConsensusMode (ConsensusMode) | ||
import Cardano.Node.PeerSelection.Bootstrap (UseBootstrapPeers) | ||
import Cardano.Node.Types (MinBigLedgerPeersForTrustedState) | ||
import Control.Concurrent.Class.MonadSTM (MonadSTM (..)) | ||
import Ouroboros.Network.PeerSelection.Governor.Types | ||
(PeerSelectionTargets (..)) | ||
|
||
-- | Cardano Node specific (extra) arguments to be passed to diffusion. | ||
-- | ||
data CardanoArgumentsExtra m = | ||
CardanoArgumentsExtra { | ||
-- | selection targets for the peer governor | ||
caePeerTargets :: ConsensusModePeerTargets | ||
, caeReadUseBootstrapPeers :: STM m UseBootstrapPeers | ||
|
||
-- | For Genesis, this sets the floor for minimum number of | ||
-- active big ledger peers we must be connected to in order | ||
-- to be able to signal trusted state (OutboundConnectionsState) | ||
, caeMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState | ||
-- | When syncing up, ie. ledgerStateJudgement == TooOld, | ||
-- when this is True we will maintain connection with many big ledger peers | ||
-- to get a strong guarantee that when syncing up we will finish with a true | ||
-- ledger state. When false, we will fall back on the previous algorithms | ||
-- that leverage UseBootstrapPeers flag | ||
, caeConsensusMode :: ConsensusMode | ||
} | ||
|
||
-- | Provides alternate peer selection targets | ||
-- for various syncing modes. | ||
-- | ||
data ConsensusModePeerTargets = ConsensusModePeerTargets { | ||
deadlineTargets :: !PeerSelectionTargets, | ||
syncTargets :: !PeerSelectionTargets | ||
} | ||
deriving (Eq, Show) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Cardano.Node.LedgerPeerConsensusInterface where | ||
|
||
import Cardano.Node.PeerSelection.LocalRootPeers (OutboundConnectionsState) | ||
import Cardano.Node.Types (LedgerStateJudgement) | ||
import Control.Concurrent.Class.MonadSTM (MonadSTM (..)) | ||
|
||
-- | Cardano Node specific consensus interface actions. | ||
-- | ||
data CardanoLedgerPeersConsensusInterface m = | ||
CardanoLedgerPeersConsensusInterface { | ||
clpciGetLedgerStateJudgement :: STM m LedgerStateJudgement | ||
|
||
-- | Callback provided by consensus to inform it if the node is | ||
-- connected to only local roots or also some external peers. | ||
-- | ||
-- This is useful in order for the Bootstrap State Machine to | ||
-- simply refuse to transition from TooOld to YoungEnough while | ||
-- it only has local peers. | ||
-- | ||
, clpciUpdateOutboundConnectionsState :: OutboundConnectionsState -> STM m () | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Cardano.Node.PeerSelection.Governor.PeerSelectionActions where | ||
|
||
import Cardano.Node.ArgumentsExtra (ConsensusModePeerTargets) | ||
import Cardano.Node.PeerSelection.Bootstrap (UseBootstrapPeers) | ||
import Control.Concurrent.Class.MonadSTM | ||
|
||
-- | Cardano Node PeerSelection Actions extension data type. | ||
-- | ||
-- It contain specific PeerSelection actions parameters to guide the Outbound | ||
-- Governor. | ||
-- | ||
data CardanoPeerSelectionActions m = | ||
CardanoPeerSelectionActions { | ||
-- | Retrieve peer targets for Genesis & non-Genesis modes | ||
-- from node's configuration for the current state | ||
-- | ||
cpsaPeerTargets :: ConsensusModePeerTargets | ||
|
||
-- | Read the current bootstrap peers flag | ||
, cpsaReadUseBootstrapPeers :: STM m UseBootstrapPeers | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Cardano.Node.PeerSelection.Governor.PeerSelectionState where | ||
|
||
import Cardano.Node.ConsensusMode (ConsensusMode) | ||
import Cardano.Node.PeerSelection.Bootstrap (UseBootstrapPeers (..)) | ||
import Cardano.Node.Types (LedgerStateJudgement (..), | ||
MinBigLedgerPeersForTrustedState (..)) | ||
import Control.Monad.Class.MonadTime.SI (Time) | ||
|
||
-- | Cardano Node PeerSelection State extension data type. | ||
-- It contain specific PeerSelection state parameters to guide the Outbound | ||
-- Governor. | ||
-- | ||
data CardanoPeerSelectionState = | ||
CardanoPeerSelectionState { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd call this type CardanoPeerSelectionState = PeerSelectionState CardanoExtraState ... ref: bae4f75 |
||
-- | Current ledger state judgement | ||
cpstLedgerStateJudgement :: !LedgerStateJudgement | ||
-- | Flag whether to sync in genesis mode when ledgerStateJudgement == TooOld | ||
-- this comes from node configuration and should be treated as read-only | ||
-- | ||
, cpstConsensusMode :: !ConsensusMode | ||
-- | Current value of 'UseBootstrapPeers'. | ||
-- | ||
, cpstBootstrapPeersFlag :: !UseBootstrapPeers | ||
-- | Has the governor fully reset its state | ||
-- | ||
, cpstHasOnlyBootstrapPeers :: !Bool | ||
-- | Has the governor fully reset its state | ||
-- | ||
, cpstBootstrapPeersTimeout :: !(Maybe Time) | ||
-- | Use in Genesis mode to check whether we can signal to | ||
-- consensus that we met criteria of trusted state to enter | ||
-- deadline mode. This parameter comes from node configuration, | ||
-- with a default value in the `Configuration` module. | ||
-- | ||
, cpstMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState | ||
} | ||
deriving Show | ||
|
||
empty :: ConsensusMode -> MinBigLedgerPeersForTrustedState -> CardanoPeerSelectionState | ||
empty consensusMode minActiveBigLedgerPeers = | ||
CardanoPeerSelectionState { | ||
cpstLedgerStateJudgement = TooOld, | ||
cpstConsensusMode = consensusMode, | ||
cpstBootstrapPeersFlag = DontUseBootstrapPeers, | ||
cpstHasOnlyBootstrapPeers = False, | ||
cpstBootstrapPeersTimeout = Nothing, | ||
cpstMinBigLedgerPeersForTrustedState = minActiveBigLedgerPeers | ||
} | ||
|
||
data CardanoDebugPeerSelectionState = | ||
CardanoDebugPeerSelectionState { | ||
cdpssLedgerStateJudgement :: !LedgerStateJudgement | ||
} | ||
deriving Show | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Cardano.Node.PeerSelection.PeerChurnArgs where | ||
|
||
import Cardano.Node.ArgumentsExtra (ConsensusModePeerTargets) | ||
import Cardano.Node.ConsensusMode (ConsensusMode) | ||
import Cardano.Node.PeerSelection.Bootstrap (UseBootstrapPeers) | ||
import Cardano.Node.PeerSelection.Types (ChurnMode) | ||
import Control.Concurrent.Class.MonadSTM.Strict | ||
import Ouroboros.Network.BlockFetch.ConsensusInterface (FetchMode) | ||
|
||
data CardanoPeerChurnArgs m = | ||
CardanoPeerChurnArgs { | ||
cpcaModeVar :: StrictTVar m ChurnMode | ||
, cpcaReadFetchMode :: STM m FetchMode | ||
, cpcaPeerTargets :: ConsensusModePeerTargets | ||
, cpcaReadUseBootstrap :: STM m UseBootstrapPeers | ||
, cpcaConsensusMode :: ConsensusMode | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Cardano.Node.PeerSelection.Types where | ||
|
||
data ChurnMode = ChurnModeBulkSync | ||
| ChurnModeNormal | ||
deriving Show | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
module Cardano.Node.PublicRootPeers where | ||
|
||
import Data.Map.Strict (Map) | ||
import Data.Map.Strict qualified as Map | ||
import Data.Set (Set) | ||
import Data.Set qualified as Set | ||
import Data.Typeable (Typeable) | ||
import Ouroboros.Network.PeerSelection.PeerAdvertise (PeerAdvertise) | ||
|
||
data CardanoPublicRootPeers peeraddr = | ||
CardanoPublicRootPeers | ||
{ cprpGetPublicConfigPeers :: !(Map peeraddr PeerAdvertise) | ||
, cprpGetBootstrapPeers :: !(Set peeraddr) | ||
} | ||
deriving (Eq, Show, Typeable) | ||
bolt12 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type should be called type CardanoPublicRootPeers peeraddr = PublicRootPeers (CardanoExtraPeers peeraddr) peeraddr ref: bae4f75 |
||
|
||
instance Ord peeraddr => Semigroup (CardanoPublicRootPeers peeraddr) where | ||
(CardanoPublicRootPeers a b) <> (CardanoPublicRootPeers a' b') = | ||
let -- Combine the sets, prioritizing bootstrapPeers | ||
combinedSet = b `Set.union` b' | ||
-- Combine the maps and remove any peers that are now in the set | ||
combinedMap = (a `Map.union` a') `Map.withoutKeys` combinedSet | ||
in CardanoPublicRootPeers combinedMap combinedSet | ||
|
||
instance Ord peeraddr => Monoid (CardanoPublicRootPeers peeraddr) where | ||
mempty = empty | ||
|
||
-- Map and Set are disjoint | ||
-- | ||
invariant :: Ord peeraddr => CardanoPublicRootPeers peeraddr -> Bool | ||
invariant (CardanoPublicRootPeers a b) = all (`Map.notMember` a) b | ||
|
||
empty :: CardanoPublicRootPeers peeraddr | ||
empty = CardanoPublicRootPeers Map.empty Set.empty | ||
|
||
nullPublicConfig :: CardanoPublicRootPeers peeraddr -> Bool | ||
nullPublicConfig CardanoPublicRootPeers { cprpGetPublicConfigPeers } = | ||
Map.null cprpGetPublicConfigPeers | ||
|
||
nullBootstrap :: CardanoPublicRootPeers peeraddr -> Bool | ||
nullBootstrap CardanoPublicRootPeers { cprpGetBootstrapPeers } = | ||
Set.null cprpGetBootstrapPeers | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check what consensus uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What did you decide to use?