From 62fa65afcd654d8c0104273284c61f418a961a0c Mon Sep 17 00:00:00 2001 From: Javier Sagredo Date: Fri, 17 Jan 2025 12:31:38 +0100 Subject: [PATCH] Provide CanUpgradeLedgerTables instances for tests --- ouroboros-consensus-cardano/app/snapshot-converter.hs | 3 +++ .../consensus-test/Test/Consensus/HardFork/Combinator/A.hs | 4 ++++ .../consensus-test/Test/Consensus/HardFork/Combinator/B.hs | 3 +++ .../src/unstable-consensus-testlib/Test/Util/TestBlock.hs | 4 +++- .../Ouroboros/Consensus/Mock/Ledger/Block.hs | 4 ++++ .../Ouroboros/Consensus/Tutorial/Simple.lhs | 3 +++ .../Ouroboros/Consensus/Tutorial/WithEpoch.lhs | 3 +++ .../Test/Consensus/Mempool/Fairness/TestBlock.hs | 3 +++ .../Test/Ouroboros/Storage/ChainDB/StateMachine.hs | 2 ++ .../Test/Ouroboros/Storage/LedgerDB/StateMachine/TestBlock.hs | 4 ++++ .../test/storage-test/Test/Ouroboros/Storage/TestBlock.hs | 3 +++ 11 files changed, 35 insertions(+), 1 deletion(-) diff --git a/ouroboros-consensus-cardano/app/snapshot-converter.hs b/ouroboros-consensus-cardano/app/snapshot-converter.hs index 5d1294363d..2d790742d5 100644 --- a/ouroboros-consensus-cardano/app/snapshot-converter.hs +++ b/ouroboros-consensus-cardano/app/snapshot-converter.hs @@ -39,6 +39,7 @@ import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.BackingStore.Impl.LMDB import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.DbChangelog as V1 import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Lock as V1 import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.Snapshots as V1 +import qualified Ouroboros.Consensus.Storage.LedgerDB.V2 as V2 import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory as V2 import qualified Ouroboros.Consensus.Storage.LedgerDB.V2.LedgerSeq as V2 import Ouroboros.Consensus.Util.CRC @@ -178,6 +179,7 @@ load :: ( LedgerDbSerialiseConstraints blk , CanStowLedgerTables (LedgerState blk) , LedgerSupportsProtocol blk + , V2.LedgerSupportsV2LedgerDB blk ) => Config -> ResourceRegistry IO @@ -226,6 +228,7 @@ store :: ( LedgerDbSerialiseConstraints blk , CanStowLedgerTables (LedgerState blk) , LedgerSupportsProtocol blk + , V2.LedgerSupportsV2LedgerDB blk ) => Config -> CodecConfig blk diff --git a/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/A.hs b/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/A.hs index 6d4c6e4c1b..1fd90e34db 100644 --- a/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/A.hs +++ b/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/A.hs @@ -82,6 +82,7 @@ import Ouroboros.Consensus.Node.Run import Ouroboros.Consensus.Node.Serialisation import Ouroboros.Consensus.Protocol.Abstract import Ouroboros.Consensus.Storage.ImmutableDB (simpleChunkInfo) +import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory import Ouroboros.Consensus.Storage.Serialisation import Ouroboros.Consensus.Util (repeatedlyM) import Ouroboros.Consensus.Util.Condense @@ -211,6 +212,9 @@ deriving via TrivialLedgerTables (Ticked (LedgerState BlockA)) instance HasLedgerTables (Ticked (LedgerState BlockA)) deriving via TrivialLedgerTables (LedgerState BlockA) instance CanStowLedgerTables (LedgerState BlockA) +deriving via TrivialLedgerTables (LedgerState BlockA) + instance CanUpgradeLedgerTables (LedgerState BlockA) + data PartialLedgerConfigA = LCfgA { lcfgA_k :: SecurityParam diff --git a/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/B.hs b/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/B.hs index af4caa05d8..4887119a12 100644 --- a/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/B.hs +++ b/ouroboros-consensus-diffusion/test/consensus-test/Test/Consensus/HardFork/Combinator/B.hs @@ -68,6 +68,7 @@ import Ouroboros.Consensus.Node.Run import Ouroboros.Consensus.Node.Serialisation import Ouroboros.Consensus.Protocol.Abstract import Ouroboros.Consensus.Storage.ImmutableDB (simpleChunkInfo) +import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory import Ouroboros.Consensus.Storage.Serialisation import Ouroboros.Consensus.Util.Condense import Ouroboros.Consensus.Util.Orphans () @@ -186,6 +187,8 @@ deriving via TrivialLedgerTables (Ticked (LedgerState BlockB)) instance HasLedgerTables (Ticked (LedgerState BlockB)) deriving via TrivialLedgerTables (LedgerState BlockB) instance CanStowLedgerTables (LedgerState BlockB) +deriving via TrivialLedgerTables (LedgerState BlockB) + instance CanUpgradeLedgerTables (LedgerState BlockB) type instance LedgerCfg (LedgerState BlockB) = () diff --git a/ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/TestBlock.hs b/ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/TestBlock.hs index ef271e5055..47aa4a9c3f 100644 --- a/ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/TestBlock.hs +++ b/ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/TestBlock.hs @@ -134,6 +134,7 @@ import Ouroboros.Consensus.Protocol.BFT import Ouroboros.Consensus.Protocol.MockChainSel import Ouroboros.Consensus.Protocol.Signed import Ouroboros.Consensus.Storage.ChainDB (SerialiseDiskConstraints) +import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory import Ouroboros.Consensus.Storage.Serialisation import Ouroboros.Consensus.Util (ShowProxy (..)) import Ouroboros.Consensus.Util.Condense @@ -145,7 +146,6 @@ import qualified System.Random as R import Test.QuickCheck hiding (Result) import Test.Util.Orphans.SignableRepresentation () import Test.Util.Orphans.ToExpr () - {------------------------------------------------------------------------------- Test infrastructure: test block -------------------------------------------------------------------------------} @@ -523,6 +523,8 @@ deriving via TrivialLedgerTables (LedgerState TestBlock) instance HasLedgerTables (Ticked (LedgerState TestBlock)) deriving via TrivialLedgerTables (LedgerState TestBlock) instance CanStowLedgerTables (LedgerState TestBlock) +deriving via TrivialLedgerTables (LedgerState TestBlock) + instance CanUpgradeLedgerTables (LedgerState TestBlock) instance PayloadSemantics ptype => ApplyBlock (LedgerState (TestBlockWith ptype)) (TestBlockWith ptype) where diff --git a/ouroboros-consensus/src/unstable-mock-block/Ouroboros/Consensus/Mock/Ledger/Block.hs b/ouroboros-consensus/src/unstable-mock-block/Ouroboros/Consensus/Mock/Ledger/Block.hs index 7fd5f195e7..a7e5f06544 100644 --- a/ouroboros-consensus/src/unstable-mock-block/Ouroboros/Consensus/Mock/Ledger/Block.hs +++ b/ouroboros-consensus/src/unstable-mock-block/Ouroboros/Consensus/Mock/Ledger/Block.hs @@ -99,6 +99,7 @@ import Ouroboros.Consensus.Mock.Ledger.State import qualified Ouroboros.Consensus.Mock.Ledger.UTxO as Mock import Ouroboros.Consensus.Storage.Common (BinaryBlockInfo (..), SizeInBytes) +import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory import Ouroboros.Consensus.Util (ShowProxy (..), hashFromBytesShortE) import Ouroboros.Consensus.Util.Condense import Test.Util.Orphans.Serialise () @@ -466,6 +467,9 @@ instance LedgerSupportsPeerSelection (SimpleBlock c ext) where type instance TxIn (LedgerState (SimpleBlock c ext)) = Mock.TxIn type instance TxOut (LedgerState (SimpleBlock c ext)) = Mock.TxOut +instance CanUpgradeLedgerTables (LedgerState (SimpleBlock c ext)) where + upgradeTables _ _ = id + instance HasLedgerTables (LedgerState (SimpleBlock c ext)) where projectLedgerTables = simpleLedgerTables withLedgerTables (SimpleLedgerState s _) = SimpleLedgerState s diff --git a/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/Simple.lhs b/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/Simple.lhs index 4ccfe8b01e..b551ef27a1 100644 --- a/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/Simple.lhs +++ b/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/Simple.lhs @@ -63,6 +63,7 @@ First, some imports we'll need: > import Ouroboros.Consensus.HeaderValidation > (ValidateEnvelope, BasicEnvelopeValidation, HasAnnTip) > import Ouroboros.Consensus.Ledger.Tables +> import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory Conceptual Overview and Definitions of Key Terms ================================================ @@ -750,3 +751,5 @@ and we use the default implementation > instance HasLedgerTables (Ticked (LedgerState BlockC)) > deriving via TrivialLedgerTables (LedgerState BlockC) > instance CanStowLedgerTables (LedgerState BlockC) +> deriving via TrivialLedgerTables (LedgerState BlockC) +> instance CanUpgradeLedgerTables (LedgerState BlockC) diff --git a/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/WithEpoch.lhs b/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/WithEpoch.lhs index c0eb31886d..64dd80679d 100644 --- a/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/WithEpoch.lhs +++ b/ouroboros-consensus/src/unstable-tutorials/Ouroboros/Consensus/Tutorial/WithEpoch.lhs @@ -91,6 +91,7 @@ And imports, of course: > import Ouroboros.Consensus.Ledger.Basics (GetTip(..)) > import Ouroboros.Consensus.Ledger.Tables +> import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory Epochs ------ @@ -690,3 +691,5 @@ For reference on these instances and their meaning, please see the appendix in > instance HasLedgerTables (Ticked (LedgerState BlockD)) > deriving via TrivialLedgerTables (LedgerState BlockD) > instance CanStowLedgerTables (LedgerState BlockD) +> deriving via TrivialLedgerTables (LedgerState BlockD) +> instance CanUpgradeLedgerTables (LedgerState BlockD) diff --git a/ouroboros-consensus/test/consensus-test/Test/Consensus/Mempool/Fairness/TestBlock.hs b/ouroboros-consensus/test/consensus-test/Test/Consensus/Mempool/Fairness/TestBlock.hs index b8a3670ac7..8f83ba96cd 100644 --- a/ouroboros-consensus/test/consensus-test/Test/Consensus/Mempool/Fairness/TestBlock.hs +++ b/ouroboros-consensus/test/consensus-test/Test/Consensus/Mempool/Fairness/TestBlock.hs @@ -27,6 +27,7 @@ import Ouroboros.Consensus.Ledger.Abstract (convertMapKind, trivialLedgerTables) import qualified Ouroboros.Consensus.Ledger.Abstract as Ledger import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Ledger +import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory import Ouroboros.Consensus.Ticked (Ticked) import qualified Test.Util.TestBlock as TestBlock import Test.Util.TestBlock (TestBlockWith) @@ -145,3 +146,5 @@ instance Ledger.LedgerTablesAreTrivial (Ticked (Ledger.LedgerState TestBlock)) w TestBlock.TickedTestLedger (Ledger.convertMapKind x) deriving via Ledger.TrivialLedgerTables (Ledger.LedgerState TestBlock) instance Ledger.CanStowLedgerTables (Ledger.LedgerState TestBlock) +deriving via Ledger.TrivialLedgerTables (Ledger.LedgerState TestBlock) + instance CanUpgradeLedgerTables (Ledger.LedgerState TestBlock) diff --git a/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs b/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs index 0336330ed9..13fd1170d3 100644 --- a/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs +++ b/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/ChainDB/StateMachine.hs @@ -115,6 +115,7 @@ import Ouroboros.Consensus.Storage.ImmutableDB.Chunks.Internal (unsafeChunkNoToEpochNo) import qualified Ouroboros.Consensus.Storage.LedgerDB.TraceEvent as LedgerDB import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.DbChangelog as DbChangelog +import Ouroboros.Consensus.Storage.LedgerDB.V2 import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB import Ouroboros.Consensus.Util (split) import Ouroboros.Consensus.Util.CallStack @@ -316,6 +317,7 @@ type TestConstraints blk = , SerialiseDiskConstraints blk , Show (LedgerState blk EmptyMK) , LedgerTablesAreTrivial (LedgerState blk) + , LedgerSupportsV2LedgerDB blk ) deriving instance (TestConstraints blk, Eq it, Eq flr) diff --git a/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB/StateMachine/TestBlock.hs b/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB/StateMachine/TestBlock.hs index 6da985b2f7..d7c96270d2 100644 --- a/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB/StateMachine/TestBlock.hs +++ b/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/LedgerDB/StateMachine/TestBlock.hs @@ -52,6 +52,7 @@ import Ouroboros.Consensus.Ledger.Extended import Ouroboros.Consensus.Ledger.Tables.Utils import Ouroboros.Consensus.Storage.LedgerDB.API import qualified Ouroboros.Consensus.Storage.LedgerDB.V1.DiffSeq as DS +import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory import Ouroboros.Consensus.Util.IOLike import Ouroboros.Network.Block (Point (Point)) import Ouroboros.Network.Point (Block (Block)) @@ -194,6 +195,9 @@ queryKeys f (LedgerTables (ValuesMK utxovals)) = f utxovals type instance TxIn (LedgerState TestBlock) = Token type instance TxOut (LedgerState TestBlock) = TValue +instance CanUpgradeLedgerTables (LedgerState TestBlock) where + upgradeTables _ _ = id + instance HasLedgerTables (LedgerState TestBlock) where projectLedgerTables st = utxtoktables $ payloadDependentState st withLedgerTables st table = st { payloadDependentState = diff --git a/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/TestBlock.hs b/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/TestBlock.hs index cd3e421417..e2bdc2d6c8 100644 --- a/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/TestBlock.hs +++ b/ouroboros-consensus/test/storage-test/Test/Ouroboros/Storage/TestBlock.hs @@ -107,6 +107,7 @@ import Ouroboros.Consensus.Protocol.ModChainSel import Ouroboros.Consensus.Protocol.Signed import Ouroboros.Consensus.Storage.ImmutableDB (Tip) import Ouroboros.Consensus.Storage.ImmutableDB.Chunks +import Ouroboros.Consensus.Storage.LedgerDB.V2.InMemory import Ouroboros.Consensus.Storage.Serialisation import Ouroboros.Consensus.Storage.VolatileDB import Ouroboros.Consensus.Util.Condense @@ -575,6 +576,8 @@ deriving via TrivialLedgerTables (Ticked (LedgerState TestBlock)) instance HasLedgerTables (Ticked (LedgerState TestBlock)) deriving via TrivialLedgerTables (LedgerState TestBlock) instance CanStowLedgerTables (LedgerState TestBlock) +deriving via TrivialLedgerTables (LedgerState TestBlock) + instance CanUpgradeLedgerTables (LedgerState TestBlock) instance ApplyBlock (LedgerState TestBlock) TestBlock where applyBlockLedgerResult _ tb@TestBlock{..} (TickedTestLedger TestLedger{..})