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

Update the ledger and improve the compile time of Shelley.Ledger.Query #2716

Merged
merged 4 commits into from
Oct 29, 2020
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
4 changes: 2 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger-specs
tag: 623bbb8d4b13bcb0157c5c576a69536387f1b5be
--sha256: 0nspz67p6ixw4zr6q4r2gzn37583mlag8f1g5pk0i4f1yisi69d1
tag: c03dd5592bde3bf4f9726f257ba09235aeb4818d
--sha256: 1rpjrcc45s58f76zp5mnibqwkgap5yipzgsgp2fhydcysm1rwblf
subdir:
byron/chain/executable-spec
byron/crypto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Cardano.Crypto.Seed (SeedBytesExhausted (..), getBytesFromSeed)
import qualified Cardano.Crypto.Signing as Crypto
import qualified Cardano.Crypto.Wallet as CC

import Ouroboros.Consensus.Util (eitherToMaybe)
import Ouroboros.Consensus.Util.Condense

class (HasSignTag a, Decoded a) => ByronSignable a
Expand Down Expand Up @@ -122,8 +123,5 @@ instance DSIGNAlgorithm ByronDSIGN where
rawDeserialiseSigDSIGN bs =
SigByronDSIGN . Signature <$> (eitherToMaybe $ CC.xsignature bs)

eitherToMaybe :: Either a b -> Maybe b
eitherToMaybe = either (const Nothing) (Just)

instance Condense (SigDSIGN ByronDSIGN) where
condense (SigByronDSIGN s) = show s
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Cardano.Crypto.KES (MockKES)
import Cardano.Ledger.Crypto (Crypto (..))
import Test.Cardano.Crypto.VRF.Fake (FakeVRF)

import Ouroboros.Consensus.Shelley.Protocol.Crypto (TPraosCrypto)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (PraosCrypto)

-- | A replacement for 'Test.Consensus.Shelley.MockCrypto' that is compatible
-- with bootstrapping from Byron.
Expand Down Expand Up @@ -42,4 +42,4 @@ instance Crypto MockCryptoCompatByron where
type KES MockCryptoCompatByron = MockKES 10
type VRF MockCryptoCompatByron = FakeVRF

instance TPraosCrypto MockCryptoCompatByron
instance PraosCrypto MockCryptoCompatByron
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ instance ShelleyBasedEra era => SingleEraBlock (ShelleyBlock era) where
singleEraName = "Shelley"
}

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

completeConsensusConfig _ tpraosEpochInfo tpraosParams = TPraosConfig {..}
Expand Down Expand Up @@ -347,7 +347,7 @@ instance ShelleyBasedEra era => HasPartialLedgerConfig (ShelleyBlock era) where
-------------------------------------------------------------------------------}

type CardanoHardForkConstraints c =
( TPraosCrypto c
( PraosCrypto c
, ShelleyBasedEra (ShelleyEra c)
, ShelleyBasedEra (AllegraEra c)
, ShelleyBasedEra (MaryEra c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ import qualified Test.Shelley.Spec.Ledger.Utils as SL hiding (mkKeyPair,

import Ouroboros.Consensus.Shelley.Eras (EraCrypto, StandardShelley)
import Ouroboros.Consensus.Shelley.Ledger
import Ouroboros.Consensus.Shelley.Protocol (TPraosCrypto,
import Ouroboros.Consensus.Shelley.Protocol (PraosCrypto,
TPraosState (..))

import Test.Util.Orphans.Arbitrary ()
Expand Down Expand Up @@ -236,7 +236,7 @@ examples = Golden.Examples {
(mkKeyHash 0)
(SL.emptyPParamsUpdate {SL._keyDeposit = SJust (SL.Coin 100)})

examplePoolDistr :: forall c. TPraosCrypto c => SL.PoolDistr c
examplePoolDistr :: forall c. PraosCrypto c => SL.PoolDistr c
examplePoolDistr = SL.PoolDistr $ Map.fromList [
(mkKeyHash 1, SL.IndividualPoolStake
1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Ouroboros.Consensus.Ledger.SupportsMempool
import qualified Shelley.Spec.Ledger.API as SL

import Ouroboros.Consensus.Shelley.Ledger
import Ouroboros.Consensus.Shelley.Protocol (TPraosCrypto,
import Ouroboros.Consensus.Shelley.Protocol (PraosCrypto,
TPraosState (..))

import Generic.Random (genericArbitraryU)
Expand Down Expand Up @@ -104,7 +104,7 @@ instance CanMock era => Arbitrary (NonMyopicMemberRewards era) where
instance CanMock era => Arbitrary (Point (ShelleyBlock era)) where
arbitrary = BlockPoint <$> arbitrary <*> arbitrary

instance TPraosCrypto c => Arbitrary (TPraosState c) where
instance PraosCrypto c => Arbitrary (TPraosState c) where
arbitrary = do
lastSlot <- frequency
[ (1, return Origin)
Expand Down Expand Up @@ -151,7 +151,7 @@ instance Arbitrary (SL.PParams' SL.StrictMaybe era) where
arbitrary = genericArbitraryU
shrink = genericShrink

instance TPraosCrypto c => Arbitrary (SL.ChainDepState c) where
instance PraosCrypto c => Arbitrary (SL.ChainDepState c) where
arbitrary = genericArbitraryU
shrink = genericShrink

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import qualified Test.Shelley.Spec.Ledger.Utils as SL (ShelleyTest)
import Ouroboros.Consensus.Shelley.Eras (EraCrypto, ShelleyBasedEra,
ShelleyEra)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (TPraosCrypto)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (PraosCrypto)

-- | A mock replacement for 'StandardCrypto'
--
Expand All @@ -48,7 +48,7 @@ instance HashAlgorithm h => Crypto (MockCrypto h) where

type MockShelley h = ShelleyEra (MockCrypto h)

instance HashAlgorithm h => TPraosCrypto (MockCrypto h)
instance HashAlgorithm h => PraosCrypto (MockCrypto h)

type Block h = ShelleyBlock (MockShelley h)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ data CoreNodeKeyInfo c = CoreNodeKeyInfo
)
}

coreNodeKeys :: forall c. TPraosCrypto c => CoreNode c -> CoreNodeKeyInfo c
coreNodeKeys :: forall c. PraosCrypto c => CoreNode c -> CoreNodeKeyInfo c
coreNodeKeys CoreNode{cnGenesisKey, cnDelegateKey, cnStakingKey} =
CoreNodeKeyInfo {
cnkiCoreNode =
Expand All @@ -162,7 +162,7 @@ coreNodeKeys CoreNode{cnGenesisKey, cnDelegateKey, cnStakingKey} =
}

genCoreNode ::
forall c. TPraosCrypto c
forall c. PraosCrypto c
=> SL.KESPeriod
-> Gen (CoreNode c)
genCoreNode startKESPeriod = do
Expand Down Expand Up @@ -200,7 +200,7 @@ genCoreNode startKESPeriod = do
genSeed :: Integral a => a -> Gen Cardano.Crypto.Seed
genSeed = fmap mkSeedFromBytes . genBytes

mkLeaderCredentials :: TPraosCrypto c => CoreNode c -> TPraosLeaderCredentials c
mkLeaderCredentials :: PraosCrypto c => CoreNode c -> TPraosLeaderCredentials c
mkLeaderCredentials CoreNode { cnDelegateKey, cnVRF, cnKES, cnOCert } =
TPraosLeaderCredentials {
tpraosLeaderCredentialsInitSignKey = cnKES
Expand Down Expand Up @@ -265,7 +265,7 @@ mkEpochSize (SecurityParam k) f =
-- but we can configure a potentially lower maximum for the ledger, that's why
-- we take it as an argument.
mkGenesisConfig
:: forall era. TPraosCrypto (EraCrypto era)
:: forall era. PraosCrypto (EraCrypto era)
=> ProtVer -- ^ Initial protocol version
-> SecurityParam
-> Rational -- ^ Initial active slot coefficient
Expand Down Expand Up @@ -510,17 +510,17 @@ initialLovelacePerCoreNode :: Word64
initialLovelacePerCoreNode = 1000

mkCredential ::
TPraosCrypto (EraCrypto era)
PraosCrypto (EraCrypto era)
=> SL.SignKeyDSIGN (EraCrypto era) -> SL.Credential r era
mkCredential = SL.KeyHashObj . mkKeyHash

mkKeyHash :: TPraosCrypto c => SL.SignKeyDSIGN c -> SL.KeyHash r c
mkKeyHash :: PraosCrypto c => SL.SignKeyDSIGN c -> SL.KeyHash r c
mkKeyHash = SL.hashKey . mkVerKey

mkVerKey :: TPraosCrypto c => SL.SignKeyDSIGN c -> SL.VKey r c
mkVerKey :: PraosCrypto c => SL.SignKeyDSIGN c -> SL.VKey r c
mkVerKey = SL.VKey . deriveVerKeyDSIGN

mkKeyPair :: TPraosCrypto c => SL.SignKeyDSIGN c -> SL.KeyPair r c
mkKeyPair :: PraosCrypto c => SL.SignKeyDSIGN c -> SL.KeyPair r c
mkKeyPair sk = SL.KeyPair { vKey = mkVerKey sk, sKey = sk }

mkKeyHashVrf :: (HashAlgorithm h, VRFAlgorithm vrf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ library
Ouroboros.Consensus.Shelley.Ledger.Ledger
Ouroboros.Consensus.Shelley.Ledger.Mempool
Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion
Ouroboros.Consensus.Shelley.Ledger.Query
Ouroboros.Consensus.Shelley.Ledger.TPraos
Ouroboros.Consensus.Shelley.Node
Ouroboros.Consensus.Shelley.Node.Serialisation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableSuperClasses #-}
module Ouroboros.Consensus.Shelley.Eras (
-- * Eras based on the Shelley ledger
ShelleyEra
Expand All @@ -19,12 +16,10 @@ module Ouroboros.Consensus.Shelley.Eras (
) where

import Cardano.Ledger.Era (Crypto)
import Cardano.Ledger.Shelley (ShelleyBased, ShelleyEra)
import Cardano.Ledger.Shelley (ShelleyEra)

import qualified Shelley.Spec.Ledger.API as SL

import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto,
TPraosCrypto)
import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)
import Shelley.Spec.Ledger.API (ShelleyBasedEra)

{-------------------------------------------------------------------------------
Eras based on the Shelley ledger
Expand Down Expand Up @@ -58,20 +53,6 @@ type StandardAllegra = AllegraEra StandardCrypto
-- | The Mary era with standard crypto
type StandardMary = MaryEra StandardCrypto

{-------------------------------------------------------------------------------
Shelley-based era
-------------------------------------------------------------------------------}

-- | Constraints needed by a Shelley-based era
class ( TPraosCrypto (EraCrypto era)
, ShelleyBased era
, SL.ApplyBlock era
, SL.GetLedgerView era
, SL.ApplyTx era
) => ShelleyBasedEra era

instance TPraosCrypto c => ShelleyBasedEra (ShelleyEra c)

{-------------------------------------------------------------------------------
Type synonyms for convenience
-------------------------------------------------------------------------------}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ import Ouroboros.Consensus.Shelley.Ledger.Integrity as X
import Ouroboros.Consensus.Shelley.Ledger.Ledger as X
import Ouroboros.Consensus.Shelley.Ledger.Mempool as X
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion as X
import Ouroboros.Consensus.Shelley.Ledger.Query as X
Loading