Skip to content

Commit 5f0d342

Browse files
committed
Add parsing logic
1 parent 5c1092e commit 5f0d342

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

cardano-node/src/Cardano/Node/Configuration/POM.hs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,28 @@ data NodeConfiguration
140140
-- 'Ouroboros.Network.Protocol.ChainSync.Codec.ChainSyncTimeout'
141141
, ncChainSyncIdleTimeout :: TimeoutOverride
142142

143+
-- Mempool timeout configurations:
144+
-- These configuration control a lightweight "defensive programming"
145+
-- feature in the Mempool.
146+
-- See documentation in @Ouroboros.Consensus.Mempool.API@ for more info
147+
148+
-- | If the mempool takes longer than this to validate a tx, then it
149+
-- discards the tx instead of adding it.
150+
, ncMempoolTimeoutSoft :: DiffTime
151+
152+
-- | If the mempool takes longer than this to validate a tx, then it
153+
-- disconnects from the peer.
154+
--
155+
-- WARNING: if this is less than 'mempoolTimeoutSoft', then
156+
-- 'mempoolTimeoutSoft' is irrelevant. If it's equal or just barely larger,
157+
-- then the soft/hard distinction will likely be unreliable.
158+
, ncMempoolTimeoutHard :: DiffTime
159+
160+
-- | If the mempool takes longer than this cumulatively to
161+
-- validate when each entered the mempool, then the mempool is at
162+
-- capacity, ie it's full, ie no tx can be added.
163+
, ncMempoolTimeoutCapacity :: DiffTime
164+
143165
-- | Node AcceptedConnectionsLimit
144166
, ncAcceptedConnectionsLimit :: !AcceptedConnectionsLimit
145167

@@ -237,6 +259,11 @@ data PartialNodeConfiguration
237259

238260
, pncChainSyncIdleTimeout :: !(Last DiffTime)
239261

262+
-- Mempool timeout configurations:
263+
, pncMempoolTimeoutSoft :: !(Last DiffTime)
264+
, pncMempoolTimeoutHard :: !(Last DiffTime)
265+
, pncMempoolTimeoutCapacity :: !(Last DiffTime)
266+
240267
-- AcceptedConnectionsLimit
241268
, pncAcceptedConnectionsLimit :: !(Last AcceptedConnectionsLimit)
242269

@@ -370,6 +397,10 @@ instance FromJSON PartialNodeConfiguration where
370397

371398
pncChainSyncIdleTimeout <- Last <$> v .:? "ChainSyncIdleTimeout"
372399

400+
pncMempoolTimeoutSoft <- Last <$> v .:? "MempoolTimeoutSoft"
401+
pncMempoolTimeoutHard <- Last <$> v .:? "MempoolTimeoutHard"
402+
pncMempoolTimeoutCapacity <- Last <$> v .:? "MempoolTimeoutCapacity"
403+
373404
-- Peer Sharing
374405
pncPeerSharing <- Last <$> v .:? "PeerSharing"
375406

@@ -404,6 +435,9 @@ instance FromJSON PartialNodeConfiguration where
404435
, pncProtocolIdleTimeout
405436
, pncTimeWaitTimeout
406437
, pncChainSyncIdleTimeout
438+
, pncMempoolTimeoutSoft
439+
, pncMempoolTimeoutHard
440+
, pncMempoolTimeoutCapacity
407441
, pncEgressPollInterval
408442
, pncAcceptedConnectionsLimit
409443
, pncDeadlineTargetOfRootPeers
@@ -658,6 +692,9 @@ defaultPartialNodeConfiguration =
658692
, pncAcceptedConnectionsLimit = Last (Just Ouroboros.defaultAcceptedConnectionsLimit)
659693
-- https://ouroboros-network.cardano.intersectmbo.org/ouroboros-network/Ouroboros-Network-Diffusion-Configuration.html#v:defaultAcceptedConnectionsLimit
660694
, pncChainSyncIdleTimeout = mempty
695+
, pncMempoolTimeoutSoft = mempty
696+
, pncMempoolTimeoutHard = mempty
697+
, pncMempoolTimeoutCapacity = mempty
661698

662699
-- these targets are set properly in makeNodeConfiguration below
663700
, pncDeadlineTargetOfRootPeers = mempty
@@ -780,6 +817,16 @@ makeNodeConfiguration pnc = do
780817
$ getLast
781818
$ pncChainSyncIdleTimeout pnc
782819

820+
let mempoolTimeouts = ( getLast (pncMempoolTimeoutSoft pnc)
821+
, getLast (pncMempoolTimeoutHard pnc)
822+
, getLast (pncMempoolTimeoutCapacity pnc)
823+
)
824+
(ncMempoolTimeoutSoft, ncMempoolTimeoutHard, ncMempoolTimeoutCapacity) <-
825+
case mempoolTimeouts of
826+
(Just s, Just h, Just c) -> pure (s, h, c)
827+
(Nothing, Nothing, Nothing) -> pure (1, 1.5, 5)
828+
_ -> Left "Mempool timeouts must be either all set or all unset"
829+
783830
let ncPeerSharing =
784831
case pncPeerSharing pnc of
785832
Last Nothing ->
@@ -851,6 +898,9 @@ makeNodeConfiguration pnc = do
851898
, ncProtocolIdleTimeout
852899
, ncTimeWaitTimeout
853900
, ncChainSyncIdleTimeout
901+
, ncMempoolTimeoutSoft
902+
, ncMempoolTimeoutHard
903+
, ncMempoolTimeoutCapacity
854904
, ncEgressPollInterval
855905
, ncAcceptedConnectionsLimit
856906
, ncDeadlineTargetOfRootPeers

cardano-node/src/Cardano/Node/Parsers.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ nodeRunParser = do
121121
, pncTimeWaitTimeout = mempty
122122
, pncEgressPollInterval = mempty
123123
, pncChainSyncIdleTimeout = mempty
124+
, pncMempoolTimeoutSoft = mempty
125+
, pncMempoolTimeoutHard = mempty
126+
, pncMempoolTimeoutCapacity = mempty
124127
, pncAcceptedConnectionsLimit = mempty
125128
, pncDeadlineTargetOfRootPeers = mempty
126129
, pncDeadlineTargetOfKnownPeers = mempty

cardano-node/src/Cardano/Node/Run.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ import System.Win32.File
166166
import Paths_cardano_node (version)
167167

168168
import Paths_cardano_node (version)
169+
import Ouroboros.Consensus.Mempool (MempoolTimeoutConfig(..))
169170

170171
{- HLINT ignore "Fuse concatMap/map" -}
171172
{- HLINT ignore "Redundant <$>" -}
@@ -466,7 +467,11 @@ handleSimpleNode blockType runP tracers nc onKernel = do
466467
, rnTraceNTN = nodeToNodeTracers tracers
467468
, rnTraceNTC = nodeToClientTracers tracers
468469
, rnProtocolInfo = pInfo
469-
, rnMempoolTimeoutConfig = Nothing -- read from config and use defaults if not provided
470+
, rnMempoolTimeoutConfig = Just $ MempoolTimeoutConfig
471+
{ mempoolTimeoutSoft = ncMempoolTimeoutSoft nc
472+
, mempoolTimeoutHard = ncMempoolTimeoutHard nc
473+
, mempoolTimeoutCapacity = ncMempoolTimeoutCapacity nc
474+
}
470475
, rnNodeKernelHook = \registry nodeKernel -> do
471476
-- set the initial block forging
472477
blockForging <- snd (Api.protocolInfo runP) (Consensus.kesAgentTracer $ consensusTracers tracers)

cardano-node/test/Test/Cardano/Node/POM.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ testPartialYamlConfig =
149149
, pncProtocolIdleTimeout = mempty
150150
, pncTimeWaitTimeout = mempty
151151
, pncChainSyncIdleTimeout = mempty
152+
, pncMempoolTimeoutSoft = mempty
153+
, pncMempoolTimeoutHard = mempty
154+
, pncMempoolTimeoutCapacity = mempty
152155
, pncAcceptedConnectionsLimit = mempty
153156
, pncDeadlineTargetOfRootPeers = mempty
154157
, pncDeadlineTargetOfKnownPeers = mempty
@@ -199,6 +202,9 @@ testPartialCliConfig =
199202
, pncProtocolIdleTimeout = mempty
200203
, pncTimeWaitTimeout = mempty
201204
, pncChainSyncIdleTimeout = mempty
205+
, pncMempoolTimeoutSoft = mempty
206+
, pncMempoolTimeoutHard = mempty
207+
, pncMempoolTimeoutCapacity = mempty
202208
, pncAcceptedConnectionsLimit = mempty
203209
, pncDeadlineTargetOfRootPeers = mempty
204210
, pncDeadlineTargetOfKnownPeers = mempty
@@ -251,6 +257,9 @@ eExpectedConfig = do
251257
, ncProtocolIdleTimeout = 5
252258
, ncTimeWaitTimeout = 60
253259
, ncChainSyncIdleTimeout = NoTimeoutOverride
260+
, ncMempoolTimeoutSoft = 1.0
261+
, ncMempoolTimeoutHard = 1.5
262+
, ncMempoolTimeoutCapacity = 5.0
254263
, ncAcceptedConnectionsLimit =
255264
AcceptedConnectionsLimit
256265
{ acceptedConnectionsHardLimit = 512

0 commit comments

Comments
 (0)