Skip to content

Commit

Permalink
Provide CanUpgradeLedgerTables instances for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Jan 20, 2025
1 parent 33b45a8 commit 62fa65a
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ouroboros-consensus-cardano/app/snapshot-converter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -178,6 +179,7 @@ load ::
( LedgerDbSerialiseConstraints blk
, CanStowLedgerTables (LedgerState blk)
, LedgerSupportsProtocol blk
, V2.LedgerSupportsV2LedgerDB blk
)
=> Config
-> ResourceRegistry IO
Expand Down Expand Up @@ -226,6 +228,7 @@ store ::
( LedgerDbSerialiseConstraints blk
, CanStowLedgerTables (LedgerState blk)
, LedgerSupportsProtocol blk
, V2.LedgerSupportsV2LedgerDB blk
)
=> Config
-> CodecConfig blk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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) = ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
-------------------------------------------------------------------------------}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
================================================
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
------
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{..})
Expand Down

0 comments on commit 62fa65a

Please sign in to comment.