1+ {-# LANGUAGE DataKinds #-}
12{-# LANGUAGE FlexibleContexts #-}
23{-# LANGUAGE FlexibleInstances #-}
34{-# LANGUAGE LambdaCase #-}
@@ -19,6 +20,8 @@ module Cardano.Node.Tracing.Tracers.Consensus
1920 , servedBlockLatest
2021 , ClientMetrics
2122 , txsMempoolTimeoutSoftCounterName
23+ , MempoolTimeoutSoftPredicate (.. )
24+ , EraMempoolTimeoutSoftPredicate (.. )
2225 , impliesMempoolTimeoutSoft
2326 ) where
2427
@@ -80,12 +83,23 @@ import Data.Int (Int64)
8083import Data.IntPSQ (IntPSQ )
8184import qualified Data.IntPSQ as Pq
8285import qualified Data.List as List
86+ import qualified Data.List.NonEmpty as NE
8387import qualified Data.Text as Text
8488import Data.Time (NominalDiffTime )
8589import Data.Word (Word32 , Word64 )
8690import Network.TypedProtocol.Core
8791
8892
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+
89103instance (LogFormatting adr , Show adr ) => LogFormatting (ConnectionId adr ) where
90104 forMachine _dtal (ConnectionId local' remote) =
91105 mconcat [ " connectionId" .= String (showT local'
@@ -1247,19 +1261,55 @@ txsMempoolTimeoutSoftCounterName :: Text.Text
12471261txsMempoolTimeoutSoftCounterName = " txsMempoolTimeoutSoft"
12481262
12491263impliesMempoolTimeoutSoft ::
1250- LedgerSupportsMempool blk => TraceEventMempool blk -> Bool
1264+ forall blk . MempoolTimeoutSoftPredicate blk => TraceEventMempool blk -> Bool
12511265impliesMempoolTimeoutSoft = \ case
12521266 TraceMempoolRejectedTx _tx txApplyErr _mpSz ->
1253- -- TODO export a proper predicate from Consensus
1254- " ApplyTxError (ConwayMempoolFailure" `List.isPrefixOf` show txApplyErr
1267+ errImpliesMempoolTimeoutSoft (Proxy @ blk ) txApplyErr
12551268 _ -> False
12561269
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+
12571306instance
12581307 ( LogFormatting (ApplyTxErr blk )
12591308 , LogFormatting (GenTx blk )
12601309 , ToJSON (GenTxId blk )
12611310 , LedgerSupportsMempool blk
12621311 , ConvertRawHash blk
1312+ , MempoolTimeoutSoftPredicate blk
12631313 ) => LogFormatting (TraceEventMempool blk ) where
12641314 forMachine dtal (TraceMempoolAddedTx tx _mpSzBefore mpSzAfter) =
12651315 mconcat
0 commit comments