Skip to content

TX Submission Logic #4887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
83070dd
tx-submission: PeerTxState & SharedTxState
coot Nov 21, 2023
d394d3c
tx-submission: decision logic
coot Dec 8, 2023
beb5f9b
tx-submission: generalised CollectPipelined
coot Feb 23, 2024
db24009
tx-submission: registry
coot Mar 13, 2024
74d15ac
tx-submission: inbound peer using tx-submission decision logic
coot Jul 15, 2024
da7f535
ouroboros-network: tx-submission module structure
coot Jul 22, 2024
0602061
tx-submission: debug tracer for SharedTxState
coot Jul 30, 2024
fb43b0d
tx-submission: refactored TxSubmission files and added V2 sim
bolt12 Jul 22, 2024
191abcb
tx-submission: fixed ArbTxDecisionPolicy generator
bolt12 Sep 10, 2024
2d65c41
tx-submission: added txSubmissionV2 simulation
bolt12 Sep 11, 2024
9ba4a81
tx-submission: rop V2 in internal APIs
coot Sep 17, 2024
bad9fb0
tx-submission: fixed a race condition
bolt12 Sep 11, 2024
6ffe01f
tx-submission: defaultTxDecisionPolicy
coot Sep 17, 2024
935ce0e
tx-submission: added test to check tx multiplicities
bolt12 Sep 11, 2024
4cbcdcc
net-sim: integrated txSubmissionV2 in testnet diffusion simulation
bolt12 Sep 11, 2024
dc4da56
tx-submission: added DebugTxLogic tracer
coot Sep 16, 2024
4f09cf0
tx-submission: label TVars in tests
coot Sep 16, 2024
7e24e8c
tx-submission: use strict STM in tests
coot Sep 16, 2024
53c4518
tx-submission: refactored test
coot Sep 17, 2024
a14a00a
tx-submission: put common types in one place
coot Sep 17, 2024
1dd9047
tx-submission: compile with ghc < 9.10
coot Sep 18, 2024
f897d0f
tx-submission: moved TxDecisionPolicy to MiniProtocolParamenters
bolt12 Sep 19, 2024
8e31665
tx-submission: added EnableNewTxSubmissionProtocol flag
bolt12 Sep 19, 2024
425c196
tx-submission: verify tx sizes
coot Sep 23, 2024
f217331
tx-submission: deriving Eq and Show for EnableNewTxSubmissionProtocol
bolt12 Sep 25, 2024
e34d898
tx-submission: TraceTxSubmissionProcessed for the new TX submission
karknu Oct 2, 2024
d4d4268
tx-submission: added duration to TxInboundAddedToMempool
karknu Oct 5, 2024
bd936ac
tx-submission: ranking of peers
karknu Oct 4, 2024
fb9675a
tx-submission: refactored conutRejectedTxs
coot Mar 10, 2025
c085912
tx-submission: code style
coot Mar 10, 2025
7f6e240
tx-submission: refactored updateRejects
coot Mar 11, 2025
0cfb61d
tx-submission: added TxsToMempool newtype
coot Mar 13, 2025
8c47dc5
tx-submission: use strict foldl' and Map.foldl'
coot Mar 14, 2025
786355f
tx-submission: improved haddocks
coot Mar 14, 2025
c8c766c
tx-submission: refactored PeerTxAPI
coot Mar 14, 2025
b9f806b
tx-submission: renamed inbound modules
coot Mar 17, 2025
52a2fe4
tx-submission: use splitLookup to combine split & lookup
coot Mar 18, 2025
5c81093
tx-submission: TxSubmisionLogicVersion type
coot Mar 24, 2025
3800063
tx-submission: added export list in the Inbound.V2 module
coot Mar 24, 2025
9b546d9
tx-submission: support the txsubmission-delay cabal flag
coot Mar 24, 2025
bd2ec26
Compilation with ghc >= 9.10 without CPPs
coot Mar 31, 2025
0998e88
mux: haddock improvements
coot Apr 11, 2025
c4d7119
net-sim: do not render saTxDecisionPolicy field of SimArgs in test co…
coot Mar 25, 2025
1ab2f13
net-sim: improved tracing
coot Apr 30, 2025
49c9d51
net-sim: tune the mustReplyTimeout chain-sync timeout
coot May 8, 2025
1a19815
net-sim: name some threads
coot May 9, 2025
f591307
tx-submission: tracing improvements
coot Apr 30, 2025
7706397
tx-submission: test refactoring
coot Apr 30, 2025
923d461
tx-submission: configurable initial delay
coot May 7, 2025
2411861
tx-submission: code style / ghc-9.12
coot May 7, 2025
70a409b
tx-submission: show number of txs transferred in test simulations
coot May 8, 2025
a762ab8
tx-submission: improved logging for prop_accept_failure test failures
coot May 9, 2025
28d62e4
tx-submission: document two protocol errors
coot May 9, 2025
cc00341
tx-submission: submit txs to the mempool even if we don't send MsgReq…
coot May 9, 2025
2429043
Updated changelog files
coot May 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion network-mux/src/Network/Mux/Bearer/Socket.hs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ socketAsBearer sduSize batchSize readBuffer_m sduTimeout pollInterval tracer sd
let ts32 = Mx.timestampMicrosecondsLow32Bits ts
buf = map (Mx.encodeSDU .
(\sdu -> Mx.setTimestamp sdu (Mx.RemoteClockModel ts32))) sdus
r <- timeout ((fromIntegral $ length sdus) * sduTimeout) $
r <- timeout (fromIntegral (length sdus) * sduTimeout) $
Socket.sendMany sd (concatMap BL.toChunks buf)
`catch` Mx.handleIOException "sendAll errored"
case r of
Expand Down
13 changes: 11 additions & 2 deletions network-mux/src/Network/Mux/Codec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ import Network.Mux.Types
-- > 0 1 2 3
-- > 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
-- > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- > | transmission time |
-- > | transmission time |
-- > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- > |M| conversation id | length |
-- > |d| mini-protocol number | length |
-- > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
--
-- All fields are in big endian byte order.
--
-- * transmission time: time when the SDU was sent
-- * @d@: mini-protocol direction (`MiniProtocolDir`):
--
-- * 1 - initiator direction
-- * 0 - responder direction
--
-- * mini-protocol number (`MiniProtocolNum`)
-- * length: length of the payload
--
encodeSDU :: SDU -> BL.ByteString
encodeSDU sdu =
let hdr = Bin.runPut enc in
Expand Down
1 change: 1 addition & 0 deletions ouroboros-network-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Non-breaking changes

* `IsLedgerPeer` added to `Ouroboros.Network.LedgerPeers.Types` module.
* Derived `Bounded` instance for `SizeInBytes`.

## 0.13.0.0 -- 2025-02-25

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Quiet (Quiet (..))
newtype SizeInBytes = SizeInBytes { getSizeInBytes :: Word32 }
deriving (Eq, Ord)
deriving Show via Quiet SizeInBytes
deriving Bounded via Word32
deriving Enum via Word32
deriving Num via Word32
deriving Real via Word32
Expand Down
3 changes: 3 additions & 0 deletions ouroboros-network-protocols/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Breaking changes

* `CollectPipelined` constructor for `TxSubmission2.Server` was modified: now
one can run a monadic action in the continuation when no message is available.

### Non-breaking changes

## 0.14.0.0 -- 2025-02-25
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ data ServerStIdle (n :: N) txid tx m a where
-- | Collect a pipelined result.
--
CollectPipelined
:: Maybe (ServerStIdle (S n) txid tx m a)
-> (Collect txid tx -> m (ServerStIdle n txid tx m a))
-> ServerStIdle (S n) txid tx m a
:: Maybe (m (ServerStIdle (S n) txid tx m a))
-> (Collect txid tx -> m ( ServerStIdle n txid tx m a))
-> ServerStIdle (S n) txid tx m a


-- | Transform a 'TxSubmissionServerPipelined' into a 'PeerPipelined'.
Expand Down Expand Up @@ -134,6 +134,6 @@ txSubmissionServerPeerPipelined (TxSubmissionServerPipelined server) =
(Effect (go <$> k))

go (CollectPipelined mNone collect) =
Collect (fmap go mNone)
(Effect . fmap go . collect)
Collect (Effect . fmap go <$> mNone)
(Effect . fmap go . collect)

Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ instance Protocol (TxSubmission2 txid tx) where
-- * The non-blocking case must be used when there are non-zero remaining
-- unacknowledged transactions.
--
-- It is a protocol error to:
--
-- * make a blocking request with `NumTxIdsToReq 0`;
--
-- * make a non-blocking request with both `NumTxIdsToAck 0` and `NumTxIdsReq 0`.
--
MsgRequestTxIds
:: forall (blocking :: StBlockingStyle) txid tx.
SingBlockingStyle blocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ directPipelined (TxSubmissionServerPipelined mserver)
SendMsgReplyTxs txs client' <- recvMsgRequestTxs txids
directSender (enqueue (CollectTxs txids txs) q) server' client'

directSender q (CollectPipelined (Just server') _) client =
directSender q (CollectPipelined (Just server) _) client = do
server' <- server
directSender q server' client

directSender (ConsQ c q) (CollectPipelined _ collect) client = do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ txSubmissionServer tracer txId maxUnacked maxTxIdsToRequest maxTxToRequest =
--
| canRequestMoreTxs st
= CollectPipelined
(Just (serverReqTxs accum (Succ n) st))
(Just (pure $ serverReqTxs accum (Succ n) st))
(handleReply accum n st)

-- In this case there is nothing else to do so we block until we
Expand Down
4 changes: 4 additions & 0 deletions ouroboros-network-testing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

### Non-breaking changes

* `renderRanges`: print a range using math notation for open/closed intervals.
* Pretty print `WithName` using `Show` instance.
* Pretty print `WithTime` using `Show` instance.

## 0.8.1.0 -- 2025-02-25

### Non-breaking changes
Expand Down
13 changes: 10 additions & 3 deletions ouroboros-network-testing/src/Test/Ouroboros/Network/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import Data.Ratio
import Data.Set (Set)
import Data.Set qualified as Set
import Text.Pretty.Simple (pPrint)
import Text.Printf

import Debug.Trace (traceShowM)
import Test.QuickCheck
Expand Down Expand Up @@ -136,7 +137,7 @@ prop_shrink_valid valid (ShrinkCarefully x) =
-- | Use in 'tabulate' to help summarise data into buckets.
--
renderRanges :: Int -> Int -> String
renderRanges r n = show lower ++ " -- " ++ show upper
renderRanges r n = "[" ++ printf "% 3d" lower ++ ", " ++ printf "% 3d" upper ++ ")"
where
lower = n - n `mod` r
upper = lower + (r-1)
Expand Down Expand Up @@ -167,13 +168,19 @@ data WithName name event = WithName {
wnName :: name,
wnEvent :: event
}
deriving (Show, Functor)
deriving Functor

instance (Show name, Show event) => Show (WithName name event) where
show WithName { wnName = name, wnEvent = event } = show name ++ ": " ++ show event

data WithTime event = WithTime {
wtTime :: Time,
wtEvent :: event
}
deriving (Show, Functor)
deriving Functor

instance Show event => Show (WithTime event) where
show WithTime { wtTime = (Time time), wtEvent = event } = show time ++ "@ " ++ show event

tracerWithName :: name -> Tracer m (WithName name a) -> Tracer m a
tracerWithName name = contramap (WithName name)
Expand Down
5 changes: 5 additions & 0 deletions ouroboros-network/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
are captured by the `DNSPeersKind` type, which also distinguishes the type
of ledger peer.
* Added `dispatchLookupWithTTL`
* Added `Ouroboros.Network.TxSubmission.Inbound.V2`.

### Breaking changes

Expand Down Expand Up @@ -38,6 +39,10 @@
- Renamed `Applications` to `DiffusionApplications`
- `runM` function now receives `ExtraParameters` as an argument
- Configurable Mux Egress Poll Interval
- `Ouroboros.Network.TxSubmission.Inbound` moved to `Ouroboros.Network.TxSubmission.Inbound.V1`
- `Ouroboros.Network.TxSubmission.Inbound.V1.txSubmissionInbound` takes extra argument: `TxSubmissionInitDelay` (previously configurable through `cabal` flags).
- Removed the `txsubmission-delay` cabal flag.
- `ProtocolErrorRequestedTooManyTxids` includes number of unacked txids.

## 0.20.1.0 -- 2025-03-13

Expand Down
25 changes: 15 additions & 10 deletions ouroboros-network/ouroboros-network.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ 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 @@ -96,7 +91,13 @@ library
Ouroboros.Network.PeerSelection.State.LocalRootPeers
Ouroboros.Network.PeerSelection.Types
Ouroboros.Network.PeerSharing
Ouroboros.Network.TxSubmission.Inbound
Ouroboros.Network.TxSubmission.Inbound.V1
Ouroboros.Network.TxSubmission.Inbound.V2
Ouroboros.Network.TxSubmission.Inbound.V2.Decision
Ouroboros.Network.TxSubmission.Inbound.V2.Policy
Ouroboros.Network.TxSubmission.Inbound.V2.Registry
Ouroboros.Network.TxSubmission.Inbound.V2.State
Ouroboros.Network.TxSubmission.Inbound.V2.Types
Ouroboros.Network.TxSubmission.Mempool.Reader
Ouroboros.Network.TxSubmission.Outbound

Expand Down Expand Up @@ -169,7 +170,8 @@ library
random,
si-timers,
strict-checked-vars ^>=0.2,
strict-stm >=1.0 && <1.6,
strict-mvar,
strict-stm,
transformers,
typed-protocols ^>=0.3,
typed-protocols-stateful,
Expand All @@ -181,9 +183,6 @@ library
if flag(asserts)
ghc-options: -fno-ignore-asserts

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

library ouroboros-orphan-instances
import: ghc-options
visibility: public
Expand Down Expand Up @@ -321,6 +320,7 @@ library testlib
bytestring,
cardano-binary,
cardano-slotting,
cardano-strict-containers,
cborg,
containers,
contra-tracer,
Expand Down Expand Up @@ -350,6 +350,7 @@ library testlib
random,
serialise,
si-timers,
strict-mvar,
strict-stm,
tasty,
tasty-hunit,
Expand Down Expand Up @@ -390,6 +391,10 @@ library testlib
Test.Ouroboros.Network.PeerSelection.PeerMetric
Test.Ouroboros.Network.PeerSelection.RootPeersDNS
Test.Ouroboros.Network.TxSubmission
Test.Ouroboros.Network.TxSubmission.AppV1
Test.Ouroboros.Network.TxSubmission.AppV2
Test.Ouroboros.Network.TxSubmission.TxLogic
Test.Ouroboros.Network.TxSubmission.Types
Test.Ouroboros.Network.Version

-- Simulation tests, and IO tests which don't require native system calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Ouroboros.Network.Diffusion.Configuration
, defaultDeadlineTargets
, defaultDeadlineChurnInterval
, defaultBulkChurnInterval
, defaultTxSubmissionLogicVersion
-- re-exports
, AcceptedConnectionsLimit (..)
, BlockFetchConfiguration (..)
Expand All @@ -20,6 +21,7 @@ module Ouroboros.Network.Diffusion.Configuration
, PeerSelectionTargets (..)
, PeerSharing (..)
, ConsensusMode (..)
, TxSubmissionLogicVersion (..)
, defaultConsensusMode
, defaultMiniProtocolParameters
, deactivateTimeout
Expand Down Expand Up @@ -57,6 +59,8 @@ import Ouroboros.Network.Protocol.ChainSync.Codec (ChainSyncTimeout (..))
import Ouroboros.Network.Protocol.Handshake (handshake_QUERY_SHUTDOWN_DELAY)
import Ouroboros.Network.Protocol.Limits (shortWait)
import Ouroboros.Network.Server.RateLimiting (AcceptedConnectionsLimit (..))
import Ouroboros.Network.TxSubmission.Inbound.V2.Types
(TxSubmissionLogicVersion (..))

-- |Outbound governor targets
-- Targets may vary depending on whether a node is operating in
Expand Down Expand Up @@ -150,3 +154,7 @@ local_PROTOCOL_IDLE_TIMEOUT = 2 -- 2 seconds
local_TIME_WAIT_TIMEOUT :: DiffTime
local_TIME_WAIT_TIMEOUT = 0

-- | The default logic version is the legacy one, the new one is still
-- experimental.
defaultTxSubmissionLogicVersion :: TxSubmissionLogicVersion
defaultTxSubmissionLogicVersion = TxSubmissionLogicV1
21 changes: 13 additions & 8 deletions ouroboros-network/src/Ouroboros/Network/NodeToNode.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

{-# OPTIONS_GHC -Wno-orphans #-}
Expand Down Expand Up @@ -99,8 +100,11 @@ import Ouroboros.Network.Protocol.Handshake.Type
import Ouroboros.Network.Protocol.Handshake.Version hiding (Accept)
import Ouroboros.Network.Protocol.TxSubmission2.Type (NumTxIdsToAck (..))
import Ouroboros.Network.Server.RateLimiting
import Ouroboros.Network.SizeInBytes
import Ouroboros.Network.Snocket
import Ouroboros.Network.Socket
import Ouroboros.Network.TxSubmission.Inbound.V2.Policy (TxDecisionPolicy (..),
defaultTxDecisionPolicy, max_TX_SIZE)
import Ouroboros.Network.Util.ShowProxy (ShowProxy, showProxy)


Expand Down Expand Up @@ -157,17 +161,16 @@ data MiniProtocolParameters = MiniProtocolParameters {
blockFetchPipeliningMax :: !Word16,
-- ^ maximal number of pipelined messages in 'block-fetch' mini-protocol.

txSubmissionMaxUnacked :: !NumTxIdsToAck
-- ^ maximal number of unacked tx (pipelining is bounded by twice this
-- number)
txDecisionPolicy :: !TxDecisionPolicy
-- ^ tx submission protocol decision logic parameters
}

defaultMiniProtocolParameters :: MiniProtocolParameters
defaultMiniProtocolParameters = MiniProtocolParameters {
chainSyncPipeliningLowMark = 200
, chainSyncPipeliningHighMark = 300
, blockFetchPipeliningMax = 100
, txSubmissionMaxUnacked = 10
, txDecisionPolicy = defaultTxDecisionPolicy
}

-- | Make an 'OuroborosApplication' for the bundle of mini-protocols that
Expand Down Expand Up @@ -295,7 +298,9 @@ blockFetchProtocolLimits MiniProtocolParameters { blockFetchPipeliningMax } = Mi
max (10 * 2_097_154 :: Int) (fromIntegral blockFetchPipeliningMax * 90_112)
}

txSubmissionProtocolLimits MiniProtocolParameters { txSubmissionMaxUnacked } = MiniProtocolLimits {
txSubmissionProtocolLimits MiniProtocolParameters
{ txDecisionPolicy = TxDecisionPolicy { maxUnacknowledgedTxIds }
} = MiniProtocolLimits {
-- tx-submission server can pipeline both 'MsgRequestTxIds' and
-- 'MsgRequestTx'. This means that there can be many
-- 'MsgReplyTxIds', 'MsgReplyTxs' messages in an inbound queue (their
Expand Down Expand Up @@ -353,12 +358,12 @@ txSubmissionProtocolLimits MiniProtocolParameters { txSubmissionMaxUnacked } = M
-- queue of 'txSubmissionOutbound' is bounded by the ingress side of
-- the 'txSubmissionInbound'
--
-- Currently the value of 'txSubmissionMaxUnacked' is '100', for
-- which the upper bound is `100 * (44 + 65_540) = 6_558_400`, we add
-- Currently the value of 'txSubmissionMaxUnacked' is '10', for
-- which the upper bound is `10 * (44 + 65_540) = 655_840`, we add
-- 10% as a safety margin.
--
maximumIngressQueue = addSafetyMargin $
fromIntegral txSubmissionMaxUnacked * (44 + 65_540)
fromIntegral maxUnacknowledgedTxIds * (44 + fromIntegral @SizeInBytes @Int max_TX_SIZE)
}

keepAliveProtocolLimits _ =
Expand Down
Loading