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

Add ReaderT of NodeToClientVersion to LocalStateQueryExpr #4809

Merged

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Jan 19, 2023

The NodeToClientVersion for a connection is established as soon as the connection is created an never changes. This makes ReaderT a good fit for holding this value so that it can be retrieved by the monadic query expressions.


-- | Execute a local state query expression.
executeLocalStateQueryExpr
:: LocalNodeConnectInfo mode
-> Maybe ChainPoint
-> (NodeToClientVersion -> LocalStateQueryExpr (BlockInMode mode) ChainPoint (QueryInMode mode) () IO a)
Copy link
Contributor Author

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
Copy link
Contributor Author

@newhoggy newhoggy Jan 19, 2023

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.

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification 👍

@newhoggy newhoggy merged commit 9665b3d into master Jan 19, 2023
@iohk-bors iohk-bors bot deleted the newhoggy/introduce-ReaderT-into-LocalStateQueryExpr branch January 19, 2023 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants