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

New NodeToClientVersionOf typeclass #4787

Merged
merged 1 commit into from
Jan 19, 2023
Merged

New NodeToClientVersionOf typeclass #4787

merged 1 commit into from
Jan 19, 2023

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Jan 15, 2023

This allows code to check what version of the node to client protocol is needed to use the query. For example:

ntcVersionOf $ QueryInEra qeInMode $ QueryInShelleyBasedEra qSbe QueryProtocolParameters

Whilst this function can be called directly, it is intended to be called by queryExpr eventually so that only queries that are valid for the current protocol are ever sent.

@newhoggy newhoggy force-pushed the newhoggy/ntc-version branch 4 times, most recently from 071959e to 5e85d20 Compare January 15, 2023 22:13
@newhoggy newhoggy marked this pull request as ready for review January 15, 2023 23:17
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, a few comments

@@ -215,6 +218,9 @@ data AnyCardanoEra where
=> CardanoEra era -- and explicit value.
-> AnyCardanoEra

instance NtcVersionOf AnyCardanoEra where
ntcVersionOf (AnyCardanoEra _) = NodeToClientV_9
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we defaulting to NodeToClientV_9 for any era? Shouldn't we be explicit with each era and assign the version as follows:

--
data NodeToClientVersion
    = NodeToClientV_9
    -- ^ enabled @CardanoNodeToClientVersion7@, i.e., Alonzo
    | NodeToClientV_10
    -- ^ added 'GetChainBlockNo' and 'GetChainPoint' queries
    | NodeToClientV_11
    -- ^ added 'GetRewardInfoPools` Block query
    | NodeToClientV_12
    -- ^ added 'LocalTxMonitor' mini-protocol
    | NodeToClientV_13
    -- ^ enabled @CardanoNodeToClientVersion9@, i.e., Babbage
    | NodeToClientV_14
    -- ^ added @GetPoolDistr, @GetPoolState, @GetSnapshots

Copy link
Contributor

Choose a reason for hiding this comment

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

I.e NodeToClientV_12 for everything up to Alonzo and NodeToClientV_14 for Babbage? The downside is we have to manually maintain this pairing.

Copy link
Contributor Author

@newhoggy newhoggy Jan 16, 2023

Choose a reason for hiding this comment

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

Why are we defaulting to NodeToClientV_9 for any era?

NodeToClientV_9 is the oldest era that is still being tracked. Any queries that exist but are not in the above list above are presume to be from an era older than NodeToClientV_9, but we set it to NodeToClientV_9 because it is long enough ago that we don't care about the precise version anymore.

Note that our API doesn't export everything. For example GetRewardInfoPools is never used in any of our code.

The downside is we have to manually maintain this pairing.

Yeah, I believe some form of this might belong in consensus. It's implemented here for the moment because getting changes in consensus can take a long time.

Even if it is implemented in consensus, some form of this will exist in our code because the type of the argument to ntcVersionOf is a type that exists in our code base.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Jan 17, 2023

Choose a reason for hiding this comment

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

NodeToClientV_9 is the oldest era that is still being tracked

Sure but the NodeToClientV_* depends on the era, so I don't think we should always default to NodeToClientV_9. E.g as things are implemented now if we call ntcVersionOf on AnyCardanoEra BabbageEra there are more queries available in Babbage than NodeToClientV_9 will allow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an interesting point. Would it be sufficient for nodeToClientVersionOf to take an era argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that we won't know the node's era unless we query for it, so it's not free.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Jan 17, 2023

Choose a reason for hiding this comment

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

I think manually doing this for now is ok.

cardano-api/src/Cardano/Api/IPC/NtcVersionOf.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Query.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/IPC/NtcVersionOf.hs Outdated Show resolved Hide resolved
@newhoggy newhoggy force-pushed the newhoggy/ntc-version branch 3 times, most recently from a2745dd to 0eb8f0a Compare January 17, 2023 00:03
@newhoggy newhoggy force-pushed the newhoggy/ntc-version branch 3 times, most recently from 8421f08 to 59c6a02 Compare January 17, 2023 05:10
@newhoggy newhoggy changed the title New NtcVersionOf typeclass New NodeToClientVersionOf typeclass Jan 17, 2023
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.

@newhoggy newhoggy force-pushed the newhoggy/ntc-version branch 2 times, most recently from 0b07afd to 76246af Compare January 17, 2023 12:46
cardano-api/src/Cardano/Api/Eras.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/IPC/Monad.hs Outdated Show resolved Hide resolved
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.

Still a couple of import changes needed

cardano-api/src/Cardano/Api/IPC/Version.hs Outdated Show resolved Hide resolved
@newhoggy newhoggy force-pushed the newhoggy/ntc-version branch 2 times, most recently from 33e927b to e4b51de Compare January 17, 2023 13:33
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.

Sorry, instance NodeToClientVersionOf AnyCardanoEra where needs to be updated to reflect the latest versions for the relevant era

@newhoggy newhoggy force-pushed the newhoggy/ntc-version branch 3 times, most recently from 0dba35c to ddee4d2 Compare January 17, 2023 22:19
@newhoggy newhoggy dismissed Jimbo4350’s stale review January 17, 2023 22:21

Removed unused typeclass instance

@newhoggy
Copy link
Contributor Author

I think there is not a strong relationship between the node to client version and the era. For example a query could be added during an era, but depending on the circumstances, the added query might work for an earlier era.

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.

LGTM

@@ -58,7 +58,6 @@ import Data.Type.Equality (TestEquality (..), (:~:) (Refl))
import Ouroboros.Consensus.Shelley.Eras as Consensus (StandardAllegra, StandardAlonzo,
StandardBabbage, StandardMary, StandardShelley)

Copy link
Contributor

Choose a reason for hiding this comment

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

Random diff

@newhoggy newhoggy merged commit fd6af7c into master Jan 19, 2023
@newhoggy newhoggy deleted the newhoggy/ntc-version branch January 19, 2023 00:57
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