Skip to content

Commit

Permalink
Added ConsensusMode option and Genesis targets for diffusion governors.
Browse files Browse the repository at this point in the history
The ConsensusMode configuration option determines whether support for
Genesis syncing is enabled. If this flag is GenesisMode, alternate
targets for active peers (non- big ledger) and all big ledger targets
is used by the peer selection and churn governors in the diffusion
layer. These targets are in effect when ledger state is deemed
`TooOld` by consensus layer. The large active big ledger peer targets
crucially depend on chain skipping to maintain performance
requirements. Otherwise, in PraosMode, the legacy algorithm with
a single set of targets is employed.
  • Loading branch information
crocodile-dentist authored and neilmayhew committed Dec 19, 2024
1 parent d2370bd commit 6a5331f
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 125 deletions.
218 changes: 137 additions & 81 deletions cardano-node/src/Cardano/Node/Configuration/POM.hs

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions cardano-node/src/Cardano/Node/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,19 @@ nodeRunParser = do
, pncTimeWaitTimeout = mempty
, pncChainSyncIdleTimeout = mempty
, pncAcceptedConnectionsLimit = mempty
, pncTargetNumberOfRootPeers = mempty
, pncTargetNumberOfKnownPeers = mempty
, pncTargetNumberOfEstablishedPeers = mempty
, pncTargetNumberOfActivePeers = mempty
, pncTargetNumberOfKnownBigLedgerPeers = mempty
, pncTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncTargetNumberOfActiveBigLedgerPeers = mempty
, pncMinBigLedgerPeersForTrustedState = mempty
, pncDeadlineTargetOfRootPeers = mempty
, pncDeadlineTargetOfKnownPeers = mempty
, pncDeadlineTargetOfEstablishedPeers = mempty
, pncDeadlineTargetOfActivePeers = mempty
, pncDeadlineTargetOfKnownBigLedgerPeers = mempty
, pncDeadlineTargetOfEstablishedBigLedgerPeers = mempty
, pncDeadlineTargetOfActiveBigLedgerPeers = mempty
, pncSyncTargetOfActivePeers = mempty
, pncSyncTargetOfKnownBigLedgerPeers = mempty
, pncSyncTargetOfEstablishedBigLedgerPeers = mempty
, pncSyncTargetOfActiveBigLedgerPeers = mempty
, pncSyncMinTrusted = mempty
, pncConsensusMode = mempty
, pncEnableP2P = mempty
, pncPeerSharing = mempty
}
Expand Down
59 changes: 34 additions & 25 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -891,26 +891,32 @@ mkP2PArguments
-> STM IO (Maybe LedgerPeerSnapshot)
-> Diffusion.ExtraArguments 'Diffusion.P2P IO
mkP2PArguments NodeConfiguration {
ncConsensusMode,
ncTargetNumberOfRootPeers,
ncTargetNumberOfKnownPeers,
ncTargetNumberOfEstablishedPeers,
ncTargetNumberOfActivePeers,
ncTargetNumberOfKnownBigLedgerPeers,
ncTargetNumberOfEstablishedBigLedgerPeers,
ncTargetNumberOfActiveBigLedgerPeers,
ncMinBigLedgerPeersForTrustedState,
ncDeadlineTargetOfRootPeers,
ncDeadlineTargetOfKnownPeers,
ncDeadlineTargetOfEstablishedPeers,
ncDeadlineTargetOfActivePeers,
ncDeadlineTargetOfKnownBigLedgerPeers,
ncDeadlineTargetOfEstablishedBigLedgerPeers,
ncDeadlineTargetOfActiveBigLedgerPeers,
ncSyncTargetOfActivePeers,
ncSyncTargetOfKnownBigLedgerPeers,
ncSyncTargetOfEstablishedBigLedgerPeers,
ncSyncTargetOfActiveBigLedgerPeers,
ncSyncMinTrusted,
ncProtocolIdleTimeout,
ncTimeWaitTimeout,
ncPeerSharing
ncPeerSharing,
ncConsensusMode
}
daReadLocalRootPeers
daReadPublicRootPeers
daReadUseLedgerPeers
daReadUseBootstrapPeers
daReadLedgerPeerSnapshot =
Diffusion.P2PArguments P2P.ArgumentsExtra
{ P2P.daPeerTargets
{ P2P.daPeerTargets = Configuration.ConsensusModePeerTargets {
Configuration.deadlineTargets,
Configuration.syncTargets }
, P2P.daReadLocalRootPeers
, P2P.daReadPublicRootPeers
, P2P.daReadUseLedgerPeers
Expand All @@ -920,24 +926,27 @@ mkP2PArguments NodeConfiguration {
, P2P.daMinBigLedgerPeersForTrustedState = ncMinBigLedgerPeersForTrustedState
, P2P.daProtocolIdleTimeout = ncProtocolIdleTimeout
, P2P.daTimeWaitTimeout = ncTimeWaitTimeout
, P2P.daDeadlineChurnInterval = 3300
, P2P.daBulkChurnInterval = 900
, P2P.daDeadlineChurnInterval = Configuration.defaultDeadlineChurnInterval
, P2P.daBulkChurnInterval = Configuration.defaultBulkChurnInterval
, P2P.daOwnPeerSharing = ncPeerSharing
, P2P.daConsensusMode = ncConsensusMode
, P2P.daMinBigLedgerPeersForTrustedState = ncSyncMinTrusted
}
where
daPeerTargets = Configuration.ConsensusModePeerTargets {
Configuration.deadlineTargets = peerSelectionTargets,
Configuration.syncTargets = peerSelectionTargets
}
peerSelectionTargets = PeerSelectionTargets {
targetNumberOfRootPeers = ncTargetNumberOfRootPeers,
targetNumberOfKnownPeers = ncTargetNumberOfKnownPeers,
targetNumberOfEstablishedPeers = ncTargetNumberOfEstablishedPeers,
targetNumberOfActivePeers = ncTargetNumberOfActivePeers,
targetNumberOfKnownBigLedgerPeers = ncTargetNumberOfKnownBigLedgerPeers,
targetNumberOfEstablishedBigLedgerPeers = ncTargetNumberOfEstablishedBigLedgerPeers,
targetNumberOfActiveBigLedgerPeers = ncTargetNumberOfActiveBigLedgerPeers
deadlineTargets = Configuration.defaultDeadlineTargets {
targetNumberOfRootPeers = ncDeadlineTargetOfRootPeers,
targetNumberOfKnownPeers = ncDeadlineTargetOfKnownPeers,
targetNumberOfEstablishedPeers = ncDeadlineTargetOfEstablishedPeers,
targetNumberOfActivePeers = ncDeadlineTargetOfActivePeers,
targetNumberOfKnownBigLedgerPeers = ncDeadlineTargetOfKnownBigLedgerPeers,
targetNumberOfEstablishedBigLedgerPeers = ncDeadlineTargetOfEstablishedBigLedgerPeers,
targetNumberOfActiveBigLedgerPeers = ncDeadlineTargetOfActiveBigLedgerPeers
}
syncTargets = Configuration.defaultSyncTargets {
targetNumberOfActivePeers = ncSyncTargetOfActivePeers,
targetNumberOfKnownBigLedgerPeers = ncSyncTargetOfKnownBigLedgerPeers,
targetNumberOfEstablishedBigLedgerPeers = ncSyncTargetOfEstablishedBigLedgerPeers,
targetNumberOfActiveBigLedgerPeers = ncSyncTargetOfActiveBigLedgerPeers }

mkNonP2PArguments
:: IPSubscriptionTarget
Expand Down
28 changes: 17 additions & 11 deletions cardano-node/test/Test/Cardano/Node/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import qualified Ouroboros.Consensus.Node as Consensus (NetworkP2PMode (..))
import Ouroboros.Consensus.Storage.LedgerDB.DiskPolicy (NumOfDiskSnapshots (..),
SnapshotInterval (..), pattern DoDiskSnapshotChecksum)
import Ouroboros.Network.Block (SlotNo (..))
import Ouroboros.Network.Diffusion.Configuration (MinBigLedgerPeersForTrustedState (..), defaultConsensusMode)
import Ouroboros.Network.NodeToNode (AcceptedConnectionsLimit (..),
DiffusionMode (InitiatorAndResponderDiffusionMode))
import Ouroboros.Network.PeerSelection.PeerSharing (PeerSharing (..))
import Ouroboros.Network.Diffusion.Configuration

import Data.Monoid (Last (..))
import Data.Text (Text)
Expand Down Expand Up @@ -118,7 +115,6 @@ testPartialYamlConfig =
, pncSocketConfig = Last . Just $ SocketConfig (Last Nothing) mempty mempty mempty
, pncShutdownConfig = Last Nothing
, pncStartAsNonProducingNode = Last $ Just False
, pncConsensusMode = mempty
, pncDiffusionMode = Last Nothing
, pncNumOfDiskSnapshots = Last Nothing
, pncSnapshotInterval = mempty
Expand Down Expand Up @@ -147,9 +143,13 @@ testPartialYamlConfig =
, pncTargetNumberOfKnownBigLedgerPeers = mempty
, pncTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncTargetNumberOfActiveBigLedgerPeers = mempty
, pncMinBigLedgerPeersForTrustedState = pure (MinBigLedgerPeersForTrustedState 3) -- TODO: Review
, pncGenesisTargetNumberOfActivePeers = mempty
, pncGenesisTargetNumberOfKnownBigLedgerPeers = mempty
, pncGenesisTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncGenesisTargetNumberOfActiveBigLedgerPeers = mempty
, pncEnableP2P = Last (Just DisabledP2PMode)
, pncPeerSharing = Last (Just PeerSharingDisabled)
, pncConsensusMode = Last (Just PraosMode)
}

-- | Example partial configuration theoretically created
Expand All @@ -163,7 +163,6 @@ testPartialCliConfig =
, pncConfigFile = mempty
, pncTopologyFile = mempty
, pncDatabaseFile = mempty
, pncConsensusMode = mempty
, pncDiffusionMode = mempty
, pncNumOfDiskSnapshots = Last Nothing
, pncSnapshotInterval = Last . Just . RequestedSnapshotInterval $ secondsToDiffTime 100
Expand All @@ -190,9 +189,13 @@ testPartialCliConfig =
, pncTargetNumberOfKnownBigLedgerPeers = mempty
, pncTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncTargetNumberOfActiveBigLedgerPeers = mempty
, pncMinBigLedgerPeersForTrustedState = pure (MinBigLedgerPeersForTrustedState 3) -- TODO: Review
, pncGenesisTargetNumberOfActivePeers = mempty
, pncGenesisTargetNumberOfKnownBigLedgerPeers = mempty
, pncGenesisTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncGenesisTargetNumberOfActiveBigLedgerPeers = mempty
, pncEnableP2P = Last (Just DisabledP2PMode)
, pncPeerSharing = Last (Just PeerSharingDisabled)
, pncConsensusMode = Last (Just GenesisMode)
}

-- | Expected final NodeConfiguration
Expand All @@ -210,7 +213,6 @@ eExpectedConfig = do
, ncProtocolFiles = ProtocolFilepaths Nothing Nothing Nothing Nothing Nothing Nothing
, ncValidateDB = True
, ncProtocolConfig = testNodeProtocolConfiguration
, ncConsensusMode = defaultConsensusMode
, ncDiffusionMode = InitiatorAndResponderDiffusionMode
, ncNumOfDiskSnapshots = DefaultNumOfDiskSnapshots
, ncSnapshotInterval = RequestedSnapshotInterval $ secondsToDiffTime 100
Expand All @@ -232,16 +234,20 @@ eExpectedConfig = do
, acceptedConnectionsSoftLimit = 384
, acceptedConnectionsDelay = 5
}
, ncTargetNumberOfRootPeers = 85
, ncTargetNumberOfRootPeers = 60
, ncTargetNumberOfKnownPeers = 85
, ncTargetNumberOfEstablishedPeers = 40
, ncTargetNumberOfActivePeers = 15
, ncTargetNumberOfKnownBigLedgerPeers = 15
, ncTargetNumberOfEstablishedBigLedgerPeers = 10
, ncTargetNumberOfActiveBigLedgerPeers = 5
, ncMinBigLedgerPeersForTrustedState = MinBigLedgerPeersForTrustedState 3 -- TODO: Review
, ncGenesisTargetNumberOfActivePeers = 0
, ncGenesisTargetNumberOfKnownBigLedgerPeers = 100
, ncGenesisTargetNumberOfEstablishedBigLedgerPeers = 50
, ncGenesisTargetNumberOfActiveBigLedgerPeers = 30
, ncEnableP2P = SomeNetworkP2PMode Consensus.DisabledP2PMode
, ncPeerSharing = PeerSharingDisabled
, ncConsensusMode = GenesisMode
}

-- -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions configuration/cardano/mainnet-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"RequiresNetworkMagic": "RequiresNoMagic",
"ShelleyGenesisFile": "mainnet-shelley-genesis.json",
"ShelleyGenesisHash": "1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81",
"ConsensusMode": "PraosMode"
"TargetNumberOfActivePeers": 20,
"TargetNumberOfEstablishedPeers": 50,
"TargetNumberOfKnownPeers": 150,
Expand Down
1 change: 1 addition & 0 deletions configuration/cardano/mainnet-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ MaxKnownMajorProtocolVersion: 2

##### Network Configuration #####

ConsensusMode: PraosMode
PeerSharing: True
TargetNumberOfActivePeers: 20
TargetNumberOfEstablishedPeers: 50
Expand Down
1 change: 1 addition & 0 deletions configuration/cardano/shelley_qa-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"RequiresNetworkMagic": "RequiresMagic",
"ShelleyGenesisFile": "shelley_qa-shelley-genesis.json",
"ShelleyGenesisHash": "73a9f6bdb0aa97f5e63190a6f14a702bd64a21f2bec831cbfc28f6037128b952",
"ConsensusMode": "PraosMode"
"TargetNumberOfActivePeers": 20,
"TargetNumberOfEstablishedPeers": 50,
"TargetNumberOfKnownPeers": 150,
Expand Down

0 comments on commit 6a5331f

Please sign in to comment.