Skip to content

Commit fef88fc

Browse files
committed
WIP add compatibility layer for EraPerams serialisation
1 parent 246fb40 commit fef88fc

File tree

31 files changed

+472
-371
lines changed

31 files changed

+472
-371
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ library
167167
ouroboros-consensus ^>=0.27,
168168
ouroboros-consensus-protocol ^>=0.12,
169169
ouroboros-network-api ^>=0.14,
170+
reflection ^>=2.1.9,
170171
serialise ^>=0.2,
171172
singletons ^>=3.0,
172173
small-steps,
@@ -492,6 +493,7 @@ test-suite cardano-test
492493
ouroboros-network-protocols:{ouroboros-network-protocols, testlib},
493494
pretty-simple,
494495
process-extras,
496+
reflection,
495497
sop-core,
496498
sop-extras,
497499
strict-sop-core,

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/ByronHFC.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Control.Monad
2626
import qualified Data.Map.Strict as Map
2727
import Data.Maybe (listToMaybe, mapMaybe)
2828
import Data.MemPack
29+
import qualified Data.Reflection as Reflection
2930
import Data.SOP.Index (Index (..))
3031
import Data.Void (Void, absurd)
3132
import Data.Word
@@ -39,6 +40,7 @@ import Ouroboros.Consensus.Config
3940
import Ouroboros.Consensus.HardFork.Combinator
4041
import Ouroboros.Consensus.HardFork.Combinator.Degenerate
4142
import Ouroboros.Consensus.HardFork.Combinator.Serialisation.Common
43+
import qualified Ouroboros.Consensus.HardFork.History as HardFork
4244
import Ouroboros.Consensus.HardFork.Simple
4345
import Ouroboros.Consensus.Ledger.Abstract
4446
import Ouroboros.Consensus.Ledger.Query
@@ -99,7 +101,8 @@ instance SerialiseConstraintsHFC ByronBlock
99101
-- existing Byron blocks.
100102
instance SerialiseHFC '[ByronBlock] where
101103
encodeDiskHfcBlock (DegenCodecConfig ccfg) (DegenBlock b) =
102-
encodeDisk ccfg b
104+
-- TODO(geo2a): do we need to hard-code EraParamsFormat here?
105+
Reflection.give HardFork.EraParamsWithoutPerasRoundLength $ encodeDisk ccfg b
103106
decodeDiskHfcBlock (DegenCodecConfig ccfg) =
104107
fmap DegenBlock <$> decodeDisk ccfg
105108
reconstructHfcPrefixLen _ =

ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Ledger/Ledger.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ byronEraParams genesis =
333333
, eraSlotLength = fromByronSlotLength $ genesisSlotLength genesis
334334
, eraSafeZone = HardFork.StandardSafeZone (2 * k)
335335
, eraGenesisWin = GenesisWindow (2 * k)
336-
, eraPerasRoundLength = Nothing
336+
, eraPerasRoundLength = Nothing
337337
}
338338
where
339339
k = unNonZero $ maxRollbacks $ genesisSecurityParam genesis

ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Ledger.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ import Ouroboros.Consensus.Config
113113
import Ouroboros.Consensus.HardFork.Abstract
114114
import Ouroboros.Consensus.HardFork.Combinator.PartialConfig
115115
import qualified Ouroboros.Consensus.HardFork.History as HardFork
116-
import Ouroboros.Consensus.HardFork.History.EraParams (EraParams (eraPerasRoundLength))
116+
import Ouroboros.Consensus.HardFork.History.EraParams (EraParams (..))
117117
import Ouroboros.Consensus.HardFork.History.Util
118118
import Ouroboros.Consensus.HardFork.Simple
119119
import Ouroboros.Consensus.HeaderValidation
@@ -343,11 +343,11 @@ instance
343343
internsFromMap $
344344
shelleyLedgerState st
345345
^. SL.nesEsL
346-
. SL.esLStateL
347-
. SL.lsCertStateL
348-
. SL.certDStateL
349-
. SL.dsUnifiedL
350-
. SL.umElemsL
346+
. SL.esLStateL
347+
. SL.lsCertStateL
348+
. SL.certDStateL
349+
. SL.dsUnifiedL
350+
. SL.umElemsL
351351
in LedgerTables . ValuesMK <$> (eraDecoder @era $ decodeMap decodeMemPack (decShareCBOR certInterns))
352352

353353
instance
@@ -462,10 +462,10 @@ slUtxoL :: SL.NewEpochState era -> SL.UTxO era -> (SL.UTxO era, SL.NewEpochState
462462
slUtxoL st vals =
463463
st
464464
& SL.nesEsL
465-
. SL.esLStateL
466-
. SL.lsUTxOStateL
467-
. SL.utxoL
468-
<<.~ vals
465+
. SL.esLStateL
466+
. SL.lsUTxOStateL
467+
. SL.utxoL
468+
<<.~ vals
469469

470470
{-------------------------------------------------------------------------------
471471
GetTip

ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/Golden.hs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
module Test.Consensus.Cardano.Golden (tests) where
99

10+
import qualified Data.Reflection as Reflection
1011
import Ouroboros.Consensus.Cardano.Block
1112
import Ouroboros.Consensus.Cardano.Node
1213
import Ouroboros.Consensus.HardFork.Combinator.Serialisation
14+
import qualified Ouroboros.Consensus.HardFork.History as HardFork
1315
import Ouroboros.Consensus.Ledger.Query (QueryVersion)
1416
import Ouroboros.Consensus.Shelley.HFEras ()
1517
import Ouroboros.Consensus.Shelley.Ledger.SupportsProtocol ()
@@ -20,19 +22,22 @@ import Test.Util.Paths
2022
import Test.Util.Serialisation.CDDL
2123
import Test.Util.Serialisation.Golden
2224

25+
-- in these tests, we force the serialisation to ignore Peras for now to keep backward compatibility.
26+
-- TODO(geo2a): remove the calls to `Reflection.give` Peras-aware serialisation is supported on mainnet
2327
tests :: TestTree
2428
tests =
25-
goldenTest_all
26-
codecConfig
27-
($(getGoldenDir) </> "cardano")
28-
( Just $
29-
CDDLsForNodeToNode
30-
("ntnblock.cddl", "serialisedCardanoBlock")
31-
("ntnheader.cddl", "header")
32-
("ntntx.cddl", "tx")
33-
("ntntxid.cddl", "txId")
34-
)
35-
examples
29+
Reflection.give HardFork.EraParamsWithoutPerasRoundLength $
30+
goldenTest_all
31+
codecConfig
32+
($(getGoldenDir) </> "cardano")
33+
( Just $
34+
CDDLsForNodeToNode
35+
("ntnblock.cddl", "serialisedCardanoBlock")
36+
("ntnheader.cddl", "header")
37+
("ntntx.cddl", "tx")
38+
("ntntxid.cddl", "txId")
39+
)
40+
examples
3641

3742
instance
3843
CardanoHardForkConstraints c =>

ouroboros-consensus-cardano/test/cardano-test/Test/Consensus/Cardano/Serialisation.hs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ module Test.Consensus.Cardano.Serialisation (tests) where
99
import qualified Codec.CBOR.Write as CBOR
1010
import qualified Data.ByteString.Lazy as Lazy
1111
import Data.Constraint
12+
import qualified Data.Reflection as Reflection
1213
import Ouroboros.Consensus.Block
1314
import Ouroboros.Consensus.Byron.Ledger
1415
import Ouroboros.Consensus.Byron.Node ()
1516
import Ouroboros.Consensus.Cardano.Block
1617
import Ouroboros.Consensus.Cardano.Node ()
1718
import Ouroboros.Consensus.HardFork.Combinator.Block
19+
import qualified Ouroboros.Consensus.HardFork.History as HardFork
1820
import Ouroboros.Consensus.Shelley.Ledger
1921
import Ouroboros.Consensus.Shelley.Node ()
2022
import Ouroboros.Consensus.Storage.Serialisation
@@ -27,27 +29,31 @@ import Test.Tasty.QuickCheck (Property, testProperty, (===))
2729
import Test.Util.Orphans.Arbitrary ()
2830
import Test.Util.Serialisation.Roundtrip
2931

32+
-- in these tests, we force the serialisation to ignore Peras for now to keep backward compatibility.
33+
-- TODO(geo2a): remove the calls to `Reflection.give` Peras-aware serialisation is supported on mainnet
3034
tests :: TestTree
3135
tests =
3236
testGroup
3337
"Cardano"
3438
[ testGroup "Examples roundtrip" $
35-
examplesRoundtrip Cardano.Examples.codecConfig Cardano.Examples.examples
36-
, roundtrip_all_skipping
37-
result
38-
testCodecCfg
39-
dictNestedHdr
40-
-- We would want to use this instead, but the generated blocks
41-
-- do not quite validate yet or sometimes they are not
42-
-- entirely coherent, so for now this is commented out.
43-
--
44-
-- It is also the case that some (conway in particular) blocks take a
45-
-- very long time to validate or consume too much memory.
46-
--
47-
-- ( Just $
48-
-- CDDLsForNodeToNode ("ntnblock.cddl", "serialisedCardanoBlock") ("ntnheader.cddl", "header")
49-
-- )
50-
Nothing
39+
Reflection.give HardFork.EraParamsWithoutPerasRoundLength $
40+
examplesRoundtrip Cardano.Examples.codecConfig Cardano.Examples.examples
41+
, Reflection.give HardFork.EraParamsWithoutPerasRoundLength $
42+
roundtrip_all_skipping
43+
result
44+
testCodecCfg
45+
dictNestedHdr
46+
-- We would want to use this instead, but the generated blocks
47+
-- do not quite validate yet or sometimes they are not
48+
-- entirely coherent, so for now this is commented out.
49+
--
50+
-- It is also the case that some (conway in particular) blocks take a
51+
-- very long time to validate or consume too much memory.
52+
--
53+
-- ( Just $
54+
-- CDDLsForNodeToNode ("ntnblock.cddl", "serialisedCardanoBlock") ("ntnheader.cddl", "header")
55+
-- )
56+
Nothing
5157
, testProperty "BinaryBlockInfo sanity check" prop_CardanoBinaryBlockInfo
5258
]
5359
where

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

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,28 @@ prop_simple_allegraMary_convergence
169169
, setupTestConfig
170170
, setupVersion
171171
} =
172-
prop_general_semisync pga testOutput
173-
.&&. prop_inSync testOutput
174-
.&&. prop_ReachesEra2 reachesEra2
175-
.&&. prop_noCPViolation
176-
.&&. ( tabulate "ReachesEra2 label" [label_ReachesEra2 reachesEra2]
177-
$ tabulate
178-
"Observed forge during a non-overlay slot in the second era"
179-
[ label_hadActiveNonOverlaySlots
180-
testOutput
181-
overlaySlots
182-
]
183-
$ tabulatePartitionDuration setupK setupPartition
184-
$ tabulateFinalIntersectionDepth
185-
setupK
186-
(NumBlocks finalIntersectionDepth)
187-
finalBlockEra
188-
$ tabulatePartitionPosition
189-
(NumSlots numFirstEraSlots)
190-
setupPartition
191-
(ledgerReachesEra2 reachesEra2)
192-
$ property True
193-
)
172+
prop_general_semisync pga testOutput
173+
.&&. prop_inSync testOutput
174+
.&&. prop_ReachesEra2 reachesEra2
175+
.&&. prop_noCPViolation
176+
.&&. ( tabulate "ReachesEra2 label" [label_ReachesEra2 reachesEra2]
177+
$ tabulate
178+
"Observed forge during a non-overlay slot in the second era"
179+
[ label_hadActiveNonOverlaySlots
180+
testOutput
181+
overlaySlots
182+
]
183+
$ tabulatePartitionDuration setupK setupPartition
184+
$ tabulateFinalIntersectionDepth
185+
setupK
186+
(NumBlocks finalIntersectionDepth)
187+
finalBlockEra
188+
$ tabulatePartitionPosition
189+
(NumSlots numFirstEraSlots)
190+
setupPartition
191+
(ledgerReachesEra2 reachesEra2)
192+
$ property True
193+
)
194194
where
195195
TestConfig
196196
{ initSeed
@@ -236,47 +236,47 @@ prop_simple_allegraMary_convergence
236236

237237
testOutput :: TestOutput AllegraMaryBlock
238238
testOutput =
239-
runTestNetwork
240-
setupTestConfig
241-
testConfigB
242-
TestConfigMB
243-
{ nodeInfo = \(CoreNodeId nid) ->
244-
let protocolParamsShelleyBased =
245-
ProtocolParamsShelleyBased
246-
{ shelleyBasedInitialNonce = setupInitialNonce
247-
, shelleyBasedLeaderCredentials =
248-
[ Shelley.mkLeaderCredentials
249-
(coreNodes !! fromIntegral nid)
250-
]
239+
runTestNetwork
240+
setupTestConfig
241+
testConfigB
242+
TestConfigMB
243+
{ nodeInfo = \(CoreNodeId nid) ->
244+
let protocolParamsShelleyBased =
245+
ProtocolParamsShelleyBased
246+
{ shelleyBasedInitialNonce = setupInitialNonce
247+
, shelleyBasedLeaderCredentials =
248+
[ Shelley.mkLeaderCredentials
249+
(coreNodes !! fromIntegral nid)
250+
]
251+
}
252+
hardForkTrigger =
253+
TriggerHardForkAtVersion $ SL.getVersion majorVersion2
254+
(protocolInfo, blockForging) =
255+
protocolInfoShelleyBasedHardFork
256+
protocolParamsShelleyBased
257+
(SL.ProtVer majorVersion1 0)
258+
(SL.ProtVer majorVersion2 0)
259+
( L.mkTransitionConfig L.NoGenesis $
260+
L.mkTransitionConfig L.NoGenesis $
261+
L.mkShelleyTransitionConfig genesisShelley
262+
)
263+
hardForkTrigger
264+
in TestNodeInitialization
265+
{ tniCrucialTxs =
266+
if not setupHardFork
267+
then []
268+
else
269+
fmap GenTxShelley1 $
270+
Shelley.mkMASetDecentralizationParamTxs
271+
coreNodes
272+
(SL.ProtVer majorVersion2 0)
273+
(SlotNo $ unNumSlots numSlots) -- never expire
274+
setupD -- unchanged
275+
, tniProtocolInfo = protocolInfo
276+
, tniBlockForging = blockForging
251277
}
252-
hardForkTrigger =
253-
TriggerHardForkAtVersion $ SL.getVersion majorVersion2
254-
(protocolInfo, blockForging) =
255-
protocolInfoShelleyBasedHardFork
256-
protocolParamsShelleyBased
257-
(SL.ProtVer majorVersion1 0)
258-
(SL.ProtVer majorVersion2 0)
259-
( L.mkTransitionConfig L.NoGenesis $
260-
L.mkTransitionConfig L.NoGenesis $
261-
L.mkShelleyTransitionConfig genesisShelley
262-
)
263-
hardForkTrigger
264-
in TestNodeInitialization
265-
{ tniCrucialTxs =
266-
if not setupHardFork
267-
then []
268-
else
269-
fmap GenTxShelley1 $
270-
Shelley.mkMASetDecentralizationParamTxs
271-
coreNodes
272-
(SL.ProtVer majorVersion2 0)
273-
(SlotNo $ unNumSlots numSlots) -- never expire
274-
setupD -- unchanged
275-
, tniProtocolInfo = protocolInfo
276-
, tniBlockForging = blockForging
277-
}
278-
, mkRekeyM = Nothing
279-
}
278+
, mkRekeyM = Nothing
279+
}
280280

281281
maxForkLength :: NumBlocks
282282
maxForkLength = NumBlocks $ unNonZero $ maxRollbacks setupK

0 commit comments

Comments
 (0)