Skip to content

Commit

Permalink
Trace transaction requests and replies in txSubmissionOutbound
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate committed Feb 24, 2020
1 parent ccc8eb1 commit c9106de
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ouroboros-network/src/Ouroboros/Network/TxSubmission/Outbound.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Control.Monad (when, unless)
import Control.Monad.Class.MonadSTM
import Control.Monad.Class.MonadThrow
import Control.Exception (Exception(..), assert)
import Control.Tracer (Tracer)
import Control.Tracer (Tracer, traceWith)

import Ouroboros.Network.Protocol.TxSubmission.Client

Expand Down Expand Up @@ -69,7 +69,13 @@ data MempoolSnapshot txid tx idx =
mempoolLookupTx :: idx -> Maybe tx
}

data TraceTxSubmissionOutbound txid tx = TraceTxSubmissionOutbound --TODO
data TraceTxSubmissionOutbound txid tx
= TraceTxSubmissionOutboundRecvMsgRequestTxs
![txid]
-- ^ The IDs of the transactions requested.
| TraceTxSubmissionOutboundSendMsgReplyTxs
![tx]
-- ^ The transactions to be sent in the response.
deriving Show

data TxSubmissionProtocolError =
Expand Down Expand Up @@ -112,7 +118,7 @@ txSubmissionOutbound
-> Word16 -- ^ Maximum number of unacknowledged txids allowed
-> TxSubmissionMempoolReader txid tx idx m
-> TxSubmissionClient txid tx m void
txSubmissionOutbound _tracer maxUnacked TxSubmissionMempoolReader{..} =
txSubmissionOutbound tracer maxUnacked TxSubmissionMempoolReader{..} =
TxSubmissionClient (pure (client Seq.empty Map.empty mempoolZeroIdx))
where
client :: StrictSeq txid -> Map txid idx -> idx -> ClientStIdle txid tx m void
Expand Down Expand Up @@ -203,6 +209,9 @@ txSubmissionOutbound _tracer maxUnacked TxSubmissionMempoolReader{..} =
recvMsgRequestTxs :: [txid]
-> m (ClientStTxs txid tx m void)
recvMsgRequestTxs txids = do
-- Trace the IDs of the transactions requested.
traceWith tracer (TraceTxSubmissionOutboundRecvMsgRequestTxs txids)

MempoolSnapshot{mempoolLookupTx} <- atomically mempoolGetSnapshot

let txidxs = [ Map.lookup txid unackedMap | txid <- txids ]
Expand All @@ -218,4 +227,7 @@ txSubmissionOutbound _tracer maxUnacked TxSubmissionMempoolReader{..} =
!unackedMap' = foldl' (flip Map.delete) unackedMap txids
client' = client unackedSeq unackedMap' lastIdx

-- Trace the transactions to be sent in the response.
traceWith tracer (TraceTxSubmissionOutboundSendMsgReplyTxs txs)

return $ SendMsgReplyTxs txs client'

0 comments on commit c9106de

Please sign in to comment.