Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define 'GetLedgerView' for Babbage. #2711

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ cradle:

- path: "libs/cardano-ledger-pretty/src"
component: "lib:cardano-ledger-pretty"

- path: "libs/cardano-protocol-tpraos"
component: "lib:cardano-protocol-tpraos"
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ library
cardano-binary,
cardano-crypto-class,
cardano-ledger-alonzo,
cardano-ledger-babbage,
cardano-ledger-core,
cardano-ledger-shelley,
cardano-ledger-shelley-ma,
Expand Down
42 changes: 39 additions & 3 deletions libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}

Expand Down Expand Up @@ -46,6 +45,8 @@ import Cardano.Ledger.Allegra (AllegraEra)
import Cardano.Ledger.Alonzo (AlonzoEra)
import qualified Cardano.Ledger.Alonzo.PParams as Alonzo (PParams' (..))
import Cardano.Ledger.BHeaderView (isOverlaySlot)
import Cardano.Ledger.Babbage (BabbageEra)
import qualified Cardano.Ledger.Babbage.PParams as Babbage (PParams' (..))
import Cardano.Ledger.BaseTypes
( Globals (..),
Nonce (NeutralNonce),
Expand Down Expand Up @@ -151,7 +152,6 @@ class
Signal (Core.EraRule "TICKF" era) ~ SlotNo,
PredicateFailure (Core.EraRule "TICKF" era) ~ TickfPredicateFailure era,
HasField "_d" (Core.PParams era) UnitInterval,
HasField "_extraEntropy" (Core.PParams era) Nonce,
HasField "_maxBBSize" (Core.PParams era) Natural,
HasField "_maxBHSize" (Core.PParams era) Natural,
HasField "_protocolVersion" (Core.PParams era) ProtVer
Expand All @@ -161,6 +161,10 @@ class
currentLedgerView ::
NewEpochState era ->
LedgerView (Crypto era)
default currentLedgerView ::
HasField "_extraEntropy" (Core.PParams era) Nonce =>
NewEpochState era ->
LedgerView (Crypto era)
currentLedgerView = view

-- $timetravel
Expand All @@ -171,7 +175,9 @@ class
SlotNo ->
m (LedgerView (Crypto era))
default futureLedgerView ::
(MonadError (FutureLedgerViewError era) m) =>
( MonadError (FutureLedgerViewError era) m,
HasField "_extraEntropy" (Core.PParams era) Nonce
) =>
Globals ->
NewEpochState era ->
SlotNo ->
Expand All @@ -186,6 +192,36 @@ instance CC.Crypto c => GetLedgerView (MaryEra c)

instance CC.Crypto c => GetLedgerView (AlonzoEra c)

-- Note that although we do not use TPraos in the Babbage era, we include this
-- because it makes it simpler to get the ledger view for Praos.
instance CC.Crypto c => GetLedgerView (BabbageEra c) where
currentLedgerView
NewEpochState
{ nesPd,
nesEs
} =
LedgerView
{ lvD = getField @"_d" . esPp $ nesEs,
lvExtraEntropy = error "Extra entropy is not set in the Babbage era",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be less scary to use the neutral nonce? though perhaps failing hard is better? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to go for failing hard, though I could be argued the other way!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fail hard!

Do not go gentle into that good night,
Old age should burn and rave at close of day;
Rage, rage against the dying of the light.

lvPoolDistr = nesPd,
lvGenDelegs =
_genDelegs . _dstate
. _delegationState
$ esLState nesEs,
lvChainChecks = pparamsToChainChecksPParams . esPp $ nesEs
}

futureLedgerView globals ss slot =
liftEither
. right currentLedgerView
. left FutureLedgerViewError
$ res
where
res =
flip runReader globals
. applySTS @(Core.EraRule "TICKF" (BabbageEra c))
$ TRC ((), ss, slot)

-- | Data required by the Transitional Praos protocol from the Shelley ledger.
data LedgerView crypto = LedgerView
{ lvD :: UnitInterval,
Expand Down