Skip to content

Commit

Permalink
TxSubmission - delay initial request for transactions
Browse files Browse the repository at this point in the history
This change delays initial request for transactions from the client,
whom may disconnect relatively quickly for reasons described in
IntersectMBO/ouroboros-network issue #4927.
  • Loading branch information
crocodile-dentist committed Aug 21, 2024
1 parent 6989f21 commit 084cdf6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ouroboros-network/ouroboros-network.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ flag asserts
manual: False
default: False

flag txsubmission-delay
description: Delay initial request for transactions from outbound/client peer
manual: True
default: True

source-repository head
type: git
location: https://github.com/intersectmbo/ouroboros-network
Expand Down Expand Up @@ -155,6 +160,9 @@ library
if flag(asserts)
ghc-options: -fno-ignore-asserts

if flag(txsubmission-delay)
cpp-options: -DTXSUBMISSION_DELAY


-- Simulation Test Library
library sim-tests-lib
Expand Down
12 changes: 11 additions & 1 deletion ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GADTs #-}
Expand All @@ -20,6 +21,7 @@ import Data.Foldable as Foldable (foldl', toList)
import Data.List.NonEmpty qualified as NonEmpty
import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Maybe
import Data.Sequence.Strict (StrictSeq)
import Data.Sequence.Strict qualified as Seq
import Data.Set qualified as Set
Expand All @@ -34,11 +36,13 @@ import Control.Exception (assert)
import Control.Monad (unless)
import Control.Monad.Class.MonadSTM
import Control.Monad.Class.MonadThrow
import Control.Monad.Class.MonadTimer.SI
import Control.Tracer (Tracer, traceWith)

import Network.TypedProtocol.Pipelined (N, Nat (..), natToInt)

import Ouroboros.Network.NodeToNode.Version (NodeToNodeVersion)
import Ouroboros.Network.Protocol.Limits
import Ouroboros.Network.Protocol.TxSubmission2.Server
import Ouroboros.Network.Protocol.TxSubmission2.Type
import Ouroboros.Network.TxSubmission.Mempool.Reader (MempoolSnapshot (..),
Expand Down Expand Up @@ -176,6 +180,7 @@ txSubmissionInbound
, NoThunks tx
, MonadSTM m
, MonadThrow m
, MonadDelay m
)
=> Tracer m (TraceTxSubmissionInbound txid tx)
-> NumTxIdsToAck -- ^ Maximum number of unacknowledged txids allowed
Expand All @@ -184,7 +189,12 @@ txSubmissionInbound
-> NodeToNodeVersion
-> TxSubmissionServerPipelined txid tx m ()
txSubmissionInbound tracer (NumTxIdsToAck maxUnacked) mpReader mpWriter _version =
TxSubmissionServerPipelined $
TxSubmissionServerPipelined $ do
#ifdef TXSUBMISSION_DELAY
-- make the client linger before asking for tx's and expending
-- our resources as well, as he may disconnect for some reason
threadDelay (fromMaybe (-1) longWait)
#endif
continueWithStateM (serverIdle Zero) initialServerState
where
-- TODO #1656: replace these fixed limits by policies based on
Expand Down

0 comments on commit 084cdf6

Please sign in to comment.