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 19, 2024
1 parent d88a587 commit 8e7dd3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ouroboros-network/ouroboros-network.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ouroboros-network
version: 0.16.1.1
version: 0.16.1.2
synopsis: A networking layer for the Ouroboros blockchain protocol
description: A networking layer for the Ouroboros blockchain protocol.
license: Apache-2.0
Expand All @@ -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 @@ -154,6 +159,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
10 changes: 10 additions & 0 deletions 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 (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.TxSubmission.Mempool.Reader (MempoolSnapshot (..),
TxSubmissionMempoolReader (..))
Expand Down Expand Up @@ -175,6 +179,7 @@ txSubmissionInbound
, NoThunks tx
, MonadSTM m
, MonadThrow m
, MonadDelay m
)
=> Tracer m (TraceTxSubmissionInbound txid tx)
-> Word16 -- ^ Maximum number of unacknowledged txids allowed
Expand All @@ -184,6 +189,11 @@ txSubmissionInbound
-> TxSubmissionServerPipelined txid tx m ()
txSubmissionInbound tracer maxUnacked mpReader mpWriter _version =
TxSubmissionServerPipelined $
#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 8e7dd3e

Please sign in to comment.