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

KES Agent Connectivity #1402

Draft
wants to merge 22 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
56 changes: 56 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ multi-repl: True

import: ./asserts.cabal

allow-newer: plutus-core:cardano-crypto-class
, bytestring
, serdoc-core:tasty-quickcheck
, kes-agent:base

package ouroboros-network
-- Certain ThreadNet tests rely on transactions to be submitted promptly after
-- a node (re)start. Therefore, we disable this flag (see
Expand All @@ -44,3 +49,54 @@ package ouroboros-network
if(os(windows))
constraints:
bitvec -simd

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: b2cec3fbcde4bacb9c961e5510d5a1d3754c4e2b
--sha256: sha256-TDEBINZ3SkhpRNomMdt53bR3gdzgkWR9jIlAr8yrU6o=
subdir:
cardano-crypto-class

source-repository-package
type: git
location: [email protected]:input-output-hk/kes-agent
tag: 7d3517d61004b3e0867b62f1b4cf02ae5eee5589
--sha256: sha256-N4XRVqC+UgWej+J16RPh3EO6MSIE3wmJvmP5/nRgIuw=
subdir:
kes-agent

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-ledger
tag: 9d380ab7d6ae52ff66aae9a19dbb3036b1b13c94
--sha256: sha256-N4XRVqC+UgWej+J16RPh3EO6MSIE3wmJvmP5/nRgIuw=
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-core
libs/cardano-ledger-test
libs/cardano-protocol-tpraos
libs/constrained-generators
libs/non-integral
libs/set-algebra
libs/small-steps
libs/vector-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Breaking

- Use new mlocked KES API for all internal KES sign key handling.
- Add finalizers to all block forgings (required by `ouroboros-consensus`).
- Change `ShelleyLeaderCredentials` to not contain the KES sign key itself
anymore. Instead, the `CanBeLeader` data structure now contains a
`praosCanBeLeaderCredentialsSource` field, which specifies how to obtain the
actual credentials (OpCert and KES SignKey).
- The `KesKey` data type in `unstable-cardano-tools` has been renamed to
`UnsoundPureKesKey`, to reflect the fact that it uses the old, unsound KES
API (which does not use mlocking or secure forgetting).
15 changes: 10 additions & 5 deletions ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ library
bytestring >=0.10 && <0.13,
cardano-binary,
cardano-crypto,
cardano-crypto-class,
cardano-crypto-class ^>= 2.2,
cardano-crypto-wrapper,
cardano-ledger-allegra ^>=1.6,
cardano-ledger-alonzo ^>=1.12,
cardano-ledger-api ^>=1.10,
cardano-ledger-babbage ^>=1.10,
cardano-ledger-binary ^>=1.5,
cardano-ledger-binary ^>=1.6,
cardano-ledger-byron ^>=1.0.1,
cardano-ledger-conway ^>=1.18,
cardano-ledger-core ^>=1.16,
cardano-ledger-core ^>=1.17,
cardano-ledger-mary ^>=1.7,
cardano-ledger-shelley ^>=1.15,
cardano-prelude,
Expand All @@ -147,9 +147,10 @@ library
cardano-strict-containers,
cborg ^>=0.2.2,
containers >=0.5 && <0.8,
cryptonite >=0.25 && <0.31,
crypton,
deepseq,
formatting >=6.3 && <7.3,
kes-agent,
Copy link
Contributor

Choose a reason for hiding this comment

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

This dependency cannot work as is, because it builds socket-unix which won't fly on Windows.

measures,
microlens,
mtl,
Expand All @@ -159,6 +160,7 @@ library
ouroboros-network-api ^>=0.12,
serialise ^>=0.2,
small-steps,
serdoc-core,
sop-core ^>=0.5,
sop-extras ^>=0.2,
strict-sop-core ^>=0.1,
Expand Down Expand Up @@ -301,7 +303,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 All @@ -311,6 +313,7 @@ library unstable-shelley-testlib
cardano-strict-containers,
containers,
generic-random,
kes-agent,
microlens,
mtl,
ouroboros-consensus:{ouroboros-consensus, unstable-consensus-testlib},
Expand All @@ -319,6 +322,7 @@ library unstable-shelley-testlib
ouroboros-consensus-protocol:{ouroboros-consensus-protocol, unstable-protocol-testlib},
ouroboros-network-api,
quiet ^>=0.2,
serdoc-core,
small-steps,

test-suite shelley-test
Expand Down Expand Up @@ -557,6 +561,7 @@ library unstable-cardano-tools
ouroboros-network-framework ^>=0.16,
ouroboros-network-protocols,
resource-registry,
serdoc-core,
serialise ^>=0.2,
singletons,
sop-core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ instance DSIGNAlgorithm ByronDSIGN where
where
seedBytes = case getBytesFromSeed 32 seed of
Just (x,_) -> x
Nothing -> throw $ SeedBytesExhausted (-1) -- TODO We can't get the seed size!
Nothing -> throw $ SeedBytesExhausted (-1) (-1) -- TODO We can't get the seed size!

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 @@ -57,8 +57,7 @@ import qualified Cardano.Ledger.Api.Transition as L
import qualified Cardano.Ledger.BaseTypes as SL
import qualified Cardano.Ledger.Shelley.API as SL
import Cardano.Prelude (cborError)
import qualified Cardano.Protocol.TPraos.OCert as Absolute (KESPeriod (..),
ocertKESPeriod)
import qualified Cardano.Protocol.TPraos.OCert as Absolute (KESPeriod (..))
import qualified Codec.CBOR.Decoding as CBOR
import Codec.CBOR.Encoding (Encoding)
import qualified Codec.CBOR.Encoding as CBOR
Expand Down Expand Up @@ -92,10 +91,9 @@ 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.Praos.AgentClient
import Ouroboros.Consensus.Protocol.TPraos (TPraos, TPraosParams (..))
import qualified Ouroboros.Consensus.Protocol.TPraos as Shelley
import Ouroboros.Consensus.Shelley.HFEras ()
Expand All @@ -105,14 +103,13 @@ import Ouroboros.Consensus.Shelley.Ledger.Block (IsShelleyBlock,
ShelleyBlockLedgerEra)
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion
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
import Ouroboros.Consensus.TypeFamilyWrappers
import Ouroboros.Consensus.Util.Assert
import Ouroboros.Consensus.Util.IOLike

{-------------------------------------------------------------------------------
SerialiseHFC
-------------------------------------------------------------------------------}
Expand Down Expand Up @@ -465,7 +462,10 @@ data CardanoProtocolParams c = CardanoProtocolParams {
-- PRECONDITION: only a single set of Shelley credentials is allowed when used
-- for mainnet (check against @'SL.gNetworkId' == 'SL.Mainnet'@).
protocolInfoCardano ::
forall c m. (IOLike m, CardanoHardForkConstraints c)
forall c m.
( CardanoHardForkConstraints c
, KESAgentContext c m
)
=> CardanoProtocolParams c
-> ( ProtocolInfo (CardanoBlock c)
, m [BlockForging m (CardanoBlock c)]
Expand All @@ -480,7 +480,7 @@ protocolInfoCardano paramsCardano
pInfoConfig = cfg
, pInfoInitLedger = initExtLedgerStateCardano
}
, blockForging
, mkBlockForgings
)
where
CardanoProtocolParams {
Expand Down Expand Up @@ -827,8 +827,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 @@ -854,24 +854,19 @@ 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

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

hotKey <- instantiatePraosCredentials
maxKESEvo
(praosCanBeLeaderCredentialsSource canBeLeader)

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 @@ -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,7 +80,7 @@ praosSharedBlockForging
ShelleyLeaderCredentials {
shelleyLeaderCredentialsCanBeLeader = canBeLeader
, shelleyLeaderCredentialsLabel = label
} = do
} =
BlockForging
{ forgeLabel = label <> "_" <> T.pack (L.eraName @era),
canBeLeader = canBeLeader,
Expand All @@ -105,5 +95,6 @@ praosSharedBlockForging
forgeShelleyBlock
hotKey
canBeLeader
cfg
cfg,
finalize = HotKey.finalize hotKey
}
Loading
Loading