Skip to content

Commit

Permalink
Merge branch 'main' of github.com:input-output-hk/ouroboros-leios
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuhn committed Jan 23, 2025
2 parents f696d80 + 2e92409 commit 7628d3c
Show file tree
Hide file tree
Showing 25 changed files with 567 additions and 297 deletions.
8 changes: 5 additions & 3 deletions data/simulation/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export interface Config {
"vote-generation-cpu-time-ms-per-ib": number;
"vote-validation-cpu-time-ms": number;
"vote-threshold": bigint;
"vote-one-eb-per-vrf-win": boolean;
"vote-size-bytes-constant": bigint;
"vote-size-bytes-per-node": bigint;
"vote-bundle-size-bytes-constant": bigint;
"vote-bundle-size-bytes-per-eb": bigint;

// deprecated:
// "vote-one-eb-per-vrf-win": boolean;

// Certificate Configuration
"cert-generation-cpu-time-ms-constant": number;
Expand Down
5 changes: 2 additions & 3 deletions data/simulation/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ vote-generation-cpu-time-ms-constant: 1.0
vote-generation-cpu-time-ms-per-ib: 1.0
vote-validation-cpu-time-ms: 3.0
vote-threshold: 150
vote-one-eb-per-vrf-win: false
vote-size-bytes-constant: 32
vote-size-bytes-per-eb: 32
vote-bundle-size-bytes-constant: 32
vote-bundle-size-bytes-per-eb: 32

################################################################################
# Certificate Configuration
Expand Down
21 changes: 9 additions & 12 deletions data/simulation/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,23 @@
"tx-validation-cpu-time-ms": {
"type": "number"
},
"vote-generation-cpu-time-ms-constant": {
"vote-bundle-size-bytes-constant": {
"additionalProperties": false,
"properties": {},
"type": "number"
},
"vote-generation-cpu-time-ms-per-ib": {
"vote-bundle-size-bytes-per-eb": {
"additionalProperties": false,
"properties": {},
"type": "number"
},
"vote-generation-probability": {
"vote-generation-cpu-time-ms-constant": {
"type": "number"
},
"vote-one-eb-per-vrf-win": {
"type": "boolean"
},
"vote-size-bytes-constant": {
"additionalProperties": false,
"properties": {},
"vote-generation-cpu-time-ms-per-ib": {
"type": "number"
},
"vote-size-bytes-per-node": {
"additionalProperties": false,
"properties": {},
"vote-generation-probability": {
"type": "number"
},
"vote-threshold": {
Expand Down
47 changes: 47 additions & 0 deletions data/simulation/former-ols-sim-default-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cert-generation-cpu-time-ms-constant: 50.0
cert-generation-cpu-time-ms-per-node: 1
cert-size-bytes-constant: 32
cert-size-bytes-per-node: 32
cert-validation-cpu-time-ms-constant: 50.0
cert-validation-cpu-time-ms-per-node: 1
eb-generation-cpu-time-ms: 300.0
eb-generation-probability: 1.5
eb-size-bytes-constant: 32
eb-size-bytes-per-ib: 32
eb-validation-cpu-time-ms: 1
ib-body-avg-size-bytes: 327680
ib-body-max-size-bytes: 327680
ib-body-validation-cpu-time-ms-constant: 50.0
ib-body-validation-cpu-time-ms-per-byte: 5.0e-4
ib-generation-cpu-time-ms: 300.0
ib-generation-probability: 5
ib-head-size-bytes: 32
ib-head-validation-cpu-time-ms: 1
leios-stage-active-voting-slots: 1
leios-stage-length-slots: 20
rb-body-legacy-praos-payload-avg-size-bytes: 0
rb-body-legacy-praos-payload-validation-cpu-time-ms-constant: 50.0
rb-body-legacy-praos-payload-validation-cpu-time-ms-per-byte: 5.0e-4
rb-body-max-size-bytes: 90112
rb-generation-cpu-time-ms: 300.0
rb-generation-probability: 5.0e-2
rb-head-size-bytes: 32
rb-head-validation-cpu-time-ms: 1
tx-generation-distribution:
distribution: exp
lambda: 0.85
scale: 1000.0
tx-max-size-bytes: 16384
tx-size-bytes-distribution:
distribution: log-normal
mu: 6.833
sigma: 1.127
tx-validation-cpu-time-ms: 1.5
vote-generation-cpu-time-ms-constant: 1
vote-generation-cpu-time-ms-per-ib: 1
vote-generation-probability: 500.0
vote-one-eb-per-vrf-win: false
vote-bundle-size-bytes-constant: 32
vote-bundle-size-bytes-per-eb: 32
vote-threshold: 150
vote-validation-cpu-time-ms: 3
47 changes: 47 additions & 0 deletions data/simulation/former-ols-viz-default-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cert-generation-cpu-time-ms-constant: 50.0
cert-generation-cpu-time-ms-per-node: 1
cert-size-bytes-constant: 32
cert-size-bytes-per-node: 32
cert-validation-cpu-time-ms-constant: 50.0
cert-validation-cpu-time-ms-per-node: 1
eb-generation-cpu-time-ms: 300.0
eb-generation-probability: 1.5
eb-size-bytes-constant: 32
eb-size-bytes-per-ib: 32
eb-validation-cpu-time-ms: 1
ib-body-avg-size-bytes: 327680
ib-body-max-size-bytes: 327680
ib-body-validation-cpu-time-ms-constant: 50.0
ib-body-validation-cpu-time-ms-per-byte: 5.0e-4
ib-generation-cpu-time-ms: 300.0
ib-generation-probability: 5
ib-head-size-bytes: 32
ib-head-validation-cpu-time-ms: 1
leios-stage-active-voting-slots: 1
leios-stage-length-slots: 5
rb-body-legacy-praos-payload-avg-size-bytes: 0
rb-body-legacy-praos-payload-validation-cpu-time-ms-constant: 50.0
rb-body-legacy-praos-payload-validation-cpu-time-ms-per-byte: 5.0e-4
rb-body-max-size-bytes: 90112
rb-generation-cpu-time-ms: 300.0
rb-generation-probability: 0.2
rb-head-size-bytes: 32
rb-head-validation-cpu-time-ms: 1
tx-generation-distribution:
distribution: exp
lambda: 0.85
scale: 1000.0
tx-max-size-bytes: 16384
tx-size-bytes-distribution:
distribution: log-normal
mu: 6.833
sigma: 1.127
tx-validation-cpu-time-ms: 1.5
vote-generation-cpu-time-ms-constant: 1
vote-generation-cpu-time-ms-per-ib: 1
vote-generation-probability: 500.0
vote-one-eb-per-vrf-win: false
vote-bundle-size-bytes-constant: 32
vote-bundle-size-bytes-per-eb: 32
vote-threshold: 150
vote-validation-cpu-time-ms: 3
1 change: 1 addition & 0 deletions simulation/ouroboros-leios-sim.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ executable ols
build-depends:
, aeson
, base
, containers
, data-default
, optparse-applicative
, ouroboros-leios-sim
Expand Down
6 changes: 4 additions & 2 deletions simulation/src/ChanDriver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeAbstractions #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
Expand All @@ -31,6 +30,9 @@ data ProtocolMessage ps where
SomeMessage st ->
ProtocolMessage ps

protocolMessage :: (forall st st'. Message ps st st' -> a) -> ProtocolMessage ps -> a
protocolMessage f (ProtocolMessage (SomeMessage msg)) = f msg

instance forall ps. (forall st st'. Show (Message ps st st')) => Show (ProtocolMessage ps) where
show (ProtocolMessage (SomeMessage msg)) = show msg

Expand Down Expand Up @@ -70,6 +72,6 @@ chanDriver cmp ch =
recvMessage _prf () = do
ProtocolMessage smsg <- readChan ch
case smsg of
SomeMessage @_ @st' msg -> case cmp @st @st' of
SomeMessage (msg :: Message ps st' st1) -> case cmp @st @st' of
Just Refl -> pure (SomeMessage msg, ())
Nothing -> error "recvMessage: read message state does not match expected state"
11 changes: 7 additions & 4 deletions simulation/src/ExamplesRelayP2P.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module ExamplesRelayP2P where

import Data.Functor.Contravariant (Contravariant (contramap))
import Data.Maybe (fromMaybe)
import Data.Word (Word8)
import P2P (P2PTopographyCharacteristics (..), genArbitraryP2PTopography)
import RelayProtocol
Expand All @@ -12,6 +13,7 @@ import SimTCPLinks (kilobytes, mkTcpConnProps)
import SimTypes
import System.Random (mkStdGen, uniform)
import TimeCompat (secondsToDiffTime)
import Topology (topologyToNetwork)
import Viz
import VizSimRelay (relaySimVizModel)
import VizSimRelayP2P
Expand Down Expand Up @@ -54,8 +56,8 @@ example1 =
trace =
traceRelayP2P
rng0
p2pTopography
(\latency -> mkTcpConnProps latency (kilobytes 1000))
p2pNetwork
(\latency -> mkTcpConnProps latency . fromMaybe undefined)
( \rng ->
RelayNodeConfig
{ blockProcessingDelay = const (secondsToDiffTime 0.1) -- 100ms
Expand All @@ -69,6 +71,7 @@ example1 =
}
)

p2pNetwork = topologyToNetwork (Just (kilobytes 1000)) p2pTopography
p2pTopography =
genArbitraryP2PTopography p2pTopographyCharacteristics rng0

Expand Down Expand Up @@ -146,8 +149,8 @@ example2 =
trace =
traceRelayP2P
rng0
p2pTopography
(\latency -> mkTcpConnProps latency (kilobytes 1000))
(topologyToNetwork (Just (kilobytes 1000)) p2pTopography)
(\latency -> mkTcpConnProps latency . fromMaybe undefined)
( \rng ->
RelayNodeConfig
{ blockProcessingDelay = const (secondsToDiffTime 0.1) -- 100ms
Expand Down
33 changes: 29 additions & 4 deletions simulation/src/LeiosProtocol/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE NoFieldSelectors #-}

module LeiosProtocol.Common (
Expand All @@ -28,19 +30,24 @@ module LeiosProtocol.Common (
NodeId,
SubSlotNo (..),
Word64,
NetworkRate (..),
NodeRate (..),
StakeFraction (..),
NumCores (..),
mkStringId,
)
where

import ChanTCP
import Control.Exception (assert)
import Control.Monad (guard)
import Data.Coerce
import Data.Hashable
import Data.Map (Map)
import Data.Word (Word64, Word8)
import GHC.Generics
import GHC.Records
import PraosProtocol.Common hiding (Block, BlockHeader)
import qualified PraosProtocol.Common as Praos (Block, BlockHeader)
import PraosProtocol.Common
import SimTypes

{-
Expand All @@ -62,7 +69,7 @@ import SimTypes
-}

type RankingBlockHeader = Praos.BlockHeader
type RankingBlockHeader = BlockHeader
data RankingBlockBody = RankingBlockBody
{ endorseBlocks :: ![(EndorseBlockId, Certificate)]
-- ^ at most one in short leios.
Expand All @@ -79,7 +86,7 @@ data RankingBlockBody = RankingBlockBody
rankingBlockBodyInvariant :: RankingBlockBody -> Bool
rankingBlockBodyInvariant rbb = rbb.payload <= rbb.size

type RankingBlock = Praos.Block RankingBlockBody
type RankingBlock = Block RankingBlockBody

type RankingBlockId = HeaderHash RankingBlock

Expand Down Expand Up @@ -220,3 +227,21 @@ instance MessageSize VoteId where

instance MessageSize VoteMsg where
messageSizeBytes b = b.size

mkStringId :: (HasField "node" a NodeId, HasField "num" a Int) => a -> String
mkStringId x = concat [show (coerce @_ @Int x.node), "-", show x.num]

instance HasField "stringId" InputBlockHeader String where
getField = mkStringId . (.id)

instance HasField "stringId" InputBlock String where
getField = mkStringId . (.id)

instance HasField "stringId" InputBlockBody String where
getField = mkStringId . (.id)

instance HasField "stringId" VoteMsg String where
getField = mkStringId . (.id)

instance HasField "stringId" EndorseBlock String where
getField = mkStringId . (.id)
38 changes: 30 additions & 8 deletions simulation/src/LeiosProtocol/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ import Data.Aeson.Types (Encoding, FromJSON (..), KeyValue ((.=)), Parser, ToJSO
import Data.Default (Default (..))
import Data.Maybe (catMaybes)
import Data.Text (Text)
import Data.Yaml (ParseException)
import qualified Data.Yaml as Yaml
import GHC.Exception (displayException)
import GHC.Generics (Generic)
import JSONCompat (Getter, always, get, omitDefault, parseFieldOrDefault)
import System.Exit (exitFailure)
import System.IO (hPutStrLn, stderr)

newtype SizeBytes = SizeBytes {unSizeBytes :: Word}
deriving newtype (Show, Eq, Ord, FromJSON, ToJSON, Num, Real, Enum, Integral)
Expand Down Expand Up @@ -69,8 +74,8 @@ data Config = Config
, voteValidationCpuTimeMs :: DurationMs
, voteThreshold :: Word
, voteOneEbPerVrfWin :: Bool
, voteSizeBytesConstant :: SizeBytes
, voteSizeBytesPerNode :: SizeBytes
, voteBundleSizeBytesConstant :: SizeBytes
, voteBundleSizeBytesPerEb :: SizeBytes
, certGenerationCpuTimeMsConstant :: DurationMs
, certGenerationCpuTimeMsPerNode :: DurationMs
, certValidationCpuTimeMsConstant :: DurationMs
Expand Down Expand Up @@ -117,8 +122,8 @@ instance Default Config where
, voteValidationCpuTimeMs = 3.0
, voteThreshold = 150
, voteOneEbPerVrfWin = False
, voteSizeBytesConstant = 32
, voteSizeBytesPerNode = 32
, voteBundleSizeBytesConstant = 32
, voteBundleSizeBytesPerEb = 32
, certGenerationCpuTimeMsConstant = 50.0
, certGenerationCpuTimeMsPerNode = 1.0
, certValidationCpuTimeMsConstant = 50.0
Expand Down Expand Up @@ -169,8 +174,8 @@ configToKVsWith getter cfg =
, get @"voteValidationCpuTimeMs" getter cfg
, get @"voteThreshold" getter cfg
, get @"voteOneEbPerVrfWin" getter cfg
, get @"voteSizeBytesConstant" getter cfg
, get @"voteSizeBytesPerNode" getter cfg
, get @"voteBundleSizeBytesConstant" getter cfg
, get @"voteBundleSizeBytesPerEb" getter cfg
, get @"certGenerationCpuTimeMsConstant" getter cfg
, get @"certGenerationCpuTimeMsPerNode" getter cfg
, get @"certValidationCpuTimeMsConstant" getter cfg
Expand Down Expand Up @@ -231,8 +236,8 @@ instance FromJSON Config where
voteValidationCpuTimeMs <- parseFieldOrDefault @Config @"voteValidationCpuTimeMs" obj
voteThreshold <- parseFieldOrDefault @Config @"voteThreshold" obj
voteOneEbPerVrfWin <- parseFieldOrDefault @Config @"voteOneEbPerVrfWin" obj
voteSizeBytesConstant <- parseFieldOrDefault @Config @"voteSizeBytesConstant" obj
voteSizeBytesPerNode <- parseFieldOrDefault @Config @"voteSizeBytesPerNode" obj
voteBundleSizeBytesConstant <- parseFieldOrDefault @Config @"voteBundleSizeBytesConstant" obj
voteBundleSizeBytesPerEb <- parseFieldOrDefault @Config @"voteBundleSizeBytesPerEb" obj
certGenerationCpuTimeMsConstant <- parseFieldOrDefault @Config @"certGenerationCpuTimeMsConstant" obj
certGenerationCpuTimeMsPerNode <- parseFieldOrDefault @Config @"certGenerationCpuTimeMsPerNode" obj
certValidationCpuTimeMsConstant <- parseFieldOrDefault @Config @"certValidationCpuTimeMsConstant" obj
Expand Down Expand Up @@ -284,3 +289,20 @@ instance FromJSON Distribution where
pure LogNormal{..}
| otherwise -> do
typeMismatch "Distribution" (Object o)

-- | Create a 'Config' from a file.
readConfigEither :: FilePath -> IO (Either ParseException Config)
readConfigEither = Yaml.decodeFileEither

readConfig :: FilePath -> IO Config
readConfig file = do
e <- readConfigEither file
case e of
Left parseError -> do
hPutStrLn stderr $ displayException parseError
exitFailure
Right config -> return config

-- | Write a 'Config' to a file.
writeConfig :: FilePath -> Config -> IO ()
writeConfig = Yaml.encodeFile
Loading

0 comments on commit 7628d3c

Please sign in to comment.