Skip to content

Commit

Permalink
Rename QueryLedger to BlockSupportsLedgerQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Apr 16, 2024
1 parent cd52ade commit ff5ad51
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 21 deletions.
Expand Up @@ -199,7 +199,7 @@ instance ApplyBlock (LedgerState ByronBlock) ByronBlock where
data instance BlockQuery ByronBlock :: Type -> Type where
GetUpdateInterfaceState :: BlockQuery ByronBlock UPI.State

instance QueryLedger ByronBlock where
instance BlockSupportsLedgerQuery ByronBlock where
answerBlockQuery _cfg GetUpdateInterfaceState (ExtLedgerState ledgerState _) =
CC.cvsUpdateState (byronLedgerState ledgerState)

Expand Down
Expand Up @@ -300,7 +300,8 @@ data instance BlockQuery (ShelleyBlock proto era) :: Type -> Type where
instance (Typeable era, Typeable proto)
=> ShowProxy (BlockQuery (ShelleyBlock proto era)) where

instance (ShelleyCompatible proto era, ProtoCrypto proto ~ crypto) => QueryLedger (ShelleyBlock proto era) where
instance (ShelleyCompatible proto era, ProtoCrypto proto ~ crypto)
=> BlockSupportsLedgerQuery (ShelleyBlock proto era) where
answerBlockQuery cfg query ext =
case query of
GetLedgerTip ->
Expand Down
Expand Up @@ -109,7 +109,7 @@ mkHandlers ::
( IOLike m
, LedgerSupportsMempool blk
, LedgerSupportsProtocol blk
, QueryLedger blk
, BlockSupportsLedgerQuery blk
, ConfigSupportsNode blk
)
=> NodeKernelArgs m addrNTN addrNTC blk
Expand Down Expand Up @@ -290,7 +290,7 @@ clientCodecs ccfg version networkVersion = Codecs {
dec = decodeNodeToClient ccfg version

-- | Identity codecs used in tests.
identityCodecs :: (Monad m, QueryLedger blk)
identityCodecs :: (Monad m, BlockSupportsLedgerQuery blk)
=> Codecs blk CodecFailure m
(AnyMessage (ChainSync (Serialised blk) (Point blk) (Tip blk)))
(AnyMessage (LocalTxSubmission (GenTx blk) (ApplyTxErr blk)))
Expand Down
Expand Up @@ -347,7 +347,7 @@ instance ShowQuery (BlockQuery BlockA) where
data instance BlockQuery BlockA result
deriving (Show)

instance QueryLedger BlockA where
instance BlockSupportsLedgerQuery BlockA where
answerBlockQuery _ qry = case qry of {}

instance SameDepIndex (BlockQuery BlockA) where
Expand Down
Expand Up @@ -283,7 +283,7 @@ instance ShowQuery (BlockQuery BlockB) where
data instance BlockQuery BlockB result
deriving (Show)

instance QueryLedger BlockB where
instance BlockSupportsLedgerQuery BlockB where
answerBlockQuery _ qry = case qry of {}

instance SameDepIndex (BlockQuery BlockB) where
Expand Down
Expand Up @@ -57,7 +57,7 @@ class ( LedgerSupportsProtocol blk
, InspectLedger blk
, LedgerSupportsMempool blk
, ConvertRawTxId (GenTx blk)
, QueryLedger blk
, BlockSupportsLedgerQuery blk
, HasPartialConsensusConfig (BlockProtocol blk)
, HasPartialLedgerConfig blk
, ConvertRawHash blk
Expand Down
Expand Up @@ -109,7 +109,7 @@ data instance BlockQuery (HardForkBlock xs) :: Type -> Type where
=> QueryHardFork (x ': xs) result
-> BlockQuery (HardForkBlock (x ': xs)) result

instance All SingleEraBlock xs => QueryLedger (HardForkBlock xs) where
instance All SingleEraBlock xs => BlockSupportsLedgerQuery (HardForkBlock xs) where
answerBlockQuery
(ExtLedgerCfg cfg)
query
Expand Down
Expand Up @@ -502,7 +502,7 @@ instance (Typeable m, Typeable a)
=> ShowProxy (BlockQuery (DualBlock m a)) where

-- | Not used in the tests: no constructors
instance Bridge m a => QueryLedger (DualBlock m a) where
instance Bridge m a => BlockSupportsLedgerQuery (DualBlock m a) where
answerBlockQuery _ = \case {}

instance SameDepIndex (BlockQuery (DualBlock m a)) where
Expand Down
Expand Up @@ -11,9 +11,9 @@
{-# LANGUAGE UndecidableInstances #-}
module Ouroboros.Consensus.Ledger.Query (
BlockQuery
, BlockSupportsLedgerQuery (..)
, ConfigSupportsNode (..)
, Query (..)
, QueryLedger (..)
, QueryVersion (..)
, ShowQuery (..)
, answerQuery
Expand Down Expand Up @@ -124,8 +124,10 @@ data QueryEncoderException blk =
(SomeSecond Query blk)
QueryVersion

deriving instance Show (SomeSecond BlockQuery blk) => Show (QueryEncoderException blk)
instance (Typeable blk, Show (SomeSecond BlockQuery blk)) => Exception (QueryEncoderException blk)
deriving instance Show (SomeSecond BlockQuery blk)
=> Show (QueryEncoderException blk)
instance (Typeable blk, Show (SomeSecond BlockQuery blk))
=> Exception (QueryEncoderException blk)

queryEncodeNodeToClient ::
forall blk.
Expand Down Expand Up @@ -202,7 +204,10 @@ queryDecodeNodeToClient codecConfig queryVersion blockVersion
(1, 3) -> requireVersion QueryVersion2 $ SomeSecond GetChainPoint
_ -> fail $ "Query: invalid size and tag" <> show (size, tag)

requireVersion :: QueryVersion -> SomeSecond Query blk -> Decoder s (SomeSecond Query blk)
requireVersion ::
QueryVersion
-> SomeSecond Query blk
-> Decoder s (SomeSecond Query blk)
requireVersion expectedVersion someSecondQuery =
if queryVersion >= expectedVersion
then return someSecondQuery
Expand Down Expand Up @@ -261,7 +266,7 @@ deriving instance Show (BlockQuery blk result) => Show (Query blk result)

-- | Answer the given query about the extended ledger state.
answerQuery ::
(QueryLedger blk, ConfigSupportsNode blk, HasAnnTip blk)
(BlockSupportsLedgerQuery blk, ConfigSupportsNode blk, HasAnnTip blk)
=> ExtLedgerCfg blk
-> Query blk result
-> ExtLedgerState blk
Expand All @@ -279,12 +284,18 @@ data family BlockQuery blk :: Type -> Type
--
-- Used by the LocalStateQuery protocol to allow clients to query the extended
-- ledger state.
class (ShowQuery (BlockQuery blk), SameDepIndex (BlockQuery blk)) => QueryLedger blk where
class (ShowQuery (BlockQuery blk), SameDepIndex (BlockQuery blk))
=> BlockSupportsLedgerQuery blk where

-- | Answer the given query about the extended ledger state.
answerBlockQuery :: ExtLedgerCfg blk -> BlockQuery blk result -> ExtLedgerState blk -> result
answerBlockQuery ::
ExtLedgerCfg blk
-> BlockQuery blk result
-> ExtLedgerState blk
-> result

instance SameDepIndex (BlockQuery blk) => Eq (SomeSecond BlockQuery blk) where
SomeSecond qry == SomeSecond qry' = isJust (sameDepIndex qry qry')

deriving instance (forall result. Show (BlockQuery blk result)) => Show (SomeSecond BlockQuery blk)
deriving instance (forall result. Show (BlockQuery blk result))
=> Show (SomeSecond BlockQuery blk)
Expand Up @@ -13,7 +13,7 @@ import Ouroboros.Network.Protocol.LocalStateQuery.Type
(AcquireFailure (..), Target (..))

localStateQueryServer ::
forall m blk. (IOLike m, QueryLedger blk, ConfigSupportsNode blk, HasAnnTip blk)
forall m blk. (IOLike m, BlockSupportsLedgerQuery blk, ConfigSupportsNode blk, HasAnnTip blk)
=> ExtLedgerCfg blk
-> STM m (Point blk)
-- ^ Get tip point
Expand Down
Expand Up @@ -80,7 +80,7 @@ class ( LedgerSupportsProtocol blk
, HasHardForkHistory blk
, LedgerSupportsMempool blk
, HasTxId (GenTx blk)
, QueryLedger blk
, BlockSupportsLedgerQuery blk
, SupportedNetworkProtocolVersion blk
, ConfigSupportsNode blk
, ConvertRawHash blk
Expand Down
Expand Up @@ -647,7 +647,7 @@ instance HasHardForkHistory TestBlock where
data instance BlockQuery TestBlock result where
QueryLedgerTip :: BlockQuery TestBlock (Point TestBlock)

instance QueryLedger TestBlock where
instance BlockSupportsLedgerQuery TestBlock where
answerBlockQuery _cfg QueryLedgerTip (ExtLedgerState TestLedger { lastAppliedPoint } _) =
lastAppliedPoint

Expand Down
Expand Up @@ -494,7 +494,7 @@ txSize = fromIntegral . Lazy.length . serialise
data instance BlockQuery (SimpleBlock c ext) result where
QueryLedgerTip :: BlockQuery (SimpleBlock c ext) (Point (SimpleBlock c ext))

instance MockProtocolSpecific c ext => QueryLedger (SimpleBlock c ext) where
instance MockProtocolSpecific c ext => BlockSupportsLedgerQuery (SimpleBlock c ext) where
answerBlockQuery _cfg QueryLedgerTip =
castPoint
. ledgerTipPoint
Expand Down

0 comments on commit ff5ad51

Please sign in to comment.