Skip to content

Commit 309e43c

Browse files
committed
Address review comments
1 parent 328af82 commit 309e43c

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

cabal.project

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ packages:
2626
sop-extras
2727
strict-sop-core
2828

29-
allow-newer: plutus-core:cardano-crypto-class
30-
3129
-- We want to always build the test-suites and benchmarks
3230
tests: true
3331
benchmarks: true

ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Ledger/HotKey.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ module Ouroboros.Consensus.Protocol.Ledger.HotKey (
2222
, kesStatus
2323
-- * Hot Key
2424
, HotKey (..)
25+
, finalize
2526
, getOCert
2627
, KESEvolutionError (..)
2728
, KESEvolutionInfo
2829
, mkHotKey
29-
, mkHotKeyEv
30+
, mkHotKeyAtEvolution
3031
, mkEmptyHotKey
3132
, sign
3233
) where
@@ -173,11 +174,16 @@ data HotKey c m = HotKey {
173174
-- ^ Start period (relative to the KES key's 0th evolution)
174175
-> m ()
175176

176-
-- | Release any resources held by the 'HotKey'. Must be run exactly once
177-
-- per 'HotKey'.
178-
, finalize :: m ()
177+
-- | Release any resources held by the 'HotKey', except for the signing
178+
-- key itself. User code should use 'finalize' instead.
179+
, finalize_ :: m ()
179180
}
180181

182+
-- | Release all resources held by the 'HotKey', including the signing key
183+
-- itself. Use this exactly once per 'HotKey' instance.
184+
finalize :: Monad m => HotKey c m -> m ()
185+
finalize hotKey = forget hotKey >> finalize_ hotKey
186+
181187
deriving via (OnlyCheckWhnfNamed "HotKey" (HotKey c m)) instance NoThunks (HotKey c m)
182188

183189
getOCert :: Monad m => HotKey c m -> m (OCert.OCert c)
@@ -224,22 +230,19 @@ mkHotKey ::
224230
-> Absolute.KESPeriod -- ^ Start period
225231
-> Word64 -- ^ Max KES evolutions
226232
-> m (HotKey c m)
227-
mkHotKey ocert initKey startPeriod maxKESEvolutions = do
228-
hotKey <- mkEmptyHotKey maxKESEvolutions (pure ())
229-
set hotKey ocert initKey 0 startPeriod
230-
return hotKey
233+
mkHotKey = mkHotKeyAtEvolution 0
231234

232235
-- Create a new 'HotKey' and initialize it to the given initial KES key. The
233236
-- initial key should be at the given evolution.
234-
mkHotKeyEv ::
237+
mkHotKeyAtEvolution ::
235238
forall m c. (Crypto c, IOLike m)
236239
=> Word
237240
-> OCert.OCert c
238241
-> SL.SignKeyKES c
239242
-> Absolute.KESPeriod -- ^ Start period
240243
-> Word64 -- ^ Max KES evolutions
241244
-> m (HotKey c m)
242-
mkHotKeyEv evolution ocert initKey startPeriod maxKESEvolutions = do
245+
mkHotKeyAtEvolution evolution ocert initKey startPeriod maxKESEvolutions = do
243246
hotKey <- mkEmptyHotKey maxKESEvolutions (pure ())
244247
set hotKey ocert initKey evolution startPeriod
245248
return hotKey
@@ -283,7 +286,7 @@ mkEmptyHotKey maxKESEvolutions finalizer = do
283286
}
284287
, kesStateKey = KESKey newOCert newKey
285288
}
286-
, finalize = finalizer
289+
, finalize_ = finalizer
287290
}
288291
where
289292
initKESState :: KESState c

ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos/Common.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,18 @@ data PraosCanBeLeader c = PraosCanBeLeader
254254
{ -- | Stake pool cold key or genesis stakeholder delegate cold key.
255255
praosCanBeLeaderColdVerKey :: !(SL.VKey 'SL.BlockIssuer c),
256256
praosCanBeLeaderSignKeyVRF :: !(SL.SignKeyVRF c),
257+
-- | How to obtain KES credentials (ocert + sign key)
257258
praosCanBeLeaderCredentialsSource :: !(PraosCredentialsSource c)
258259
}
259260
deriving (Generic)
260261

261262
instance (NoThunks (KES.UnsoundPureSignKeyKES (KES c)), Crypto c) => NoThunks (PraosCanBeLeader c)
262263

264+
-- | Defines a method for obtaining Praos credentials (opcert + KES signing key).
265+
-- Currently, the only available method is passing the credentials directly
266+
-- (using an unsound KES key that is subject to swapping and can be loaded from
267+
-- disk). Future versions may add constructors for sound methods (mlocking KES
268+
-- keys along the entire chain).
263269
data PraosCredentialsSource c
264270
= PraosCredentialsUnsound (OCert.OCert c) (KES.UnsoundPureSignKeyKES (KES c))
265271
deriving (Generic)

0 commit comments

Comments
 (0)