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

Validate the Shelley genesis config #2423

Merged
merged 1 commit into from
Jul 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ protocolInfoCardano
protocolInfoCardano genesisByron mSigThresh pVer sVer mbCredsByron
genesisShelley initialNonce protVer maxMajorPV mbCredsShelley
mbLowerBound triggerHardFork =
assertWithMsg (checkMaxKESEvolutions genesisShelley) $
assertWithMsg (validateGenesis genesisShelley) $
ProtocolInfo {
pInfoConfig = cfg
, pInfoInitLedger = ExtLedgerState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ library
, containers >=0.5 && <0.7
, mtl >=2.2 && <2.3
, serialise >=0.2 && <0.3
, text >=1.2 && <1.3
, transformers

-- cardano-ledger-specs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ module Ouroboros.Consensus.Shelley.Node (
, SL.Nonce (..)
, SL.emptyGenesisStaking
, shelleyMaintainForgeState
, checkMaxKESEvolutions
, validateGenesis
) where

import Control.Monad.Except (throwError)
import Control.Monad.Reader (runReader)
import Data.Bifunctor (first)
import Data.Functor.Identity (Identity)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import Data.Void

import Cardano.Prelude (Natural)
Expand Down Expand Up @@ -116,27 +117,15 @@ shelleyMaintainForgeState TPraosParams{..} (TPraosLeaderCredentials signKeyKES i
, hkKey = signKeyKES
}

-- | TODO this should be done as part of
-- <https://github.com/input-output-hk/cardano-ledger-specs/issues/1516>
checkMaxKESEvolutions
:: forall c. TPraosCrypto c
=> SL.ShelleyGenesis c
-> Either String ()
checkMaxKESEvolutions genesis
| configuredMaxKESEvo > fromIntegral supportedMaxKESEvo
= throwError $ mconcat [
"sgMaxKESEvolutions greater than the supported evolutions"
, " by the KES algorithm: "
, show configuredMaxKESEvo
, " > "
, show supportedMaxKESEvo
]
| otherwise
= return ()
-- | Check the validity of the genesis config. To be used in conjunction with
-- 'assertWithMsg'.
validateGenesis :: TPraosCrypto c => SL.ShelleyGenesis c -> Either String ()
validateGenesis = first errsToString . SL.validateGenesis
where
configuredMaxKESEvo = SL.sgMaxKESEvolutions genesis
-- Max evolutions supported by the chosen KES algorithm
supportedMaxKESEvo = totalPeriodsKES (Proxy @(KES c))
errsToString :: [SL.ValidationErr] -> String
errsToString errs =
Text.unpack $ Text.unlines
("Invalid genesis config:" : map SL.describeValidationErr errs)

protocolInfoShelley
:: forall m c. (IOLike m, TPraosCrypto c)
Expand All @@ -149,7 +138,7 @@ protocolInfoShelley
-> Maybe (TPraosLeaderCredentials c)
-> ProtocolInfo m (ShelleyBlock c)
protocolInfoShelley genesis initialNonce maxMajorPV protVer mbCredentials =
assertWithMsg (checkMaxKESEvolutions genesis) $
assertWithMsg (validateGenesis genesis) $
ProtocolInfo {
pInfoConfig = topLevelConfig
, pInfoInitLedger = initExtLedgerState
Expand Down