Skip to content
Permalink
Browse files

Trace an event for each tx instead of one event containing a list

Otherwise, we would have to check whether the list is empty or not, because
constantly tracing `TraceMempoolRemoveTxs` with an empty list is silly (which
is happening now). The `mapM_` function will now take care of the empty list
case for us.
  • Loading branch information...
mrBliss committed Jul 12, 2019
1 parent 8456d4f commit dbe754a3a188d73701254f5556cad8eb9281e056
@@ -208,27 +208,27 @@ data MempoolSnapshot txid tx idx = MempoolSnapshot {

-- | Events traced by the Mempool.
data TraceEventMempool blk
= TraceMempoolAddTxs
{ _txs :: [GenTx blk]
-- ^ New, valid transaction were added to the Mempool.
, _txsInMempool :: Word64
-- ^ The total number of transactions now in the Mempool.
= TraceMempoolAddTx
{ _txsInMempool :: Word64
-- ^ The total number of transactions now in the Mempool
, _tx :: (GenTx blk)
-- ^ A new, valid transaction was added to the Mempool..
}

| TraceMempoolRejectedTxs
{ _txs :: [GenTx blk]
-- ^ New, invalid transaction were rejected and thus not added to the
-- Mempool.
, _txsInMempool :: Word64
-- ^ The total number of transactions now in the Mempool.
| TraceMempoolRejectedTx
{ _txsInMempool :: Word64
-- ^ The total number of transactions now in the Mempool
, _tx :: (GenTx blk)
-- ^ A new, invalid transaction was rejected and thus not added to the
-- Mempool..
}
| TraceMempoolRemoveTxs
{ _txs :: [GenTx blk]
-- ^ Previously valid transactions that are no longer valid because of
-- changes in the ledger state. These transactions have been removed
-- from the Mempool.
, _txsInMempool :: Word64
-- ^ The total number of transactions now in the Mempool.
| TraceMempoolRemoveTx
{ _txsInMempool :: Word64
-- ^ The total number of transactions now in the Mempool
, _tx :: (GenTx blk)
-- ^ A previously valid transaction that is no longer valid because of
-- changes in the ledger state. This transaction has been removed from
-- the Mempool..
}

deriving instance Eq (GenTx blk) => Eq (TraceEventMempool blk)
@@ -129,14 +129,14 @@ implAddTxs mpEnv@MempoolEnv{mpEnvStateVar, mpEnvLedgerCfg, mpEnvTracer} txs = do
mempoolSize <- getMempoolSize mpEnv
return (removed, accepted, rejected, mempoolSize)

trace $ TraceMempoolRemoveTxs (map fst removed) mempoolSize
trace $ TraceMempoolAddTxs accepted mempoolSize
trace $ TraceMempoolRejectedTxs (map fst rejected) mempoolSize
traceAll (TraceMempoolRemoveTx mempoolSize) (map fst removed)
traceAll (TraceMempoolAddTx mempoolSize) accepted
traceAll (TraceMempoolRejectedTx mempoolSize) (map fst rejected)

return $ [(tx, Just err) | (tx, err) <- rejected] ++
zip accepted (repeat Nothing)
where
trace = traceWith mpEnvTracer
traceAll mkEv = mapM_ (traceWith mpEnvTracer . mkEv)

-- | We first reset 'vrInvalid' to an empty list such that afterwards it
-- will only contain the /new/ invalid transactions.
@@ -158,7 +158,7 @@ implSyncState mpEnv@MempoolEnv{mpEnvTracer, mpEnvStateVar} = do
-- transactions.
mempoolSize <- getMempoolSize mpEnv
return (map fst vrInvalid, mempoolSize)
traceWith mpEnvTracer $ TraceMempoolRemoveTxs removed mempoolSize
mapM_ (traceWith mpEnvTracer . TraceMempoolRemoveTx mempoolSize) removed

implGetSnapshot :: ( MonadSTM m
, ApplyTx blk

0 comments on commit dbe754a

Please sign in to comment.
You can’t perform that action at this time.