Skip to content

Commit

Permalink
Fix decoding of Hydra keys and ignore problematic head init
Browse files Browse the repository at this point in the history
We were not correctly decoding Hydra verification keys (but crashing via
error) because of a missing data constructor.

This also makes the observeInitTx sort out heads that would have such
problematic party datums.

An example transaction with problematic data is:
b860a236a7e77577628bf705286d449188831cf90d714934f1cc06369c6e3953 on preprod
  • Loading branch information
ch1bo committed Feb 14, 2025
1 parent 5e55e3e commit 61f57fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions hydra-tx/src/Hydra/Tx/Crypto.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Hydra.Cardano.Api (
Key (..),
SerialiseAsCBOR,
SerialiseAsRawBytes (..),
SerialiseAsRawBytesError (..),
serialiseToRawBytesHexText,
)
import Hydra.Contract.HeadState qualified as OnChain
Expand Down Expand Up @@ -83,7 +84,10 @@ instance SerialiseAsRawBytes (Hash HydraKey) where
serialiseToRawBytes (HydraKeyHash vkh) = hashToBytes vkh

deserialiseFromRawBytes (AsHash AsHydraKey) bs =
maybe (error "TODO: SerialiseAsRawBytesError, but constructor not exported") (Right . HydraKeyHash) (hashFromBytes bs)
maybe
(Left $ SerialiseAsRawBytesError "invalid length when deserializing Hash HydraKey")
(Right . HydraKeyHash)
(hashFromBytes bs)

instance Key HydraKey where
-- Hydra verification key, which can be used to 'verify' signed messages.
Expand Down Expand Up @@ -140,7 +144,10 @@ instance SerialiseAsRawBytes (VerificationKey HydraKey) where
rawSerialiseVerKeyDSIGN vk

deserialiseFromRawBytes (AsVerificationKey AsHydraKey) bs =
maybe (error "TODO: SerialiseAsRawBytesError, but constructor not exported") (Right . HydraVerificationKey) (rawDeserialiseVerKeyDSIGN bs)
maybe
(Left $ SerialiseAsRawBytesError "invalid length when deserializing VerificationKey HydraKey")
(Right . HydraVerificationKey)
(rawDeserialiseVerKeyDSIGN bs)

instance ToJSON (VerificationKey HydraKey) where
toJSON = toJSON . serialiseToRawBytesHexText
Expand Down
4 changes: 4 additions & 0 deletions hydra-tx/src/Hydra/Tx/Observe.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ data HeadObservation
-- | Observe any Hydra head transaction.
observeHeadTx :: NetworkId -> UTxO -> Tx -> HeadObservation
observeHeadTx networkId utxo tx =
-- XXX: This is throwing away valuable information! We should be collecting
-- all "not an XX" reasons here in case we fall through and want that
-- diagnostic information in the call site of this function. Collecting errors
-- could be done with 'validation' or a similar package.
fromMaybe NoHeadTx $
either (const Nothing) (Just . Init) (observeInitTx tx)
<|> Abort <$> observeAbortTx utxo tx
Expand Down

0 comments on commit 61f57fa

Please sign in to comment.