Skip to content

Commit 992a3ec

Browse files
committed
ouroboros-network: tx-submission module structure
Export everything from the `Ouroboros.Network.TxSubmission.Inbound` module.
1 parent c6b9ab4 commit 992a3ec

File tree

6 files changed

+98
-67
lines changed

6 files changed

+98
-67
lines changed

ouroboros-network/ouroboros-network.cabal

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ library
6969
Ouroboros.Network.PeerSelection.RootPeersDNS.PublicRootPeers
7070
Ouroboros.Network.PeerSharing
7171
Ouroboros.Network.TxSubmission.Inbound
72-
Ouroboros.Network.TxSubmission.Inbound.Server
7372
Ouroboros.Network.TxSubmission.Inbound.Decision
7473
Ouroboros.Network.TxSubmission.Inbound.Policy
75-
Ouroboros.Network.TxSubmission.Inbound.State
7674
Ouroboros.Network.TxSubmission.Inbound.Registry
75+
Ouroboros.Network.TxSubmission.Inbound.Server
76+
Ouroboros.Network.TxSubmission.Inbound.State
77+
Ouroboros.Network.TxSubmission.Inbound.Types
7778
Ouroboros.Network.TxSubmission.Mempool.Reader
7879
Ouroboros.Network.TxSubmission.Outbound
7980
other-modules: Ouroboros.Network.Diffusion.Common

ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/TxSubmission.hs

-2
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ import Ouroboros.Network.Protocol.TxSubmission2.Codec
6666
import Ouroboros.Network.Protocol.TxSubmission2.Server
6767
import Ouroboros.Network.Protocol.TxSubmission2.Type
6868
import Ouroboros.Network.TxSubmission.Inbound
69-
import Ouroboros.Network.TxSubmission.Inbound.Decision
7069
import Ouroboros.Network.TxSubmission.Inbound.Decision qualified as TXS
71-
import Ouroboros.Network.TxSubmission.Inbound.Policy
7270
import Ouroboros.Network.TxSubmission.Inbound.State (PeerTxState (..),
7371
SharedTxState (..))
7472
import Ouroboros.Network.TxSubmission.Inbound.State qualified as TXS

ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound.hs

+14-61
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
-- | Legacy `tx-submission` inbound peer.
1313
--
1414
module Ouroboros.Network.TxSubmission.Inbound
15-
( txSubmissionInbound
16-
, TxSubmissionMempoolWriter (..)
17-
, TraceTxSubmissionInbound (..)
18-
, TxSubmissionProtocolError (..)
15+
( -- * New Tx-Submission server
16+
module Server
17+
, module Types
18+
, module Decision
19+
, module Registry
20+
, module Policy
21+
-- * Legacy Tx-Submission server
22+
, txSubmissionInbound
1923
, ProcessedTxCount (..)
2024
) where
2125

@@ -47,70 +51,19 @@ import Ouroboros.Network.NodeToNode.Version (NodeToNodeVersion)
4751
import Ouroboros.Network.Protocol.Limits
4852
import Ouroboros.Network.Protocol.TxSubmission2.Server
4953
import Ouroboros.Network.Protocol.TxSubmission2.Type
50-
import Ouroboros.Network.TxSubmission.Inbound.Decision (TxDecision)
5154
import Ouroboros.Network.TxSubmission.Mempool.Reader (MempoolSnapshot (..),
5255
TxSubmissionMempoolReader (..))
5356

54-
-- | The consensus layer functionality that the inbound side of the tx
55-
-- submission logic requires.
5657
--
57-
-- This is provided to the tx submission logic by the consensus layer.
58+
-- re-exports
5859
--
59-
data TxSubmissionMempoolWriter txid tx idx m =
60-
TxSubmissionMempoolWriter {
6160

62-
-- | Compute the transaction id from a transaction.
63-
--
64-
-- This is used in the protocol handler to verify a full transaction
65-
-- matches a previously given transaction id.
66-
--
67-
txId :: tx -> txid,
61+
import Ouroboros.Network.TxSubmission.Inbound.Types as Types
62+
import Ouroboros.Network.TxSubmission.Inbound.Decision as Decision
63+
import Ouroboros.Network.TxSubmission.Inbound.Registry as Registry
64+
import Ouroboros.Network.TxSubmission.Inbound.Policy as Policy
65+
import Ouroboros.Network.TxSubmission.Inbound.Server as Server
6866

69-
-- | Supply a batch of transactions to the mempool. They are either
70-
-- accepted or rejected individually, but in the order supplied.
71-
--
72-
-- The 'txid's of all transactions that were added successfully are
73-
-- returned.
74-
mempoolAddTxs :: [tx] -> m [txid]
75-
}
76-
77-
data ProcessedTxCount = ProcessedTxCount {
78-
-- | Just accepted this many transactions.
79-
ptxcAccepted :: Int
80-
-- | Just rejected this many transactions.
81-
, ptxcRejected :: Int
82-
}
83-
deriving (Eq, Show)
84-
85-
data TraceTxSubmissionInbound txid tx =
86-
-- | Number of transactions just about to be inserted.
87-
TraceTxSubmissionCollected Int
88-
-- | Just processed transaction pass/fail breakdown.
89-
| TraceTxSubmissionProcessed ProcessedTxCount
90-
-- | Server received 'MsgDone'
91-
| TraceTxInboundCanRequestMoreTxs Int
92-
| TraceTxInboundCannotRequestMoreTxs Int
93-
94-
--
95-
-- messages emitted by the new implementation of the server in
96-
-- "Ouroboros.Network.TxSubmission.Inbound.Server"; some of them are also
97-
-- used in this module.
98-
--
99-
100-
| TraceTxInboundTerminated
101-
| TraceTxInboundDecision (TxDecision txid tx)
102-
deriving (Eq, Show)
103-
104-
data TxSubmissionProtocolError =
105-
ProtocolErrorTxNotRequested
106-
| ProtocolErrorTxIdsNotRequested
107-
deriving Show
108-
109-
instance Exception TxSubmissionProtocolError where
110-
displayException ProtocolErrorTxNotRequested =
111-
"The peer replied with a transaction we did not ask for."
112-
displayException ProtocolErrorTxIdsNotRequested =
113-
"The peer replied with more txids than we asked for."
11467

11568

11669
-- | Information maintained internally in the 'txSubmissionInbound' server

ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound/Registry.hs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
module Ouroboros.Network.TxSubmission.Inbound.Registry
88
( SharedTxStateVar
99
, newSharedTxStateVar
10+
, TxChannelsVar
11+
, newTxChannelsVar
1012
, PeerTxAPI (..)
1113
, decisionLogicThread
1214
, withPeer
@@ -43,6 +45,9 @@ newtype TxChannels m peeraddr txid tx = TxChannels {
4345

4446
type TxChannelsVar m peeraddr txid tx = StrictMVar m (TxChannels m peeraddr txid tx)
4547

48+
newTxChannelsVar :: MonadMVar m => m (TxChannelsVar m peeraddr txid tx)
49+
newTxChannelsVar = newMVar (TxChannels Map.empty)
50+
4651
-- | API to access `PeerTxState` inside `PeerTxStateVar`.
4752
--
4853
data PeerTxAPI m txid tx = PeerTxAPI {

ouroboros-network/src/Ouroboros/Network/TxSubmission/Inbound/Server.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import Network.TypedProtocol.Pipelined
2222

2323
import Control.Monad (unless)
2424
import Ouroboros.Network.Protocol.TxSubmission2.Server
25-
import Ouroboros.Network.TxSubmission.Inbound (TraceTxSubmissionInbound (..),
26-
TxSubmissionMempoolWriter (..), TxSubmissionProtocolError (..))
25+
import Ouroboros.Network.TxSubmission.Inbound.Types
2726
import Ouroboros.Network.TxSubmission.Inbound.Decision (TxDecision (..))
2827
import Ouroboros.Network.TxSubmission.Inbound.Registry (PeerTxAPI (..))
2928

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module Ouroboros.Network.TxSubmission.Inbound.Types
2+
( ProcessedTxCount (..)
3+
, TxSubmissionMempoolWriter (..)
4+
, TraceTxSubmissionInbound (..)
5+
, TxSubmissionProtocolError (..)
6+
) where
7+
8+
import Control.Exception (Exception (..))
9+
10+
import Ouroboros.Network.TxSubmission.Inbound.Decision (TxDecision (..))
11+
12+
13+
data ProcessedTxCount = ProcessedTxCount {
14+
-- | Just accepted this many transactions.
15+
ptxcAccepted :: Int
16+
-- | Just rejected this many transactions.
17+
, ptxcRejected :: Int
18+
}
19+
deriving (Eq, Show)
20+
21+
22+
-- | The consensus layer functionality that the inbound side of the tx
23+
-- submission logic requires.
24+
--
25+
-- This is provided to the tx submission logic by the consensus layer.
26+
--
27+
data TxSubmissionMempoolWriter txid tx idx m =
28+
TxSubmissionMempoolWriter {
29+
30+
-- | Compute the transaction id from a transaction.
31+
--
32+
-- This is used in the protocol handler to verify a full transaction
33+
-- matches a previously given transaction id.
34+
--
35+
txId :: tx -> txid,
36+
37+
-- | Supply a batch of transactions to the mempool. They are either
38+
-- accepted or rejected individually, but in the order supplied.
39+
--
40+
-- The 'txid's of all transactions that were added successfully are
41+
-- returned.
42+
mempoolAddTxs :: [tx] -> m [txid]
43+
}
44+
45+
46+
data TraceTxSubmissionInbound txid tx =
47+
-- | Number of transactions just about to be inserted.
48+
TraceTxSubmissionCollected Int
49+
-- | Just processed transaction pass/fail breakdown.
50+
| TraceTxSubmissionProcessed ProcessedTxCount
51+
-- | Server received 'MsgDone'
52+
| TraceTxInboundCanRequestMoreTxs Int
53+
| TraceTxInboundCannotRequestMoreTxs Int
54+
55+
--
56+
-- messages emitted by the new implementation of the server in
57+
-- "Ouroboros.Network.TxSubmission.Inbound.Server"; some of them are also
58+
-- used in this module.
59+
--
60+
61+
| TraceTxInboundTerminated
62+
| TraceTxInboundDecision (TxDecision txid tx)
63+
deriving (Eq, Show)
64+
65+
66+
data TxSubmissionProtocolError =
67+
ProtocolErrorTxNotRequested
68+
| ProtocolErrorTxIdsNotRequested
69+
deriving Show
70+
71+
instance Exception TxSubmissionProtocolError where
72+
displayException ProtocolErrorTxNotRequested =
73+
"The peer replied with a transaction we did not ask for."
74+
displayException ProtocolErrorTxIdsNotRequested =
75+
"The peer replied with more txids than we asked for."

0 commit comments

Comments
 (0)