Skip to content

Commit 5904cbf

Browse files
nfrisbypalas
authored andcommitted
Integrate the TraceMempoolRejectedTx fix
1 parent 30ecaad commit 5904cbf

File tree

4 files changed

+19
-70
lines changed

4 files changed

+19
-70
lines changed

cardano-node/src/Cardano/Node/TraceConstraints.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,4 @@ type TraceConstraints blk =
7474
, LogFormatting (ForgeStateUpdateError blk)
7575
, LogFormatting (Set (Credential 'Staking))
7676
, LogFormatting (NonEmpty.NonEmpty (KeyHash 'Staking))
77-
78-
, ConsensusTracers.MempoolTimeoutSoftPredicate blk
7977
)

cardano-node/src/Cardano/Node/Tracing/Tracers/Consensus.hs

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ module Cardano.Node.Tracing.Tracers.Consensus
2020
, servedBlockLatest
2121
, ClientMetrics
2222
, txsMempoolTimeoutSoftCounterName
23-
, MempoolTimeoutSoftPredicate (..)
24-
, EraMempoolTimeoutSoftPredicate (..)
2523
, impliesMempoolTimeoutSoft
2624
) where
2725

@@ -48,7 +46,8 @@ import Ouroboros.Consensus.Ledger.Inspect (LedgerEvent (..), LedgerUpd
4846
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, ByteSize32 (..), GenTxId,
4947
HasTxId, LedgerSupportsMempool, txForgetValidated, txId)
5048
import Ouroboros.Consensus.Ledger.SupportsProtocol
51-
import Ouroboros.Consensus.Mempool (MempoolSize (..), TraceEventMempool (..))
49+
import Ouroboros.Consensus.Mempool (MempoolRejectionDetails (..), MempoolSize (..),
50+
TraceEventMempool (..), jsonMempoolRejectionDetails)
5251
import Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
5352
(TraceBlockFetchServerEvent (..))
5453
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client
@@ -83,23 +82,11 @@ import Data.Int (Int64)
8382
import Data.IntPSQ (IntPSQ)
8483
import qualified Data.IntPSQ as Pq
8584
import qualified Data.List as List
86-
import qualified Data.List.NonEmpty as NE
8785
import qualified Data.Text as Text
8886
import Data.Time (NominalDiffTime)
8987
import Data.Word (Word32, Word64)
9088
import Network.TypedProtocol.Core
9189

92-
93-
-- all for MempoolTimeoutSoftPredicate
94-
import qualified Cardano.Ledger.Conway.Rules as Conway
95-
import qualified Cardano.Ledger.Core as SL (EraRule)
96-
import qualified Cardano.Ledger.Shelley.API as SL (ApplyTxError (..))
97-
import qualified Data.SOP as SOP
98-
import Ouroboros.Consensus.Byron.Ledger.Block as Consensus
99-
import Ouroboros.Consensus.HardFork.Combinator as Consensus
100-
import Ouroboros.Consensus.Shelley.Ledger.Block as Consensus
101-
import Ouroboros.Consensus.TypeFamilyWrappers as Consensus
102-
10390
instance (LogFormatting adr, Show adr) => LogFormatting (ConnectionId adr) where
10491
forMachine _dtal (ConnectionId local' remote) =
10592
mconcat [ "connectionId" .= String (showT local'
@@ -1260,71 +1247,36 @@ instance MetaTrace (TraceLocalTxSubmissionServerEvent blk) where
12601247
txsMempoolTimeoutSoftCounterName :: Text.Text
12611248
txsMempoolTimeoutSoftCounterName = "txsMempoolTimeoutSoft"
12621249

1263-
impliesMempoolTimeoutSoft ::
1264-
forall blk. MempoolTimeoutSoftPredicate blk => TraceEventMempool blk -> Bool
1250+
impliesMempoolTimeoutSoft :: TraceEventMempool blk -> Bool
12651251
impliesMempoolTimeoutSoft = \case
1266-
TraceMempoolRejectedTx _tx txApplyErr _mpSz ->
1267-
errImpliesMempoolTimeoutSoft (Proxy @blk) txApplyErr
1252+
TraceMempoolRejectedTx _tx _txApplyErr details _mpSz ->
1253+
case details of
1254+
MempoolRejectedByTimeoutSoft{} -> True
1255+
MempoolRejectedByLedger -> False
12681256
_ -> False
12691257

1270-
class MempoolTimeoutSoftPredicate blk where
1271-
-- | Does the error indicate a mempool timeout
1272-
errImpliesMempoolTimeoutSoft :: proxy blk -> ApplyTxErr blk -> Bool
1273-
1274-
instance SOP.All MempoolTimeoutSoftPredicate xs => MempoolTimeoutSoftPredicate (Consensus.HardForkBlock xs) where
1275-
errImpliesMempoolTimeoutSoft _prx = \case
1276-
Consensus.HardForkApplyTxErrWrongEra{} -> False
1277-
Consensus.HardForkApplyTxErrFromEra (Consensus.OneEraApplyTxErr ns) ->
1278-
SOP.hcollapse $ SOP.hcmap (Proxy @MempoolTimeoutSoftPredicate) f ns
1279-
where
1280-
f :: forall x. MempoolTimeoutSoftPredicate x => Consensus.WrapApplyTxErr x -> SOP.K Bool x
1281-
f (Consensus.WrapApplyTxErr err) = SOP.K $ errImpliesMempoolTimeoutSoft (Proxy @x) err
1282-
1283-
instance MempoolTimeoutSoftPredicate Consensus.ByronBlock where
1284-
errImpliesMempoolTimeoutSoft = \_prx _err -> False
1285-
1286-
instance EraMempoolTimeoutSoftPredicate era => MempoolTimeoutSoftPredicate (Consensus.ShelleyBlock proto era) where
1287-
errImpliesMempoolTimeoutSoft _prx = \case
1288-
SL.ApplyTxError (err NE.:| errs) ->
1289-
null errs && eraImpliesMempoolTimeoutSoft (Proxy @era) err
1290-
1291-
class EraMempoolTimeoutSoftPredicate era where
1292-
-- | Does the error indicate a mempool timeout
1293-
eraImpliesMempoolTimeoutSoft :: proxy era -> Conway.PredicateFailure (SL.EraRule "LEDGER" era) -> Bool
1294-
1295-
instance EraMempoolTimeoutSoftPredicate ShelleyEra where eraImpliesMempoolTimeoutSoft _prx _err = False
1296-
instance EraMempoolTimeoutSoftPredicate AllegraEra where eraImpliesMempoolTimeoutSoft _prx _err = False
1297-
instance EraMempoolTimeoutSoftPredicate MaryEra where eraImpliesMempoolTimeoutSoft _prx _err = False
1298-
instance EraMempoolTimeoutSoftPredicate AlonzoEra where eraImpliesMempoolTimeoutSoft _prx _err = False
1299-
instance EraMempoolTimeoutSoftPredicate BabbageEra where eraImpliesMempoolTimeoutSoft _prx _err = False
1300-
instance EraMempoolTimeoutSoftPredicate ConwayEra where
1301-
eraImpliesMempoolTimeoutSoft _prx = \case
1302-
Conway.ConwayMempoolFailure txt -> Text.pack "MempoolTxTooSlow" `Text.isPrefixOf` txt
1303-
_ -> False
1304-
instance EraMempoolTimeoutSoftPredicate DijkstraEra where eraImpliesMempoolTimeoutSoft _prx _err = False
1305-
13061258
instance
13071259
( LogFormatting (ApplyTxErr blk)
13081260
, LogFormatting (GenTx blk)
13091261
, ToJSON (GenTxId blk)
13101262
, LedgerSupportsMempool blk
13111263
, ConvertRawHash blk
1312-
, MempoolTimeoutSoftPredicate blk
13131264
) => LogFormatting (TraceEventMempool blk) where
13141265
forMachine dtal (TraceMempoolAddedTx tx _mpSzBefore mpSzAfter) =
13151266
mconcat
13161267
[ "kind" .= String "TraceMempoolAddedTx"
13171268
, "tx" .= forMachine dtal (txForgetValidated tx)
13181269
, "mempoolSize" .= forMachine dtal mpSzAfter
13191270
]
1320-
forMachine dtal (TraceMempoolRejectedTx tx txApplyErr _ mpSz) =
1271+
forMachine dtal (TraceMempoolRejectedTx tx txApplyErr details mpSz) =
13211272
mconcat $
13221273
[ "kind" .= String "TraceMempoolRejectedTx"
13231274
, "tx" .= forMachine dtal tx
13241275
, "mempoolSize" .= forMachine dtal mpSz
13251276
] <>
1277+
if dtal < DDetailed then [] else
13261278
[ "err" .= forMachine dtal txApplyErr
1327-
| dtal >= DDetailed
1279+
, "errdetails" .= jsonMempoolRejectionDetails details
13281280
]
13291281
forMachine dtal (TraceMempoolRemoveTxs txs mpSz) =
13301282
mconcat
@@ -1374,7 +1326,7 @@ instance
13741326
[ IntM "txsInMempool" (fromIntegral $ msNumTxs mpSz)
13751327
, IntM "mempoolBytes" (fromIntegral . unByteSize32 . msNumBytes $ mpSz)
13761328
]
1377-
asMetrics ev@(TraceMempoolRejectedTx _tx _txApplyErr mpSz) =
1329+
asMetrics ev@(TraceMempoolRejectedTx _tx _txApplyErr _details mpSz) =
13781330
[ IntM "txsInMempool" (fromIntegral $ msNumTxs mpSz)
13791331
, IntM "mempoolBytes" (fromIntegral . unByteSize32 . msNumBytes $ mpSz)
13801332
]

cardano-node/src/Cardano/Tracing/OrphanInstances/Consensus.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ import Ouroboros.Consensus.Ledger.Inspect (InspectLedger, LedgerEvent
4444
import Ouroboros.Consensus.Ledger.SupportsMempool (ApplyTxErr, ByteSize32 (..), GenTx,
4545
GenTxId, HasTxId, LedgerSupportsMempool, TxId, txForgetValidated, txId)
4646
import Ouroboros.Consensus.Ledger.SupportsProtocol (LedgerSupportsProtocol)
47-
import Ouroboros.Consensus.Mempool (MempoolSize (..), TraceEventMempool (..))
47+
import Ouroboros.Consensus.Mempool (MempoolSize (..), TraceEventMempool (..),
48+
jsonMempoolRejectionDetails)
4849
import Ouroboros.Consensus.MiniProtocol.BlockFetch.Server
4950
(TraceBlockFetchServerEvent (..))
5051
import Ouroboros.Consensus.MiniProtocol.ChainSync.Client (TraceChainSyncClientEvent (..))
@@ -1543,14 +1544,15 @@ instance ( ToObject (ApplyTxErr blk), ToObject (GenTx blk),
15431544
, "tx" .= toObject verb (txForgetValidated tx)
15441545
, "mempoolSize" .= toObject verb mpSzAfter
15451546
]
1546-
toObject verb (TraceMempoolRejectedTx tx txApplyErr _ mpSz) =
1547+
toObject verb (TraceMempoolRejectedTx tx txApplyErr details mpSz) =
15471548
mconcat $
15481549
[ "kind" .= String "TraceMempoolRejectedTx"
15491550
, "tx" .= toObject verb tx
15501551
, "mempoolSize" .= toObject verb mpSz
15511552
] <>
1553+
if verb /= MaximalVerbosity then [] else
15521554
[ "err" .= toObject verb txApplyErr
1553-
| verb == MaximalVerbosity
1555+
, "errdetails" .= jsonMempoolRejectionDetails details
15541556
]
15551557
toObject verb (TraceMempoolRemoveTxs txs mpSz) =
15561558
mconcat

cardano-node/src/Cardano/Tracing/Tracers.hs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ mkConsensusTracers
758758
, ToObject (ValidationErr (BlockProtocol blk))
759759
, ToObject (ForgeStateUpdateError blk)
760760
, Consensus.RunNode blk
761-
, ConsensusTracers.MempoolTimeoutSoftPredicate blk
762761
, HasKESMetricsData blk
763762
, HasKESInfo blk
764763
)
@@ -1273,8 +1272,7 @@ notifyBlockForging fStats tr = Tracer $ \case
12731272
--------------------------------------------------------------------------------
12741273

12751274
notifyTxsMempoolTimeoutSoft ::
1276-
ConsensusTracers.MempoolTimeoutSoftPredicate blk
1277-
=> Maybe EKGDirect
1275+
Maybe EKGDirect
12781276
-> Tracer IO (TraceEventMempool blk)
12791277
notifyTxsMempoolTimeoutSoft mbEKGDirect = case mbEKGDirect of
12801278
Nothing -> nullTracer
@@ -1302,9 +1300,9 @@ mempoolMetricsTraceTransformer :: Trace IO a -> Tracer IO (TraceEventMempool blk
13021300
mempoolMetricsTraceTransformer tr = Tracer $ \mempoolEvent -> do
13031301
let tr' = appendName "metrics" tr
13041302
(_n, tot_m) = case mempoolEvent of
1305-
TraceMempoolAddedTx _tx0 _ tot0 -> (1, Just tot0)
1303+
TraceMempoolAddedTx _tx0 _ tot0 -> (1, Just tot0)
13061304
TraceMempoolRejectedTx _tx0 _ _ tot0 -> (1, Just tot0)
1307-
TraceMempoolRemoveTxs txs0 tot0 -> (length txs0, Just tot0)
1305+
TraceMempoolRemoveTxs txs0 tot0 -> (length txs0, Just tot0)
13081306
TraceMempoolManuallyRemovedTxs txs0 txs1 tot0 -> ( length txs0 + length txs1, Just tot0)
13091307
TraceMempoolSynced _ -> (0, Nothing)
13101308
_ -> (0, Nothing)
@@ -1324,7 +1322,6 @@ mempoolTracer
13241322
, ToObject (ApplyTxErr blk)
13251323
, ToObject (GenTx blk)
13261324
, LedgerSupportsMempool blk
1327-
, ConsensusTracers.MempoolTimeoutSoftPredicate blk
13281325
, ConvertRawHash blk
13291326
)
13301327
=> Maybe EKGDirect

0 commit comments

Comments
 (0)