@@ -27,11 +27,10 @@ import qualified Cardano.Ledger.Alonzo.PlutusScriptApi as Alonzo
2727import Cardano.Ledger.Alonzo.Rules (AlonzoBbodyPredFailure , AlonzoUtxoPredFailure ,
2828 AlonzoUtxosPredFailure , AlonzoUtxowPredFailure (.. ))
2929import qualified Cardano.Ledger.Alonzo.Rules as Alonzo
30- import qualified Cardano.Ledger.Alonzo.Tx as Alonzo
3130import qualified Cardano.Ledger.AuxiliaryData as Ledger
3231import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure , BabbageUtxowPredFailure )
3332import qualified Cardano.Ledger.Babbage.Rules as Babbage
34- import Cardano.Ledger.BaseTypes (activeSlotLog )
33+ import Cardano.Ledger.BaseTypes (activeSlotLog , strictMaybeToMaybe )
3534import Cardano.Ledger.Chain
3635import Cardano.Ledger.Conway.Governance (govActionIdToText )
3736import qualified Cardano.Ledger.Conway.Rules as Conway
@@ -42,6 +41,8 @@ import qualified Cardano.Ledger.SafeHash as SafeHash
4241import Cardano.Ledger.Shelley.API
4342import Cardano.Ledger.Shelley.Rules
4443import Cardano.Logging
44+ import Cardano.Node.Tracing.Render (renderMissingRedeemers , renderScriptHash ,
45+ renderScriptIntegrityHash )
4546import Cardano.Protocol.TPraos.API (ChainTransitionError (ChainTransitionError ))
4647import Cardano.Protocol.TPraos.BHeader (LastAppliedBlock , labBlockNo )
4748import Cardano.Protocol.TPraos.OCert (KESPeriod (KESPeriod ))
@@ -66,8 +67,7 @@ import Ouroboros.Consensus.Util.Condense (condense)
6667import Ouroboros.Network.Block (SlotNo (.. ), blockHash , blockNo , blockSlot )
6768import Ouroboros.Network.Point (WithOrigin , withOriginToMaybe )
6869
69- import Data.Aeson (ToJSON (.. ), Value (.. ), (.=) )
70- import qualified Data.Aeson as Aeson
70+ import Data.Aeson (ToJSON (.. ), Value (.. ), object , (.=) )
7171import Data.Set (Set )
7272import qualified Data.Set as Set
7373import Data.Text (Text )
@@ -89,18 +89,83 @@ instance
8989 : [ " tx" .= condense tx | dtal == DDetailed ]
9090
9191instance LogFormatting (Set (Credential 'Staking StandardCrypto )) where
92- forMachine _dtal creds = mconcat
93- [ " stake credentials" .= Set. map show creds ] -- TODO: Conway era - render this in a nicer way
92+ forMachine _dtal creds =
93+ mconcat [ " kind" .= String " StakeCreds"
94+ , " stakeCreds" .= map forMachine' (Set. toList creds)
95+ ]
96+ where
97+ forMachine' = object . \ case
98+ ScriptHashObj sHash -> [" scriptHash" .= renderScriptHash sHash]
99+ KeyHashObj keyHash -> [" keyHash" .= textShow keyHash]
94100
95101instance
96- ( Show (PredicateFailure (Ledger. EraRule " DELEG" era ))
97- , Show (PredicateFailure (Ledger. EraRule " POOL" era ))
98- , Show (PredicateFailure (Ledger. EraRule " VDEL" era ))
102+ ( LogFormatting (PredicateFailure (Ledger. EraRule " DELEG" era ))
103+ , LogFormatting (PredicateFailure (Ledger. EraRule " POOL" era ))
104+ , LogFormatting (PredicateFailure (Ledger. EraRule " VDEL" era ))
99105 ) => LogFormatting (Conway. ConwayCertPredFailure era ) where
100- forMachine _dtal cfail =
101- mconcat [ " kind" .= String " ConwayCertPredFailure"
102- , " failure" .= show cfail -- TODO: Conway era - render in a nicer way
103- ]
106+ forMachine dtal = mconcat . \ case
107+ Conway. DelegFailure f ->
108+ [ " kind" .= String " DelegFailure " , " failure" .= forMachine dtal f ]
109+ Conway. PoolFailure f ->
110+ [ " kind" .= String " PoolFailure" , " failure" .= forMachine dtal f ]
111+ Conway. VDelFailure f ->
112+ [ " kind" .= String " VDelFailure" , " failure" .= forMachine dtal f ]
113+
114+ instance LogFormatting (Conway. ConwayVDelPredFailure era ) where
115+ forMachine _dtal = mconcat . \ case
116+ Conway. ConwayDRepAlreadyRegisteredVDEL credential ->
117+ [ " kind" .= String " ConwayDRepAlreadyRegisteredVDEL"
118+ , " credential" .= String (textShow credential)
119+ , " error" .= String " DRep is already registered"
120+ ]
121+ Conway. ConwayDRepNotRegisteredVDEL credential ->
122+ [ " kind" .= String " ConwayDRepNotRegisteredVDEL"
123+ , " credential" .= String (textShow credential)
124+ , " error" .= String " DRep is not registered"
125+ ]
126+ Conway. ConwayDRepIncorrectDepositVDEL coin ->
127+ [ " kind" .= String " ConwayDRepIncorrectDepositVDEL"
128+ , " coin" .= coin
129+ , " error" .= String " DRep delegation has incorrect deposit"
130+ ]
131+ Conway. ConwayCommitteeHasResignedVDEL kHash ->
132+ [ " kind" .= String " ConwayCommitteeHasResignedVDEL"
133+ , " credential" .= String (textShow kHash)
134+ , " error" .= String " Committee has resigned"
135+ ]
136+
137+
138+ instance LogFormatting (Conway. ConwayDelegPredFailure era ) where
139+ forMachine _dtal = mconcat . \ case
140+ Conway. IncorrectDepositDELEG coin ->
141+ [ " kind" .= String " IncorrectDepositDELEG"
142+ , " amount" .= coin
143+ , " error" .= String " Incorrect deposit amount"
144+ ]
145+ Conway. StakeKeyAlreadyRegisteredDELEG credential ->
146+ [ " kind" .= String " StakeKeyAlreadyRegisteredDELEG"
147+ , " credential" .= String (textShow credential)
148+ , " error" .= String " Stake key already registered"
149+ ]
150+ Conway. StakeKeyNotRegisteredDELEG credential ->
151+ [ " kind" .= String " StakeKeyNotRegisteredDELEG"
152+ , " amount" .= String (textShow credential)
153+ , " error" .= String " Stake key not registered"
154+ ]
155+ Conway. StakeKeyHasNonZeroAccountBalanceDELEG coin ->
156+ [ " kind" .= String " StakeKeyHasNonZeroAccountBalanceDELEG"
157+ , " amount" .= coin
158+ , " error" .= String " Stake key has non-zero account balance"
159+ ]
160+ Conway. DRepAlreadyRegisteredForStakeKeyDELEG credential ->
161+ [ " kind" .= String " DRepAlreadyRegisteredForStakeKeyDELEG"
162+ , " amount" .= String (textShow credential)
163+ , " error" .= String " DRep already registered for the stake key"
164+ ]
165+ Conway. WrongCertificateTypeDELEG ->
166+ [ " kind" .= String " WrongCertificateTypeDELEG"
167+ , " error" .= String " Wrong certificate type"
168+ ]
104169
105170instance
106171 ( ShelleyCompatible protocol era
@@ -278,14 +343,15 @@ instance
278343
279344instance
280345 ( Consensus. ShelleyBasedEra era
346+ , Ledger. EraCrypto era ~ StandardCrypto
281347 , LogFormatting (PPUPPredFailure era )
282348 , LogFormatting (PredicateFailure (Ledger. EraRule " UTXO" era ))
283349 ) => LogFormatting (AlonzoUtxowPredFailure era ) where
284350 forMachine dtal (ShelleyInAlonzoUtxowPredFailure utxoPredFail) =
285351 forMachine dtal utxoPredFail
286- forMachine _ (MissingRedeemers _scripts ) =
352+ forMachine _ (MissingRedeemers scripts ) =
287353 mconcat [ " kind" .= String " MissingRedeemers"
288- , " scripts" .= String " TODO: Conway era " -- TODO: Conway era - need to parameterize renderMissingRedeemers over the era
354+ , " scripts" .= renderMissingRedeemers scripts
289355 ]
290356 forMachine _ (MissingRequiredDatums required received) =
291357 mconcat [ " kind" .= String " MissingRequiredDatums"
@@ -294,10 +360,10 @@ instance
294360 , " received" .= map (Crypto. hashToTextAsHex . SafeHash. extractHash)
295361 (Set. toList received)
296362 ]
297- forMachine _ (PPViewHashesDontMatch _ppHashInTxBody _ppHashFromPParams ) =
363+ forMachine _ (PPViewHashesDontMatch ppHashInTxBody ppHashFromPParams ) =
298364 mconcat [ " kind" .= String " PPViewHashesDontMatch"
299- , " fromTxBody" .= String " TODO: Conway error " -- renderScriptIntegrityHash (strictMaybeToMaybe ppHashInTxBody)
300- , " fromPParams" .= String " TODO: Conway error " -- renderScriptIntegrityHash (strictMaybeToMaybe ppHashFromPParams)
365+ , " fromTxBody" .= renderScriptIntegrityHash (strictMaybeToMaybe ppHashInTxBody)
366+ , " fromPParams" .= renderScriptIntegrityHash (strictMaybeToMaybe ppHashFromPParams)
301367 ]
302368 forMachine _ (MissingRequiredSigners missingKeyWitnesses) =
303369 mconcat [ " kind" .= String " MissingRequiredSigners"
@@ -313,18 +379,14 @@ instance
313379 , " acceptable" .= Set. toList acceptable
314380 ]
315381 forMachine _ (ExtraRedeemers rdmrs) =
316- mconcat [ " kind" .= String " ExtraRedeemers"
317- , " rdmrs" .= map Api. fromAlonzoRdmrPtr rdmrs
318- ]
319-
320-
321- _renderScriptIntegrityHash :: Maybe (Alonzo. ScriptIntegrityHash StandardCrypto ) -> Aeson. Value
322- _renderScriptIntegrityHash (Just witPPDataHash) =
323- Aeson. String . Crypto. hashToTextAsHex $ SafeHash. extractHash witPPDataHash
324- _renderScriptIntegrityHash Nothing = Aeson. Null
382+ mconcat
383+ [ " kind" .= String " ExtraRedeemers"
384+ , " rdmrs" .= map Api. fromAlonzoRdmrPtr rdmrs
385+ ]
325386
326387instance
327388 ( Consensus. ShelleyBasedEra era
389+ , Ledger. EraCrypto era ~ StandardCrypto
328390 , ToJSON (Ledger. AuxiliaryDataHash (Ledger. EraCrypto era ))
329391 , LogFormatting (PredicateFailure (ShelleyUTXO era ))
330392 , LogFormatting (PredicateFailure (Ledger. EraRule " UTXO" era ))
@@ -366,9 +428,9 @@ instance
366428 forMachine _dtal InvalidMetadata =
367429 mconcat [ " kind" .= String " InvalidMetadata"
368430 ]
369- forMachine _dtal (ExtraneousScriptWitnessesUTXOW _shashes ) =
431+ forMachine _dtal (ExtraneousScriptWitnessesUTXOW scriptHashes ) =
370432 mconcat [ " kind" .= String " ExtraneousScriptWitnessesUTXOW"
371- , " scriptHashes" .= String " TODO: Conway era " -- Set.map Api.fromShelleyScriptHash shashes
433+ , " scriptHashes" .= Set. map renderScriptHash scriptHashes
372434 ]
373435
374436instance
@@ -952,9 +1014,9 @@ instance
9521014 , " isvalidating" .= isValidating
9531015 , " reason" .= reason
9541016 ]
955- forMachine _ (Alonzo. CollectErrors _errors ) =
1017+ forMachine _ (Alonzo. CollectErrors errors ) =
9561018 mconcat [ " kind" .= String " CollectErrors"
957- , " errors" .= String " TODO: Conway era " -- errors
1019+ , " errors" .= errors
9581020 ]
9591021 forMachine dtal (Alonzo. UpdateFailure pFailure) =
9601022 forMachine dtal pFailure
@@ -994,6 +1056,7 @@ instance
9941056
9951057instance
9961058 ( Ledger. Era era
1059+ , Ledger. EraCrypto era ~ StandardCrypto
9971060 , ShelleyBasedEra era
9981061 , LogFormatting (PPUPPredFailure era )
9991062 , LogFormatting (ShelleyUtxowPredFailure era )
0 commit comments