Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine the CDDL spec of the LocalStateQuery mini-protocol #5074

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ouroboros-network-protocols/bench-cddl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ localStateQueryMessages =
, AnyMessageWithResult
(Stateful.AnyMessage
StateAcquired
(MsgQuery (Query largeCBORBS)))
(MsgQuery (Query . BlockQuery $ largeCBORBS)))
, AnyMessageWithResult
(Stateful.AnyMessage
(StateQuerying (Query largeCBORBS))
(StateQuerying (Query . BlockQuery $ largeCBORBS))
(MsgResult (Result (Any CBOR.TNull))))
, AnyMessageWithResult
(Stateful.AnyMessage
Expand Down
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