Skip to content

Commit

Permalink
Re-enable (and fix) the Praos tests
Browse files Browse the repository at this point in the history
Closes #1545
  • Loading branch information
edsko committed Feb 20, 2020
1 parent 013e0a6 commit f4eca9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import Data.Proxy (Proxy (..))
import Data.Typeable
import Data.Word (Word64)
import GHC.Generics (Generic)
import GHC.Stack
import Numeric.Natural

import Cardano.Crypto.DSIGN.Ed448 (Ed448DSIGN)
Expand Down Expand Up @@ -141,38 +142,59 @@ forgePraosFields :: ( MonadRandom m
-> (PraosExtraFields c -> toSign)
-> m (PraosFields c toSign)
forgePraosFields PraosNodeConfig{..} updateState PraosProof{..} mkToSign = do
keyKES <- runUpdate updateState $ \case
-- For the mock implementation, we consider the KES period to be the slot.
-- In reality, there will be some kind of constants slotsPerPeriod factor.
let kesPeriod :: Natural
kesPeriod = fromIntegral (unSlotNo praosProofSlot)

oldKey <- runUpdate updateState $ \case
PraosKeyEvolving ->
-- Another thread is currently evolving the key; wait
Nothing
PraosKeyAvailable oldKey ->
-- TODO : We should not update the key on each signing, but X slots
-- (for configurable param X)
return (PraosKeyEvolving, oldKey)

-- Evolve the key (if needed)
-- Evolve the key
newKey <- fromMaybe (error "mkOutoborosPayload: updateKES failed") <$>
updateKES () keyKES
updateKESTo () kesPeriod oldKey
runUpdate updateState $ \_ -> return (PraosKeyAvailable newKey, ())

let signedFields = PraosExtraFields {
praosCreator = praosLeader
, praosRho = praosProofRho
, praosY = praosProofY
}
m <- signedKES
()
(fromIntegral (unSlotNo praosProofSlot))
(mkToSign signedFields)
keyKES
m <- signedKES () kesPeriod (mkToSign signedFields) newKey
case m of
Nothing -> error "mkOutoborosPayload: signedKES failed"
Just signature -> do
return $ PraosFields {
praosSignature = signature
praosSignature = signature
, praosExtraFields = signedFields
}

-- | Update key to specified period
--
-- Throws an error if the key is already /past/ the period
updateKESTo :: forall m v. (MonadRandom m, HasCallStack, KESAlgorithm v)
=> ContextKES v
-> Natural -- ^ KES period to evolve to
-> SignKeyKES v
-> m (Maybe (SignKeyKES v))
updateKESTo ctxt evolveTo = go
where
go :: SignKeyKES v -> m (Maybe (SignKeyKES v))
go key
| iterationCountKES ctxt key < evolveTo = do
mKey' <- updateKES ctxt key
case mKey' of
Nothing -> return Nothing
Just key' -> go key'
| iterationCountKES ctxt key == evolveTo =
return (Just key)
| otherwise =
error "updateKESTo: key already past period"

{-------------------------------------------------------------------------------
Praos specific types
-------------------------------------------------------------------------------}
Expand Down
4 changes: 2 additions & 2 deletions ouroboros-consensus/ouroboros-consensus-mock/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import qualified Test.Consensus.Ledger.Mock (tests)
import qualified Test.ThreadNet.BFT (tests)
import qualified Test.ThreadNet.LeaderSchedule (tests)
import qualified Test.ThreadNet.PBFT (tests)
-- import qualified Test.ThreadNet.Praos (tests)
import qualified Test.ThreadNet.Praos (tests)

main :: IO ()
main = defaultMain tests
Expand All @@ -18,5 +18,5 @@ tests =
, Test.ThreadNet.BFT.tests
, Test.ThreadNet.LeaderSchedule.tests
, Test.ThreadNet.PBFT.tests
-- , Test.ThreadNet.Praos.tests
, Test.ThreadNet.Praos.tests
]

0 comments on commit f4eca9d

Please sign in to comment.