Skip to content

Commit 90a926f

Browse files
authored
Version ledger tables and encode TxIns in big-endian (#1652)
Closes #1532
2 parents 4179899 + 5005ee7 commit 90a926f

File tree

26 files changed

+250
-52
lines changed

26 files changed

+250
-52
lines changed

ouroboros-consensus-cardano/app/snapshot-converter.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ main = withStdTerminalHandles $ do
287287
let crcOut = maybe inCRC (crcOfConcat inCRC) mCRCOut
288288

289289
lift $ putStr "Generating new metadata file..." >> hFlush stdout
290-
putMetadata outFilePath (SnapshotMetadata outBackend crcOut)
290+
putMetadata outFilePath (SnapshotMetadata outBackend crcOut TablesCodecVersion1)
291291

292292
lift $ putColored Green True "Done"
293293

@@ -356,7 +356,7 @@ main = withStdTerminalHandles $ do
356356
InEnv
357357
st
358358
fp
359-
(fromInMemory (fp F.</> "tables" F.</> "tvar"))
359+
(fromInMemory (fp F.</> "tables"))
360360
("InMemory@[" <> fp <> "]")
361361
c
362362
mtd
@@ -412,7 +412,7 @@ main = withStdTerminalHandles $ do
412412
pure $
413413
OutEnv
414414
fp
415-
(toInMemory (fp F.</> "tables" F.</> "tvar"))
415+
(toInMemory (fp F.</> "tables"))
416416
(Just "tables")
417417
(Nothing)
418418
("InMemory@[" <> fp <> "]")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Patch
10+
11+
- A bullet item for the Patch category.
12+
13+
-->
14+
<!--
15+
### Non-Breaking
16+
17+
- A bullet item for the Non-Breaking category.
18+
19+
-->
20+
21+
### Breaking
22+
23+
- Flip serialization of `TxIx` in Mempack, to ensure lexicographic order on the
24+
serialized form matches the Haskell Ord, allowing for incremental streaming of
25+
values among backends. Note this happens at the same time as the versioning of
26+
the LedgerTables codec which will induce a replay of the chain.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ test-suite shelley-test
378378
contra-tracer,
379379
filepath,
380380
measures,
381+
mempack,
381382
microlens,
382383
ouroboros-consensus:{ouroboros-consensus, unstable-consensus-testlib},
383384
ouroboros-consensus-cardano,

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/CanHardFork.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE ConstraintKinds #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE EmptyCase #-}
@@ -12,7 +13,10 @@
1213
{-# LANGUAGE TypeFamilies #-}
1314
{-# LANGUAGE TypeOperators #-}
1415
{-# LANGUAGE UndecidableInstances #-}
15-
{-# OPTIONS_GHC -Wno-orphans #-}
16+
{-# OPTIONS_GHC -Wno-orphans -Wno-x-ord-preserving-coercions #-}
17+
#if __GLASGOW_HASKELL__ < 908
18+
{-# OPTIONS_GHC -Wno-unrecognised-warning-flags #-}
19+
#endif
1620

1721
module Ouroboros.Consensus.Cardano.CanHardFork
1822
( CardanoHardForkConstraints
@@ -92,7 +96,7 @@ import Ouroboros.Consensus.Shelley.Node ()
9296
import Ouroboros.Consensus.Shelley.Protocol.Praos ()
9397
import Ouroboros.Consensus.Shelley.ShelleyHFC
9498
import Ouroboros.Consensus.TypeFamilyWrappers
95-
import Ouroboros.Consensus.Util (eitherToMaybe)
99+
import Ouroboros.Consensus.Util (coerceMapKeys, eitherToMaybe)
96100

97101
{-------------------------------------------------------------------------------
98102
CanHardFork
@@ -466,6 +470,7 @@ translateLedgerStateShelleyToAllegraWrapper =
466470
LedgerTables
467471
. DiffMK
468472
. Diff.fromMapDeletes
473+
. coerceMapKeys
469474
. Map.map SL.upgradeTxOut
470475
$ avvms
471476

@@ -478,6 +483,7 @@ translateLedgerStateShelleyToAllegraWrapper =
478483
. withLedgerTables ls
479484
. LedgerTables
480485
. ValuesMK
486+
. coerceMapKeys
481487
$ avvms
482488

483489
resultingState =

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Ledger.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Cardano.Ledger.Binary.Decoding hiding (Decoder)
2828
import Cardano.Ledger.Binary.Encoding hiding (Encoding)
2929
import qualified Cardano.Ledger.Conway.State as SL
3030
import Cardano.Ledger.Core (Era, eraDecoder, eraProtVerLow)
31-
import qualified Cardano.Ledger.Shelley.API as SL
3231
import Cardano.Ledger.Shelley.LedgerState as SL
3332
( esLStateL
3433
, lsCertStateL
@@ -57,7 +56,8 @@ import Ouroboros.Consensus.Ledger.Tables
5756
import Ouroboros.Consensus.Protocol.Praos (Praos)
5857
import Ouroboros.Consensus.Protocol.TPraos (TPraos)
5958
import Ouroboros.Consensus.Shelley.Ledger
60-
( IsShelleyBlock
59+
( BigEndianTxIn
60+
, IsShelleyBlock
6161
, ShelleyBlock
6262
, ShelleyCompatible
6363
, shelleyLedgerState
@@ -70,7 +70,7 @@ instance
7070
HasCanonicalTxIn (CardanoEras c)
7171
where
7272
newtype CanonicalTxIn (CardanoEras c) = CardanoTxIn
73-
{ getCardanoTxIn :: SL.TxIn
73+
{ getCardanoTxIn :: BigEndianTxIn
7474
}
7575
deriving stock (Show, Eq, Ord)
7676
deriving newtype NoThunks

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/QueryHF.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
module Ouroboros.Consensus.Cardano.QueryHF () where
2121

22+
import Data.Coerce
2223
import Data.Functor.Product
2324
import Data.SOP.BasicFunctors
2425
import Data.SOP.Constraint
@@ -98,14 +99,14 @@ instance CardanoHardForkConstraints c => BlockSupportsHFLedgerQuery (CardanoEras
9899
answerShelleyLookupQueries
99100
(injectLedgerTables idx)
100101
(ejectHardForkTxOut idx)
101-
(ejectCanonicalTxIn idx)
102+
(coerce . ejectCanonicalTxIn idx)
102103
)
103104
answerBlockQueryHFTraverse =
104105
answerCardanoQueryHF
105106
( \idx ->
106107
answerShelleyTraversingQueries
107108
(ejectHardForkTxOut idx)
108-
(ejectCanonicalTxIn idx)
109+
(coerce . ejectCanonicalTxIn idx)
109110
(queryLedgerGetTraversingFilter idx)
110111
)
111112

0 commit comments

Comments
 (0)