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

Use mlocked KES #1284

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
83 changes: 81 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ repository cardano-haskell-packages
-- update either of these.
index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2024-10-22T14:26:27Z
, hackage.haskell.org 2024-12-10T00:00:00Z
-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2024-10-30T11:23:17Z
, cardano-haskell-packages 2024-11-27T20:49:28Z

packages:
ouroboros-consensus
Expand Down Expand Up @@ -47,3 +47,82 @@ if(os(windows))

-- https://github.com/ulidtko/cabal-doctest/issues/85
constraints: Cabal < 3.13

-- For the time being, we need to override some dependency bounds
allow-newer: plutus-core:cardano-crypto-class
, cardano-slotting

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 391a2c5cfd30d2234097e000dbd8d9db21ef94d7
--sha256: sha256-cw1BmYagp37B1n4PVWJF4AJ8nc/MYjSRlTLEWwL+EEk=
subdir:
-- cardano-binary
cardano-crypto-class
cardano-crypto-tests
cardano-crypto-praos
cardano-mempool
-- cardano-slotting

source-repository-package
type: git
location: https://github.com/IntersectMBO/formal-ledger-specifications.git
-- !WARNING!:
-- MAKE SURE THIS POINTS TO A COMMIT IN `MAlonzo-code` BEFORE MERGE!
subdir: generated
tag: cc93692f5a57a9a66956b232662152676f659954
--sha256: sha256-s9ikqfXmz1wBrk4qEFR/iOloKvMOPGTB5IpHO34NSLE=
-- NOTE: If you would like to update the above, look for the `MAlonzo-code`
-- branch in the `formal-ledger-specifications` repo and copy the SHA of
-- the commit you need. The `MAlonzo-code` branch functions like an alternative
-- `master / main` branch for the generated code, see the details here:
-- https://github.com/IntersectMBO/formal-ledger-specifications/pull/530
-- If you are working on something in `formal-ledger-specifications`
-- and would like to see how they reflect here, just open a PR / draft PR
-- in `formal-ledger-specifications` for your branch and that will
-- automatically create a branch for the generated code that you can try here
-- by editing the above SRP.
-- Once your changes are merged in `formal-ledger-specifications`, the branch
-- for the generated code will be merged into `MAlonzo-code` automatically.
-- Before merging a PR in `cardano-ledger`, make sure that the above SRP
-- points to a commit in `MAlonzo-code` if you were fiddling with the SRP
-- as part of your PR.

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: a549a45ef73ad9d71903ad1816f2b53360ab310d
--sha256: 0944wg2nqazmhlmsynwgdwxxj6ay0hb9qig9l128isb2cjia0hlp
subdir:
eras/allegra/impl
eras/alonzo/impl
eras/alonzo/test-suite
eras/babbage/impl
eras/babbage/test-suite
eras/byron/chain/executable-spec
eras/byron/crypto
eras/byron/crypto/test
eras/byron/ledger/executable-spec
eras/byron/ledger/impl
eras/byron/ledger/impl/test
eras/conway/impl
eras/conway/test-suite
eras/mary/impl
eras/shelley/impl
eras/shelley-ma/test-suite
eras/shelley/test-suite
libs/cardano-data
libs/cardano-ledger-api
libs/cardano-ledger-binary
libs/cardano-ledger-conformance
libs/cardano-ledger-core
libs/cardano-ledger-test
libs/cardano-protocol-tpraos
libs/constrained-generators
libs/ledger-state
libs/non-integral
libs/plutus-preprocessor
libs/set-algebra
libs/small-steps
libs/vector-map
19 changes: 10 additions & 9 deletions ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ library
cardano-crypto-class,
cardano-crypto-wrapper,
cardano-ledger-allegra ^>=1.6,
cardano-ledger-alonzo ^>=1.11,
cardano-ledger-api ^>=1.9.3,
cardano-ledger-alonzo ^>=1.12,
cardano-ledger-api ^>=1.10,
cardano-ledger-babbage ^>=1.10,
cardano-ledger-binary ^>=1.4,
cardano-ledger-binary ^>=1.5,
cardano-ledger-byron ^>=1.0.1,
cardano-ledger-conway ^>=1.17.2,
cardano-ledger-core ^>=1.15,
cardano-ledger-conway ^>=1.18,
cardano-ledger-core ^>=1.16,
cardano-ledger-mary ^>=1.7,
cardano-ledger-shelley ^>=1.14,
cardano-ledger-shelley ^>=1.15,
cardano-prelude,
cardano-protocol-tpraos ^>=1.2,
cardano-protocol-tpraos ^>=1.3,
cardano-slotting,
cardano-strict-containers,
cborg ^>=0.2.2,
Expand Down Expand Up @@ -304,7 +304,7 @@ library unstable-shelley-testlib
cardano-ledger-alonzo,
cardano-ledger-alonzo-test,
cardano-ledger-babbage-test,
cardano-ledger-conway-test >=1.2.1,
cardano-ledger-conway-test >=1.3.0,
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-mary,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
Expand Down Expand Up @@ -535,7 +535,7 @@ library unstable-cardano-tools
cardano-ledger-mary,
cardano-ledger-shelley,
cardano-prelude,
cardano-protocol-tpraos ^>=1.2,
cardano-protocol-tpraos ^>=1.3,
cardano-slotting,
cardano-strict-containers,
cborg ^>=0.2.2,
Expand All @@ -546,6 +546,7 @@ library unstable-cardano-tools
filepath,
fs-api ^>=0.3,
githash,
io-classes ^>=1.5,
microlens,
mtl,
network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Cardano.Crypto (ProtocolMagicId, SignTag (..), Signature (..),
SigningKey (..), VerificationKey (..), deterministicKeyGen,
signRaw, toVerification, verifySignatureRaw)
import Cardano.Crypto.DSIGN.Class
import Cardano.Crypto.Seed (SeedBytesExhausted (..), getBytesFromSeed)
import Cardano.Crypto.Seed (getBytesFromSeedEither)
import qualified Cardano.Crypto.Signing as Crypto
import qualified Cardano.Crypto.Wallet as CC
import Cardano.Ledger.Binary
Expand Down Expand Up @@ -90,9 +90,9 @@ instance DSIGNAlgorithm ByronDSIGN where
genKeyDSIGN seed =
SignKeyByronDSIGN . snd $ deterministicKeyGen seedBytes
where
seedBytes = case getBytesFromSeed 32 seed of
Just (x,_) -> x
Nothing -> throw $ SeedBytesExhausted (-1) -- TODO We can't get the seed size!
seedBytes = case getBytesFromSeedEither 32 seed of
Right (x,_) -> x
Left err -> throw err

deriveVerKeyDSIGN (SignKeyByronDSIGN sk) = VerKeyByronDSIGN $ toVerification sk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ byronBlockForging creds = BlockForging {
slot
tickedPBftState
, forgeBlock = \cfg -> return ....: forgeByronBlock cfg
, finalize = pure ()
}
where
canBeLeader = mkPBftCanBeLeader creds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module Ouroboros.Consensus.Cardano.Node (
, CardanoHardForkTriggers (.., CardanoHardForkTriggers', triggerHardForkShelley, triggerHardForkAllegra, triggerHardForkMary, triggerHardForkAlonzo, triggerHardForkBabbage, triggerHardForkConway)
, CardanoProtocolParams (..)
, MaxMajorProtVer (..)
, ProtocolParamsByron
, ProtocolParamsShelleyBased
, CheckpointsMap
, TriggerHardFork (..)
, protocolClientInfoCardano
, protocolInfoCardano
Expand Down Expand Up @@ -103,10 +106,8 @@ import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Node.NetworkProtocolVersion
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosParams (..))
import Ouroboros.Consensus.Protocol.Praos.Common
(praosCanBeLeaderOpCert)
import Ouroboros.Consensus.Protocol.Praos.Common (PraosCanBeLeader (..), instantiatePraosCredentials)
import Ouroboros.Consensus.Protocol.TPraos (TPraos, TPraosParams (..))
import qualified Ouroboros.Consensus.Protocol.TPraos as Shelley
import Ouroboros.Consensus.Shelley.HFEras ()
Expand All @@ -115,9 +116,9 @@ import qualified Ouroboros.Consensus.Shelley.Ledger as Shelley
import Ouroboros.Consensus.Shelley.Ledger.Block (IsShelleyBlock,
ShelleyBlockLedgerEra)
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Shelley.Node
import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto,
shelleyBlockIssuerVKey)
import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto, shelleyBlockIssuerVKey)
import qualified Ouroboros.Consensus.Shelley.Node.Praos as Praos
import qualified Ouroboros.Consensus.Shelley.Node.TPraos as TPraos
import Ouroboros.Consensus.Storage.Serialisation
Expand Down Expand Up @@ -664,12 +665,12 @@ protocolInfoCardano paramsCardano
, length credssShelleyBased > 1
= error "Multiple Shelley-based credentials not allowed for mainnet"
| otherwise
= assertWithMsg (validateGenesis genesisShelley)
= assertWithMsg (validateGenesis genesisShelley) $
( ProtocolInfo {
pInfoConfig = cfg
, pInfoInitLedger = initExtLedgerStateCardano
}
, blockForging
, mkBlockForgings
)
where
CardanoProtocolParams {
Expand Down Expand Up @@ -1016,8 +1017,8 @@ protocolInfoCardano paramsCardano
-- credentials. If there are multiple Shelley credentials, we merge the
-- Byron credentials with the first Shelley one but still have separate
-- threads for the remaining Shelley ones.
blockForging :: m [BlockForging m (CardanoBlock c)]
blockForging = do
mkBlockForgings :: m ([BlockForging m (CardanoBlock c)])
mkBlockForgings = do
shelleyBased <- traverse blockForgingShelleyBased credssShelleyBased
let blockForgings :: [NonEmptyOptNP (BlockForging m) (CardanoEras c)]
blockForgings = case (mBlockForgingByron, shelleyBased) of
Expand All @@ -1043,24 +1044,26 @@ protocolInfoCardano paramsCardano
ShelleyLeaderCredentials c
-> m (NonEmptyOptNP (BlockForging m) (CardanoEras c))
blockForgingShelleyBased credentials = do
let ShelleyLeaderCredentials
{ shelleyLeaderCredentialsInitSignKey = initSignKey
, shelleyLeaderCredentialsCanBeLeader = canBeLeader
} = credentials

hotKey <- do
let maxKESEvo :: Word64
maxKESEvo = assert (tpraosMaxKESEvo == praosMaxKESEvo) praosMaxKESEvo

startPeriod :: Absolute.KESPeriod
startPeriod = Absolute.ocertKESPeriod $ praosCanBeLeaderOpCert canBeLeader

HotKey.mkHotKey @m @c initSignKey startPeriod maxKESEvo
let canBeLeader = shelleyLeaderCredentialsCanBeLeader credentials

let slotToPeriod :: SlotNo -> Absolute.KESPeriod
slotToPeriod (SlotNo slot) = assert (tpraosSlotsPerKESPeriod == praosSlotsPerKESPeriod) $
Absolute.KESPeriod $ fromIntegral $ slot `div` praosSlotsPerKESPeriod

(ocert, sk) <- instantiatePraosCredentials (praosCanBeLeaderCredentialsSource canBeLeader)

let startPeriod :: Absolute.KESPeriod
startPeriod = SL.ocertKESPeriod ocert

let maxKESEvo :: Word64
maxKESEvo = assert (tpraosMaxKESEvo == praosMaxKESEvo) praosMaxKESEvo

hotKey :: HotKey.HotKey c m <- HotKey.mkHotKey
ocert
sk
startPeriod
maxKESEvo

let tpraos :: forall era.
ShelleyEraWithCrypto c (TPraos c) era
=> BlockForging m (ShelleyBlock (TPraos c) era)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Ouroboros.Consensus.Shelley.Ledger
import Ouroboros.Consensus.Shelley.Ledger.Inspect ()
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
import Ouroboros.Consensus.Shelley.Node.DiffusionPipelining ()
import Ouroboros.Consensus.Shelley.Node.Common
import Ouroboros.Consensus.Shelley.Node.Serialisation ()
import Ouroboros.Consensus.Shelley.Node.TPraos
import Ouroboros.Consensus.Shelley.Protocol.Abstract (pHeaderIssuer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ import Ouroboros.Consensus.Storage.ImmutableDB
-------------------------------------------------------------------------------}

data ShelleyLeaderCredentials c = ShelleyLeaderCredentials
{ -- | The unevolved signing KES key (at evolution 0).
--
-- Note that this is not inside 'ShelleyCanBeLeader' since it gets evolved
-- automatically, whereas 'ShelleyCanBeLeader' does not change.
shelleyLeaderCredentialsInitSignKey :: SL.SignKeyKES c,
shelleyLeaderCredentialsCanBeLeader :: PraosCanBeLeader c,
{ shelleyLeaderCredentialsCanBeLeader :: PraosCanBeLeader c,
-- | Identifier for this set of credentials.
--
-- Useful when the node is running with multiple sets of credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Mempool
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosParams (..),
praosCheckCanForge)
import Ouroboros.Consensus.Protocol.Praos.Common
(PraosCanBeLeader (praosCanBeLeaderOpCert))
import Ouroboros.Consensus.Shelley.Eras (EraCrypto)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock,
ShelleyCompatible, forgeShelleyBlock)
Expand All @@ -51,21 +49,13 @@ praosBlockForging ::
, IOLike m
)
=> PraosParams
-> HotKey.HotKey c m
-> ShelleyLeaderCredentials (EraCrypto era)
-> m (BlockForging m (ShelleyBlock (Praos c) era))
praosBlockForging praosParams credentials = do
hotKey <- HotKey.mkHotKey @m @c initSignKey startPeriod praosMaxKESEvo
pure $ praosSharedBlockForging hotKey slotToPeriod credentials
-> BlockForging m (ShelleyBlock (Praos c) era)
praosBlockForging praosParams hotKey credentials =
praosSharedBlockForging hotKey slotToPeriod credentials
where
PraosParams {praosMaxKESEvo, praosSlotsPerKESPeriod} = praosParams

ShelleyLeaderCredentials {
shelleyLeaderCredentialsInitSignKey = initSignKey
, shelleyLeaderCredentialsCanBeLeader = canBeLeader
} = credentials

startPeriod :: Absolute.KESPeriod
startPeriod = SL.ocertKESPeriod $ praosCanBeLeaderOpCert canBeLeader
PraosParams {praosSlotsPerKESPeriod} = praosParams

slotToPeriod :: SlotNo -> Absolute.KESPeriod
slotToPeriod (SlotNo slot) =
Expand All @@ -90,13 +80,15 @@ praosSharedBlockForging
ShelleyLeaderCredentials {
shelleyLeaderCredentialsCanBeLeader = canBeLeader
, shelleyLeaderCredentialsLabel = label
} = do
} =
BlockForging
{ forgeLabel = label <> "_" <> T.pack (L.eraName @era),
canBeLeader = canBeLeader,

updateForgeState = \_ curSlot _ ->
forgeStateUpdateInfoFromUpdateInfo
<$> HotKey.evolve hotKey (slotToPeriod curSlot),

checkCanForge = \cfg curSlot _tickedChainDepState _isLeader ->
praosCheckCanForge
(configConsensus cfg)
Expand All @@ -105,5 +97,6 @@ praosSharedBlockForging
forgeShelleyBlock
hotKey
canBeLeader
cfg
cfg,
finalize = HotKey.finalize hotKey
}
Loading
Loading