From f6bf35f3799c48f3bf1c07c9883d89c542b53781 Mon Sep 17 00:00:00 2001 From: Nicolas Frisby Date: Mon, 12 Aug 2019 09:14:17 -0700 Subject: [PATCH 1/3] fix typo in PBftLeaderCredentials field name --- .../src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs b/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs index b4effa85b96..a5321b06c53 100644 --- a/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs +++ b/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs @@ -51,7 +51,7 @@ import qualified Test.Cardano.Chain.Genesis.Dummy as Dummy data PBftLeaderCredentials = PBftLeaderCredentials { plcSignKey :: Crypto.SigningKey , plcDlgCert :: Delegation.Certificate - , plcCodeNodeId :: CoreNodeId + , plcCoreNodeId :: CoreNodeId } deriving Show -- | Make the 'PBftLeaderCredentials', with a couple sanity checks: @@ -76,7 +76,7 @@ mkPBftLeaderCredentials gc sk cert = do return PBftLeaderCredentials { plcSignKey = sk , plcDlgCert = cert - , plcCodeNodeId = nid + , plcCoreNodeId = nid } where (?!) :: Maybe a -> e -> Either e a From 26c6676e4333ac72f078bceaefb4e3b3db98f2a6 Mon Sep 17 00:00:00 2001 From: Nicolas Frisby Date: Mon, 12 Aug 2019 09:23:46 -0700 Subject: [PATCH 2/3] test-consensus: add failing test for RealPBFT test setup --- .../Consensus/Node/ProtocolInfo/Byron.hs | 2 ++ .../test-consensus/Test/Dynamic/RealPBFT.hs | 26 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs b/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs index a5321b06c53..7bc4971bc27 100644 --- a/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs +++ b/ouroboros-consensus/src/Ouroboros/Consensus/Node/ProtocolInfo/Byron.hs @@ -15,6 +15,8 @@ module Ouroboros.Consensus.Node.ProtocolInfo.Byron ( , PBftLeaderCredentials , PBftLeaderCredentialsError , mkPBftLeaderCredentials + -- * For testing + , plcCoreNodeId ) where import Control.Exception (Exception) diff --git a/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs b/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs index 58453e48791..dc51a5f6eb6 100644 --- a/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs +++ b/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs @@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -25,6 +26,7 @@ import Ouroboros.Consensus.BlockchainTime import Ouroboros.Consensus.Demo import Ouroboros.Consensus.Ledger.Byron (ByronBlockOrEBB, ByronGiven) import Ouroboros.Consensus.Node.ProtocolInfo +import Ouroboros.Consensus.Node.ProtocolInfo.Byron (plcCoreNodeId) import Ouroboros.Consensus.NodeId import Ouroboros.Consensus.Protocol import Ouroboros.Consensus.Util.Random @@ -42,13 +44,33 @@ import Test.Dynamic.Util import Test.Util.Orphans.Arbitrary () tests :: TestTree -tests = testGroup "Dynamic chain generation" [ - testProperty "simple Real PBFT convergence" $ +tests = testGroup "Dynamic chain generation" + [ testProperty "check Real PBFT setup" $ + \numCoreNodes -> + forAll (elements (enumCoreNodes numCoreNodes)) $ \coreNodeId -> + prop_setup_coreNodeId numCoreNodes coreNodeId + , testProperty "simple Real PBFT convergence" $ prop_simple_real_pbft_convergence sp ] where sp = defaultSecurityParam +prop_setup_coreNodeId :: + NumCoreNodes + -> CoreNodeId + -> Property +prop_setup_coreNodeId numCoreNodes coreNodeId = + case mkProtocolRealPBFT numCoreNodes coreNodeId genesisConfig genesisSecrets of + ProtocolRealPBFT _cfg _th _pv _swv (Just plc) -> + coreNodeId === plcCoreNodeId plc + _ -> + counterexample "mkProtocolRealPBFT did not use ProtocolRealPBFT" $ + property False + where + genesisConfig :: Genesis.Config + genesisSecrets :: Genesis.GeneratedSecrets + (genesisConfig, genesisSecrets) = generateGenesisConfig numCoreNodes + prop_simple_real_pbft_convergence :: SecurityParam -> NumCoreNodes -> NumSlots From b51de58b090dada56c821df643baa077c48ef73d Mon Sep 17 00:00:00 2001 From: Nicolas Frisby Date: Mon, 12 Aug 2019 09:04:20 -0700 Subject: [PATCH 3/3] test-consensus bugfix: use order of gdHeavyDelegation, not of gsRichSecrets --- .../test-consensus/Test/Dynamic/RealPBFT.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs b/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs index dc51a5f6eb6..7ecfd22bfd7 100644 --- a/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs +++ b/ouroboros-consensus/test-consensus/Test/Dynamic/RealPBFT.hs @@ -128,12 +128,12 @@ mkProtocolRealPBFT (NumCoreNodes n) (CoreNodeId i) 1.0 / (fromIntegral n + 1.0) dlgKey :: Crypto.SigningKey - dlgKey = Genesis.gsRichSecrets genesisSecrets !! i + dlgKey = fromJust $ + find (\sec -> Delegation.delegateVK dlgCert == Crypto.toVerification sec) + $ Genesis.gsRichSecrets genesisSecrets dlgCert :: Delegation.Certificate - dlgCert = fromJust $ - find (\crt -> Delegation.delegateVK crt == Crypto.toVerification dlgKey) - (Map.elems dlgMap) + dlgCert = snd $ Map.toAscList dlgMap !! i dlgMap :: Map Common.KeyHash Delegation.Certificate dlgMap = Genesis.unGenesisDelegation