Skip to content

Commit 493a96d

Browse files
ana-pantilielehins
andcommitted
Ledger changes; fix parsing errors
Co-authored-by: Alexey Kuleshevich <lehins@yandex.ru>
1 parent 5f5739d commit 493a96d

File tree

2 files changed

+80
-22
lines changed

2 files changed

+80
-22
lines changed

cardano-node/src/Cardano/Node/Tracing/Era/Shelley.hs

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,18 @@ instance LogFormatting (Conway.ConwayDelegPredFailure era) where
183183
, "credential" .= String (textShow credential)
184184
, "error" .= String "Delegated rep is not registered for provided stake key"
185185
]
186-
-- TODO: fix
187-
Conway.DepositIncorrectDELEG _ -> undefined
188-
Conway.RefundIncorrectDELEG _ -> undefined
186+
Conway.DepositIncorrectDELEG Mismatch {mismatchSupplied, mismatchExpected} ->
187+
[ "kind" .= String "DepositIncorrectDELEG"
188+
, "givenRefund" .= mismatchSupplied
189+
, "expectedRefund" .= mismatchExpected
190+
, "error" .= String "Deposit mismatch"
191+
]
192+
Conway.RefundIncorrectDELEG Mismatch {mismatchSupplied, mismatchExpected} ->
193+
[ "kind" .= String "RefundIncorrectDELEG"
194+
, "givenRefund" .= mismatchSupplied
195+
, "expectedRefund" .= mismatchExpected
196+
, "error" .= String "Refund mismatch"
197+
]
189198

190199
instance
191200
( ShelleyCompatible protocol era
@@ -380,8 +389,16 @@ instance
380389
]
381390
)
382391
(Api.shelleyBasedEra :: Api.ShelleyBasedEra era)
383-
-- TODO: fix
384-
forMachine _ (ScriptIntegrityHashMismatch _ _) = undefined
392+
forMachine _ (ScriptIntegrityHashMismatch Mismatch {mismatchSupplied, mismatchExpected} mBytes) =
393+
mconcat [ "kind" .= String "ScriptIntegrityHashMismatch"
394+
, "supplied" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchSupplied)
395+
, "expected" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchExpected)
396+
, "hashHexPreimage" .= formatAsHex (strictMaybeToMaybe mBytes)
397+
]
398+
399+
formatAsHex :: Maybe Crypto.ByteString -> String
400+
formatAsHex Nothing = ""
401+
formatAsHex (Just bs) = show bs
385402

386403
instance
387404
( Consensus.ShelleyBasedEra era
@@ -718,8 +735,12 @@ instance LogFormatting (ShelleyPoolPredFailure era) where
718735
, "poolId" .= String (textShow poolId)
719736
, "error" .= String "Wrong network ID in pool registration certificate"
720737
]
721-
-- TODO: fix
722-
forMachine _dtal (VRFKeyHashAlreadyRegistered _ _) = undefined
738+
forMachine _dtal (VRFKeyHashAlreadyRegistered poolId vrfKeyHash) =
739+
mconcat [ "kind" .= String "VRFKeyHashAlreadyRegistered"
740+
, "poolId" .= String (textShow poolId)
741+
, "vrfKeyHash" .= String (textShow vrfKeyHash)
742+
, "error" .= String "Pool with the same VRF Key Hash is already registered"
743+
]
723744

724745

725746
instance LogFormatting TicknPredicateFailure where
@@ -1024,8 +1045,12 @@ instance
10241045
mconcat [ "kind" .= String "MalformedReferenceScripts"
10251046
, "scripts" .= s
10261047
]
1027-
-- TODO: fix
1028-
Babbage.ScriptIntegrityHashMismatch _ _ -> undefined
1048+
Babbage.ScriptIntegrityHashMismatch Mismatch {mismatchSupplied, mismatchExpected} mBytes ->
1049+
mconcat [ "kind" .= String "ScriptIntegrityHashMismatch"
1050+
, "supplied" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchSupplied)
1051+
, "expected" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchExpected)
1052+
, "hashHexPreimage" .= formatAsHex (strictMaybeToMaybe mBytes)
1053+
]
10291054
--------------------------------------------------------------------------------
10301055
-- Conway related
10311056
--------------------------------------------------------------------------------
@@ -1475,8 +1500,12 @@ instance
14751500
mconcat [ "kind" .= String "MalformedReferenceScripts"
14761501
, "scripts" .= scripts
14771502
]
1478-
-- TODO: fix
1479-
Conway.ScriptIntegrityHashMismatch _ _ -> undefined
1503+
Conway.ScriptIntegrityHashMismatch Mismatch {mismatchSupplied, mismatchExpected} mBytes ->
1504+
mconcat [ "kind" .= String "ScriptIntegrityHashMismatch"
1505+
, "supplied" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchSupplied)
1506+
, "expected" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchExpected)
1507+
, "hashHexPreimage" .= formatAsHex (strictMaybeToMaybe mBytes)
1508+
]
14801509

14811510
instance LogFormatting (Praos.PraosTiebreakerView crypto) where
14821511
forMachine _dtal (Praos.PraosTiebreakerView sl issuer issueNo vrf) =

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,18 @@ instance ToObject (Conway.ConwayDelegPredFailure era) where
221221
, "credential" .= String (textShow credential)
222222
, "error" .= String "Delegated rep is not registered for provided stake key"
223223
]
224-
-- TODO: fix
225-
Conway.DepositIncorrectDELEG _ -> undefined
226-
Conway.RefundIncorrectDELEG _ -> undefined
224+
Conway.DepositIncorrectDELEG Mismatch {mismatchSupplied, mismatchExpected} ->
225+
[ "kind" .= String "DepositIncorrectDELEG"
226+
, "givenRefund" .= mismatchSupplied
227+
, "expectedRefund" .= mismatchExpected
228+
, "error" .= String "Deposit mismatch"
229+
]
230+
Conway.RefundIncorrectDELEG Mismatch {mismatchSupplied, mismatchExpected} ->
231+
[ "kind" .= String "RefundIncorrectDELEG"
232+
, "givenRefund" .= mismatchSupplied
233+
, "expectedRefund" .= mismatchExpected
234+
, "error" .= String "Refund mismatch"
235+
]
227236

228237
instance ToObject (Set (Credential 'Staking)) where
229238
toObject _verb creds =
@@ -485,8 +494,12 @@ instance
485494
]
486495
)
487496
(Api.shelleyBasedEra :: Api.ShelleyBasedEra era)
488-
-- TODO: fix
489-
toObject _ _ = undefined
497+
toObject _ (ScriptIntegrityHashMismatch poolId vrfKeyHash) =
498+
mconcat [ "kind" .= String "VRFKeyHashAlreadyRegistered"
499+
, "poolId" .= String (textShow poolId)
500+
, "vrfKeyHash" .= String (textShow vrfKeyHash)
501+
, "error" .= String "Pool with the same VRF Key Hash is already registered"
502+
]
490503

491504
instance
492505
( ToObject (PredicateFailure (Core.EraRule "UTXO" ledgerera))
@@ -815,8 +828,12 @@ instance ToObject (ShelleyPoolPredFailure era) where
815828
, "hashSize" .= String (textShow hashSize)
816829
, "error" .= String "The stake pool metadata hash is too large"
817830
]
818-
-- TODO: fix
819-
toObject _verb (VRFKeyHashAlreadyRegistered _ _) = undefined
831+
toObject _ (VRFKeyHashAlreadyRegistered poolId vrfKeyHash) =
832+
mconcat [ "kind" .= String "VRFKeyHashAlreadyRegistered"
833+
, "poolId" .= String (textShow poolId)
834+
, "vrfKeyHash" .= String (textShow vrfKeyHash)
835+
, "error" .= String "Pool with the same VRF Key Hash is already registered"
836+
]
820837

821838
-- Apparently this should never happen according to the Shelley exec spec
822839
-- toObject _verb (WrongCertificateTypePOOL index) =
@@ -1183,8 +1200,16 @@ instance
11831200
mconcat [ "kind" .= String "MalformedReferenceScripts"
11841201
, "scripts" .= s
11851202
]
1186-
-- TODO: fix
1187-
Babbage.ScriptIntegrityHashMismatch _ _ -> undefined
1203+
Babbage.ScriptIntegrityHashMismatch Mismatch {mismatchSupplied, mismatchExpected} mBytes ->
1204+
mconcat [ "kind" .= String "ScriptIntegrityHashMismatch"
1205+
, "supplied" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchSupplied)
1206+
, "expected" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchExpected)
1207+
, "hashHexPreimage" .= formatAsHex (strictMaybeToMaybe mBytes)
1208+
]
1209+
1210+
formatAsHex :: Maybe Crypto.ByteString -> String
1211+
formatAsHex Nothing = ""
1212+
formatAsHex (Just bs) = show bs
11881213

11891214
instance Core.Crypto crypto => ToObject (Praos.PraosValidationErr crypto) where
11901215
toObject _ err' =
@@ -1525,8 +1550,12 @@ instance
15251550
mconcat [ "kind" .= String "MalformedReferenceScripts"
15261551
, "scripts" .= scripts
15271552
]
1528-
-- TODO: fix
1529-
Conway.ScriptIntegrityHashMismatch _ _ -> undefined
1553+
Conway.ScriptIntegrityHashMismatch Mismatch {mismatchSupplied, mismatchExpected} mBytes ->
1554+
mconcat [ "kind" .= String "ScriptIntegrityHashMismatch"
1555+
, "supplied" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchSupplied)
1556+
, "expected" .= renderScriptIntegrityHash (strictMaybeToMaybe mismatchExpected)
1557+
, "hashHexPreimage" .= formatAsHex (strictMaybeToMaybe mBytes)
1558+
]
15301559

15311560
instance ToObject (Praos.PraosTiebreakerView crypto) where
15321561
toObject v (Praos.PraosTiebreakerView sl issuer issueNo vrf) =

0 commit comments

Comments
 (0)