Skip to content

Commit

Permalink
Refine local-state-query.cddl by specifying possible queries
Browse files Browse the repository at this point in the history
  • Loading branch information
geo2a committed Feb 10, 2025
1 parent a933425 commit 6073392
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
11 changes: 10 additions & 1 deletion ouroboros-network-protocols/cddl/specs/local-state-query.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ acquireFailurePointNotOnChain = 1
failure = acquireFailurePointTooOld
/ acquireFailurePointNotOnChain

query = any
blockQuery = [0, point]
getSystemStart = [1]
getChainBlockNo = [2]
getChainPoint = [3]

query = blockQuery
/ getSystemStart
/ getChainBlockNo
/ getChainPoint

result = any

msgAcquire = [0, point]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
Expand All @@ -20,14 +22,29 @@ import Ouroboros.Network.Protocol.BlockFetch.Codec.CDDL (Block, BlockPoint)
import Ouroboros.Network.Protocol.LocalStateQuery.Codec
import Ouroboros.Network.Protocol.LocalStateQuery.Type
import Test.Data.CDDL (Any)
import Test.QuickCheck (Arbitrary (..))
import Test.QuickCheck (Arbitrary (..), oneof)

newtype Result = Result Any
deriving (Eq, Show, Arbitrary, Serialise, Generic, NFData)
deriving stock (Eq, Show, Generic)
deriving newtype (Arbitrary, Serialise, NFData)

data QueryPayload =
BlockQuery Any
| GetSystemStart
| GetChainBlockNo
| GetChainPoint
deriving stock (Eq, Show, Generic)
deriving anyclass (Serialise, NFData)

instance Arbitrary QueryPayload where
arbitrary = oneof [ BlockQuery <$> arbitrary
, pure GetSystemStart
, pure GetChainBlockNo
, pure GetChainPoint
]

-- TODO: add payload to the query
data Query result where
Query :: Any -> Query Result
Query :: QueryPayload -> Query Result

instance NFData (Query result) where
rnf (Query a) = rnf a
Expand Down

0 comments on commit 6073392

Please sign in to comment.