@@ -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
0 commit comments