{-# LANGUAGE ConstraintKinds          #-}
{-# LANGUAGE DataKinds                #-}
{-# LANGUAGE DeriveAnyClass           #-}
{-# LANGUAGE DeriveGeneric            #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE FlexibleContexts         #-}
{-# LANGUAGE FlexibleInstances        #-}
{-# LANGUAGE LambdaCase               #-}
{-# LANGUAGE MultiParamTypeClasses    #-}
{-# LANGUAGE NamedFieldPuns           #-}
{-# LANGUAGE OverloadedStrings        #-}
{-# LANGUAGE RecordWildCards          #-}
{-# LANGUAGE ScopedTypeVariables      #-}
{-# LANGUAGE TupleSections            #-}
{-# LANGUAGE TypeApplications         #-}
{-# LANGUAGE TypeFamilies             #-}
{-# LANGUAGE TypeOperators            #-}
{-# LANGUAGE UndecidableInstances     #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Ouroboros.Consensus.Cardano.CanHardFork (
    TriggerHardFork (..)
  , ByronPartialLedgerConfig (..)
  , ShelleyPartialLedgerConfig (..)
  , CardanoHardForkConstraints
  ) where

import           Control.Monad
import           Control.Monad.Except (Except, throwError)
import qualified Data.Map.Strict as Map
import           Data.Maybe (listToMaybe, mapMaybe)
import           Data.Proxy
import           Data.SOP.Strict ((:.:) (..), NP (..))
import           Data.Void (Void)
import           Data.Word
import           GHC.Generics (Generic)
import           NoThunks.Class (NoThunks)

import           Cardano.Crypto.DSIGN (Ed25519DSIGN)
import           Cardano.Crypto.Hash.Blake2b (Blake2b_224, Blake2b_256)

import qualified Cardano.Chain.Common as CC
import qualified Cardano.Chain.Genesis as CC.Genesis
import qualified Cardano.Chain.Update as CC.Update

import           Ouroboros.Consensus.Block
import           Ouroboros.Consensus.Forecast
import           Ouroboros.Consensus.HardFork.History (Bound (boundSlot),
                     addSlots)
import           Ouroboros.Consensus.Ledger.Abstract
import           Ouroboros.Consensus.TypeFamilyWrappers
import           Ouroboros.Consensus.Util.RedundantConstraints

import           Ouroboros.Consensus.HardFork.Combinator
import           Ouroboros.Consensus.HardFork.Combinator.State.Types
import           Ouroboros.Consensus.HardFork.Combinator.Util.InPairs
                     (RequiringBoth (..), ignoringBoth)
import           Ouroboros.Consensus.HardFork.Combinator.Util.Tails (Tails (..))

import           Ouroboros.Consensus.Byron.Ledger
import qualified Ouroboros.Consensus.Byron.Ledger.Inspect as Byron.Inspect
import           Ouroboros.Consensus.Byron.Node ()
import           Ouroboros.Consensus.Protocol.PBFT (PBft, PBftCrypto)
import           Ouroboros.Consensus.Protocol.PBFT.State (PBftState)
import qualified Ouroboros.Consensus.Protocol.PBFT.State as PBftState

import           Ouroboros.Consensus.Shelley.Ledger
import qualified Ouroboros.Consensus.Shelley.Ledger.Inspect as Shelley.Inspect
import           Ouroboros.Consensus.Shelley.Node ()
import           Ouroboros.Consensus.Shelley.Protocol

import           Cardano.Ledger.Allegra.Translation ()
import           Cardano.Ledger.Crypto (ADDRHASH, DSIGN, HASH)
import qualified Cardano.Ledger.Era as SL
import           Cardano.Ledger.Mary.Translation ()
import qualified Shelley.Spec.Ledger.API as SL

import           Ouroboros.Consensus.Cardano.Block

{-------------------------------------------------------------------------------
  Figure out the transition point for Byron

  The Byron ledger defines the update 'State' in
  "Cardano.Chain.Update.Validation.Interface". The critical piece of state we
  need is

  > candidateProtocolUpdates :: ![CandidateProtocolUpdate]

  which are the update proposals that have been voted on, accepted, and
  endorsed, and now need to become stable. In `tryBumpVersion`
  ("Cardano.Chain.Update.Validation.Interface.ProtocolVersionBump") we
  find the candidates that are at least 'kUpdateStabilityParam' (@== 4k@) deep,
  and then construct

  > State
  > { nextProtocolVersion    = cpuProtocolVersion
  > , nextProtocolParameters = cpuProtocolParameters
  > }

  (with 'State' from "Cardano.Chain.Update.Validation.Interface.ProtocolVersionBump")
  where 'cpuProtocolVersion'/'cpuProtocolParameters' are the version and
  parameters from the update. This then ends up in the following callstack

  > applyChainTick
  > |
  > \-- epochTransition
  >     |
  >     \-- registerEpoch
  >         |
  >         \-- tryBumpVersion

  Now, if this is changing the major version of the protocol, then this actually
  indicates the transition to Shelley, and the Byron 'applyChainTick' won't
  actually happen. Instead, in 'singleEraTransition' we will report the
  'EpochNo' of the transition as soon as it's @2k@ (not @4k@!) deep: in other
  words, as soon as it is stable; at this point, the HFC will do the rest.

  A slightly subtle point is that the Byron ledger does not record any
  information about /past/ updates to the protocol parameters, and so if we
  /were/ to ask the Byron ledger /after/ the update when the transition is
  going to take place (did take place), it will say 'Nothing': transition not
  yet known. In practice this won't matter, as it will have been translated to
  a Shelley ledger at that point.
-------------------------------------------------------------------------------}

byronTransition :: PartialLedgerConfig ByronBlock
                -> Word16   -- ^ Shelley major protocol version
                -> LedgerState ByronBlock
                -> Maybe EpochNo
byronTransition :: PartialLedgerConfig ByronBlock
-> Word16 -> LedgerState ByronBlock -> Maybe EpochNo
byronTransition ByronPartialLedgerConfig{..} Word16
shelleyMajorVersion LedgerState ByronBlock
state =
      [EpochNo] -> Maybe EpochNo
forall a. [a] -> Maybe a
takeAny
    ([EpochNo] -> Maybe EpochNo)
-> (LedgerState ByronBlock -> [EpochNo])
-> LedgerState ByronBlock
-> Maybe EpochNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ProtocolUpdate -> Maybe EpochNo) -> [ProtocolUpdate] -> [EpochNo]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ProtocolUpdate -> Maybe EpochNo
isTransitionToShelley
    ([ProtocolUpdate] -> [EpochNo])
-> (LedgerState ByronBlock -> [ProtocolUpdate])
-> LedgerState ByronBlock
-> [EpochNo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerConfig ByronBlock
-> LedgerState ByronBlock -> [ProtocolUpdate]
Byron.Inspect.protocolUpdates LedgerConfig ByronBlock
byronLedgerConfig
    (LedgerState ByronBlock -> Maybe EpochNo)
-> LedgerState ByronBlock -> Maybe EpochNo
forall a b. (a -> b) -> a -> b
$ LedgerState ByronBlock
state
  where
    ByronTransitionInfo Map ProtocolVersion BlockNo
transitionInfo = LedgerState ByronBlock -> ByronTransition
byronLedgerTransition LedgerState ByronBlock
state

    genesis :: LedgerConfig ByronBlock
genesis = LedgerConfig ByronBlock
byronLedgerConfig
    k :: BlockCount
k       = GenesisData -> BlockCount
CC.Genesis.gdK (GenesisData -> BlockCount) -> GenesisData -> BlockCount
forall a b. (a -> b) -> a -> b
$ Config -> GenesisData
CC.Genesis.configGenesisData Config
LedgerConfig ByronBlock
genesis

    isTransitionToShelley :: Byron.Inspect.ProtocolUpdate -> Maybe EpochNo
    isTransitionToShelley :: ProtocolUpdate -> Maybe EpochNo
isTransitionToShelley ProtocolUpdate
update = do
        Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ ProtocolVersion -> Word16
CC.Update.pvMajor ProtocolVersion
version Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
shelleyMajorVersion
        case ProtocolUpdate -> UpdateState
Byron.Inspect.protocolUpdateState ProtocolUpdate
update of
          Byron.Inspect.UpdateCandidate SlotNo
_becameCandidateSlotNo EpochNo
adoptedIn -> do
            BlockNo
becameCandidateBlockNo <- ProtocolVersion -> Map ProtocolVersion BlockNo -> Maybe BlockNo
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup ProtocolVersion
version Map ProtocolVersion BlockNo
transitionInfo
            Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ BlockNo -> Bool
isReallyStable BlockNo
becameCandidateBlockNo
            EpochNo -> Maybe EpochNo
forall (m :: * -> *) a. Monad m => a -> m a
return EpochNo
adoptedIn
          Byron.Inspect.UpdateStableCandidate EpochNo
adoptedIn ->
            -- If the Byron ledger thinks it's stable, it's _definitely_ stable
            EpochNo -> Maybe EpochNo
forall (m :: * -> *) a. Monad m => a -> m a
return EpochNo
adoptedIn
          UpdateState
_otherwise ->
            -- The proposal isn't yet a candidate, never mind a stable one
            Maybe EpochNo
forall (m :: * -> *) a. MonadPlus m => m a
mzero
      where
        version :: CC.Update.ProtocolVersion
        version :: ProtocolVersion
version = ProtocolUpdate -> ProtocolVersion
Byron.Inspect.protocolUpdateVersion ProtocolUpdate
update

    -- Normally, stability in the ledger is defined in terms of slots, not
    -- blocks. Byron considers the proposal to be stable after the slot is more
    -- than @2k@ old. That is not wrong: after @2k@, the block indeed is stable.
    --
    -- Unfortunately, this means that the /conclusion about stability itself/
    -- is /not/ stable: if we were to switch to a denser fork, we might change
    -- our mind (on the sparse chain we thought the block was already stable,
    -- but on the dense chain we conclude it is it not yet stable).
    --
    -- It is unclear at the moment if this presents a problem; the HFC assumes
    -- monotonicity of timing info, in the sense that that any slot/time
    -- conversions are either unknown or else not subject to rollback.
    -- The problem sketched above might mean that we can go from "conversion
    -- known" to "conversion unknown", but then when we go back again to
    -- "conversion known", we /are/ guaranteed that we'd get the same answer.
    --
    -- Rather than trying to analyse this subtle problem, we instead base
    -- stability on block numbers; after the block is `k` deep, we know for sure
    -- that it is stable, and moreover, no matter which chain we switch to, that
    -- will remain to be the case.
    --
    -- The Byron 'UpdateState' records the 'SlotNo' of the block in which the
    -- proposal became a candidate (i.e., when the last required endorsement
    -- came in). That doesn't tell us very much, we need to know the block
    -- number; that's precisely what the 'ByronTransition' part of the Byron
    -- state tells us.
    isReallyStable :: BlockNo -> Bool
    isReallyStable :: BlockNo -> Bool
isReallyStable (BlockNo Word64
bno) = Word64
distance Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= BlockCount -> Word64
CC.unBlockCount BlockCount
k
      where
        distance :: Word64
        distance :: Word64
distance = case LedgerState ByronBlock -> WithOrigin BlockNo
byronLedgerTipBlockNo LedgerState ByronBlock
state of
                     WithOrigin BlockNo
Origin                  -> Word64
bno Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1
                     NotOrigin (BlockNo Word64
tip) -> Word64
tip Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
bno

    -- We only expect a single proposal that updates to Shelley, but in case
    -- there are multiple, any one will do
    takeAny :: [a] -> Maybe a
    takeAny :: [a] -> Maybe a
takeAny = [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe

{-------------------------------------------------------------------------------
  Figure out the transition point for Shelley
-------------------------------------------------------------------------------}

shelleyTransition ::
     forall era.
     PartialLedgerConfig (ShelleyBlock era)
  -> Word16   -- ^ Next era's major protocol version
  -> LedgerState (ShelleyBlock era)
  -> Maybe EpochNo
shelleyTransition :: PartialLedgerConfig (ShelleyBlock era)
-> Word16 -> LedgerState (ShelleyBlock era) -> Maybe EpochNo
shelleyTransition ShelleyPartialLedgerConfig{..}
                  Word16
transitionMajorVersion
                  LedgerState (ShelleyBlock era)
state =
      [EpochNo] -> Maybe EpochNo
forall a. [a] -> Maybe a
takeAny
    ([EpochNo] -> Maybe EpochNo)
-> (LedgerState (ShelleyBlock era) -> [EpochNo])
-> LedgerState (ShelleyBlock era)
-> Maybe EpochNo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ProtocolUpdate era -> Maybe EpochNo)
-> [ProtocolUpdate era] -> [EpochNo]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ProtocolUpdate era -> Maybe EpochNo
isTransition
    ([ProtocolUpdate era] -> [EpochNo])
-> (LedgerState (ShelleyBlock era) -> [ProtocolUpdate era])
-> LedgerState (ShelleyBlock era)
-> [EpochNo]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyGenesis era
-> LedgerState (ShelleyBlock era) -> [ProtocolUpdate era]
forall era.
ShelleyGenesis era
-> LedgerState (ShelleyBlock era) -> [ProtocolUpdate era]
Shelley.Inspect.protocolUpdates ShelleyGenesis era
genesis
    (LedgerState (ShelleyBlock era) -> Maybe EpochNo)
-> LedgerState (ShelleyBlock era) -> Maybe EpochNo
forall a b. (a -> b) -> a -> b
$ LedgerState (ShelleyBlock era)
state
  where
    ShelleyTransitionInfo{Word32
shelleyAfterVoting :: ShelleyTransition -> Word32
shelleyAfterVoting :: Word32
..} = LedgerState (ShelleyBlock era) -> ShelleyTransition
forall era. LedgerState (ShelleyBlock era) -> ShelleyTransition
shelleyLedgerTransition LedgerState (ShelleyBlock era)
state

    -- 'shelleyLedgerConfig' contains a dummy 'EpochInfo' but this does not
    -- matter for extracting the genesis config
    genesis :: SL.ShelleyGenesis era
    genesis :: ShelleyGenesis era
genesis = ShelleyLedgerConfig era -> ShelleyGenesis era
forall era. ShelleyLedgerConfig era -> ShelleyGenesis era
shelleyLedgerGenesis ShelleyLedgerConfig era
shelleyLedgerConfig

    k :: Word64
    k :: Word64
k = ShelleyGenesis era -> Word64
forall era. ShelleyGenesis era -> Word64
SL.sgSecurityParam ShelleyGenesis era
genesis

    isTransition :: Shelley.Inspect.ProtocolUpdate era -> Maybe EpochNo
    isTransition :: ProtocolUpdate era -> Maybe EpochNo
isTransition Shelley.Inspect.ProtocolUpdate{UpdateProposal era
UpdateState (EraCrypto era)
protocolUpdateProposal :: forall era. ProtocolUpdate era -> UpdateProposal era
protocolUpdateState :: forall era. ProtocolUpdate era -> UpdateState (EraCrypto era)
protocolUpdateState :: UpdateState (EraCrypto era)
protocolUpdateProposal :: UpdateProposal era
..} = do
         SL.ProtVer Natural
major Natural
_minor <- Maybe ProtVer
proposalVersion
         Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Natural -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
major Word16 -> Word16 -> Bool
forall a. Eq a => a -> a -> Bool
== Word16
transitionMajorVersion
         Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Bool
proposalReachedQuorum
         Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Maybe ()) -> Bool -> Maybe ()
forall a b. (a -> b) -> a -> b
$ Word32
shelleyAfterVoting Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64 -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
k
         EpochNo -> Maybe EpochNo
forall (m :: * -> *) a. Monad m => a -> m a
return EpochNo
proposalEpoch
       where
         Shelley.Inspect.UpdateProposal{Maybe ProtVer
EpochNo
PParamsUpdate era
proposalParams :: forall era. UpdateProposal era -> PParamsUpdate era
proposalVersion :: forall era. UpdateProposal era -> Maybe ProtVer
proposalEpoch :: forall era. UpdateProposal era -> EpochNo
proposalParams :: PParamsUpdate era
proposalEpoch :: EpochNo
proposalVersion :: Maybe ProtVer
..} = UpdateProposal era
protocolUpdateProposal
         Shelley.Inspect.UpdateState{Bool
[KeyHash 'Genesis (EraCrypto era)]
proposalVotes :: forall c. UpdateState c -> [KeyHash 'Genesis c]
proposalReachedQuorum :: forall c. UpdateState c -> Bool
proposalVotes :: [KeyHash 'Genesis (EraCrypto era)]
proposalReachedQuorum :: Bool
..}    = UpdateState (EraCrypto era)
protocolUpdateState

    -- In principle there could be multiple proposals that all change the
    -- major protocol version. In practice this can't happen because each
    -- delegate can only vote for one proposal, but the types don't guarantee
    -- this. We don't need to worry about this, and just pick any of them.
    takeAny :: [a] -> Maybe a
    takeAny :: [a] -> Maybe a
takeAny = [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe

{-------------------------------------------------------------------------------
  SingleEraBlock Byron
-------------------------------------------------------------------------------}

instance SingleEraBlock ByronBlock where
  singleEraTransition :: PartialLedgerConfig ByronBlock
-> EraParams -> Bound -> LedgerState ByronBlock -> Maybe EpochNo
singleEraTransition PartialLedgerConfig ByronBlock
pcfg EraParams
_eraParams Bound
_eraStart LedgerState ByronBlock
ledgerState =
      case ByronPartialLedgerConfig -> TriggerHardFork
byronTriggerHardFork PartialLedgerConfig ByronBlock
ByronPartialLedgerConfig
pcfg of
        TriggerHardFork
TriggerHardForkNever                         -> Maybe EpochNo
forall a. Maybe a
Nothing
        TriggerHardForkAtEpoch   EpochNo
epoch               -> EpochNo -> Maybe EpochNo
forall a. a -> Maybe a
Just EpochNo
epoch
        TriggerHardForkAtVersion Word16
shelleyMajorVersion ->
            PartialLedgerConfig ByronBlock
-> Word16 -> LedgerState ByronBlock -> Maybe EpochNo
byronTransition
              PartialLedgerConfig ByronBlock
pcfg
              Word16
shelleyMajorVersion
              LedgerState ByronBlock
ledgerState

  singleEraInfo :: proxy ByronBlock -> SingleEraInfo ByronBlock
singleEraInfo proxy ByronBlock
_ = SingleEraInfo :: forall blk. Text -> SingleEraInfo blk
SingleEraInfo {
      singleEraName :: Text
singleEraName = Text
"Byron"
    }

instance PBftCrypto bc => HasPartialConsensusConfig (PBft bc)
  -- Use defaults

-- | The trigger condition that will cause the hard fork transition.
data TriggerHardFork =
    -- | Trigger the transition when the on-chain protocol major version (from
    -- the ledger state) reaches this number.
    TriggerHardForkAtVersion !Word16
    -- | For testing only, trigger the transition at a specific hard-coded
    -- epoch, irrespective of the ledger state.
  | TriggerHardForkAtEpoch !EpochNo
    -- | Never trigger a hard fork
  | TriggerHardForkNever
  deriving (Int -> TriggerHardFork -> ShowS
[TriggerHardFork] -> ShowS
TriggerHardFork -> String
(Int -> TriggerHardFork -> ShowS)
-> (TriggerHardFork -> String)
-> ([TriggerHardFork] -> ShowS)
-> Show TriggerHardFork
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TriggerHardFork] -> ShowS
$cshowList :: [TriggerHardFork] -> ShowS
show :: TriggerHardFork -> String
$cshow :: TriggerHardFork -> String
showsPrec :: Int -> TriggerHardFork -> ShowS
$cshowsPrec :: Int -> TriggerHardFork -> ShowS
Show, (forall x. TriggerHardFork -> Rep TriggerHardFork x)
-> (forall x. Rep TriggerHardFork x -> TriggerHardFork)
-> Generic TriggerHardFork
forall x. Rep TriggerHardFork x -> TriggerHardFork
forall x. TriggerHardFork -> Rep TriggerHardFork x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TriggerHardFork x -> TriggerHardFork
$cfrom :: forall x. TriggerHardFork -> Rep TriggerHardFork x
Generic, Context -> TriggerHardFork -> IO (Maybe ThunkInfo)
Proxy TriggerHardFork -> String
(Context -> TriggerHardFork -> IO (Maybe ThunkInfo))
-> (Context -> TriggerHardFork -> IO (Maybe ThunkInfo))
-> (Proxy TriggerHardFork -> String)
-> NoThunks TriggerHardFork
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy TriggerHardFork -> String
$cshowTypeOf :: Proxy TriggerHardFork -> String
wNoThunks :: Context -> TriggerHardFork -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> TriggerHardFork -> IO (Maybe ThunkInfo)
noThunks :: Context -> TriggerHardFork -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> TriggerHardFork -> IO (Maybe ThunkInfo)
NoThunks)

-- | When Byron is part of the hard-fork combinator, we use the partial ledger
-- config. Standalone Byron uses the regular ledger config. This means that
-- the partial ledger config is the perfect place to store the trigger
-- condition for the hard fork to Shelley, as we don't have to modify the
-- ledger config for standalone Byron.
data ByronPartialLedgerConfig = ByronPartialLedgerConfig {
      ByronPartialLedgerConfig -> LedgerConfig ByronBlock
byronLedgerConfig    :: !(LedgerConfig ByronBlock)
    , ByronPartialLedgerConfig -> TriggerHardFork
byronTriggerHardFork :: !TriggerHardFork
    }
  deriving ((forall x.
 ByronPartialLedgerConfig -> Rep ByronPartialLedgerConfig x)
-> (forall x.
    Rep ByronPartialLedgerConfig x -> ByronPartialLedgerConfig)
-> Generic ByronPartialLedgerConfig
forall x.
Rep ByronPartialLedgerConfig x -> ByronPartialLedgerConfig
forall x.
ByronPartialLedgerConfig -> Rep ByronPartialLedgerConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ByronPartialLedgerConfig x -> ByronPartialLedgerConfig
$cfrom :: forall x.
ByronPartialLedgerConfig -> Rep ByronPartialLedgerConfig x
Generic, Context -> ByronPartialLedgerConfig -> IO (Maybe ThunkInfo)
Proxy ByronPartialLedgerConfig -> String
(Context -> ByronPartialLedgerConfig -> IO (Maybe ThunkInfo))
-> (Context -> ByronPartialLedgerConfig -> IO (Maybe ThunkInfo))
-> (Proxy ByronPartialLedgerConfig -> String)
-> NoThunks ByronPartialLedgerConfig
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy ByronPartialLedgerConfig -> String
$cshowTypeOf :: Proxy ByronPartialLedgerConfig -> String
wNoThunks :: Context -> ByronPartialLedgerConfig -> IO (Maybe ThunkInfo)
$cwNoThunks :: Context -> ByronPartialLedgerConfig -> IO (Maybe ThunkInfo)
noThunks :: Context -> ByronPartialLedgerConfig -> IO (Maybe ThunkInfo)
$cnoThunks :: Context -> ByronPartialLedgerConfig -> IO (Maybe ThunkInfo)
NoThunks)

instance HasPartialLedgerConfig ByronBlock where

  type PartialLedgerConfig ByronBlock = ByronPartialLedgerConfig

  completeLedgerConfig :: proxy ByronBlock
-> EpochInfo Identity
-> PartialLedgerConfig ByronBlock
-> LedgerConfig ByronBlock
completeLedgerConfig proxy ByronBlock
_ EpochInfo Identity
_ = PartialLedgerConfig ByronBlock -> LedgerConfig ByronBlock
ByronPartialLedgerConfig -> LedgerConfig ByronBlock
byronLedgerConfig

{-------------------------------------------------------------------------------
  SingleEraBlock Shelley
-------------------------------------------------------------------------------}

instance ShelleyBasedEra era => SingleEraBlock (ShelleyBlock era) where
  singleEraTransition :: PartialLedgerConfig (ShelleyBlock era)
-> EraParams
-> Bound
-> LedgerState (ShelleyBlock era)
-> Maybe EpochNo
singleEraTransition PartialLedgerConfig (ShelleyBlock era)
pcfg EraParams
_eraParams Bound
_eraStart LedgerState (ShelleyBlock era)
ledgerState =
      case ShelleyPartialLedgerConfig era -> TriggerHardFork
forall era. ShelleyPartialLedgerConfig era -> TriggerHardFork
shelleyTriggerHardFork PartialLedgerConfig (ShelleyBlock era)
ShelleyPartialLedgerConfig era
pcfg of
        TriggerHardFork
TriggerHardForkNever                         -> Maybe EpochNo
forall a. Maybe a
Nothing
        TriggerHardForkAtEpoch   EpochNo
epoch               -> EpochNo -> Maybe EpochNo
forall a. a -> Maybe a
Just EpochNo
epoch
        TriggerHardForkAtVersion Word16
shelleyMajorVersion ->
            PartialLedgerConfig (ShelleyBlock era)
-> Word16 -> LedgerState (ShelleyBlock era) -> Maybe EpochNo
forall era.
PartialLedgerConfig (ShelleyBlock era)
-> Word16 -> LedgerState (ShelleyBlock era) -> Maybe EpochNo
shelleyTransition
              PartialLedgerConfig (ShelleyBlock era)
pcfg
              Word16
shelleyMajorVersion
              LedgerState (ShelleyBlock era)
ledgerState

  singleEraInfo :: proxy (ShelleyBlock era) -> SingleEraInfo (ShelleyBlock era)
singleEraInfo proxy (ShelleyBlock era)
_ = SingleEraInfo :: forall blk. Text -> SingleEraInfo blk
SingleEraInfo {
      singleEraName :: Text
singleEraName = Text
"Shelley"
    }

instance PraosCrypto c => HasPartialConsensusConfig (TPraos c) where
  type PartialConsensusConfig (TPraos c) = TPraosParams

  completeConsensusConfig :: proxy (TPraos c)
-> EpochInfo Identity
-> PartialConsensusConfig (TPraos c)
-> ConsensusConfig (TPraos c)
completeConsensusConfig proxy (TPraos c)
_ EpochInfo Identity
tpraosEpochInfo PartialConsensusConfig (TPraos c)
tpraosParams = TPraosConfig :: forall c.
TPraosParams -> EpochInfo Identity -> ConsensusConfig (TPraos c)
TPraosConfig {EpochInfo Identity
PartialConsensusConfig (TPraos c)
TPraosParams
tpraosParams :: TPraosParams
tpraosEpochInfo :: EpochInfo Identity
tpraosParams :: PartialConsensusConfig (TPraos c)
tpraosEpochInfo :: EpochInfo Identity
..}

  -- 'ChainSelConfig' is ()
  partialChainSelConfig :: proxy (TPraos c)
-> PartialConsensusConfig (TPraos c) -> ChainSelConfig (TPraos c)
partialChainSelConfig proxy (TPraos c)
_ PartialConsensusConfig (TPraos c)
_ = ()

data ShelleyPartialLedgerConfig era = ShelleyPartialLedgerConfig {
      -- | We cache the non-partial ledger config containing a dummy
      -- 'EpochInfo' that needs to be replaced with the correct one.
      --
      -- We do this to avoid recomputing the ledger config each time
      -- 'completeLedgerConfig' is called, as 'mkShelleyLedgerConfig' does
      -- some rather expensive computations that shouldn't be repeated too
      -- often (e.g., 'sgActiveSlotCoeff').
      ShelleyPartialLedgerConfig era -> ShelleyLedgerConfig era
shelleyLedgerConfig    :: !(ShelleyLedgerConfig era)
    , ShelleyPartialLedgerConfig era -> TriggerHardFork
shelleyTriggerHardFork :: !TriggerHardFork
    }
  deriving ((forall x.
 ShelleyPartialLedgerConfig era
 -> Rep (ShelleyPartialLedgerConfig era) x)
-> (forall x.
    Rep (ShelleyPartialLedgerConfig era) x
    -> ShelleyPartialLedgerConfig era)
-> Generic (ShelleyPartialLedgerConfig era)
forall x.
Rep (ShelleyPartialLedgerConfig era) x
-> ShelleyPartialLedgerConfig era
forall x.
ShelleyPartialLedgerConfig era
-> Rep (ShelleyPartialLedgerConfig era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x.
Rep (ShelleyPartialLedgerConfig era) x
-> ShelleyPartialLedgerConfig era
forall era x.
ShelleyPartialLedgerConfig era
-> Rep (ShelleyPartialLedgerConfig era) x
$cto :: forall era x.
Rep (ShelleyPartialLedgerConfig era) x
-> ShelleyPartialLedgerConfig era
$cfrom :: forall era x.
ShelleyPartialLedgerConfig era
-> Rep (ShelleyPartialLedgerConfig era) x
Generic, Context -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo)
Proxy (ShelleyPartialLedgerConfig era) -> String
(Context -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo))
-> (Context
    -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo))
-> (Proxy (ShelleyPartialLedgerConfig era) -> String)
-> NoThunks (ShelleyPartialLedgerConfig era)
forall era.
ShelleyBasedEra era =>
Context -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo)
forall era.
ShelleyBasedEra era =>
Proxy (ShelleyPartialLedgerConfig era) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
showTypeOf :: Proxy (ShelleyPartialLedgerConfig era) -> String
$cshowTypeOf :: forall era.
ShelleyBasedEra era =>
Proxy (ShelleyPartialLedgerConfig era) -> String
wNoThunks :: Context -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall era.
ShelleyBasedEra era =>
Context -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo)
noThunks :: Context -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo)
$cnoThunks :: forall era.
ShelleyBasedEra era =>
Context -> ShelleyPartialLedgerConfig era -> IO (Maybe ThunkInfo)
NoThunks)

instance ShelleyBasedEra era => HasPartialLedgerConfig (ShelleyBlock era) where
  type PartialLedgerConfig (ShelleyBlock era) = ShelleyPartialLedgerConfig era

  -- Replace the dummy 'EpochInfo' with the real one
  completeLedgerConfig :: proxy (ShelleyBlock era)
-> EpochInfo Identity
-> PartialLedgerConfig (ShelleyBlock era)
-> LedgerConfig (ShelleyBlock era)
completeLedgerConfig proxy (ShelleyBlock era)
_ EpochInfo Identity
epochInfo (ShelleyPartialLedgerConfig cfg _) =
      ShelleyLedgerConfig era
cfg {
          shelleyLedgerGlobals :: Globals
shelleyLedgerGlobals = (ShelleyLedgerConfig era -> Globals
forall era. ShelleyLedgerConfig era -> Globals
shelleyLedgerGlobals ShelleyLedgerConfig era
cfg) {
              epochInfo :: EpochInfo Identity
SL.epochInfo = EpochInfo Identity
epochInfo
            }
        }

{-------------------------------------------------------------------------------
  CanHardFork
-------------------------------------------------------------------------------}

type CardanoHardForkConstraints c =
  ( PraosCrypto c
  , ShelleyBasedEra (ShelleyEra c)
  , ShelleyBasedEra (AllegraEra c)
  , ShelleyBasedEra (MaryEra    c)
    -- These equalities allow the transition from Byron to Shelley, since
    -- @shelley-spec-ledger@ requires Ed25519 for Byron bootstrap addresses and
    -- the current Byron-to-Shelley translation requires a 224-bit hash for
    -- address and a 256-bit hash for header hashes.
  , HASH     c ~ Blake2b_256
  , ADDRHASH c ~ Blake2b_224
  , DSIGN    c ~ Ed25519DSIGN
  )

instance CardanoHardForkConstraints c => CanHardFork (CardanoEras c) where
  hardForkEraTranslation :: EraTranslation (CardanoEras c)
hardForkEraTranslation = EraTranslation :: forall (xs :: [*]).
InPairs (RequiringBoth WrapLedgerConfig (Translate LedgerState)) xs
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     xs
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     xs
-> EraTranslation xs
EraTranslation {
      translateLedgerState :: InPairs
  (RequiringBoth WrapLedgerConfig (Translate LedgerState))
  (CardanoEras c)
translateLedgerState   =
          RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     (CardanoEras c)
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
forall c.
(ShelleyBasedEra (ShelleyEra c), HASH c ~ Blake2b_256,
 ADDRHASH c ~ Blake2b_224) =>
RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
translateLedgerStateByronToShelleyWrapper
        (InPairs
   (RequiringBoth WrapLedgerConfig (Translate LedgerState))
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
     ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapLedgerConfig (Translate LedgerState))
      (CardanoEras c))
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     (CardanoEras c)
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
forall c.
RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
translateLedgerStateShelleyToAllegraWrapper
        (InPairs
   (RequiringBoth WrapLedgerConfig (Translate LedgerState))
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapLedgerConfig (Translate LedgerState))
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
        ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
forall c.
RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
translateLedgerStateAllegraToMaryWrapper
        (InPairs
   (RequiringBoth WrapLedgerConfig (Translate LedgerState))
   '[ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapLedgerConfig (Translate LedgerState))
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig (Translate LedgerState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ InPairs
  (RequiringBoth WrapLedgerConfig (Translate LedgerState))
  '[ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k). InPairs f '[x]
PNil
    , translateChainDepState :: InPairs
  (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
  (CardanoEras c)
translateChainDepState =
          RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     (CardanoEras c)
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
forall c.
RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
translateChainDepStateByronToShelleyWrapper
        (InPairs
   (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
     ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
      (CardanoEras c))
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     (CardanoEras c)
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
forall eraFrom eraTo.
(EraCrypto eraFrom ~ EraCrypto eraTo) =>
RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  (ShelleyBlock eraFrom)
  (ShelleyBlock eraTo)
translateChainDepStateAcrossShelley
        (InPairs
   (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
        ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
forall eraFrom eraTo.
(EraCrypto eraFrom ~ EraCrypto eraTo) =>
RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  (ShelleyBlock eraFrom)
  (ShelleyBlock eraTo)
translateChainDepStateAcrossShelley
        (InPairs
   (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
   '[ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ InPairs
  (RequiringBoth WrapConsensusConfig (Translate WrapChainDepState))
  '[ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k). InPairs f '[x]
PNil
    , translateLedgerView :: InPairs
  (RequiringBoth
     WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
  (CardanoEras c)
translateLedgerView    =
          RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     (CardanoEras c)
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
forall c.
RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
translateLedgerViewByronToShelleyWrapper
        (InPairs
   (RequiringBoth
      WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
     ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth
         WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
      (CardanoEras c))
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     (CardanoEras c)
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
forall eraFrom eraTo.
(EraCrypto eraFrom ~ EraCrypto eraTo, ShelleyBasedEra eraFrom) =>
RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  (ShelleyBlock eraFrom)
  (ShelleyBlock eraTo)
translateLedgerViewAcrossShelley
        (InPairs
   (RequiringBoth
      WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth
         WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
        ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
forall eraFrom eraTo.
(EraCrypto eraFrom ~ EraCrypto eraTo, ShelleyBasedEra eraFrom) =>
RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  (ShelleyBlock eraFrom)
  (ShelleyBlock eraTo)
translateLedgerViewAcrossShelley
        (InPairs
   (RequiringBoth
      WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
   '[ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth
         WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth
        WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ InPairs
  (RequiringBoth
     WrapLedgerConfig (TranslateForecast LedgerState WrapLedgerView))
  '[ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k). InPairs f '[x]
PNil
    }
  hardForkChainSel :: Tails AcrossEraSelection (CardanoEras c)
hardForkChainSel =
        -- Byron <-> Shelley, ...
        NP
  (AcrossEraSelection ByronBlock)
  '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
    ShelleyBlock (ShelleyEra c)]
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> Tails AcrossEraSelection (CardanoEras c)
forall k (f :: k -> k -> *) (x :: k) (xs1 :: [k]).
NP (f x) xs1 -> Tails f xs1 -> Tails f (x : xs1)
TCons (AcrossEraSelection ByronBlock (ShelleyBlock (ShelleyEra c))
forall a b. AcrossEraSelection a b
CompareBlockNo AcrossEraSelection ByronBlock (ShelleyBlock (ShelleyEra c))
-> NP
     (AcrossEraSelection ByronBlock)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> NP
     (AcrossEraSelection ByronBlock)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:* AcrossEraSelection ByronBlock (ShelleyBlock (ShelleyEra c))
forall a b. AcrossEraSelection a b
CompareBlockNo AcrossEraSelection ByronBlock (ShelleyBlock (ShelleyEra c))
-> NP
     (AcrossEraSelection ByronBlock) '[ShelleyBlock (ShelleyEra c)]
-> NP
     (AcrossEraSelection ByronBlock)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:* AcrossEraSelection ByronBlock (ShelleyBlock (ShelleyEra c))
forall a b. AcrossEraSelection a b
CompareBlockNo AcrossEraSelection ByronBlock (ShelleyBlock (ShelleyEra c))
-> NP (AcrossEraSelection ByronBlock) '[]
-> NP
     (AcrossEraSelection ByronBlock) '[ShelleyBlock (ShelleyEra c)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:* NP (AcrossEraSelection ByronBlock) '[]
forall k (a :: k -> *). NP a '[]
Nil)
        -- Shelley <-> Allegra, ...
      (Tails
   AcrossEraSelection
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
     ShelleyBlock (ShelleyEra c)]
 -> Tails AcrossEraSelection (CardanoEras c))
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> Tails AcrossEraSelection (CardanoEras c)
forall a b. (a -> b) -> a -> b
$ NP
  (AcrossEraSelection (ShelleyBlock (ShelleyEra c)))
  '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (xs1 :: [k]).
NP (f x) xs1 -> Tails f xs1 -> Tails f (x : xs1)
TCons (AcrossEraSelection
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
forall a b.
(BlockProtocol a ~ BlockProtocol b) =>
AcrossEraSelection a b
SelectSameProtocol AcrossEraSelection
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
-> NP
     (AcrossEraSelection (ShelleyBlock (ShelleyEra c)))
     '[ShelleyBlock (ShelleyEra c)]
-> NP
     (AcrossEraSelection (ShelleyBlock (ShelleyEra c)))
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:* AcrossEraSelection
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
forall a b.
(BlockProtocol a ~ BlockProtocol b) =>
AcrossEraSelection a b
SelectSameProtocol AcrossEraSelection
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
-> NP (AcrossEraSelection (ShelleyBlock (ShelleyEra c))) '[]
-> NP
     (AcrossEraSelection (ShelleyBlock (ShelleyEra c)))
     '[ShelleyBlock (ShelleyEra c)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:* NP (AcrossEraSelection (ShelleyBlock (ShelleyEra c))) '[]
forall k (a :: k -> *). NP a '[]
Nil)
        -- Allegra <-> Mary, ...
      (Tails
   AcrossEraSelection
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
 -> Tails
      AcrossEraSelection
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
        ShelleyBlock (ShelleyEra c)])
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ NP
  (AcrossEraSelection (ShelleyBlock (ShelleyEra c)))
  '[ShelleyBlock (ShelleyEra c)]
-> Tails AcrossEraSelection '[ShelleyBlock (ShelleyEra c)]
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (xs1 :: [k]).
NP (f x) xs1 -> Tails f xs1 -> Tails f (x : xs1)
TCons (AcrossEraSelection
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
forall a b.
(BlockProtocol a ~ BlockProtocol b) =>
AcrossEraSelection a b
SelectSameProtocol AcrossEraSelection
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
-> NP (AcrossEraSelection (ShelleyBlock (ShelleyEra c))) '[]
-> NP
     (AcrossEraSelection (ShelleyBlock (ShelleyEra c)))
     '[ShelleyBlock (ShelleyEra c)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:* NP (AcrossEraSelection (ShelleyBlock (ShelleyEra c))) '[]
forall k (a :: k -> *). NP a '[]
Nil)
        -- Mary <-> ...
      (Tails AcrossEraSelection '[ShelleyBlock (ShelleyEra c)]
 -> Tails
      AcrossEraSelection
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)])
-> Tails AcrossEraSelection '[ShelleyBlock (ShelleyEra c)]
-> Tails
     AcrossEraSelection
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ NP (AcrossEraSelection (ShelleyBlock (ShelleyEra c))) '[]
-> Tails AcrossEraSelection '[]
-> Tails AcrossEraSelection '[ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (xs1 :: [k]).
NP (f x) xs1 -> Tails f xs1 -> Tails f (x : xs1)
TCons NP (AcrossEraSelection (ShelleyBlock (ShelleyEra c))) '[]
forall k (a :: k -> *). NP a '[]
Nil
      (Tails AcrossEraSelection '[]
 -> Tails AcrossEraSelection '[ShelleyBlock (ShelleyEra c)])
-> Tails AcrossEraSelection '[]
-> Tails AcrossEraSelection '[ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ Tails AcrossEraSelection '[]
forall k (f :: k -> k -> *). Tails f '[]
TNil
  hardForkInjectTxs :: InPairs (RequiringBoth WrapLedgerConfig InjectTx) (CardanoEras c)
hardForkInjectTxs =
        RequiringBoth
  WrapLedgerConfig InjectTx ByronBlock (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx) (CardanoEras c)
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons (InjectTx ByronBlock (ShelleyBlock (ShelleyEra c))
-> RequiringBoth
     WrapLedgerConfig InjectTx ByronBlock (ShelleyBlock (ShelleyEra c))
forall k (f :: k -> k -> *) (x :: k) (y :: k) (h :: k -> *).
f x y -> RequiringBoth h f x y
ignoringBoth InjectTx ByronBlock (ShelleyBlock (ShelleyEra c))
forall blk blk'. InjectTx blk blk'
cannotInjectTx)
      (InPairs
   (RequiringBoth WrapLedgerConfig InjectTx)
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
     ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapLedgerConfig InjectTx) (CardanoEras c))
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx) (CardanoEras c)
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapLedgerConfig
  InjectTx
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons (InjectTx
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
-> RequiringBoth
     WrapLedgerConfig
     InjectTx
     (ShelleyBlock (ShelleyEra c))
     (ShelleyBlock (ShelleyEra c))
forall k (f :: k -> k -> *) (x :: k) (y :: k) (h :: k -> *).
f x y -> RequiringBoth h f x y
ignoringBoth InjectTx
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
forall c.
InjectTx
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
translateTxShelleyToAllegraWrapper)
      (InPairs
   (RequiringBoth WrapLedgerConfig InjectTx)
   '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapLedgerConfig InjectTx)
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
        ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c),
       ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ RequiringBoth
  WrapLedgerConfig
  InjectTx
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k) (y :: k) (zs :: [k]).
f x y -> InPairs f (y : zs) -> InPairs f (x : y : zs)
PCons (InjectTx
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
-> RequiringBoth
     WrapLedgerConfig
     InjectTx
     (ShelleyBlock (ShelleyEra c))
     (ShelleyBlock (ShelleyEra c))
forall k (f :: k -> k -> *) (x :: k) (y :: k) (h :: k -> *).
f x y -> RequiringBoth h f x y
ignoringBoth InjectTx
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
forall c.
InjectTx
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
translateTxAllegraToMaryWrapper)
      (InPairs
   (RequiringBoth WrapLedgerConfig InjectTx)
   '[ShelleyBlock (ShelleyEra c)]
 -> InPairs
      (RequiringBoth WrapLedgerConfig InjectTx)
      '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)])
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c)]
-> InPairs
     (RequiringBoth WrapLedgerConfig InjectTx)
     '[ShelleyBlock (ShelleyEra c), ShelleyBlock (ShelleyEra c)]
forall a b. (a -> b) -> a -> b
$ InPairs
  (RequiringBoth WrapLedgerConfig InjectTx)
  '[ShelleyBlock (ShelleyEra c)]
forall k (f :: k -> k -> *) (x :: k). InPairs f '[x]
PNil

{-------------------------------------------------------------------------------
  Translation from Byron to Shelley
-------------------------------------------------------------------------------}

translateHeaderHashByronToShelley ::
     forall c.
     ( ShelleyBasedEra (ShelleyEra c)
     , HASH c ~ Blake2b_256
     )
  => HeaderHash ByronBlock
  -> HeaderHash (ShelleyBlock (ShelleyEra c))
translateHeaderHashByronToShelley :: HeaderHash ByronBlock -> HeaderHash (ShelleyBlock (ShelleyEra c))
translateHeaderHashByronToShelley =
      Proxy (ShelleyBlock (ShelleyEra c))
-> ShortByteString -> HeaderHash (ShelleyBlock (ShelleyEra c))
forall blk (proxy :: * -> *).
ConvertRawHash blk =>
proxy blk -> ShortByteString -> HeaderHash blk
fromShortRawHash (Proxy (ShelleyBlock (ShelleyEra c))
forall k (t :: k). Proxy t
Proxy @(ShelleyBlock (ShelleyEra c)))
    (ShortByteString -> ShelleyHash c)
-> (ByronHash -> ShortByteString) -> ByronHash -> ShelleyHash c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proxy ByronBlock -> HeaderHash ByronBlock -> ShortByteString
forall blk (proxy :: * -> *).
ConvertRawHash blk =>
proxy blk -> HeaderHash blk -> ShortByteString
toShortRawHash   (Proxy ByronBlock
forall k (t :: k). Proxy t
Proxy @ByronBlock)
  where
    -- Byron uses 'Blake2b_256' for header hashes
    ()
_ = Proxy (HASH c ~ Blake2b_256) -> ()
forall (c :: Constraint) (proxy :: Constraint -> *).
c =>
proxy c -> ()
keepRedundantConstraint (Proxy (HASH c ~ Blake2b_256)
forall k (t :: k). Proxy t
Proxy @(HASH c ~ Blake2b_256))

translatePointByronToShelley ::
     ( ShelleyBasedEra (ShelleyEra c)
     , HASH c ~ Blake2b_256
     )
  => Point ByronBlock
  -> WithOrigin BlockNo
  -> WithOrigin (ShelleyTip (ShelleyEra c))
translatePointByronToShelley :: Point ByronBlock
-> WithOrigin BlockNo -> WithOrigin (ShelleyTip (ShelleyEra c))
translatePointByronToShelley Point ByronBlock
point WithOrigin BlockNo
bNo =
    case (Point ByronBlock
point, WithOrigin BlockNo
bNo) of
      (Point ByronBlock
GenesisPoint, WithOrigin BlockNo
Origin) ->
        WithOrigin (ShelleyTip (ShelleyEra c))
forall t. WithOrigin t
Origin
      (BlockPoint SlotNo
s HeaderHash ByronBlock
h, NotOrigin BlockNo
n) -> ShelleyTip (ShelleyEra c) -> WithOrigin (ShelleyTip (ShelleyEra c))
forall t. t -> WithOrigin t
NotOrigin ShelleyTip :: forall era.
SlotNo
-> BlockNo -> HeaderHash (ShelleyBlock era) -> ShelleyTip era
ShelleyTip {
          shelleyTipSlotNo :: SlotNo
shelleyTipSlotNo  = SlotNo
s
        , shelleyTipBlockNo :: BlockNo
shelleyTipBlockNo = BlockNo
n
        , shelleyTipHash :: HeaderHash (ShelleyBlock (ShelleyEra c))
shelleyTipHash    = HeaderHash ByronBlock -> HeaderHash (ShelleyBlock (ShelleyEra c))
forall c.
(ShelleyBasedEra (ShelleyEra c), HASH c ~ Blake2b_256) =>
HeaderHash ByronBlock -> HeaderHash (ShelleyBlock (ShelleyEra c))
translateHeaderHashByronToShelley HeaderHash ByronBlock
h
        }
      (Point ByronBlock, WithOrigin BlockNo)
_otherwise ->
        String -> WithOrigin (ShelleyTip (ShelleyEra c))
forall a. HasCallStack => String -> a
error String
"translatePointByronToShelley: invalid Byron state"

translateLedgerStateByronToShelleyWrapper ::
     ( ShelleyBasedEra (ShelleyEra c)
     , HASH     c ~ Blake2b_256
     , ADDRHASH c ~ Blake2b_224
     )
  => RequiringBoth
       WrapLedgerConfig
       (Translate LedgerState)
       ByronBlock
       (ShelleyBlock (ShelleyEra c))
translateLedgerStateByronToShelleyWrapper :: RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
translateLedgerStateByronToShelleyWrapper =
    (WrapLedgerConfig ByronBlock
 -> WrapLedgerConfig (ShelleyBlock (ShelleyEra c))
 -> Translate LedgerState ByronBlock (ShelleyBlock (ShelleyEra c)))
-> RequiringBoth
     WrapLedgerConfig
     (Translate LedgerState)
     ByronBlock
     (ShelleyBlock (ShelleyEra c))
forall k (h :: k -> *) (f :: k -> k -> *) (x :: k) (y :: k).
(h x -> h y -> f x y) -> RequiringBoth h f x y
RequireBoth ((WrapLedgerConfig ByronBlock
  -> WrapLedgerConfig (ShelleyBlock (ShelleyEra c))
  -> Translate LedgerState ByronBlock (ShelleyBlock (ShelleyEra c)))
 -> RequiringBoth
      WrapLedgerConfig
      (Translate LedgerState)
      ByronBlock
      (ShelleyBlock (ShelleyEra c)))
-> (WrapLedgerConfig ByronBlock
    -> WrapLedgerConfig (ShelleyBlock (ShelleyEra c))
    -> Translate LedgerState ByronBlock (ShelleyBlock (ShelleyEra c)))
-> RequiringBoth
     WrapLedgerConfig
     (Translate LedgerState)
     ByronBlock
     (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$ \WrapLedgerConfig ByronBlock
_ (WrapLedgerConfig LedgerConfig (ShelleyBlock (ShelleyEra c))
cfgShelley) ->
    (EpochNo
 -> LedgerState ByronBlock
 -> LedgerState (ShelleyBlock (ShelleyEra c)))
-> Translate LedgerState ByronBlock (ShelleyBlock (ShelleyEra c))
forall (f :: * -> *) x y.
(EpochNo -> f x -> f y) -> Translate f x y
Translate   ((EpochNo
  -> LedgerState ByronBlock
  -> LedgerState (ShelleyBlock (ShelleyEra c)))
 -> Translate LedgerState ByronBlock (ShelleyBlock (ShelleyEra c)))
-> (EpochNo
    -> LedgerState ByronBlock
    -> LedgerState (ShelleyBlock (ShelleyEra c)))
-> Translate LedgerState ByronBlock (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$ \EpochNo
epochNo LedgerState ByronBlock
ledgerByron ->
      ShelleyLedgerState :: forall era.
WithOrigin (ShelleyTip era)
-> NewEpochState era
-> ShelleyTransition
-> LedgerState (ShelleyBlock era)
ShelleyLedgerState {
        shelleyLedgerTip :: WithOrigin (ShelleyTip (ShelleyEra c))
shelleyLedgerTip =
          Point ByronBlock
-> WithOrigin BlockNo -> WithOrigin (ShelleyTip (ShelleyEra c))
forall c.
(ShelleyBasedEra (ShelleyEra c), HASH c ~ Blake2b_256) =>
Point ByronBlock
-> WithOrigin BlockNo -> WithOrigin (ShelleyTip (ShelleyEra c))
translatePointByronToShelley
            (Proxy ByronBlock -> LedgerState ByronBlock -> Point ByronBlock
forall blk.
UpdateLedger blk =>
Proxy blk -> LedgerState blk -> Point blk
ledgerTipPoint (Proxy ByronBlock
forall k (t :: k). Proxy t
Proxy @ByronBlock) LedgerState ByronBlock
ledgerByron)
            (LedgerState ByronBlock -> WithOrigin BlockNo
byronLedgerTipBlockNo LedgerState ByronBlock
ledgerByron)
      , shelleyLedgerState :: NewEpochState (ShelleyEra c)
shelleyLedgerState =
          ShelleyGenesis (ShelleyEra c)
-> EpochNo -> ChainValidationState -> NewEpochState (ShelleyEra c)
forall c.
(Crypto c, ADDRHASH c ~ Blake2b_224) =>
ShelleyGenesis (ShelleyEra c)
-> EpochNo -> ChainValidationState -> NewEpochState (ShelleyEra c)
SL.translateToShelleyLedgerState
            (ShelleyLedgerConfig (ShelleyEra c) -> ShelleyGenesis (ShelleyEra c)
forall era. ShelleyLedgerConfig era -> ShelleyGenesis era
shelleyLedgerGenesis LedgerConfig (ShelleyBlock (ShelleyEra c))
ShelleyLedgerConfig (ShelleyEra c)
cfgShelley)
            EpochNo
epochNo
            (LedgerState ByronBlock -> ChainValidationState
byronLedgerState LedgerState ByronBlock
ledgerByron)
      , shelleyLedgerTransition :: ShelleyTransition
shelleyLedgerTransition =
          ShelleyTransitionInfo :: Word32 -> ShelleyTransition
ShelleyTransitionInfo{shelleyAfterVoting :: Word32
shelleyAfterVoting = Word32
0}
      }

translateChainDepStateByronToShelleyWrapper ::
     RequiringBoth
       WrapConsensusConfig
       (Translate WrapChainDepState)
       ByronBlock
       (ShelleyBlock (ShelleyEra c))
translateChainDepStateByronToShelleyWrapper :: RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
translateChainDepStateByronToShelleyWrapper =
    (WrapConsensusConfig ByronBlock
 -> WrapConsensusConfig (ShelleyBlock (ShelleyEra c))
 -> Translate
      WrapChainDepState ByronBlock (ShelleyBlock (ShelleyEra c)))
-> RequiringBoth
     WrapConsensusConfig
     (Translate WrapChainDepState)
     ByronBlock
     (ShelleyBlock (ShelleyEra c))
forall k (h :: k -> *) (f :: k -> k -> *) (x :: k) (y :: k).
(h x -> h y -> f x y) -> RequiringBoth h f x y
RequireBoth ((WrapConsensusConfig ByronBlock
  -> WrapConsensusConfig (ShelleyBlock (ShelleyEra c))
  -> Translate
       WrapChainDepState ByronBlock (ShelleyBlock (ShelleyEra c)))
 -> RequiringBoth
      WrapConsensusConfig
      (Translate WrapChainDepState)
      ByronBlock
      (ShelleyBlock (ShelleyEra c)))
-> (WrapConsensusConfig ByronBlock
    -> WrapConsensusConfig (ShelleyBlock (ShelleyEra c))
    -> Translate
         WrapChainDepState ByronBlock (ShelleyBlock (ShelleyEra c)))
-> RequiringBoth
     WrapConsensusConfig
     (Translate WrapChainDepState)
     ByronBlock
     (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$ \WrapConsensusConfig ByronBlock
_ (WrapConsensusConfig ConsensusConfig (BlockProtocol (ShelleyBlock (ShelleyEra c)))
cfgShelley) ->
      (EpochNo
 -> WrapChainDepState ByronBlock
 -> WrapChainDepState (ShelleyBlock (ShelleyEra c)))
-> Translate
     WrapChainDepState ByronBlock (ShelleyBlock (ShelleyEra c))
forall (f :: * -> *) x y.
(EpochNo -> f x -> f y) -> Translate f x y
Translate ((EpochNo
  -> WrapChainDepState ByronBlock
  -> WrapChainDepState (ShelleyBlock (ShelleyEra c)))
 -> Translate
      WrapChainDepState ByronBlock (ShelleyBlock (ShelleyEra c)))
-> (EpochNo
    -> WrapChainDepState ByronBlock
    -> WrapChainDepState (ShelleyBlock (ShelleyEra c)))
-> Translate
     WrapChainDepState ByronBlock (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$ \EpochNo
_ (WrapChainDepState ChainDepState (BlockProtocol ByronBlock)
pbftState) ->
        ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c)))
-> WrapChainDepState (ShelleyBlock (ShelleyEra c))
forall blk.
ChainDepState (BlockProtocol blk) -> WrapChainDepState blk
WrapChainDepState (ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c)))
 -> WrapChainDepState (ShelleyBlock (ShelleyEra c)))
-> ChainDepState (BlockProtocol (ShelleyBlock (ShelleyEra c)))
-> WrapChainDepState (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$
          ConsensusConfig (TPraos c)
-> PBftState PBftByronCrypto -> TPraosState c
forall bc c.
ConsensusConfig (TPraos c) -> PBftState bc -> TPraosState c
translateChainDepStateByronToShelley ConsensusConfig (BlockProtocol (ShelleyBlock (ShelleyEra c)))
ConsensusConfig (TPraos c)
cfgShelley PBftState PBftByronCrypto
ChainDepState (BlockProtocol ByronBlock)
pbftState

translateChainDepStateByronToShelley ::
     forall bc c.
     ConsensusConfig (TPraos c)
  -> PBftState bc
  -> TPraosState c
translateChainDepStateByronToShelley :: ConsensusConfig (TPraos c) -> PBftState bc -> TPraosState c
translateChainDepStateByronToShelley TPraosConfig { tpraosParams } PBftState bc
pbftState =
    -- Note that the 'PBftState' doesn't know about EBBs. So if the last slot of
    -- the Byron era were occupied by an EBB (and no regular block in that same
    -- slot), we would pick the wrong slot here, i.e., the slot of the regular
    -- block before the EBB.
    --
    -- Fortunately, this is impossible for two reasons:
    --
    -- 1. On mainnet we stopped producing EBBs a while before the transition.
    -- 2. The transition happens at the start of an epoch, so if the last slot
    --    were occupied by an EBB, it must have been the EBB at the start of the
    --    previous epoch. This means the previous epoch must have been empty,
    --    which is a violation of the "@k@ blocks per @2k@ slots" property.
    WithOrigin SlotNo -> ChainDepState c -> TPraosState c
forall c. WithOrigin SlotNo -> ChainDepState c -> TPraosState c
TPraosState (PBftState bc -> WithOrigin SlotNo
forall c. PBftState c -> WithOrigin SlotNo
PBftState.lastSignedSlot PBftState bc
pbftState) (ChainDepState c -> TPraosState c)
-> ChainDepState c -> TPraosState c
forall a b. (a -> b) -> a -> b
$
      ChainDepState :: forall crypto.
PrtclState crypto -> TicknState -> Nonce -> ChainDepState crypto
SL.ChainDepState
        { csProtocol :: PrtclState c
SL.csProtocol = Map (KeyHash 'BlockIssuer c) Word64
-> Nonce -> Nonce -> PrtclState c
forall crypto.
Map (KeyHash 'BlockIssuer crypto) Word64
-> Nonce -> Nonce -> PrtclState crypto
SL.PrtclState Map (KeyHash 'BlockIssuer c) Word64
forall k a. Map k a
Map.empty Nonce
nonce Nonce
nonce
        , csTickn :: TicknState
SL.csTickn    = TicknState :: Nonce -> Nonce -> TicknState
SL.TicknState {
              ticknStateEpochNonce :: Nonce
ticknStateEpochNonce    = Nonce
nonce
            , ticknStatePrevHashNonce :: Nonce
ticknStatePrevHashNonce = Nonce
SL.NeutralNonce
            }
          -- Overridden before used
        , csLabNonce :: Nonce
SL.csLabNonce = Nonce
SL.NeutralNonce
        }
  where
    nonce :: Nonce
nonce = TPraosParams -> Nonce
tpraosInitialNonce TPraosParams
tpraosParams

translateLedgerViewByronToShelleyWrapper ::
     forall c.
     RequiringBoth
       WrapLedgerConfig
       (TranslateForecast LedgerState WrapLedgerView)
       ByronBlock
       (ShelleyBlock (ShelleyEra c))
translateLedgerViewByronToShelleyWrapper :: RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  ByronBlock
  (ShelleyBlock (ShelleyEra c))
translateLedgerViewByronToShelleyWrapper =
    (WrapLedgerConfig ByronBlock
 -> WrapLedgerConfig (ShelleyBlock (ShelleyEra c))
 -> TranslateForecast
      LedgerState
      WrapLedgerView
      ByronBlock
      (ShelleyBlock (ShelleyEra c)))
-> RequiringBoth
     WrapLedgerConfig
     (TranslateForecast LedgerState WrapLedgerView)
     ByronBlock
     (ShelleyBlock (ShelleyEra c))
forall k (h :: k -> *) (f :: k -> k -> *) (x :: k) (y :: k).
(h x -> h y -> f x y) -> RequiringBoth h f x y
RequireBoth ((WrapLedgerConfig ByronBlock
  -> WrapLedgerConfig (ShelleyBlock (ShelleyEra c))
  -> TranslateForecast
       LedgerState
       WrapLedgerView
       ByronBlock
       (ShelleyBlock (ShelleyEra c)))
 -> RequiringBoth
      WrapLedgerConfig
      (TranslateForecast LedgerState WrapLedgerView)
      ByronBlock
      (ShelleyBlock (ShelleyEra c)))
-> (WrapLedgerConfig ByronBlock
    -> WrapLedgerConfig (ShelleyBlock (ShelleyEra c))
    -> TranslateForecast
         LedgerState
         WrapLedgerView
         ByronBlock
         (ShelleyBlock (ShelleyEra c)))
-> RequiringBoth
     WrapLedgerConfig
     (TranslateForecast LedgerState WrapLedgerView)
     ByronBlock
     (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$ \WrapLedgerConfig ByronBlock
_ (WrapLedgerConfig LedgerConfig (ShelleyBlock (ShelleyEra c))
cfgShelley) ->
      (Bound
 -> SlotNo
 -> LedgerState ByronBlock
 -> Except
      OutsideForecastRange
      (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))))
-> TranslateForecast
     LedgerState WrapLedgerView ByronBlock (ShelleyBlock (ShelleyEra c))
forall (f :: * -> *) (g :: * -> *) x y.
(Bound
 -> SlotNo -> f x -> Except OutsideForecastRange (Ticked (g y)))
-> TranslateForecast f g x y
TranslateForecast (ShelleyLedgerConfig (ShelleyEra c)
-> Bound
-> SlotNo
-> LedgerState ByronBlock
-> Except
     OutsideForecastRange
     (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
forecast LedgerConfig (ShelleyBlock (ShelleyEra c))
ShelleyLedgerConfig (ShelleyEra c)
cfgShelley)
  where
    -- We ignore the Byron ledger view and create a new Shelley.
    --
    -- The full Shelley forecast range (stability window) starts from the first
    -- slot of the Shelley era, no matter how many slots there are between the
    -- Byron ledger and the first Shelley slot. Note that this number of slots
    -- is still guaranteed to be less than the forecast range of the HFC in the
    -- Byron era.
    forecast ::
         ShelleyLedgerConfig (ShelleyEra c)
      -> Bound
      -> SlotNo
      -> LedgerState ByronBlock
      -> Except
           OutsideForecastRange
           (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
    forecast :: ShelleyLedgerConfig (ShelleyEra c)
-> Bound
-> SlotNo
-> LedgerState ByronBlock
-> Except
     OutsideForecastRange
     (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
forecast ShelleyLedgerConfig (ShelleyEra c)
cfgShelley Bound
bound SlotNo
forecastFor LedgerState ByronBlock
currentByronState
        | SlotNo
forecastFor SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
< SlotNo
maxFor
        = Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))
-> Except
     OutsideForecastRange
     (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
forall (m :: * -> *) a. Monad m => a -> m a
return (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))
 -> Except
      OutsideForecastRange
      (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))))
-> Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))
-> Except
     OutsideForecastRange
     (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
forall a b. (a -> b) -> a -> b
$
            Ticked (LedgerView (BlockProtocol (ShelleyBlock (ShelleyEra c))))
-> Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))
forall blk.
Ticked (LedgerView (BlockProtocol blk))
-> Ticked (WrapLedgerView blk)
WrapTickedLedgerView (Ticked (LedgerView (BlockProtocol (ShelleyBlock (ShelleyEra c))))
 -> Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
-> Ticked
     (LedgerView (BlockProtocol (ShelleyBlock (ShelleyEra c))))
-> Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))
forall a b. (a -> b) -> a -> b
$ LedgerView c -> Ticked (LedgerView c)
forall c. LedgerView c -> Ticked (LedgerView c)
TickedPraosLedgerView (LedgerView c -> Ticked (LedgerView c))
-> LedgerView c -> Ticked (LedgerView c)
forall a b. (a -> b) -> a -> b
$
              ShelleyGenesis (ShelleyEra c) -> LedgerView c
forall c. ShelleyGenesis (ShelleyEra c) -> LedgerView c
SL.mkInitialShelleyLedgerView
                (ShelleyLedgerConfig (ShelleyEra c) -> ShelleyGenesis (ShelleyEra c)
forall era. ShelleyLedgerConfig era -> ShelleyGenesis era
shelleyLedgerGenesis ShelleyLedgerConfig (ShelleyEra c)
cfgShelley)
        | Bool
otherwise
        = OutsideForecastRange
-> Except
     OutsideForecastRange
     (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (OutsideForecastRange
 -> Except
      OutsideForecastRange
      (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c)))))
-> OutsideForecastRange
-> Except
     OutsideForecastRange
     (Ticked (WrapLedgerView (ShelleyBlock (ShelleyEra c))))
forall a b. (a -> b) -> a -> b
$ OutsideForecastRange :: WithOrigin SlotNo -> SlotNo -> SlotNo -> OutsideForecastRange
OutsideForecastRange {
              outsideForecastAt :: WithOrigin SlotNo
outsideForecastAt     = LedgerState ByronBlock -> WithOrigin SlotNo
forall blk.
UpdateLedger blk =>
LedgerState blk -> WithOrigin SlotNo
ledgerTipSlot LedgerState ByronBlock
currentByronState
            , outsideForecastMaxFor :: SlotNo
outsideForecastMaxFor = SlotNo
maxFor
            , outsideForecastFor :: SlotNo
outsideForecastFor    = SlotNo
forecastFor
            }
      where
        globals :: Globals
globals = ShelleyLedgerConfig (ShelleyEra c) -> Globals
forall era. ShelleyLedgerConfig era -> Globals
shelleyLedgerGlobals ShelleyLedgerConfig (ShelleyEra c)
cfgShelley
        swindow :: Word64
swindow = Globals -> Word64
SL.stabilityWindow Globals
globals

        -- This is the exclusive upper bound of the forecast range
        --
        -- If Shelley's stability window is 0, it means we can't forecast /at
        -- all/ in the Shelley era. Not even to the first slot in the Shelley
        -- era! Remember that forecasting to slot @S@ means forecasting the
        -- ledger view obtained from the ledger state /after/ applying the block
        -- with slot @S@. If the stability window is 0, we can't even forecast
        -- after the very first "virtual" Shelley block, meaning we can't
        -- forecast into the Shelley era when still in the Byron era.
        maxFor :: SlotNo
        maxFor :: SlotNo
maxFor = Word64 -> SlotNo -> SlotNo
addSlots Word64
swindow (Bound -> SlotNo
boundSlot Bound
bound)

{-------------------------------------------------------------------------------
  Translation from one Shelley-based era to another Shelley-based era
-------------------------------------------------------------------------------}

instance ( ShelleyBasedEra era
         , ShelleyBasedEra (SL.PreviousEra era)
         , EraCrypto (SL.PreviousEra era) ~ EraCrypto era
         ) => SL.TranslateEra era ShelleyTip where
  translateEra :: TranslationContext era
-> ShelleyTip (PreviousEra era)
-> Except (TranslationError era ShelleyTip) (ShelleyTip era)
translateEra TranslationContext era
_ (ShelleyTip SlotNo
sno BlockNo
bno (ShelleyHash hash)) =
      ShelleyTip era -> ExceptT Void Identity (ShelleyTip era)
forall (m :: * -> *) a. Monad m => a -> m a
return (ShelleyTip era -> ExceptT Void Identity (ShelleyTip era))
-> ShelleyTip era -> ExceptT Void Identity (ShelleyTip era)
forall a b. (a -> b) -> a -> b
$ SlotNo
-> BlockNo -> HeaderHash (ShelleyBlock era) -> ShelleyTip era
forall era.
SlotNo
-> BlockNo -> HeaderHash (ShelleyBlock era) -> ShelleyTip era
ShelleyTip SlotNo
sno BlockNo
bno (HashHeader (EraCrypto era) -> ShelleyHash (EraCrypto era)
forall c. HashHeader c -> ShelleyHash c
ShelleyHash HashHeader (EraCrypto era)
hash)

instance ( ShelleyBasedEra era
         , SL.TranslateEra era ShelleyTip
         , SL.TranslateEra era SL.NewEpochState
         , SL.TranslationError era SL.NewEpochState ~ Void
         ) => SL.TranslateEra era (LedgerState :.: ShelleyBlock) where
  translateEra :: TranslationContext era
-> (:.:) LedgerState ShelleyBlock (PreviousEra era)
-> Except
     (TranslationError era (LedgerState :.: ShelleyBlock))
     ((:.:) LedgerState ShelleyBlock era)
translateEra TranslationContext era
ctxt (Comp (ShelleyLedgerState tip state _transition)) = do
      WithOrigin (ShelleyTip era)
tip'   <- (ShelleyTip (PreviousEra era)
 -> ExceptT Void Identity (ShelleyTip era))
-> WithOrigin (ShelleyTip (PreviousEra era))
-> ExceptT Void Identity (WithOrigin (ShelleyTip era))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (TranslationContext era
-> ShelleyTip (PreviousEra era)
-> Except (TranslationError era ShelleyTip) (ShelleyTip era)
forall era (f :: * -> *).
TranslateEra era f =>
TranslationContext era
-> f (PreviousEra era) -> Except (TranslationError era f) (f era)
SL.translateEra TranslationContext era
ctxt) WithOrigin (ShelleyTip (PreviousEra era))
tip
      NewEpochState era
state' <- TranslationContext era
-> NewEpochState (PreviousEra era)
-> Except (TranslationError era NewEpochState) (NewEpochState era)
forall era (f :: * -> *).
TranslateEra era f =>
TranslationContext era
-> f (PreviousEra era) -> Except (TranslationError era f) (f era)
SL.translateEra TranslationContext era
ctxt NewEpochState (PreviousEra era)
state
      (:.:) LedgerState ShelleyBlock era
-> ExceptT Void Identity ((:.:) LedgerState ShelleyBlock era)
forall (m :: * -> *) a. Monad m => a -> m a
return ((:.:) LedgerState ShelleyBlock era
 -> ExceptT Void Identity ((:.:) LedgerState ShelleyBlock era))
-> (:.:) LedgerState ShelleyBlock era
-> ExceptT Void Identity ((:.:) LedgerState ShelleyBlock era)
forall a b. (a -> b) -> a -> b
$ LedgerState (ShelleyBlock era)
-> (:.:) LedgerState ShelleyBlock era
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (LedgerState (ShelleyBlock era)
 -> (:.:) LedgerState ShelleyBlock era)
-> LedgerState (ShelleyBlock era)
-> (:.:) LedgerState ShelleyBlock era
forall a b. (a -> b) -> a -> b
$ ShelleyLedgerState :: forall era.
WithOrigin (ShelleyTip era)
-> NewEpochState era
-> ShelleyTransition
-> LedgerState (ShelleyBlock era)
ShelleyLedgerState {
          shelleyLedgerTip :: WithOrigin (ShelleyTip era)
shelleyLedgerTip        = WithOrigin (ShelleyTip era)
tip'
        , shelleyLedgerState :: NewEpochState era
shelleyLedgerState      = NewEpochState era
state'
        , shelleyLedgerTransition :: ShelleyTransition
shelleyLedgerTransition = Word32 -> ShelleyTransition
ShelleyTransitionInfo Word32
0
        }

instance ( ShelleyBasedEra era
         , SL.TranslateEra era SL.Tx
         ) => SL.TranslateEra era (GenTx :.: ShelleyBlock) where
  type TranslationError era (GenTx :.: ShelleyBlock) = SL.TranslationError era SL.Tx
  translateEra :: TranslationContext era
-> (:.:) GenTx ShelleyBlock (PreviousEra era)
-> Except
     (TranslationError era (GenTx :.: ShelleyBlock))
     ((:.:) GenTx ShelleyBlock era)
translateEra TranslationContext era
ctxt (Comp (ShelleyTx _txId tx)) =
    -- TODO will the txId stay the same? If so, we could avoid recomputing it
    GenTx (ShelleyBlock era) -> (:.:) GenTx ShelleyBlock era
forall l k (f :: l -> *) (g :: k -> l) (p :: k).
f (g p) -> (:.:) f g p
Comp (GenTx (ShelleyBlock era) -> (:.:) GenTx ShelleyBlock era)
-> (Tx era -> GenTx (ShelleyBlock era))
-> Tx era
-> (:.:) GenTx ShelleyBlock era
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx era -> GenTx (ShelleyBlock era)
forall era.
ShelleyBasedEra era =>
Tx era -> GenTx (ShelleyBlock era)
mkShelleyTx (Tx era -> (:.:) GenTx ShelleyBlock era)
-> ExceptT (TranslationError era Tx) Identity (Tx era)
-> ExceptT
     (TranslationError era Tx) Identity ((:.:) GenTx ShelleyBlock era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TranslationContext era
-> Tx (PreviousEra era)
-> ExceptT (TranslationError era Tx) Identity (Tx era)
forall era (f :: * -> *).
TranslateEra era f =>
TranslationContext era
-> f (PreviousEra era) -> Except (TranslationError era f) (f era)
SL.translateEra TranslationContext era
ctxt Tx (PreviousEra era)
tx

-- | Forecast from a Shelley-based era to the next Shelley-based era.
forecastAcrossShelley ::
     forall eraFrom eraTo.
     ( EraCrypto eraFrom ~ EraCrypto eraTo
     , ShelleyBasedEra eraFrom
     )
  => ShelleyLedgerConfig eraFrom
  -> ShelleyLedgerConfig eraTo
  -> Bound  -- ^ Transition between the two eras
  -> SlotNo -- ^ Forecast for this slot
  -> LedgerState (ShelleyBlock eraFrom)
  -> Except OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forecastAcrossShelley :: ShelleyLedgerConfig eraFrom
-> ShelleyLedgerConfig eraTo
-> Bound
-> SlotNo
-> LedgerState (ShelleyBlock eraFrom)
-> Except
     OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forecastAcrossShelley ShelleyLedgerConfig eraFrom
cfgFrom ShelleyLedgerConfig eraTo
cfgTo Bound
transition SlotNo
forecastFor LedgerState (ShelleyBlock eraFrom)
ledgerStateFrom
    | SlotNo
forecastFor SlotNo -> SlotNo -> Bool
forall a. Ord a => a -> a -> Bool
< SlotNo
maxFor
    = Ticked (WrapLedgerView (ShelleyBlock eraTo))
-> Except
     OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forall (m :: * -> *) a. Monad m => a -> m a
return (Ticked (WrapLedgerView (ShelleyBlock eraTo))
 -> Except
      OutsideForecastRange
      (Ticked (WrapLedgerView (ShelleyBlock eraTo))))
-> Ticked (WrapLedgerView (ShelleyBlock eraTo))
-> Except
     OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forall a b. (a -> b) -> a -> b
$ SlotNo -> Ticked (WrapLedgerView (ShelleyBlock eraTo))
futureLedgerView SlotNo
forecastFor
    | Bool
otherwise
    = OutsideForecastRange
-> Except
     OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (OutsideForecastRange
 -> Except
      OutsideForecastRange
      (Ticked (WrapLedgerView (ShelleyBlock eraTo))))
-> OutsideForecastRange
-> Except
     OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forall a b. (a -> b) -> a -> b
$ OutsideForecastRange :: WithOrigin SlotNo -> SlotNo -> SlotNo -> OutsideForecastRange
OutsideForecastRange {
          outsideForecastAt :: WithOrigin SlotNo
outsideForecastAt     = LedgerState (ShelleyBlock eraFrom) -> WithOrigin SlotNo
forall blk.
UpdateLedger blk =>
LedgerState blk -> WithOrigin SlotNo
ledgerTipSlot LedgerState (ShelleyBlock eraFrom)
ledgerStateFrom
        , outsideForecastMaxFor :: SlotNo
outsideForecastMaxFor = SlotNo
maxFor
        , outsideForecastFor :: SlotNo
outsideForecastFor    = SlotNo
forecastFor
        }
  where
    -- | 'SL.futureLedgerView' imposes its own bounds. Those bounds could
    -- /exceed/ the 'maxFor' we have computed, but should never be /less/.
    futureLedgerView :: SlotNo -> Ticked (WrapLedgerView (ShelleyBlock eraTo))
    futureLedgerView :: SlotNo -> Ticked (WrapLedgerView (ShelleyBlock eraTo))
futureLedgerView =
          Ticked (LedgerView (Crypto eraTo))
-> Ticked (WrapLedgerView (ShelleyBlock eraTo))
forall blk.
Ticked (LedgerView (BlockProtocol blk))
-> Ticked (WrapLedgerView blk)
WrapTickedLedgerView
        (Ticked (LedgerView (Crypto eraTo))
 -> Ticked (WrapLedgerView (ShelleyBlock eraTo)))
-> (SlotNo -> Ticked (LedgerView (Crypto eraTo)))
-> SlotNo
-> Ticked (WrapLedgerView (ShelleyBlock eraTo))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LedgerView (Crypto eraTo) -> Ticked (LedgerView (Crypto eraTo))
forall c. LedgerView c -> Ticked (LedgerView c)
TickedPraosLedgerView
        (LedgerView (Crypto eraTo) -> Ticked (LedgerView (Crypto eraTo)))
-> (SlotNo -> LedgerView (Crypto eraTo))
-> SlotNo
-> Ticked (LedgerView (Crypto eraTo))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FutureLedgerViewError eraFrom -> LedgerView (Crypto eraTo))
-> (LedgerView (Crypto eraTo) -> LedgerView (Crypto eraTo))
-> Either
     (FutureLedgerViewError eraFrom) (LedgerView (Crypto eraTo))
-> LedgerView (Crypto eraTo)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
            (\FutureLedgerViewError eraFrom
e -> String -> LedgerView (Crypto eraTo)
forall a. HasCallStack => String -> a
error (String
"futureLedgerView failed: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> FutureLedgerViewError eraFrom -> String
forall a. Show a => a -> String
show FutureLedgerViewError eraFrom
e))
            LedgerView (Crypto eraTo) -> LedgerView (Crypto eraTo)
forall a. a -> a
id
        (Either (FutureLedgerViewError eraFrom) (LedgerView (Crypto eraTo))
 -> LedgerView (Crypto eraTo))
-> (SlotNo
    -> Either
         (FutureLedgerViewError eraFrom) (LedgerView (Crypto eraTo)))
-> SlotNo
-> LedgerView (Crypto eraTo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Globals
-> NewEpochState eraFrom
-> SlotNo
-> Either
     (FutureLedgerViewError eraFrom) (LedgerView (Crypto eraFrom))
forall era (m :: * -> *).
(GetLedgerView era, MonadError (FutureLedgerViewError era) m) =>
Globals
-> NewEpochState era -> SlotNo -> m (LedgerView (Crypto era))
SL.futureLedgerView
            (ShelleyLedgerConfig eraFrom -> Globals
forall era. ShelleyLedgerConfig era -> Globals
shelleyLedgerGlobals ShelleyLedgerConfig eraFrom
cfgFrom)
            (LedgerState (ShelleyBlock eraFrom) -> NewEpochState eraFrom
forall era. LedgerState (ShelleyBlock era) -> NewEpochState era
shelleyLedgerState LedgerState (ShelleyBlock eraFrom)
ledgerStateFrom)

    -- Exclusive upper bound
    maxFor :: SlotNo
    maxFor :: SlotNo
maxFor = WithOrigin SlotNo -> SlotNo -> Word64 -> Word64 -> SlotNo
crossEraForecastBound
               (LedgerState (ShelleyBlock eraFrom) -> WithOrigin SlotNo
forall blk.
UpdateLedger blk =>
LedgerState blk -> WithOrigin SlotNo
ledgerTipSlot LedgerState (ShelleyBlock eraFrom)
ledgerStateFrom)
               (Bound -> SlotNo
boundSlot Bound
transition)
               (Globals -> Word64
SL.stabilityWindow (ShelleyLedgerConfig eraFrom -> Globals
forall era. ShelleyLedgerConfig era -> Globals
shelleyLedgerGlobals ShelleyLedgerConfig eraFrom
cfgFrom))
               (Globals -> Word64
SL.stabilityWindow (ShelleyLedgerConfig eraTo -> Globals
forall era. ShelleyLedgerConfig era -> Globals
shelleyLedgerGlobals ShelleyLedgerConfig eraTo
cfgTo))

translateChainDepStateAcrossShelley ::
     forall eraFrom eraTo.
     EraCrypto eraFrom ~ EraCrypto eraTo
  => RequiringBoth
       WrapConsensusConfig
       (Translate WrapChainDepState)
       (ShelleyBlock eraFrom)
       (ShelleyBlock eraTo)
translateChainDepStateAcrossShelley :: RequiringBoth
  WrapConsensusConfig
  (Translate WrapChainDepState)
  (ShelleyBlock eraFrom)
  (ShelleyBlock eraTo)
translateChainDepStateAcrossShelley =
    Translate
  WrapChainDepState (ShelleyBlock eraFrom) (ShelleyBlock eraTo)
-> RequiringBoth
     WrapConsensusConfig
     (Translate WrapChainDepState)
     (ShelleyBlock eraFrom)
     (ShelleyBlock eraTo)
forall k (f :: k -> k -> *) (x :: k) (y :: k) (h :: k -> *).
f x y -> RequiringBoth h f x y
ignoringBoth (Translate
   WrapChainDepState (ShelleyBlock eraFrom) (ShelleyBlock eraTo)
 -> RequiringBoth
      WrapConsensusConfig
      (Translate WrapChainDepState)
      (ShelleyBlock eraFrom)
      (ShelleyBlock eraTo))
-> Translate
     WrapChainDepState (ShelleyBlock eraFrom) (ShelleyBlock eraTo)
-> RequiringBoth
     WrapConsensusConfig
     (Translate WrapChainDepState)
     (ShelleyBlock eraFrom)
     (ShelleyBlock eraTo)
forall a b. (a -> b) -> a -> b
$
      (EpochNo
 -> WrapChainDepState (ShelleyBlock eraFrom)
 -> WrapChainDepState (ShelleyBlock eraTo))
-> Translate
     WrapChainDepState (ShelleyBlock eraFrom) (ShelleyBlock eraTo)
forall (f :: * -> *) x y.
(EpochNo -> f x -> f y) -> Translate f x y
Translate ((EpochNo
  -> WrapChainDepState (ShelleyBlock eraFrom)
  -> WrapChainDepState (ShelleyBlock eraTo))
 -> Translate
      WrapChainDepState (ShelleyBlock eraFrom) (ShelleyBlock eraTo))
-> (EpochNo
    -> WrapChainDepState (ShelleyBlock eraFrom)
    -> WrapChainDepState (ShelleyBlock eraTo))
-> Translate
     WrapChainDepState (ShelleyBlock eraFrom) (ShelleyBlock eraTo)
forall a b. (a -> b) -> a -> b
$ \EpochNo
_epochNo (WrapChainDepState ChainDepState (BlockProtocol (ShelleyBlock eraFrom))
chainDepState) ->
        -- Same protocol, same 'ChainDepState'. Note that we don't have to apply
        -- any changes related to an epoch transition, this is already done when
        -- ticking the state.
        ChainDepState (BlockProtocol (ShelleyBlock eraTo))
-> WrapChainDepState (ShelleyBlock eraTo)
forall blk.
ChainDepState (BlockProtocol blk) -> WrapChainDepState blk
WrapChainDepState ChainDepState (BlockProtocol (ShelleyBlock eraFrom))
ChainDepState (BlockProtocol (ShelleyBlock eraTo))
chainDepState

translateLedgerViewAcrossShelley ::
     forall eraFrom eraTo.
     ( EraCrypto eraFrom ~ EraCrypto eraTo
     , ShelleyBasedEra eraFrom
     )
  => RequiringBoth
       WrapLedgerConfig
       (TranslateForecast LedgerState WrapLedgerView)
       (ShelleyBlock eraFrom)
       (ShelleyBlock eraTo)
translateLedgerViewAcrossShelley :: RequiringBoth
  WrapLedgerConfig
  (TranslateForecast LedgerState WrapLedgerView)
  (ShelleyBlock eraFrom)
  (ShelleyBlock eraTo)
translateLedgerViewAcrossShelley =
    (WrapLedgerConfig (ShelleyBlock eraFrom)
 -> WrapLedgerConfig (ShelleyBlock eraTo)
 -> TranslateForecast
      LedgerState
      WrapLedgerView
      (ShelleyBlock eraFrom)
      (ShelleyBlock eraTo))
-> RequiringBoth
     WrapLedgerConfig
     (TranslateForecast LedgerState WrapLedgerView)
     (ShelleyBlock eraFrom)
     (ShelleyBlock eraTo)
forall k (h :: k -> *) (f :: k -> k -> *) (x :: k) (y :: k).
(h x -> h y -> f x y) -> RequiringBoth h f x y
RequireBoth ((WrapLedgerConfig (ShelleyBlock eraFrom)
  -> WrapLedgerConfig (ShelleyBlock eraTo)
  -> TranslateForecast
       LedgerState
       WrapLedgerView
       (ShelleyBlock eraFrom)
       (ShelleyBlock eraTo))
 -> RequiringBoth
      WrapLedgerConfig
      (TranslateForecast LedgerState WrapLedgerView)
      (ShelleyBlock eraFrom)
      (ShelleyBlock eraTo))
-> (WrapLedgerConfig (ShelleyBlock eraFrom)
    -> WrapLedgerConfig (ShelleyBlock eraTo)
    -> TranslateForecast
         LedgerState
         WrapLedgerView
         (ShelleyBlock eraFrom)
         (ShelleyBlock eraTo))
-> RequiringBoth
     WrapLedgerConfig
     (TranslateForecast LedgerState WrapLedgerView)
     (ShelleyBlock eraFrom)
     (ShelleyBlock eraTo)
forall a b. (a -> b) -> a -> b
$ \(WrapLedgerConfig LedgerConfig (ShelleyBlock eraFrom)
cfgFrom)
                   (WrapLedgerConfig LedgerConfig (ShelleyBlock eraTo)
cfgTo) ->
      (Bound
 -> SlotNo
 -> LedgerState (ShelleyBlock eraFrom)
 -> Except
      OutsideForecastRange
      (Ticked (WrapLedgerView (ShelleyBlock eraTo))))
-> TranslateForecast
     LedgerState
     WrapLedgerView
     (ShelleyBlock eraFrom)
     (ShelleyBlock eraTo)
forall (f :: * -> *) (g :: * -> *) x y.
(Bound
 -> SlotNo -> f x -> Except OutsideForecastRange (Ticked (g y)))
-> TranslateForecast f g x y
TranslateForecast ((Bound
  -> SlotNo
  -> LedgerState (ShelleyBlock eraFrom)
  -> Except
       OutsideForecastRange
       (Ticked (WrapLedgerView (ShelleyBlock eraTo))))
 -> TranslateForecast
      LedgerState
      WrapLedgerView
      (ShelleyBlock eraFrom)
      (ShelleyBlock eraTo))
-> (Bound
    -> SlotNo
    -> LedgerState (ShelleyBlock eraFrom)
    -> Except
         OutsideForecastRange
         (Ticked (WrapLedgerView (ShelleyBlock eraTo))))
-> TranslateForecast
     LedgerState
     WrapLedgerView
     (ShelleyBlock eraFrom)
     (ShelleyBlock eraTo)
forall a b. (a -> b) -> a -> b
$ ShelleyLedgerConfig eraFrom
-> ShelleyLedgerConfig eraTo
-> Bound
-> SlotNo
-> LedgerState (ShelleyBlock eraFrom)
-> Except
     OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forall eraFrom eraTo.
(EraCrypto eraFrom ~ EraCrypto eraTo, ShelleyBasedEra eraFrom) =>
ShelleyLedgerConfig eraFrom
-> ShelleyLedgerConfig eraTo
-> Bound
-> SlotNo
-> LedgerState (ShelleyBlock eraFrom)
-> Except
     OutsideForecastRange (Ticked (WrapLedgerView (ShelleyBlock eraTo)))
forecastAcrossShelley LedgerConfig (ShelleyBlock eraFrom)
ShelleyLedgerConfig eraFrom
cfgFrom LedgerConfig (ShelleyBlock eraTo)
ShelleyLedgerConfig eraTo
cfgTo

{-------------------------------------------------------------------------------
  Translation from Shelley to Allegra
-------------------------------------------------------------------------------}

translateLedgerStateShelleyToAllegraWrapper ::
    RequiringBoth
       WrapLedgerConfig
       (Translate LedgerState)
       (ShelleyBlock (ShelleyEra c))
       (ShelleyBlock (AllegraEra c))
translateLedgerStateShelleyToAllegraWrapper :: RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
translateLedgerStateShelleyToAllegraWrapper =
    Translate
  LedgerState
  (ShelleyBlock (ShelleyEra c))
  (ShelleyBlock (ShelleyEra c))
-> RequiringBoth
     WrapLedgerConfig
     (Translate LedgerState)
     (ShelleyBlock (ShelleyEra c))
     (ShelleyBlock (ShelleyEra c))
forall k (f :: k -> k -> *) (x :: k) (y :: k) (h :: k -> *).
f x y -> RequiringBoth h f x y
ignoringBoth (Translate
   LedgerState
   (ShelleyBlock (ShelleyEra c))
   (ShelleyBlock (ShelleyEra c))
 -> RequiringBoth
      WrapLedgerConfig
      (Translate LedgerState)
      (ShelleyBlock (ShelleyEra c))
      (ShelleyBlock (ShelleyEra c)))
-> Translate
     LedgerState
     (ShelleyBlock (ShelleyEra c))
     (ShelleyBlock (ShelleyEra c))
-> RequiringBoth
     WrapLedgerConfig
     (Translate LedgerState)
     (ShelleyBlock (ShelleyEra c))
     (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$
      (EpochNo
 -> LedgerState (ShelleyBlock (ShelleyEra c))
 -> LedgerState (ShelleyBlock (ShelleyEra c)))
-> Translate
     LedgerState
     (ShelleyBlock (ShelleyEra c))
     (ShelleyBlock (ShelleyEra c))
forall (f :: * -> *) x y.
(EpochNo -> f x -> f y) -> Translate f x y
Translate ((EpochNo
  -> LedgerState (ShelleyBlock (ShelleyEra c))
  -> LedgerState (ShelleyBlock (ShelleyEra c)))
 -> Translate
      LedgerState
      (ShelleyBlock (ShelleyEra c))
      (ShelleyBlock (ShelleyEra c)))
-> (EpochNo
    -> LedgerState (ShelleyBlock (ShelleyEra c))
    -> LedgerState (ShelleyBlock (ShelleyEra c)))
-> Translate
     LedgerState
     (ShelleyBlock (ShelleyEra c))
     (ShelleyBlock (ShelleyEra c))
forall a b. (a -> b) -> a -> b
$ \EpochNo
_epochNo LedgerState (ShelleyBlock (ShelleyEra c))
ledgerShelley -> LedgerState (ShelleyBlock (ShelleyEra c))
ledgerShelley

translateTxShelleyToAllegraWrapper ::
     InjectTx
       (ShelleyBlock (ShelleyEra c))
       (ShelleyBlock (AllegraEra c))
translateTxShelleyToAllegraWrapper :: InjectTx
  (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
translateTxShelleyToAllegraWrapper = (GenTx (ShelleyBlock (ShelleyEra c))
 -> Maybe (GenTx (ShelleyBlock (ShelleyEra c))))
-> InjectTx
     (ShelleyBlock (ShelleyEra c)) (ShelleyBlock (ShelleyEra c))
forall blk blk'.
(GenTx blk -> Maybe (GenTx blk')) -> InjectTx blk blk'
InjectTx GenTx (ShelleyBlock (ShelleyEra c))
-> Maybe (GenTx (ShelleyBlock (ShelleyEra c)))
forall a. a -> Maybe a
Just

{-------------------------------------------------------------------------------
  Translation from Shelley to Allegra
-------------------------------------------------------------------------------}

translateLedgerStateAllegraToMaryWrapper ::
    RequiringBoth
       WrapLedgerConfig
       (Translate LedgerState)
       (ShelleyBlock (AllegraEra c))
       (ShelleyBlock (MaryEra c))
translateLedgerStateAllegraToMaryWrapper :: RequiringBoth
  WrapLedgerConfig
  (Translate LedgerState)
  (ShelleyBlock (AllegraEra c))
  (ShelleyBlock (AllegraEra c))
translateLedgerStateAllegraToMaryWrapper =
    Translate
  LedgerState
  (ShelleyBlock (AllegraEra c))
  (ShelleyBlock (AllegraEra c))
-> RequiringBoth
     WrapLedgerConfig
     (Translate LedgerState)
     (ShelleyBlock (AllegraEra c))
     (ShelleyBlock (AllegraEra c))
forall k (f :: k -> k -> *) (x :: k) (y :: k) (h :: k -> *).
f x y -> RequiringBoth h f x y
ignoringBoth (Translate
   LedgerState
   (ShelleyBlock (AllegraEra c))
   (ShelleyBlock (AllegraEra c))
 -> RequiringBoth
      WrapLedgerConfig
      (Translate LedgerState)
      (ShelleyBlock (AllegraEra c))
      (ShelleyBlock (AllegraEra c)))
-> Translate
     LedgerState
     (ShelleyBlock (AllegraEra c))
     (ShelleyBlock (AllegraEra c))
-> RequiringBoth
     WrapLedgerConfig
     (Translate LedgerState)
     (ShelleyBlock (AllegraEra c))
     (ShelleyBlock (AllegraEra c))
forall a b. (a -> b) -> a -> b
$
      (EpochNo
 -> LedgerState (ShelleyBlock (AllegraEra c))
 -> LedgerState (ShelleyBlock (AllegraEra c)))
-> Translate
     LedgerState
     (ShelleyBlock (AllegraEra c))
     (ShelleyBlock (AllegraEra c))
forall (f :: * -> *) x y.
(EpochNo -> f x -> f y) -> Translate f x y
Translate ((EpochNo
  -> LedgerState (ShelleyBlock (AllegraEra c))
  -> LedgerState (ShelleyBlock (AllegraEra c)))
 -> Translate
      LedgerState
      (ShelleyBlock (AllegraEra c))
      (ShelleyBlock (AllegraEra c)))
-> (EpochNo
    -> LedgerState (ShelleyBlock (AllegraEra c))
    -> LedgerState (ShelleyBlock (AllegraEra c)))
-> Translate
     LedgerState
     (ShelleyBlock (AllegraEra c))
     (ShelleyBlock (AllegraEra c))
forall a b. (a -> b) -> a -> b
$ \EpochNo
_epochNo LedgerState (ShelleyBlock (AllegraEra c))
ledgerAllegra -> LedgerState (ShelleyBlock (AllegraEra c))
ledgerAllegra

translateTxAllegraToMaryWrapper ::
     InjectTx
       (ShelleyBlock (AllegraEra c))
       (ShelleyBlock (MaryEra c))
translateTxAllegraToMaryWrapper :: InjectTx
  (ShelleyBlock (AllegraEra c)) (ShelleyBlock (AllegraEra c))
translateTxAllegraToMaryWrapper = (GenTx (ShelleyBlock (AllegraEra c))
 -> Maybe (GenTx (ShelleyBlock (AllegraEra c))))
-> InjectTx
     (ShelleyBlock (AllegraEra c)) (ShelleyBlock (AllegraEra c))
forall blk blk'.
(GenTx blk -> Maybe (GenTx blk')) -> InjectTx blk blk'
InjectTx GenTx (ShelleyBlock (AllegraEra c))
-> Maybe (GenTx (ShelleyBlock (AllegraEra c)))
forall a. a -> Maybe a
Just