Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Unify Node APIs #3882

Merged
merged 15 commits into from
Nov 27, 2018
Merged

Unify Node APIs #3882

merged 15 commits into from
Nov 27, 2018

Conversation

parsonsmatt
Copy link
Contributor

Description

This PR unifies the two node APIs in the new Node API.

@parsonsmatt parsonsmatt changed the title Unify Node APIs [WIP] Unify Node APIs Nov 22, 2018
@KtorZ KtorZ self-requested a review November 22, 2018 17:32
ourAppName :: HasUpdateConfiguration => ApplicationName
ourAppName = ccApplicationName updateConfiguration
ourAppName :: UpdateConfiguration -> ApplicationName
ourAppName = ccApplicationName
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got annoyed at the UpdateConfiguration and went down a bit of a rabbit hole getting that to not be an implicit param.

@@ -74,7 +74,7 @@ import Pos.Util.Wlog (WithLogger, logDebug)

-- | A set of constraints necessary to create a block from mempool.
type MonadCreateBlock ctx m
= ( HasUpdateConfiguration
= ( HasLens' ctx UpdateConfiguration
Copy link
Contributor Author

Choose a reason for hiding this comment

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

but instead of passing the UpdateConfiguration around directly, I have decided to pass it in the various Context's that are used in a MonadReader manner. That's part of why this PR is as small as it is.

Unfortunately, the Ether lensy stuff is super verbose and boilerplatey. I'll swap it over to generic-lens soon...

, HasPrimaryKey r, HasLens TxpHolderTag r (GenericTxpLocalData ext)
, HasLens UpdateConfiguration r UpdateConfiguration
, HasSscContext r
) => ServerT NodeApi m
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generalized this one so I could reuse it with less context than all of WorkMode

@@ -273,29 +284,34 @@ nodeServantHandlers =
-- :<|> getOurSecret
-- :<|> getSscStage

getLeaders :: Maybe EpochIndex -> WebMode ext SlotLeaders
getLeaders :: MonadDBRead m => Maybe EpochIndex -> m SlotLeaders
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the point of all these mtl classes if you just run everything in SomeMonstrousMonad anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

🙃 ...

= "v1"
:> ( Node.API
:<|> Legacy.NodeApi
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hooray, a v1 prefix!

Copy link
Contributor

Choose a reason for hiding this comment

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

As a matter of fact, I think we are now "technically" at v2 😂 ...

@@ -8,8 +8,9 @@ module Cardano.Node.API where
import Universum
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This module is where most of the real work is done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! Was looking for it 😛 ! Would have been nice to make two PRs I believe, but then I know.. CI.. :(

:: !SscContext
, legacyCtxNodeDBs
:: !DB.NodeDBs
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I define a separate LegacyCtx so that I can instantiate all the classes etc that I need.

With generic-lens, this (can) become a tuple of all the things it needs, and the entire datatype disappears. Alternatively, you have the datatype + the fields and a deriving Generic line.

legacyNodeApi r =
hoistServer
(Proxy :: Proxy Legacy.NodeApi)
(Handler . ExceptT . try . flip runReaderT r)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This trys for ServantErrors that are thrown via IO.

Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂️

-> NtpConfiguration
-> NodeResources ext
-> NodeResources ()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'd be nice if NodeResources were a Functor so I could void :: Functor f => f a -> f () and retain polymorphism. However, the ext eventually bottoms out to a TVar ext in GenericTxpLocalData, and TVar isn't a Functor, so, oh well.

@@ -264,16 +341,14 @@ instance HasLens LastKnownHeaderTag InfoCtx LastKnownHeader where
lensOf =
lens infoCtxLastKnownHeader (\i s -> i { infoCtxLastKnownHeader = s })

instance
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 MonadTrans instance for MonadDBRead is super frustrating. It clashes with any polymorphic implementation like this, and even an OVERLAPPING pragma doesn't shut it up. So, you need dozens of instances like this.

@parsonsmatt parsonsmatt changed the title [WIP] Unify Node APIs Unify Node APIs Nov 26, 2018
@parsonsmatt parsonsmatt removed the wip label Nov 26, 2018
@parsonsmatt parsonsmatt force-pushed the matt/fold-in-other-node-api branch from 0f397d8 to d393b58 Compare November 26, 2018 21:27
Copy link
Member

@erikd erikd left a comment

Choose a reason for hiding this comment

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

Seems legit!

Would be good to drop the -fno-warn-orphans if possible.

@@ -1,5 +1,7 @@
{-# LANGUAGE TypeFamilies #-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

Copy link
Member

Choose a reason for hiding this comment

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

Is that really needed? I don't see any typeclass instances added to this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's for instance (...) MonadDBPollRead DBPoll, because DBPoll is a type alias and not a newtype.

{ etcGState :: !GS.GStateContext
, etcSystemStart :: !Timestamp
, etcSSlottingVar :: !SimpleSlottingStateVar
, etcSlotId :: !(Maybe SlotId)
Copy link
Member

Choose a reason for hiding this comment

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

This is why I am against vertical alignment. This change is semanically null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

strong agree

legacyNodeApi r =
hoistServer
(Proxy :: Proxy Legacy.NodeApi)
(Handler . ExceptT . try . flip runReaderT r)
Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants