Skip to content

Commit 22a7bc2

Browse files
committed
tx-submission: added DebugTxLogic tracer
Module structure needs to be reorganised to have just one debug tracer.
1 parent fda2141 commit 22a7bc2

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ import Ouroboros.Network.PeerSelection.RootPeersDNS.DNSActions (DNSLookupType)
107107
import Ouroboros.Network.PeerSelection.State.LocalRootPeers (HotValency,
108108
WarmValency)
109109
import Ouroboros.Network.TxSubmission.Inbound.Policy (TxDecisionPolicy)
110-
import Ouroboros.Network.TxSubmission.Inbound.Registry (decisionLogicThread)
110+
import Ouroboros.Network.TxSubmission.Inbound.Registry (DebugTxLogic,
111+
decisionLogicThread)
111112
import Ouroboros.Network.TxSubmission.Inbound.State (DebugSharedTxState)
112113
import Ouroboros.Network.TxSubmission.Inbound.Types (TraceTxSubmissionInbound)
113114
import Test.Ouroboros.Network.Diffusion.Node.ChainDB (addBlock,
@@ -205,8 +206,9 @@ run :: forall resolver m.
205206
-> Tracer m (TraceLabelPeer NtNAddr (TraceFetchClientState BlockHeader))
206207
-> Tracer m (TraceTxSubmissionInbound Int (Tx Int))
207208
-> Tracer m (DebugSharedTxState NtNAddr Int (Tx Int))
209+
-> Tracer m (DebugTxLogic NtNAddr Int (Tx Int))
208210
-> m Void
209-
run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch tracerTxSubmissionInbound tracerTxSubmissionDebug =
211+
run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch tracerTxSubmissionInbound tracerTxSubmissionDebug tracerTxLogic =
210212
Node.withNodeKernelThread blockGeneratorArgs (aTxs na)
211213
$ \ nodeKernel nodeKernelThread -> do
212214
dnsTimeoutScriptVar <- newTVarIO (aDNSTimeoutScript na)
@@ -292,7 +294,7 @@ run blockGeneratorArgs limits ni na tracersExtra tracerBlockFetch tracerTxSubmis
292294
withAsync (blockFetch nodeKernel) $ \blockFetchLogicThread ->
293295

294296
withAsync (decisionLogicThread
295-
tracerTxSubmissionDebug
297+
tracerTxLogic
296298
(aTxDecisionPolicy na)
297299
(readPeerGSVs (nkFetchClientRegistry nodeKernel))
298300
(nkTxChannelsVar nodeKernel)

ouroboros-network/sim-tests-lib/Test/Ouroboros/Network/Testnet/Simulation/Node.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ import Ouroboros.Network.Protocol.PeerSharing.Codec (byteLimitsPeerSharing,
144144
import Ouroboros.Network.Protocol.TxSubmission2.Codec (byteLimitsTxSubmission2,
145145
timeLimitsTxSubmission2)
146146
import Ouroboros.Network.TxSubmission.Inbound.Policy (TxDecisionPolicy)
147+
import Ouroboros.Network.TxSubmission.Inbound.Registry (DebugTxLogic)
147148
import Ouroboros.Network.TxSubmission.Inbound.State (DebugSharedTxState)
148149
import Ouroboros.Network.TxSubmission.Inbound.Types (TraceTxSubmissionInbound)
149150
import Test.Ouroboros.Network.LedgerPeers (LedgerPools (..), genLedgerPoolsFrom)
@@ -1004,6 +1005,7 @@ data DiffusionTestTrace =
10041005
| DiffusionFetchTrace (TraceFetchClientState BlockHeader)
10051006
| DiffusionTxSubmissionInbound (TraceTxSubmissionInbound Int (Tx Int))
10061007
| DiffusionTxSubmissionDebug (DebugSharedTxState NtNAddr Int (Tx Int))
1008+
| DiffusionTxLogicDebug (DebugTxLogic NtNAddr Int (Tx Int))
10071009
| DiffusionDebugTrace String
10081010
deriving (Show)
10091011

@@ -1307,6 +1309,10 @@ diffusionSimulation
13071309
. tracerWithName addr
13081310
. tracerWithTime
13091311
$ nodeTracer)
1312+
( contramap DiffusionTxLogicDebug
1313+
. tracerWithName addr
1314+
. tracerWithTime
1315+
$ nodeTracer)
13101316

13111317
domainResolver :: StrictTVar m (Map Domain [(IP, TTL)])
13121318
-> DNSLookupType

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,15 @@ runTxSubmissionV2
138138
)
139139
=> Tracer m (String, TraceSendRecv (TxSubmission2 txid (Tx txid)))
140140
-> Tracer m (DebugSharedTxState peeraddr txid (Tx txid))
141+
-> Tracer m (DebugTxLogic peeraddr txid (Tx txid))
141142
-> Map peeraddr ( [Tx txid]
142143
, ControlMessageSTM m
143144
, Maybe DiffTime
144145
, Maybe DiffTime
145146
)
146147
-> TxDecisionPolicy
147148
-> m ([Tx txid], [[Tx txid]])
148-
runTxSubmissionV2 tracer tracerDST state txDecisionPolicy = do
149+
runTxSubmissionV2 tracer tracerDST tracerTxLogic state txDecisionPolicy = do
149150

150151
state' <- traverse (\(b, c, d, e) -> do
151152
mempool <- newMempool b
@@ -190,10 +191,10 @@ runTxSubmissionV2 tracer tracerDST state txDecisionPolicy = do
190191
-> m b
191192
runTxSubmission st txChannelsVar sharedTxStateVar
192193
inboundMempool gsvVar k =
193-
withAsync (decisionLogicThread tracerDST txDecisionPolicy (Strict.readTVar gsvVar) txChannelsVar sharedTxStateVar) $ \a -> do
194+
withAsync (decisionLogicThread tracerTxLogic txDecisionPolicy (Strict.readTVar gsvVar) txChannelsVar sharedTxStateVar) $ \a -> do
194195
-- Construct txSubmission outbound client
195196
let clients = (\(addr, (mempool, ctrlMsgSTM, outDelay, _, outChannel, _)) -> do
196-
let client = txSubmissionOutbound verboseTracer
197+
let client = txSubmissionOutbound (Tracer $ say . show)
197198
(NumTxIdsToAck $ getNumTxIdsToReq
198199
$ maxUnacknowledgedTxIds
199200
$ txDecisionPolicy)
@@ -274,9 +275,9 @@ txSubmissionV2Simulation (TxSubmissionV2State state txDecisionPolicy) = do
274275
threadDelay (simDelayTime + 1000)
275276
atomically (traverse_ (`writeTVar` Terminate) controlMessageVars)
276277

277-
let tracer = verboseTracer <> debugTracer
278-
tracer' = verboseTracer <> debugTracer
279-
runTxSubmissionV2 tracer tracer' state'' txDecisionPolicy
278+
let tracer :: forall a. Show a => Tracer (IOSim s) a
279+
tracer = verboseTracer <> debugTracer
280+
runTxSubmissionV2 tracer tracer tracer state'' txDecisionPolicy
280281

281282
-- | Tests overall tx submission semantics. The properties checked in this
282283
-- property test are the same as for tx submission v1. We need this to know we

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ module Ouroboros.Network.TxSubmission.Inbound.Registry
1212
, newTxChannelsVar
1313
, PeerTxAPI (..)
1414
, decisionLogicThread
15+
, DebugTxLogic (..)
1516
, withPeer
1617
) where
1718

1819
import Control.Concurrent.Class.MonadMVar.Strict
1920
import Control.Concurrent.Class.MonadSTM.Strict
21+
import Control.Monad.Class.MonadFork
2022
import Control.Monad.Class.MonadThrow
2123
import Control.Monad.Class.MonadTimer.SI
2224

23-
import Data.Foldable (foldl', traverse_)
25+
import Data.Foldable (traverse_)
2426
import Data.Map.Strict (Map)
2527
import Data.Map.Strict qualified as Map
2628
import Data.Maybe (fromMaybe)
@@ -211,22 +213,32 @@ withPeer tracer
211213
collectTxs tracer sharedStateVar peeraddr txids txs
212214

213215

216+
-- | TODO: reorganise modules so there's just one `Debug` tracer.
217+
data DebugTxLogic peeraddr txid tx =
218+
DebugTxLogicSharedTxState (SharedTxState peeraddr txid tx)
219+
| DebugTxLogicDecisions (Map peeraddr (TxDecision txid tx))
220+
deriving Show
221+
222+
214223
decisionLogicThread
215224
:: forall m peeraddr txid tx.
216225
( MonadDelay m
217226
, MonadMVar m
218227
, MonadSTM m
219-
, MonadMask m
228+
, MonadMask m
229+
, MonadFork m
220230
, Ord peeraddr
221231
, Ord txid
222232
)
223-
=> Tracer m (DebugSharedTxState peeraddr txid tx)
233+
=> Tracer m (DebugTxLogic peeraddr txid tx)
224234
-> TxDecisionPolicy
225235
-> STM m (Map peeraddr PeerGSV)
226236
-> TxChannelsVar m peeraddr txid tx
227237
-> SharedTxStateVar m peeraddr txid tx
228238
-> m Void
229-
decisionLogicThread tracer policy readGSVVar txChannelsVar sharedStateVar = go
239+
decisionLogicThread tracer policy readGSVVar txChannelsVar sharedStateVar = do
240+
labelThisThread "tx-decision"
241+
go
230242
where
231243
go :: m Void
232244
go = do
@@ -247,7 +259,8 @@ decisionLogicThread tracer policy readGSVVar txChannelsVar sharedStateVar = go
247259
let (sharedState, decisions) = makeDecisions policy sharedCtx activePeers
248260
writeTVar sharedStateVar sharedState
249261
return (decisions, sharedState)
250-
traceWith tracer (DebugSharedTxState "decisionLogicThread" st)
262+
traceWith tracer (DebugTxLogicSharedTxState st)
263+
traceWith tracer (DebugTxLogicDecisions decisions)
251264
TxChannels { txChannelMap } <- readMVar txChannelsVar
252265
traverse_
253266
(\(mvar, d) -> modifyMVarWithDefault_ mvar d (\d' -> pure (d' <> d)))

0 commit comments

Comments
 (0)