Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit f713e1c

Browse files
authored
[GH-223] Add Block specific configuration options using CLI. (#228)
1 parent 71a8257 commit f713e1c

File tree

4 files changed

+128
-27
lines changed

4 files changed

+128
-27
lines changed

src/Cardano/Shell/Configuration/Lib.hs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ import Cardano.Shell.Configuration.Types (BlockchainConfig,
2929
OSConfig, TopologyConfig,
3030
WalletConfig, renderCluster,
3131
renderOS)
32-
import Cardano.Shell.Constants.PartialTypes (PartialCardanoConfiguration (..),
32+
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..), PartialCardanoConfiguration (..),
3333
PartialCore (..),
3434
PartialGenesis (..),
3535
PartialNode (..))
36-
import Cardano.Shell.Constants.Types (CardanoConfiguration (..),
36+
import Cardano.Shell.Constants.Types (Block (..),
37+
CardanoConfiguration (..),
3738
Core (..), Genesis (..),
3839
Node (..))
3940

@@ -62,14 +63,16 @@ finaliseCardanoConfiguration PartialCardanoConfiguration{..} = do
6263
ccTXP <- lastToEither "Unspecified ccTXP" pccTXP
6364
ccSSC <- lastToEither "Unspecified ccSSC" pccSSC
6465
ccDLG <- lastToEither "Unspecified ccDLG" pccDLG
65-
ccBlock <- lastToEither "Unspecified ccBlock" pccBlock
66+
ccBlock <- join $ finaliseBlock <$>
67+
lastToEither "Unspecified ccBlock" pccBlock
6668
ccNode <- join $ finaliseNode <$>
6769
lastToEither "Unspecified ccNode" pccNode
6870
ccTLS <- lastToEither "Unspecified ccTLS" pccTLS
6971
ccWallet <- lastToEither "Unspecified ccWallet" pccWallet
7072

7173
pure CardanoConfiguration{..}
7274

75+
-- | Finalize the @PartialCore@, convert to @Core@.
7376
finaliseCore :: PartialCore -> Either Text Core
7477
finaliseCore PartialCore{..} = do
7578
coGenesis <- join $ finaliseGenesis <$>
@@ -79,6 +82,7 @@ finaliseCore PartialCore{..} = do
7982

8083
pure Core{..}
8184

85+
-- | Finalize the @PartialGenesis@, convert to @Genesis@.
8286
finaliseGenesis :: PartialGenesis -> Either Text Genesis
8387
finaliseGenesis PartialGenesis{..} = do
8488

@@ -88,6 +92,7 @@ finaliseGenesis PartialGenesis{..} = do
8892

8993
pure Genesis{..}
9094

95+
-- | Finalize the @PartialNode@, convert to @Node@.
9196
finaliseNode :: PartialNode -> Either Text Node
9297
finaliseNode PartialNode{..} = do
9398

@@ -108,6 +113,22 @@ finaliseNode PartialNode{..} = do
108113

109114
pure Node{..}
110115

116+
-- | Finalize the @PartialBlock@, convert to @Block@.
117+
finaliseBlock :: PartialBlock -> Either Text Block
118+
finaliseBlock PartialBlock{..} = do
119+
120+
blNetworkDiameter <- lastToEither "Unspecified blNetworkDiameter" pblNetworkDiameter
121+
blRecoveryHeadersMessage <- lastToEither "Unspecified blRecoveryHeadersMessage" pblRecoveryHeadersMessage
122+
blStreamWindow <- lastToEither "Unspecified blStreamWindow" pblStreamWindow
123+
blNonCriticalCQBootstrap <- lastToEither "Unspecified blNonCriticalCQBootstrap" pblNonCriticalCQBootstrap
124+
blNonCriticalCQ <- lastToEither "Unspecified blNonCriticalCQ" pblNonCriticalCQ
125+
blCriticalCQ <- lastToEither "Unspecified blCriticalCQ" pblCriticalCQ
126+
blCriticalCQBootstrap <- lastToEither "Unspecified blCriticalCQBootstrap" pblCriticalCQBootstrap
127+
blCriticalForkThreshold <- lastToEither "Unspecified blCriticalForkThreshold" pblCriticalForkThreshold
128+
blFixedTimeCQ <- lastToEither "Unspecified blFixedTimeCQ" pblFixedTimeCQ
129+
130+
pure Block{..}
131+
111132

112133
-- | Generate 'TopologyConfig' with given 'Cluster'
113134
mkTopology :: Cluster -> IO TopologyConfig

src/Cardano/Shell/Constants/CLI.hs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module Cardano.Shell.Constants.CLI
66
, configDBVersionCLIParser
77
-- * Node
88
, configNodeCLIParser
9+
-- * Block
10+
, configBlockCLIParser
911
) where
1012

1113
import Cardano.Prelude hiding (option)
@@ -128,3 +130,57 @@ configNodeCLIParser =
128130
<> help "Enable explorer extended API for fetching more."
129131
)
130132

133+
--------------------------------------------------------------------------------
134+
-- Block
135+
--------------------------------------------------------------------------------
136+
137+
-- | Block CLI parser.
138+
configBlockCLIParser :: Parser PartialBlock
139+
configBlockCLIParser =
140+
PartialBlock
141+
<$> option auto
142+
( long "network-diameter"
143+
<> metavar "NETWORK-DIAMETER-TIME"
144+
<> help "Estimated time needed to broadcast message from one node to all other nodes."
145+
)
146+
<*> option auto
147+
( long "recovery-headers-amount"
148+
<> metavar "RECOVERY-HEADERS-AMOUNT"
149+
<> help "Maximum amount of headers node can put into headers message while in 'after offline' or 'recovery' mode."
150+
)
151+
<*> option auto
152+
( long "stream-window"
153+
<> metavar "STREAM-WINDOW-CAPACITY"
154+
<> help "Number of blocks to have inflight."
155+
)
156+
<*> option auto
157+
( long "noncritical-cq-bootstrap"
158+
<> metavar "NONCRITICAL-CQ-BOOTSTRAP"
159+
<> help "If chain quality in bootstrap era is less than this value, non critical misbehavior will be reported."
160+
)
161+
<*> option auto
162+
( long "critical-cq-bootstrap"
163+
<> metavar "CRITICAL-CQ-BOOTSTRAP"
164+
<> help "If chain quality in bootstrap era is less than this value, critical misbehavior will be reported."
165+
)
166+
<*> option auto
167+
( long "noncritical-cq"
168+
<> metavar "NONCRITICAL-CQ"
169+
<> help "If chain quality after bootstrap era is less than this value, non critical misbehavior will be reported."
170+
)
171+
<*> option auto
172+
( long "critical-cq"
173+
<> metavar "CRITICAL-CQ"
174+
<> help "If chain quality after bootstrap era is less than this value, critical misbehavior will be reported."
175+
)
176+
<*> option auto
177+
( long "critical-fork-threshold"
178+
<> metavar "CRITICAL-FORK-THRESHOLD"
179+
<> help "Number of blocks such that if so many blocks are rolled back, it requires immediate reaction."
180+
)
181+
<*> option auto
182+
( long "fixed-time-cq"
183+
<> metavar "FIXED-TIME-CQ"
184+
<> help "Chain quality will be also calculated for this amount of seconds."
185+
)
186+

src/Cardano/Shell/Constants/PartialTypes.hs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Cardano.Shell.Constants.PartialTypes
77
, PartialCore (..)
88
, PartialGenesis (..)
99
, PartialNode (..)
10+
, PartialBlock (..)
1011
-- * re-exports
1112
, RequireNetworkMagic (..)
1213
) where
@@ -29,7 +30,7 @@ data PartialCardanoConfiguration = PartialCardanoConfiguration
2930
, pccTXP :: !(Last TXP)
3031
, pccSSC :: !(Last SSC)
3132
, pccDLG :: !(Last DLG)
32-
, pccBlock :: !(Last Block)
33+
, pccBlock :: !(Last PartialBlock)
3334
, pccNode :: !(Last PartialNode)
3435
, pccTLS :: !(Last TLS)
3536
, pccWallet :: !(Last Wallet)
@@ -74,3 +75,27 @@ data PartialNode = PartialNode
7475
deriving Semigroup via GenericSemigroup PartialNode
7576
deriving Monoid via GenericMonoid PartialNode
7677

78+
-- | Partial @Block@ configuration.
79+
data PartialBlock = PartialBlock
80+
{ pblNetworkDiameter :: !(Last Int)
81+
-- ^Estimated time needed to broadcast message from one node to all other nodes.
82+
, pblRecoveryHeadersMessage :: !(Last Int)
83+
-- ^Maximum amount of headers node can put into headers message while in "after offline" or "recovery" mode.
84+
, pblStreamWindow :: !(Last Int)
85+
-- ^ Number of blocks to have inflight
86+
, pblNonCriticalCQBootstrap :: !(Last Double)
87+
-- ^ If chain quality in bootstrap era is less than this value, non critical misbehavior will be reported.
88+
, pblNonCriticalCQ :: !(Last Double)
89+
-- ^ If chain quality after bootstrap era is less than this value, non critical misbehavior will be reported.
90+
, pblCriticalCQ :: !(Last Double)
91+
-- ^ If chain quality after bootstrap era is less than this value, critical misbehavior will be reported.
92+
, pblCriticalCQBootstrap :: !(Last Double)
93+
-- ^ If chain quality in bootstrap era is less than this value, critical misbehavior will be reported.
94+
, pblCriticalForkThreshold :: !(Last Int)
95+
-- ^ Number of blocks such that if so many blocks are rolled back, it requires immediate reaction.
96+
, pblFixedTimeCQ :: !(Last Int)
97+
-- ^ Chain quality will be also calculated for this amount of seconds.
98+
} deriving (Eq, Show, Generic)
99+
deriving Semigroup via GenericSemigroup PartialBlock
100+
deriving Monoid via GenericMonoid PartialBlock
101+

src/Cardano/Shell/Presets.hs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ module Cardano.Shell.Presets
55

66
import Cardano.Prelude
77

8-
import Cardano.Shell.Constants.PartialTypes (PartialCardanoConfiguration (..),
8+
import Cardano.Shell.Constants.PartialTypes (PartialBlock (..), PartialCardanoConfiguration (..),
99
PartialCore (..),
1010
PartialGenesis (..),
1111
PartialNode (..))
12-
import Cardano.Shell.Constants.Types (Block (..), Certificate (..),
13-
DLG (..),
12+
import Cardano.Shell.Constants.Types (Certificate (..), DLG (..),
1413
LastKnownBlockVersion (..),
1514
NTP (..),
1615
RequireNetworkMagic (..),
@@ -77,16 +76,16 @@ mainnetConfiguration =
7776
, dlgMessageCacheTimeout = 30
7877
}
7978
, pccBlock = pure
80-
Block
81-
{ blNetworkDiameter = 18
82-
, blRecoveryHeadersMessage = 2200
83-
, blStreamWindow = 2048
84-
, blNonCriticalCQBootstrap = 0.95
85-
, blNonCriticalCQ = 0.8
86-
, blCriticalCQBootstrap = 0.8888
87-
, blCriticalCQ = 0.654321
88-
, blCriticalForkThreshold = 3
89-
, blFixedTimeCQ = 3600
79+
PartialBlock
80+
{ pblNetworkDiameter = pure 18
81+
, pblRecoveryHeadersMessage = pure 2200
82+
, pblStreamWindow = pure 2048
83+
, pblNonCriticalCQBootstrap = pure 0.95
84+
, pblNonCriticalCQ = pure 0.8
85+
, pblCriticalCQBootstrap = pure 0.8888
86+
, pblCriticalCQ = pure 0.654321
87+
, pblCriticalForkThreshold = pure 3
88+
, pblFixedTimeCQ = pure 3600
9089
}
9190
, pccNode = pure
9291
PartialNode
@@ -198,16 +197,16 @@ devConfiguration =
198197
, dlgMessageCacheTimeout = 30
199198
}
200199
, pccBlock = pure
201-
Block
202-
{ blNetworkDiameter = 3
203-
, blRecoveryHeadersMessage = 20
204-
, blStreamWindow = 2048
205-
, blNonCriticalCQBootstrap = 0.95
206-
, blNonCriticalCQ = 0.8
207-
, blCriticalCQBootstrap = 0.8888
208-
, blCriticalCQ = 0.654321
209-
, blCriticalForkThreshold = 2
210-
, blFixedTimeCQ = 10
200+
PartialBlock
201+
{ pblNetworkDiameter = pure 3
202+
, pblRecoveryHeadersMessage = pure 20
203+
, pblStreamWindow = pure 2048
204+
, pblNonCriticalCQBootstrap = pure 0.95
205+
, pblNonCriticalCQ = pure 0.8
206+
, pblCriticalCQBootstrap = pure 0.8888
207+
, pblCriticalCQ = pure 0.654321
208+
, pblCriticalForkThreshold = pure 2
209+
, pblFixedTimeCQ = pure 10
211210
}
212211
, pccNode = pure
213212
PartialNode

0 commit comments

Comments
 (0)