Skip to content

Commit a9e65f6

Browse files
committed
HFqueries
1 parent fd0fd4b commit a9e65f6

File tree

3 files changed

+23
-23
lines changed
  • ouroboros-consensus-cardano/src
    • byron/Ouroboros/Consensus/Byron/Ledger
    • ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano
  • ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Protocol

3 files changed

+23
-23
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{-# LANGUAGE StandaloneDeriving #-}
1616
{-# LANGUAGE TypeFamilies #-}
1717
{-# OPTIONS_GHC -Wno-orphans #-}
18+
{-# LANGUAGE TypeApplications #-}
1819

1920
-- | Instances requires for consensus/ledger integration
2021
module Ouroboros.Consensus.Byron.Ledger.Ledger
@@ -95,6 +96,7 @@ import Ouroboros.Consensus.Ledger.SupportsProtocol
9596
import Ouroboros.Consensus.Ledger.Tables.Utils
9697
import Ouroboros.Consensus.Storage.LedgerDB
9798
import Ouroboros.Consensus.Util (ShowProxy (..))
99+
import Ouroboros.Consensus.Util.IndexedMemPack
98100

99101
{-------------------------------------------------------------------------------
100102
LedgerState
@@ -199,19 +201,15 @@ instance IsLedger (LedgerState ByronBlock) where
199201
byronLedgerTransition
200202
}
201203

202-
-- type instance TxIn (LedgerState ByronBlock) = Void
203204
type instance TxOut ByronBlock = Void
204205
type instance TablesForBlock ByronBlock = '[]
205206

206-
-- instance LedgerTablesAreTrivial (LedgerState ByronBlock) where
207-
-- convertMapKind (ByronLedgerState x y z) = ByronLedgerState x y z
208-
-- instance LedgerTablesAreTrivial (Ticked (LedgerState ByronBlock)) where
209-
-- convertMapKind (TickedByronLedgerState x y) = TickedByronLedgerState x y
210-
211-
-- deriving via
212-
-- Void
213-
-- instance
214-
-- IndexedMemPack (LedgerState ByronBlock EmptyMK) Void
207+
instance IndexedMemPack LedgerState ByronBlock UTxOTable where
208+
type IndexedValue LedgerState UTxOTable ByronBlock = Value UTxOTable ByronBlock
209+
indexedPackM _ _ _ _ = absurd
210+
indexedUnpackM _ _ _ _ = error "absurd"
211+
indexedPackedByteCount _ _ _ _ = absurd
212+
indexedTypeName _ _ _ = typeName @Void
215213

216214
instance HasLedgerTables LedgerState ByronBlock where
217215
projectLedgerTables _ = LedgerTables Nil

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE ConstraintKinds #-}
31
{-# LANGUAGE DataKinds #-}
4-
{-# LANGUAGE DerivingStrategies #-}
52
{-# LANGUAGE EmptyCase #-}
63
{-# LANGUAGE FlexibleContexts #-}
74
{-# LANGUAGE FlexibleInstances #-}
85
{-# LANGUAGE LambdaCase #-}
9-
{-# LANGUAGE MultiParamTypeClasses #-}
10-
{-# LANGUAGE PolyKinds #-}
116
{-# LANGUAGE RankNTypes #-}
127
{-# LANGUAGE ScopedTypeVariables #-}
138
{-# LANGUAGE TypeApplications #-}
14-
{-# LANGUAGE TypeFamilyDependencies #-}
9+
{-# LANGUAGE MonoLocalBinds #-}
1510
{-# LANGUAGE TypeOperators #-}
16-
{-# LANGUAGE UndecidableInstances #-}
17-
{-# LANGUAGE UndecidableSuperClasses #-}
1811
{-# OPTIONS_GHC -Wno-orphans #-}
1912

2013
module Ouroboros.Consensus.Cardano.QueryHF () where
2114

15+
import Ouroboros.Consensus.Ledger.Tables.Utils
16+
import Lens.Micro ((.~), (&))
2217
import Data.Functor.Product
2318
import Data.SOP.BasicFunctors
2419
import Data.SOP.Constraint
@@ -91,12 +86,15 @@ shelleyCardanoFilter ::
9186
Bool
9287
shelleyCardanoFilter q = eliminateCardanoTxOut (\_ -> shelleyQFTraverseTablesPredicate q)
9388

94-
instance CardanoHardForkConstraints c => BlockSupportsHFLedgerQuery (CardanoEras c) where
89+
instance
90+
CardanoHardForkConstraints c =>
91+
BlockSupportsHFLedgerQuery (CardanoEras c)
92+
where
9593
answerBlockQueryHFLookup =
9694
answerCardanoQueryHF
9795
( \idx ->
9896
answerShelleyLookupQueries
99-
(undefined ) -- injectLedgerTables idx)
97+
castKeys
10098
(ejectHardForkTxOut idx)
10199
)
102100
answerBlockQueryHFTraverse =
@@ -120,6 +118,12 @@ instance CardanoHardForkConstraints c => BlockSupportsHFLedgerQuery (CardanoEras
120118
IS (IS (IS (IS (IS (IS (IS IZ)))))) -> shelleyCardanoFilter q
121119
IS (IS (IS (IS (IS (IS (IS (IS idx'))))))) -> case idx' of {}
122120

121+
castKeys :: forall blk blk'. (SListI (TablesForBlock blk), SingI (TablesForBlock blk), LedgerTablesConstraints blk') => LedgerTables blk KeysMK -> LedgerTables blk' KeysMK
122+
castKeys np =
123+
emptyLedgerTables
124+
& onUTxOTable (Proxy @blk') .~ maybe (Table (KeysMK mempty)) (\(Table (KeysMK km)) -> Table (KeysMK km)) (getTableByTag (sing @UTxOTable) np)
125+
& onInstantStakeTable (Proxy @blk') .~ maybe (Table (KeysMK mempty)) (\(Table (KeysMK km)) -> Table (KeysMK km)) (getTableByTag (sing @InstantStakeTable) np)
126+
123127
byronCardanoFilter ::
124128
BlockQuery ByronBlock QFTraverseTables result ->
125129
TxOut (HardForkBlock (CardanoEras c)) ->

ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Protocol/PBFT.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
{-# LANGUAGE TypeFamilies #-}
12
{-# LANGUAGE CPP #-}
23
{-# LANGUAGE DeriveAnyClass #-}
34
{-# LANGUAGE DeriveGeneric #-}
45
{-# LANGUAGE DerivingVia #-}
56
{-# LANGUAGE ExistentialQuantification #-}
67
{-# LANGUAGE FlexibleContexts #-}
7-
{-# LANGUAGE FlexibleInstances #-}
8-
{-# LANGUAGE MultiParamTypeClasses #-}
98
{-# LANGUAGE NamedFieldPuns #-}
109
{-# LANGUAGE RecordWildCards #-}
1110
{-# LANGUAGE ScopedTypeVariables #-}
1211
{-# LANGUAGE StandaloneDeriving #-}
13-
{-# LANGUAGE TypeFamilyDependencies #-}
1412
{-# LANGUAGE UndecidableInstances #-}
1513

1614
#if __GLASGOW_HASKELL__ >= 908

0 commit comments

Comments
 (0)