Skip to content

Commit

Permalink
Merge pull request #1255 from input-output-hk/era-not-supported-message
Browse files Browse the repository at this point in the history
Improve message printed when era is not supported
  • Loading branch information
ch1bo authored Jan 17, 2024
2 parents 2a68a74 + 16f8e93 commit d845064
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions hydra-node/src/Hydra/Chain/Direct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Control.Monad.Trans.Except (runExcept)
import Hydra.Cardano.Api (
Block (..),
BlockInMode (..),
CardanoEra (BabbageEra),
CardanoEra (..),
CardanoMode,
ChainPoint,
ChainTip,
Expand Down Expand Up @@ -259,16 +259,23 @@ newtype IntersectionNotFoundException = IntersectionNotFound

instance Exception IntersectionNotFoundException

data ChainClientException = EraNotSupportedException
{ otherEraName :: Text
, ledgerEraName :: Text
}
data EraNotSupportedException
= EraNotSupportedAnymore {otherEraName :: Text}
| EraNotSupportedYet {otherEraName :: Text}
deriving stock (Show)

instance Exception ChainClientException where
instance Exception EraNotSupportedException where
displayException = \case
EraNotSupportedException{ledgerEraName, otherEraName} ->
printf "Received blocks in unsupported era %s. Please upgrade your hydra-node to era %s." otherEraName ledgerEraName
EraNotSupportedAnymore{otherEraName} ->
printf
"Received blocks of not anymore supported era (%s). \
\Please wait for your cardano-node to be fully synchronized."
otherEraName
EraNotSupportedYet{otherEraName} ->
printf
"Received blocks of not yet supported era (%s). \
\Please upgrade your hydra-node."
otherEraName

-- | The block type used in the node-to-client protocols.
type BlockType = BlockInMode CardanoMode
Expand Down Expand Up @@ -308,13 +315,7 @@ chainSyncClient handler wallet startingPoint =
ClientStNext
{ recvMsgRollForward = \blockInMode _tip -> ChainSyncClient $ do
case blockInMode of
BlockInMode _ (Block header txs) BabbageEraInCardanoMode -> do
-- Update the tiny wallet
update wallet header txs
-- Observe Hydra transactions
onRollForward handler header txs
pure clientStIdle
BlockInMode _ block ConwayEraInCardanoMode -> do
BlockInMode ConwayEra block _ -> do
-- TODO: uses cardano-api:internal
-- NOTE: we should remove this dependency once we have ShelleyBlock available
-- on the normal cardano-api library.
Expand All @@ -332,7 +333,17 @@ chainSyncClient handler wallet startingPoint =
-- Observe Hydra transactions
onRollForward handler header txs
pure clientStIdle
(BlockInMode era _ _) -> throwIO $ EraNotSupportedException{ledgerEraName = show era, otherEraName = show BabbageEra}
BlockInMode BabbageEra (Block header txs) _ -> do
-- Update the tiny wallet
update wallet header txs
-- Observe Hydra transactions
onRollForward handler header txs
pure clientStIdle
BlockInMode era@AlonzoEra _ _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
BlockInMode era@AllegraEra _ _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
BlockInMode era@MaryEra _ _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
BlockInMode era@ShelleyEra _ _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
BlockInMode era@ByronEra _ _ -> throwIO $ EraNotSupportedAnymore{otherEraName = show era}
, recvMsgRollBackward = \point _tip -> ChainSyncClient $ do
-- Re-initialize the tiny wallet
reset wallet
Expand Down

0 comments on commit d845064

Please sign in to comment.