diff --git a/cabal.project b/cabal.project index 1e62c863fce..31a62773098 100644 --- a/cabal.project +++ b/cabal.project @@ -104,8 +104,8 @@ source-repository-package type: git location: https://github.com/tweag/cardano-cls.git subdir: merkle-tree-incremental mempack-scls scls-cbor scls-cardano scls-format scls-core - --sha256: sha256-BoAotLgxMipOIMcZrmlr6EtQzqC5HyEA0ZpK8nvCmJs= - tag: 5161deb34247a51160f2e8d58b6cc2d48044ea2c + --sha256: sha256-02j6m1UBYiZrdgAzGFb5yO+tFf8pN6DmykZjk9tdOUg= + tag: 940f6ad992382e856082f73c437a162211e50ba8 constraints: -- Happy version 2.2.1 fails to compile haskell-src-exts diff --git a/libs/cardano-ledger-canonical-state/cardano-ledger-canonical-state.cabal b/libs/cardano-ledger-canonical-state/cardano-ledger-canonical-state.cabal index b5acbe4ae2b..1ff6dc3db01 100644 --- a/libs/cardano-ledger-canonical-state/cardano-ledger-canonical-state.cabal +++ b/libs/cardano-ledger-canonical-state/cardano-ledger-canonical-state.cabal @@ -45,6 +45,7 @@ library Cardano.Ledger.CanonicalState.Namespace Cardano.Ledger.CanonicalState.Namespace.Blocks.V0 Cardano.Ledger.CanonicalState.Namespace.EntitiesCommittee.V0 + Cardano.Ledger.CanonicalState.Namespace.EntitiesDormantEpochs.V0 Cardano.Ledger.CanonicalState.Namespace.GovCommittee.V0 Cardano.Ledger.CanonicalState.Namespace.GovConstitution.V0 Cardano.Ledger.CanonicalState.Namespace.GovPParams.V0 diff --git a/libs/cardano-ledger-canonical-state/conway/Cardano/Ledger/CanonicalState/Conway.hs b/libs/cardano-ledger-canonical-state/conway/Cardano/Ledger/CanonicalState/Conway.hs index 171c3a013d3..1822c8e7525 100644 --- a/libs/cardano-ledger-canonical-state/conway/Cardano/Ledger/CanonicalState/Conway.hs +++ b/libs/cardano-ledger-canonical-state/conway/Cardano/Ledger/CanonicalState/Conway.hs @@ -64,6 +64,8 @@ type instance NamespaceEra "blocks/v0" = ConwayEra type instance NamespaceEra "entities/committee/v0" = ConwayEra +type instance NamespaceEra "entities/dormant_epochs/v0" = ConwayEra + type instance NamespaceEra "gov/committee/v0" = ConwayEra type instance NamespaceEra "gov/constitution/v0" = ConwayEra diff --git a/libs/cardano-ledger-canonical-state/src/Cardano/Ledger/CanonicalState/Namespace/EntitiesDormantEpochs/V0.hs b/libs/cardano-ledger-canonical-state/src/Cardano/Ledger/CanonicalState/Namespace/EntitiesDormantEpochs/V0.hs new file mode 100644 index 00000000000..557757996d0 --- /dev/null +++ b/libs/cardano-ledger-canonical-state/src/Cardano/Ledger/CanonicalState/Namespace/EntitiesDormantEpochs/V0.hs @@ -0,0 +1,92 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingVia #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} + +module Cardano.Ledger.CanonicalState.Namespace.EntitiesDormantEpochs.V0 ( + EntitiesDormantEpochsIn (..), + EntitiesDormantEpochsOut (..), +) where + +import Cardano.Ledger.BaseTypes (EpochNo) +import Cardano.Ledger.CanonicalState.Namespace (Era, NamespaceEra) +import Cardano.SCLS.CBOR.Canonical.Decoder (FromCanonicalCBOR (..)) +import Cardano.SCLS.CBOR.Canonical.Encoder (ToCanonicalCBOR (..)) +import Cardano.SCLS.Entry.IsKey (IsKey (..)) +import Cardano.SCLS.NamespaceCodec ( + CanonicalCBOREntryDecoder (..), + CanonicalCBOREntryEncoder (..), + KnownNamespace (..), + NamespaceKeySize, + namespaceKeySize, + ) +import Cardano.SCLS.Versioned (Versioned (..)) +import Data.MemPack (MemPack (packM, unpackM)) +import Data.Proxy (Proxy (..)) +import Data.Word (Word8) +import GHC.Generics (Generic) + +instance + ( Era era + , NamespaceEra "entities/dormant_epochs/v0" ~ era + , ToCanonicalCBOR "entities/dormant_epochs/v0" EntitiesDormantEpochsOut + , FromCanonicalCBOR "entities/dormant_epochs/v0" EntitiesDormantEpochsOut + ) => + KnownNamespace "entities/dormant_epochs/v0" + where + type NamespaceKey "entities/dormant_epochs/v0" = EntitiesDormantEpochsIn + type NamespaceEntry "entities/dormant_epochs/v0" = EntitiesDormantEpochsOut + +instance + ( Era era + , NamespaceEra "entities/dormant_epochs/v0" ~ era + , ToCanonicalCBOR "entities/dormant_epochs/v0" EntitiesDormantEpochsOut + ) => + CanonicalCBOREntryEncoder "entities/dormant_epochs/v0" EntitiesDormantEpochsOut + where + encodeEntry = toCanonicalCBOR (Proxy @"entities/dormant_epochs/v0") + +instance + ( Era era + , NamespaceEra "entities/dormant_epochs/v0" ~ era + , FromCanonicalCBOR "entities/dormant_epochs/v0" EntitiesDormantEpochsOut + ) => + CanonicalCBOREntryDecoder "entities/dormant_epochs/v0" EntitiesDormantEpochsOut + where + decodeEntry = fromCanonicalCBOR + +data EntitiesDormantEpochsIn = EntitiesDormantEpochsIn + deriving (Eq, Ord, Show, Enum, Generic) + +type instance NamespaceKeySize "entities/dormant_epochs/v0" = 1 + +instance IsKey EntitiesDormantEpochsIn where + keySize = namespaceKeySize @"entities/dormant_epochs/v0" + packKeyM = + packM . fromIntegral @_ @Word8 . fromEnum + unpackKeyM = + toEnum . fromIntegral @Word8 @Int <$> unpackM + +newtype EntitiesDormantEpochsOut + = EntitiesDormantEpochsOut EpochNo + deriving (Eq, Show, Generic) + +deriving newtype instance + ToCanonicalCBOR "entities/dormant_epochs/v0" EpochNo => + ToCanonicalCBOR "entities/dormant_epochs/v0" EntitiesDormantEpochsOut + +deriving newtype instance + FromCanonicalCBOR "entities/dormant_epochs/v0" EpochNo => + FromCanonicalCBOR "entities/dormant_epochs/v0" EntitiesDormantEpochsOut diff --git a/libs/cardano-ledger-canonical-state/test/Test/Cardano/Ledger/CanonicalState/Spec.hs b/libs/cardano-ledger-canonical-state/test/Test/Cardano/Ledger/CanonicalState/Spec.hs index 022bd741414..730dded1687 100644 --- a/libs/cardano-ledger-canonical-state/test/Test/Cardano/Ledger/CanonicalState/Spec.hs +++ b/libs/cardano-ledger-canonical-state/test/Test/Cardano/Ledger/CanonicalState/Spec.hs @@ -13,11 +13,12 @@ module Test.Cardano.Ledger.CanonicalState.Spec (spec) where -import Cardano.Ledger.BaseTypes (EpochInterval, NonNegativeInterval, UnitInterval) +import Cardano.Ledger.BaseTypes (EpochInterval, EpochNo, NonNegativeInterval, UnitInterval) import Cardano.Ledger.CanonicalState.BasicTypes (CanonicalExUnits (..)) import Cardano.Ledger.CanonicalState.Conway () import qualified Cardano.Ledger.CanonicalState.Namespace.Blocks.V0 as Blocks.V0 import qualified Cardano.Ledger.CanonicalState.Namespace.EntitiesCommittee.V0 as Committee.V0 +import qualified Cardano.Ledger.CanonicalState.Namespace.EntitiesDormantEpochs.V0 as EntitiesDormantEpochs.V0 import qualified Cardano.Ledger.CanonicalState.Namespace.GovCommittee.V0 as GovCommittee.V0 import qualified Cardano.Ledger.CanonicalState.Namespace.GovConstitution.V0 as GovConstitution.V0 import qualified Cardano.Ledger.CanonicalState.Namespace.GovPParams.V0 as GovPParams.V0 @@ -47,6 +48,12 @@ spec = do isCanonical @"entities/committee/v0" @Committee.V0.CanonicalCommitteeAuthorization validateType @"entities/committee/v0" @Committee.V0.CanonicalCommitteeAuthorization "committee_authorization" + describe "entities/dormant_epochs/v0" $ do + isCanonical @"entities/dormant_epochs/v0" @EpochNo + validateType @"entities/dormant_epochs/v0" @EpochNo "epoch_no" + isCanonical @"entities/dormant_epochs/v0" @EntitiesDormantEpochs.V0.EntitiesDormantEpochsOut + validateType @"entities/dormant_epochs/v0" @EntitiesDormantEpochs.V0.EntitiesDormantEpochsOut + "record_entry" describe "gov/committee/v0" $ do isCanonical @"gov/committee/v0" @GovCommittee.V0.CanonicalCommittee validateType @"gov/committee/v0" @GovCommittee.V0.CanonicalCommittee "committee" @@ -70,6 +77,7 @@ spec = do testNS @"blocks/v0" testNS @"utxo/v0" testNS @"entities/committee/v0" + testNS @"entities/dormant_epochs/v0" testNS @"gov/constitution/v0" testNS @"gov/committee/v0" testNS @"gov/pparams/v0" diff --git a/libs/cardano-ledger-canonical-state/testlib/Test/Cardano/Ledger/Conway/CanonicalState/Arbitrary.hs b/libs/cardano-ledger-canonical-state/testlib/Test/Cardano/Ledger/Conway/CanonicalState/Arbitrary.hs index 1a2976e75a0..73ab0189f39 100644 --- a/libs/cardano-ledger-canonical-state/testlib/Test/Cardano/Ledger/Conway/CanonicalState/Arbitrary.hs +++ b/libs/cardano-ledger-canonical-state/testlib/Test/Cardano/Ledger/Conway/CanonicalState/Arbitrary.hs @@ -12,6 +12,7 @@ import Cardano.Ledger.CanonicalState.Conway ( fromGovActionState, mkCanonicalConstitution, ) +import qualified Cardano.Ledger.CanonicalState.Namespace.EntitiesDormantEpochs.V0 as EntitiesDormantEpochs.V0 import qualified Cardano.Ledger.CanonicalState.Namespace.GovConstitution.V0 as GovConstitution.V0 import qualified Cardano.Ledger.CanonicalState.Namespace.GovPParams.V0 as GovPParams.V0 import qualified Cardano.Ledger.CanonicalState.Namespace.GovProposals.V0 as GovProposals.V0 @@ -32,3 +33,6 @@ instance Arbitrary (GovPParams.V0.GovPParamsOut ConwayEra) where instance Arbitrary (GovProposals.V0.GovProposalOut CanonicalGovActionState) where arbitrary = snd . fromGovActionState <$> arbitrary @(GovActionState ConwayEra) + +instance Arbitrary EntitiesDormantEpochs.V0.EntitiesDormantEpochsOut where + arbitrary = genericArbitraryU