Skip to content

Commit c86093c

Browse files
committed
feat(simulation): add new configuration options
1 parent 2ea3480 commit c86093c

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

simulation/src/LeiosProtocol/Config.hs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
module LeiosProtocol.Config where
1717

18-
import Data.Aeson (Options (allNullaryToStringTag), defaultOptions, genericToJSON)
18+
import Data.Aeson (Options (allNullaryToStringTag), defaultOptions, genericToEncoding, genericToJSON)
1919
import Data.Aeson.Encoding (pairs)
2020
import Data.Aeson.Types (Encoding, FromJSON (..), KeyValue ((.=)), Options (constructorTagModifier), Parser, ToJSON (..), Value (..), genericParseJSON, object, typeMismatch, withObject, (.:))
2121
import Data.Default (Default (..))
@@ -52,8 +52,16 @@ data DiffusionStrategy
5252
OldestFirst
5353
deriving (Show, Eq, Generic)
5454

55+
data RelayStrategy
56+
= RequestFromFirst
57+
| RequestFromAll
58+
deriving (Show, Eq, Generic)
59+
5560
data Config = Config
56-
{ leiosStageLengthSlots :: Word
61+
{ relayStrategy :: RelayStrategy
62+
, tcpCongestionControl :: Bool
63+
, multiplexMiniProtocols :: Bool
64+
, leiosStageLengthSlots :: Word
5765
, leiosStageActiveVotingSlots :: Word
5866
, leiosVoteSendRecvStages :: Bool
5967
, txGenerationDistribution :: Distribution
@@ -113,7 +121,10 @@ instance Default Config where
113121
def :: Config
114122
def =
115123
Config
116-
{ leiosStageLengthSlots = 20
124+
{ relayStrategy = RequestFromFirst
125+
, tcpCongestionControl = True
126+
, multiplexMiniProtocols = True
127+
, leiosStageLengthSlots = 20
117128
, leiosStageActiveVotingSlots = 1
118129
, leiosVoteSendRecvStages = False
119130
, txGenerationDistribution = Exp{lambda = 0.85, scale = Just 1000}
@@ -251,6 +262,9 @@ instance ToJSON (OmitDefault Config) where
251262

252263
instance FromJSON Config where
253264
parseJSON = withObject "Config" $ \obj -> do
265+
relayStrategy <- parseFieldOrDefault @Config @"relayStrategy" obj
266+
tcpCongestionControl <- parseFieldOrDefault @Config @"tcpCongestionControl" obj
267+
multiplexMiniProtocols <- parseFieldOrDefault @Config @"multiplexMiniProtocols" obj
254268
leiosStageLengthSlots <- parseFieldOrDefault @Config @"leiosStageLengthSlots" obj
255269
leiosStageActiveVotingSlots <- parseFieldOrDefault @Config @"leiosStageActiveVotingSlots" obj
256270
leiosVoteSendRecvStages <- parseFieldOrDefault @Config @"leiosVoteSendRecvStages" obj
@@ -350,21 +364,26 @@ instance FromJSON Distribution where
350364
| otherwise -> do
351365
typeMismatch "Distribution" (Object o)
352366

367+
defaultEnumOptions :: Options
368+
defaultEnumOptions =
369+
defaultOptions
370+
{ constructorTagModifier = camelToKebab
371+
, allNullaryToStringTag = True
372+
}
373+
353374
instance FromJSON DiffusionStrategy where
354-
parseJSON =
355-
genericParseJSON
356-
defaultOptions
357-
{ constructorTagModifier = camelToKebab
358-
, allNullaryToStringTag = True
359-
}
375+
parseJSON = genericParseJSON defaultEnumOptions
360376

361377
instance ToJSON DiffusionStrategy where
362-
toJSON =
363-
genericToJSON
364-
defaultOptions
365-
{ constructorTagModifier = camelToKebab
366-
, allNullaryToStringTag = True
367-
}
378+
toJSON = genericToJSON defaultEnumOptions
379+
toEncoding = genericToEncoding defaultEnumOptions
380+
381+
instance FromJSON RelayStrategy where
382+
parseJSON = genericParseJSON defaultEnumOptions
383+
384+
instance ToJSON RelayStrategy where
385+
toJSON = genericToJSON defaultEnumOptions
386+
toEncoding = genericToEncoding defaultEnumOptions
368387

369388
-- | Create a 'Config' from a file.
370389
readConfigEither :: FilePath -> IO (Either ParseException Config)

0 commit comments

Comments
 (0)