@@ -118,6 +118,13 @@ import Ouroboros.Network.Protocol.TxSubmission2.Codec
118
118
import Ouroboros.Network.Protocol.TxSubmission2.Server
119
119
import Ouroboros.Network.Protocol.TxSubmission2.Type
120
120
import Ouroboros.Network.TxSubmission.Inbound
121
+ import Ouroboros.Network.TxSubmission.Inbound.Policy
122
+ (TxDecisionPolicy (.. ))
123
+ import Ouroboros.Network.TxSubmission.Inbound.Registry (PeerTxAPI ,
124
+ withPeer )
125
+ import Ouroboros.Network.TxSubmission.Inbound.Server
126
+ (EnableNewTxSubmissionProtocol (.. ), txSubmissionInboundV2 )
127
+ import Ouroboros.Network.TxSubmission.Inbound.Types (TraceTxLogic )
121
128
import Ouroboros.Network.TxSubmission.Mempool.Reader
122
129
(mapTxSubmissionMempoolReader )
123
130
import Ouroboros.Network.TxSubmission.Outbound
@@ -168,7 +175,13 @@ data Handlers m addr blk = Handlers {
168
175
, hTxSubmissionServer
169
176
:: NodeToNodeVersion
170
177
-> ConnectionId addr
171
- -> TxSubmissionServerPipelined (GenTxId blk) (GenTx blk) m ()
178
+ -> Either
179
+ (TxSubmissionServerPipelined (GenTxId blk) (GenTx blk) m ())
180
+ (PeerTxAPI m (GenTxId blk) (GenTx blk)
181
+ -> TxSubmissionServerPipelined (GenTxId blk) (GenTx blk) m ())
182
+ -- ^ Either we use the legacy tx submission protocol or the newest one
183
+ -- which require PeerTxAPI. This is decided by
184
+ -- 'EnableNewTxSubmissionProtocol' flag.
172
185
173
186
, hKeepAliveClient
174
187
:: NodeToNodeVersion
@@ -209,10 +222,12 @@ mkHandlers ::
209
222
)
210
223
=> NodeKernelArgs m addrNTN addrNTC blk
211
224
-> NodeKernel m addrNTN addrNTC blk
225
+ -> EnableNewTxSubmissionProtocol
212
226
-> Handlers m addrNTN blk
213
227
mkHandlers
214
228
NodeKernelArgs {chainSyncFutureCheck, chainSyncHistoricityCheck, keepAliveRng, miniProtocolParameters}
215
- NodeKernel {getChainDB, getMempool, getTopLevelConfig, getTracers = tracers, getPeerSharingAPI, getGsmState} =
229
+ NodeKernel {getChainDB, getMempool, getTopLevelConfig, getTracers = tracers, getPeerSharingAPI, getGsmState}
230
+ enableNewTxSubmissionProtocol =
216
231
Handlers {
217
232
hChainSyncClient = \ peer _isBigLedgerpeer dynEnv ->
218
233
CsClient. chainSyncClient
@@ -243,17 +258,32 @@ mkHandlers
243
258
, hTxSubmissionClient = \ version controlMessageSTM peer ->
244
259
txSubmissionOutbound
245
260
(contramap (TraceLabelPeer peer) (Node. txOutboundTracer tracers))
246
- (NumTxIdsToAck $ txSubmissionMaxUnacked miniProtocolParameters)
261
+ (NumTxIdsToAck $ getNumTxIdsToReq
262
+ $ maxUnacknowledgedTxIds
263
+ $ txDecisionPolicy
264
+ $ miniProtocolParameters)
247
265
(mapTxSubmissionMempoolReader txForgetValidated $ getMempoolReader getMempool)
248
266
version
249
267
controlMessageSTM
250
268
, hTxSubmissionServer = \ version peer ->
251
- txSubmissionInbound
252
- (contramap (TraceLabelPeer peer) (Node. txInboundTracer tracers))
253
- (NumTxIdsToAck $ txSubmissionMaxUnacked miniProtocolParameters)
254
- (mapTxSubmissionMempoolReader txForgetValidated $ getMempoolReader getMempool)
255
- (getMempoolWriter getMempool)
256
- version
269
+ case enableNewTxSubmissionProtocol of
270
+ EnableNewTxSubmissionProtocol ->
271
+ Right $ \ api ->
272
+ txSubmissionInboundV2
273
+ (contramap (TraceLabelPeer peer) (Node. txInboundTracer tracers))
274
+ (getMempoolWriter getMempool)
275
+ api
276
+ DisableNewTxSubmissionProtocol ->
277
+ Left
278
+ $ txSubmissionInbound
279
+ (contramap (TraceLabelPeer peer) (Node. txInboundTracer tracers))
280
+ (NumTxIdsToAck $ getNumTxIdsToReq
281
+ $ maxUnacknowledgedTxIds
282
+ $ txDecisionPolicy
283
+ $ miniProtocolParameters)
284
+ (mapTxSubmissionMempoolReader txForgetValidated $ getMempoolReader getMempool)
285
+ (getMempoolWriter getMempool)
286
+ version
257
287
, hKeepAliveClient = \ _version -> keepAliveClient (Node. keepAliveClientTracer tracers) keepAliveRng
258
288
, hKeepAliveServer = \ _version _peer -> keepAliveServer
259
289
, hPeerSharingClient = \ _version controlMessageSTM _peer -> peerSharingClient controlMessageSTM
@@ -375,6 +405,7 @@ data Tracers' peer blk e f = Tracers {
375
405
, tBlockFetchTracer :: f (TraceLabelPeer peer (TraceSendRecv (BlockFetch blk (Point blk ))))
376
406
, tBlockFetchSerialisedTracer :: f (TraceLabelPeer peer (TraceSendRecv (BlockFetch (Serialised blk ) (Point blk ))))
377
407
, tTxSubmission2Tracer :: f (TraceLabelPeer peer (TraceSendRecv (TxSubmission2 (GenTxId blk ) (GenTx blk ))))
408
+ , tTxLogicTracer :: f (TraceLabelPeer peer (TraceTxLogic peer (GenTxId blk ) (GenTx blk )))
378
409
}
379
410
380
411
instance (forall a . Semigroup (f a )) => Semigroup (Tracers' peer blk e f ) where
@@ -384,6 +415,7 @@ instance (forall a. Semigroup (f a)) => Semigroup (Tracers' peer blk e f) where
384
415
, tBlockFetchTracer = f tBlockFetchTracer
385
416
, tBlockFetchSerialisedTracer = f tBlockFetchSerialisedTracer
386
417
, tTxSubmission2Tracer = f tTxSubmission2Tracer
418
+ , tTxLogicTracer = f tTxLogicTracer
387
419
}
388
420
where
389
421
f :: forall a . Semigroup a
@@ -399,6 +431,7 @@ nullTracers = Tracers {
399
431
, tBlockFetchTracer = nullTracer
400
432
, tBlockFetchSerialisedTracer = nullTracer
401
433
, tTxSubmission2Tracer = nullTracer
434
+ , tTxLogicTracer = nullTracer
402
435
}
403
436
404
437
showTracers :: ( Show blk
@@ -416,6 +449,7 @@ showTracers tr = Tracers {
416
449
, tBlockFetchTracer = showTracing tr
417
450
, tBlockFetchSerialisedTracer = showTracing tr
418
451
, tTxSubmission2Tracer = showTracing tr
452
+ , tTxLogicTracer = showTracing tr
419
453
}
420
454
421
455
{- ------------------------------------------------------------------------------
@@ -533,7 +567,7 @@ mkApps ::
533
567
, ShowProxy blk
534
568
, ShowProxy (Header blk )
535
569
, ShowProxy (TxId (GenTx blk ))
536
- , ShowProxy (GenTx blk )
570
+ , ShowProxy (GenTx blk ), HasTxId ( GenTx blk ), LedgerSupportsMempool blk , Show addrNTN
537
571
)
538
572
=> NodeKernel m addrNTN addrNTC blk -- ^ Needed for bracketing only
539
573
-> Tracers m (ConnectionId addrNTN ) blk e
@@ -695,13 +729,27 @@ mkApps kernel Tracers {..} mkCodecs ByteLimits {..} genChainSyncTimeout lopBucke
695
729
-> m (() , Maybe bTX )
696
730
aTxSubmission2Server version ResponderContext { rcConnectionId = them } channel = do
697
731
labelThisThread " TxSubmissionServer"
698
- runPipelinedPeerWithLimits
699
- (contramap (TraceLabelPeer them) tTxSubmission2Tracer)
700
- (cTxSubmission2Codec (mkCodecs version))
701
- blTxSubmission2
702
- timeLimitsTxSubmission2
703
- channel
704
- (txSubmissionServerPeerPipelined (hTxSubmissionServer version them))
732
+
733
+ let runServer serverApi =
734
+ runPipelinedPeerWithLimits
735
+ (contramap (TraceLabelPeer them) tTxSubmission2Tracer)
736
+ (cTxSubmission2Codec (mkCodecs version))
737
+ blTxSubmission2
738
+ timeLimitsTxSubmission2
739
+ channel
740
+ (txSubmissionServerPeerPipelined serverApi)
741
+
742
+ case hTxSubmissionServer version them of
743
+ Left legacyTxSubmissionServer ->
744
+ runServer legacyTxSubmissionServer
745
+ Right newTxSubmissionServer ->
746
+ withPeer (contramap (TraceLabelPeer them) tTxLogicTracer)
747
+ (getTxChannelsVar kernel)
748
+ (getSharedTxStateVar kernel)
749
+ (mapTxSubmissionMempoolReader txForgetValidated
750
+ $ getMempoolReader (getMempool kernel))
751
+ them $ \ api ->
752
+ runServer (newTxSubmissionServer api)
705
753
706
754
aKeepAliveClient
707
755
:: NodeToNodeVersion
0 commit comments