-
Notifications
You must be signed in to change notification settings - Fork 720
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
Add ReaderT of NodeToClientVersion to LocalStateQueryExpr #4809
Add ReaderT of NodeToClientVersion to LocalStateQueryExpr #4809
Conversation
|
||
-- | Execute a local state query expression. | ||
executeLocalStateQueryExpr | ||
:: LocalNodeConnectInfo mode | ||
-> Maybe ChainPoint | ||
-> (NodeToClientVersion -> LocalStateQueryExpr (BlockInMode mode) ChainPoint (QueryInMode mode) () IO a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of ReaderT
allows this argument to simplify. This means that a query can be run like this:
executeLocalStateQueryExpr ... $ do
...
expr
...
instead of like this:
executeLocalStateQueryExpr ... $ \ntcVersion -> do
...
expr
...
We are transitioning from the later code because we want the ntcVersion
to be checked automatically rather than manually. The ntcVersion
argument was passed in via a lambda before because the monadic query expression previously check the version manually which is error prone.
@@ -284,7 +284,8 @@ runQueryTip (AnyConsensusModeParams cModeParams) network mOutFile = do | |||
CardanoMode -> do | |||
let localNodeConnInfo = LocalNodeConnectInfo cModeParams network sockPath | |||
|
|||
eLocalState <- liftIO $ executeLocalStateQueryExpr localNodeConnInfo Nothing $ \ntcVersion -> do | |||
eLocalState <- liftIO $ executeLocalStateQueryExpr localNodeConnInfo Nothing $ do | |||
ntcVersion <- ask |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This monadic expression checks the node to client version manually. It will switch to automatic checking in a future PR to be less error prone, but for until that capability is avilable, ntcVersion
is still accessible via ask
so manual check is still possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simplification 👍
The
NodeToClientVersion
for a connection is established as soon as the connection is created an never changes. This makesReaderT
a good fit for holding this value so that it can be retrieved by the monadic query expressions.