Skip to content

Commit

Permalink
Integrate o-network and o-consensus
Browse files Browse the repository at this point in the history
Missing updating Node Configuration parser to read genesis targets and
ledger snapshot.
  • Loading branch information
crocodile-dentist committed Nov 13, 2024
1 parent f5a4215 commit 982cd1d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 51 deletions.
1 change: 1 addition & 0 deletions bench/tx-generator/src/Cardano/Benchmarking/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import GHC.Weak as Weak (deRefWeak)
import System.Posix.Signals as Sig (Handler (CatchInfo),
SignalInfo (..), SignalSpecificInfo (..), installHandler,
sigINT, sigTERM)
import Foreign.C (Errno(..))
#if MIN_VERSION_base(4,18,0)
import Data.Maybe as Maybe (fromMaybe)
import GHC.Conc.Sync as Conc (threadLabel)
Expand Down
1 change: 1 addition & 0 deletions bench/tx-generator/tx-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ library
, transformers-except
, unordered-containers
, yaml
, microlens

default-language: Haskell2010
default-extensions: OverloadedStrings
Expand Down
30 changes: 19 additions & 11 deletions cardano-node/src/Cardano/Node/Configuration/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ data NodeConfiguration
-- by the diffusion layer when syncing
, ncConsensusMode :: !ConsensusMode

-- Minimum number of active big ledger peers we must be connected to
-- in Genesis mode
, ncMinBigLedgerPeersForTrustedState :: MinBigLedgerPeersForTrustedState

-- Enable experimental P2P mode
, ncEnableP2P :: SomeNetworkP2PMode

Expand Down Expand Up @@ -232,7 +236,9 @@ data PartialNodeConfiguration
, pncSyncTargetOfKnownBigLedgerPeers :: !(Last Int)
, pncSyncTargetOfEstablishedBigLedgerPeers :: !(Last Int)
, pncSyncTargetOfActiveBigLedgerPeers :: !(Last Int)
, pncSyncMinTrusted :: !(Last MinBigLedgerPeersForTrustedState)
-- Minimum number of active big ledger peers we must be connected to
-- in Genesis mode
, pncMinBigLedgerPeersForTrustedState :: !(Last MinBigLedgerPeersForTrustedState)

-- Consensus mode for diffusion layer
, pncConsensusMode :: !(Last ConsensusMode)
Expand Down Expand Up @@ -328,7 +334,9 @@ instance FromJSON PartialNodeConfiguration where
pncSyncTargetOfKnownBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfKnownBigLedgerPeers"
pncSyncTargetOfEstablishedBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfEstablishedBigLedgerPeers"
pncSyncTargetOfActiveBigLedgerPeers <- Last <$> v .:? "SyncTargetNumberOfActiveBigLedgerPeers"
pncSyncMinTrusted <- Last <$> v .:? "SyncMinNumberOfBigLedgerPeersForTrustedState"
-- Minimum number of active big ledger peers we must be connected to
-- in Genesis mode
pncMinBigLedgerPeersForTrustedState <- Last <$> v .:? "MinBigLedgerPeersForTrustedState"

pncConsensusMode <- Last <$> v .:? "ConsensusMode"

Expand All @@ -344,7 +352,7 @@ instance FromJSON PartialNodeConfiguration where

-- Peer Sharing
-- DISABLED BY DEFAULT
pncPeerSharing <- Last <$> v .:? "PeerSharing" .!= Just Configuration.PeerSharingDisabled
pncPeerSharing <- Last <$> v .:? "PeerSharing"

pure PartialNodeConfiguration {
pncProtocolConfig
Expand Down Expand Up @@ -382,7 +390,7 @@ instance FromJSON PartialNodeConfiguration where
, pncSyncTargetOfKnownBigLedgerPeers
, pncSyncTargetOfEstablishedBigLedgerPeers
, pncSyncTargetOfActiveBigLedgerPeers
, pncSyncMinTrusted
, pncMinBigLedgerPeersForTrustedState
, pncConsensusMode
, pncEnableP2P
, pncPeerSharing
Expand Down Expand Up @@ -564,10 +572,10 @@ defaultPartialNodeConfiguration =
, pncSyncTargetOfKnownBigLedgerPeers = Last (Just syncBigKnown)
, pncSyncTargetOfEstablishedBigLedgerPeers = Last (Just syncBigEst)
, pncSyncTargetOfActiveBigLedgerPeers = Last (Just syncBigAct)
, pncSyncMinTrusted = Last (Just defaultMinBigLedgerPeersForTrustedState)
, pncConsensusMode = mempty
, pncMinBigLedgerPeersForTrustedState = Last (Just defaultMinBigLedgerPeersForTrustedState)
, pncConsensusMode = Last (Just defaultConsensusMode)
, pncEnableP2P = Last (Just EnabledP2PMode)
, pncPeerSharing = Last (Just Configuration.PeerSharingDisabled)
, pncPeerSharing = Last (Just defaultPeerSharing)
}
where
Configuration.PeerSelectionTargets {
Expand Down Expand Up @@ -637,9 +645,9 @@ makeNodeConfiguration pnc = do
ncSyncTargetOfActiveBigLedgerPeers <-
lastToEither "Missing SyncTargetNumberOfActiveBigLedgerPeers"
$ pncSyncTargetOfActiveBigLedgerPeers pnc
ncSyncMinTrusted <-
lastToEither "Missing SyncMinNumberOfBigLedgerPeersForTrustedState"
$ pncSyncMinTrusted pnc
ncMinBigLedgerPeersForTrustedState <-
lastToEither "Missing MinBigLedgerPeersForTrustedState"
$ pncMinBigLedgerPeersForTrustedState pnc
ncConsensusMode <-
lastToEither "Missing ConsensusMode"
$ pncConsensusMode pnc
Expand Down Expand Up @@ -712,7 +720,7 @@ makeNodeConfiguration pnc = do
, ncSyncTargetOfKnownBigLedgerPeers
, ncSyncTargetOfEstablishedBigLedgerPeers
, ncSyncTargetOfActiveBigLedgerPeers
, ncSyncMinTrusted
, ncMinBigLedgerPeersForTrustedState
, ncEnableP2P = case enableP2P of
EnabledP2PMode -> SomeNetworkP2PMode Consensus.EnabledP2PMode
DisabledP2PMode -> SomeNetworkP2PMode Consensus.DisabledP2PMode
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ nodeRunParser = do
, pncSyncTargetOfKnownBigLedgerPeers = mempty
, pncSyncTargetOfEstablishedBigLedgerPeers = mempty
, pncSyncTargetOfActiveBigLedgerPeers = mempty
, pncSyncMinTrusted = mempty
, pncMinBigLedgerPeersForTrustedState = mempty
, pncConsensusMode = mempty
, pncEnableP2P = mempty
, pncPeerSharing = mempty
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ mkP2PArguments NodeConfiguration {
ncSyncTargetOfKnownBigLedgerPeers,
ncSyncTargetOfEstablishedBigLedgerPeers,
ncSyncTargetOfActiveBigLedgerPeers,
ncSyncMinTrusted,
ncMinBigLedgerPeersForTrustedState,
ncProtocolIdleTimeout,
ncTimeWaitTimeout,
ncPeerSharing,
Expand All @@ -926,7 +926,7 @@ mkP2PArguments NodeConfiguration {
, P2P.daBulkChurnInterval = Configuration.defaultBulkChurnInterval
, P2P.daOwnPeerSharing = ncPeerSharing
, P2P.daConsensusMode = ncConsensusMode
, P2P.daMinBigLedgerPeersForTrustedState = ncSyncMinTrusted
, P2P.daMinBigLedgerPeersForTrustedState = ncMinBigLedgerPeersForTrustedState
}
where
deadlineTargets = Configuration.defaultDeadlineTargets {
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Node/Tracing/Tracers/P2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ instance MetaTrace (TracePeerSelection SockAddr) where
documentFor (Namespace [] ["DebugState"]) = Just
"peer selection internal state"
documentFor (Namespace [] ["VerifyPeerSnapshot"]) = Just
"Big ledger peer snapshot file failed integrity check against the ledger"
"Verification outcome of big ledger peer snapshot"
documentFor _ = Nothing

metricsDocFor (Namespace [] ["ChurnAction"]) =
Expand Down
2 changes: 2 additions & 0 deletions cardano-node/src/Cardano/Tracing/OrphanInstances/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,7 @@ instance ToJSON NodeToClientVersion where
toJSON NodeToClientV_16 = Number 16
toJSON NodeToClientV_17 = Number 17
toJSON NodeToClientV_18 = Number 18
toJSON NodeToClientV_19 = Number 19
-- NB: When adding a new version here, update FromJSON below as well!

instance FromJSON NodeToClientVersion where
Expand All @@ -2214,6 +2215,7 @@ instance FromJSON NodeToClientVersion where
parseJSON (Number 16) = return NodeToClientV_16
parseJSON (Number 17) = return NodeToClientV_17
parseJSON (Number 18) = return NodeToClientV_18
parseJSON (Number 19) = return NodeToClientV_19
parseJSON (Number x) = fail ("FromJSON.NodeToClientVersion: unsupported node-to-client protocol version " ++ show x)
parseJSON x = fail ("FromJSON.NodeToClientVersion: error parsing NodeToClientVersion: " ++ show x)

Expand Down
75 changes: 39 additions & 36 deletions cardano-node/test/Test/Cardano/Node/POM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,21 @@ testPartialYamlConfig =
, pncTimeWaitTimeout = mempty
, pncChainSyncIdleTimeout = mempty
, pncAcceptedConnectionsLimit = mempty
, pncTargetNumberOfRootPeers = mempty
, pncTargetNumberOfKnownPeers = mempty
, pncTargetNumberOfEstablishedPeers = mempty
, pncTargetNumberOfActivePeers = mempty
, pncTargetNumberOfKnownBigLedgerPeers = mempty
, pncTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncTargetNumberOfActiveBigLedgerPeers = mempty
, pncGenesisTargetNumberOfActivePeers = mempty
, pncGenesisTargetNumberOfKnownBigLedgerPeers = mempty
, pncGenesisTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncGenesisTargetNumberOfActiveBigLedgerPeers = mempty
, pncDeadlineTargetOfRootPeers = mempty
, pncDeadlineTargetOfKnownPeers = mempty
, pncDeadlineTargetOfEstablishedPeers = mempty
, pncDeadlineTargetOfActivePeers = mempty
, pncDeadlineTargetOfKnownBigLedgerPeers = mempty
, pncDeadlineTargetOfEstablishedBigLedgerPeers = mempty
, pncDeadlineTargetOfActiveBigLedgerPeers = mempty
, pncSyncTargetNumberOfActivePeers = mempty
, pncSyncTargetNumberOfKnownBigLedgerPeers = mempty
, pncSyncTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncSyncTargetNumberOfActiveBigLedgerPeers = mempty
, pncMinBigLedgerPeersForTrustedState = mempty
, pncEnableP2P = Last (Just DisabledP2PMode)
, pncPeerSharing = Last (Just PeerSharingDisabled)
, pncConsensusMode = Last (Just PraosMode)
, pncConsensusMode = mempty
}

-- | Example partial configuration theoretically created
Expand Down Expand Up @@ -179,20 +180,21 @@ testPartialCliConfig =
, pncTimeWaitTimeout = mempty
, pncChainSyncIdleTimeout = mempty
, pncAcceptedConnectionsLimit = mempty
, pncTargetNumberOfRootPeers = mempty
, pncTargetNumberOfKnownPeers = mempty
, pncTargetNumberOfEstablishedPeers = mempty
, pncTargetNumberOfActivePeers = mempty
, pncTargetNumberOfKnownBigLedgerPeers = mempty
, pncTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncTargetNumberOfActiveBigLedgerPeers = mempty
, pncGenesisTargetNumberOfActivePeers = mempty
, pncGenesisTargetNumberOfKnownBigLedgerPeers = mempty
, pncGenesisTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncGenesisTargetNumberOfActiveBigLedgerPeers = mempty
, pncDeadlineTargetNumberOfRootPeers = mempty
, pncDeadlineTargetNumberOfKnownPeers = mempty
, pncDeadlineTargetNumberOfEstablishedPeers = mempty
, pncDeadlineTargetNumberOfActivePeers = mempty
, pncDeadlineTargetNumberOfKnownBigLedgerPeers = mempty
, pncDeadlineTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncDeadlineTargetNumberOfActiveBigLedgerPeers = mempty
, pncSyncTargetNumberOfActivePeers = mempty
, pncSyncTargetNumberOfKnownBigLedgerPeers = mempty
, pncSyncTargetNumberOfEstablishedBigLedgerPeers = mempty
, pncSyncTargetNumberOfActiveBigLedgerPeers = mempty
, pncMinBigLedgerPeersForTrustedState = Last (Just defaultMinBigLedgerPeersForTrustedState)
, pncEnableP2P = Last (Just DisabledP2PMode)
, pncPeerSharing = Last (Just PeerSharingDisabled)
, pncConsensusMode = Last (Just GenesisMode)
, pncConsensusMode = Last (Just PraosMode)
}

-- | Expected final NodeConfiguration
Expand Down Expand Up @@ -230,20 +232,21 @@ eExpectedConfig = do
, acceptedConnectionsSoftLimit = 384
, acceptedConnectionsDelay = 5
}
, ncTargetNumberOfRootPeers = 60
, ncTargetNumberOfKnownPeers = 85
, ncTargetNumberOfEstablishedPeers = 40
, ncTargetNumberOfActivePeers = 15
, ncTargetNumberOfKnownBigLedgerPeers = 15
, ncTargetNumberOfEstablishedBigLedgerPeers = 10
, ncTargetNumberOfActiveBigLedgerPeers = 5
, ncGenesisTargetNumberOfActivePeers = 0
, ncGenesisTargetNumberOfKnownBigLedgerPeers = 100
, ncGenesisTargetNumberOfEstablishedBigLedgerPeers = 50
, ncGenesisTargetNumberOfActiveBigLedgerPeers = 30
, ncDeadlineTargetNumberOfRootPeers = 60
, ncDeadlineTargetNumberOfKnownPeers = 85
, ncDeadlineTargetNumberOfEstablishedPeers = 40
, ncDeadlineTargetNumberOfActivePeers = 15
, ncDeadlineTargetNumberOfKnownBigLedgerPeers = 15
, ncDeadlineTargetNumberOfEstablishedBigLedgerPeers = 10
, ncDeadlineTargetNumberOfActiveBigLedgerPeers = 5
, ncSyncTargetNumberOfActivePeers = 0
, ncSyncTargetNumberOfKnownBigLedgerPeers = 100
, ncSyncTargetNumberOfEstablishedBigLedgerPeers = 50
, ncSyncTargetNumberOfActiveBigLedgerPeers = 30
, ncMinBigLedgerPeersForTrustedState = defaultMinBigLedgerPeersForTrustedState
, ncEnableP2P = SomeNetworkP2PMode Consensus.DisabledP2PMode
, ncPeerSharing = PeerSharingDisabled
, ncConsensusMode = GenesisMode
, ncConsensusMode = PraosMode
}

-- -----------------------------------------------------------------------------
Expand Down

0 comments on commit 982cd1d

Please sign in to comment.