Skip to content

Commit c791ead

Browse files
committed
WIP ThreadNet: move era crossing infra to an existing module
1 parent d1e4079 commit c791ead

File tree

7 files changed

+120
-126
lines changed

7 files changed

+120
-126
lines changed

ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ test-suite cardano-test
456456
Test.Consensus.Cardano.Translation
457457
Test.ThreadNet.AllegraMary
458458
Test.ThreadNet.Cardano
459-
Test.ThreadNet.EraCrossingInfra
460459
Test.ThreadNet.MaryAlonzo
461460
Test.ThreadNet.ShelleyAllegra
462461

ouroboros-consensus-cardano/src/unstable-cardano-testlib/Test/ThreadNet/Infra/TwoEras.hs

Lines changed: 119 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE FlexibleContexts #-}
34
{-# LANGUAGE GADTs #-}
45
{-# LANGUAGE LambdaCase #-}
56
{-# LANGUAGE MultiWayIf #-}
67
{-# LANGUAGE NamedFieldPuns #-}
8+
{-# LANGUAGE ScopedTypeVariables #-}
9+
{-# LANGUAGE StandaloneDeriving #-}
10+
{-# LANGUAGE TypeApplications #-}
711
{-# LANGUAGE TypeOperators #-}
12+
{-# LANGUAGE UndecidableInstances #-}
813

914
-- | Definitions used in ThreadNet tests that involve two eras.
1015
module Test.ThreadNet.Infra.TwoEras
11-
( -- * Generators
12-
Partition (..)
16+
( -- * Common infrastructure used in the ThreadNet tests that perform an era crossing
17+
18+
-- ** A hard-fork block for two eras
19+
DualBlock
20+
21+
-- ** The varying data of the tests crossing between Shelley-based eras
22+
, TestSetup (..)
23+
24+
-- ** Generators
25+
, Partition (..)
1326
, genNonce
1427
, genPartition
1528
, genTestConfig
1629

17-
-- * Era inspection
30+
-- ** Era inspection
1831
, ReachesEra2 (..)
1932
, activeSlotCoeff
2033
, isFirstEraBlock
@@ -25,7 +38,7 @@ module Test.ThreadNet.Infra.TwoEras
2538
, secondEraOverlaySlots
2639
, shelleyEpochSize
2740

28-
-- * Properties
41+
-- ** Properties
2942
, label_ReachesEra2
3043
, label_hadActiveNonOverlaySlots
3144
, prop_ReachesEra2
@@ -37,42 +50,138 @@ module Test.ThreadNet.Infra.TwoEras
3750
import qualified Cardano.Chain.Common as CC.Common
3851
import Cardano.Chain.ProtocolConstants (kEpochSlots)
3952
import Cardano.Chain.Slotting (unEpochSlots)
40-
import Cardano.Ledger.BaseTypes (unNonZero)
53+
import Cardano.Ledger.BaseTypes (nonZero, unNonZero)
4154
import qualified Cardano.Ledger.BaseTypes as SL
4255
import qualified Cardano.Protocol.TPraos.Rules.Overlay as SL
4356
import Cardano.Slotting.EpochInfo
44-
import Cardano.Slotting.Slot
45-
( EpochNo (..)
46-
, EpochSize (..)
47-
, SlotNo (..)
48-
)
57+
import Cardano.Slotting.Slot (EpochNo (..), EpochSize (..), SlotNo (..))
4958
import Control.Exception (assert)
5059
import Data.Functor ((<&>))
5160
import qualified Data.Map.Strict as Map
5261
import Data.Maybe (isJust)
62+
import Data.Proxy (Proxy (..))
5363
import Data.SOP.Strict (NS (..))
5464
import Data.Set (Set)
5565
import qualified Data.Set as Set
5666
import Data.Word (Word64)
5767
import GHC.Generics (Generic)
68+
import Ouroboros.Consensus.BlockchainTime
69+
import Ouroboros.Consensus.Cardano.Condense ()
5870
import Ouroboros.Consensus.Config.SecurityParam
5971
import Ouroboros.Consensus.HardFork.Combinator
6072
( HardForkBlock (..)
6173
, OneEraBlock (..)
6274
)
75+
import Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common
76+
( isHardForkNodeToNodeEnabled
77+
)
6378
import qualified Ouroboros.Consensus.HardFork.History.Util as Util
79+
import Ouroboros.Consensus.Node.NetworkProtocolVersion
6480
import Ouroboros.Consensus.Node.ProtocolInfo
6581
import Ouroboros.Consensus.NodeId
82+
import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol ()
83+
import Test.Consensus.Shelley.MockCrypto (MockCrypto)
6684
import Test.QuickCheck
6785
import Test.ThreadNet.General
6886
import qualified Test.ThreadNet.Infra.Shelley as Shelley
87+
import Test.ThreadNet.Infra.ShelleyBasedHardFork
6988
import Test.ThreadNet.Network (CalcMessageDelay (..), NodeOutput (..))
89+
import Test.ThreadNet.TxGen.Allegra ()
7090
import Test.ThreadNet.Util.Expectations (NumBlocks (..))
91+
import Test.ThreadNet.Util.NodeToNodeVersion (genVersionFiltered)
7192
import qualified Test.ThreadNet.Util.NodeTopology as Topo
7293
import qualified Test.Util.BoolProps as BoolProps
7394
import Test.Util.Orphans.Arbitrary ()
7495
import Test.Util.Slots (NumSlots (..))
7596

97+
{-------------------------------------------------------------------------------
98+
Block Type
99+
-------------------------------------------------------------------------------}
100+
101+
-- | A hard-fork block for two Shelley-based eras
102+
type DualBlock proto era1 era2 =
103+
ShelleyBasedHardForkBlock (proto MockCrypto) era1 (proto MockCrypto) era2
104+
105+
{-------------------------------------------------------------------------------
106+
Test Setup
107+
-------------------------------------------------------------------------------}
108+
109+
-- | The varying data of the tests crossing between Shelley-based eras
110+
--
111+
-- Note: The Shelley nodes in this test all join, propose an update, and endorse
112+
-- it literally as soon as possible. Therefore, if the test reaches the end of
113+
-- the first epoch, the proposal will be adopted.
114+
data TestSetup proto era1 era2 = TestSetup
115+
{ setupD :: Shelley.DecentralizationParam
116+
, setupHardFork :: Bool
117+
-- ^ whether the proposal should trigger a hard fork or not
118+
, setupInitialNonce :: SL.Nonce
119+
-- ^ the initial Shelley 'SL.ticknStateEpochNonce'
120+
--
121+
-- We vary it to ensure we explore different leader schedules.
122+
, setupK :: SecurityParam
123+
, setupPartition :: Partition
124+
, setupSlotLength :: SlotLength
125+
, setupTestConfig :: TestConfig
126+
, setupVersion :: (NodeToNodeVersion, BlockNodeToNodeVersion (DualBlock proto era1 era2))
127+
}
128+
129+
deriving instance Show (TestSetup proto era1 era2)
130+
131+
instance
132+
SupportedNetworkProtocolVersion (DualBlock proto era1 era2) =>
133+
Arbitrary (TestSetup proto era1 era2)
134+
where
135+
arbitrary = do
136+
setupD <-
137+
arbitrary
138+
-- The decentralization parameter cannot be 0 in the first
139+
-- Shelley epoch, since stake pools can only be created and
140+
-- delegated to via Shelley transactions.
141+
`suchThat` ((/= 0) . Shelley.decentralizationParamToRational)
142+
setupK <- SecurityParam <$> choose (8, 10) `suchThatMap` nonZero
143+
-- If k < 8, common prefix violations become too likely in
144+
-- Praos mode for thin overlay schedules (ie low d), even for
145+
-- f=0.2.
146+
147+
setupInitialNonce <- genNonce
148+
149+
setupSlotLength <- arbitrary
150+
151+
let epochSize = EpochSize $ shelleyEpochSize setupK
152+
setupTestConfig <-
153+
genTestConfig
154+
setupK
155+
(epochSize, epochSize)
156+
let TestConfig{numCoreNodes, numSlots} = setupTestConfig
157+
158+
setupHardFork <- frequency [(49, pure True), (1, pure False)]
159+
160+
-- TODO How reliable is the Byron-based partition duration logic when
161+
-- reused for Shelley?
162+
setupPartition <- genPartition numCoreNodes numSlots setupK
163+
164+
setupVersion <-
165+
genVersionFiltered
166+
isHardForkNodeToNodeEnabled
167+
(Proxy @(DualBlock proto era1 era2))
168+
169+
pure
170+
TestSetup
171+
{ setupD
172+
, setupHardFork
173+
, setupInitialNonce
174+
, setupK
175+
, setupPartition
176+
, setupSlotLength
177+
, setupTestConfig
178+
, setupVersion
179+
}
180+
181+
{-------------------------------------------------------------------------------
182+
Network Partitions
183+
-------------------------------------------------------------------------------}
184+
76185
-- | When and for how long the nodes are partitioned
77186
--
78187
-- The nodes are divided via message delays into two sub-networks by the parity

ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/AllegraMary.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import Test.Consensus.Shelley.MockCrypto (MockCrypto)
4848
import Test.QuickCheck
4949
import Test.Tasty
5050
import Test.Tasty.QuickCheck
51-
import Test.ThreadNet.EraCrossingInfra (DualBlock, TestSetup (..))
5251
import Test.ThreadNet.General
5352
import qualified Test.ThreadNet.Infra.Shelley as Shelley
5453
import Test.ThreadNet.Infra.ShelleyBasedHardFork

ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/Cardano.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import Test.Tasty.QuickCheck
7373
import Test.ThreadNet.General
7474
import qualified Test.ThreadNet.Infra.Byron as Byron
7575
import qualified Test.ThreadNet.Infra.Shelley as Shelley
76-
import Test.ThreadNet.Infra.TwoEras
76+
import Test.ThreadNet.Infra.TwoEras hiding (TestSetup (..))
7777
import Test.ThreadNet.Network
7878
( NodeOutput (..)
7979
, TestNodeInitialization (..)

ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/EraCrossingInfra.hs

Lines changed: 0 additions & 111 deletions
This file was deleted.

ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/MaryAlonzo.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import Test.Consensus.Shelley.MockCrypto (MockCrypto)
5454
import Test.QuickCheck
5555
import Test.Tasty
5656
import Test.Tasty.QuickCheck
57-
import Test.ThreadNet.EraCrossingInfra (DualBlock, TestSetup (..))
5857
import Test.ThreadNet.General
5958
import qualified Test.ThreadNet.Infra.Shelley as Shelley
6059
import Test.ThreadNet.Infra.ShelleyBasedHardFork

ouroboros-consensus-cardano/test/cardano-test/Test/ThreadNet/ShelleyAllegra.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import Test.Consensus.Shelley.MockCrypto (MockCrypto)
4848
import Test.QuickCheck
4949
import Test.Tasty
5050
import Test.Tasty.QuickCheck
51-
import Test.ThreadNet.EraCrossingInfra (DualBlock, TestSetup (..))
5251
import Test.ThreadNet.General
5352
import qualified Test.ThreadNet.Infra.Shelley as Shelley
5453
import Test.ThreadNet.Infra.ShelleyBasedHardFork

0 commit comments

Comments
 (0)