-
Notifications
You must be signed in to change notification settings - Fork 631
Conversation
ourAppName :: HasUpdateConfiguration => ApplicationName | ||
ourAppName = ccApplicationName updateConfiguration | ||
ourAppName :: UpdateConfiguration -> ApplicationName | ||
ourAppName = ccApplicationName |
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.
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 |
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.
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 |
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.
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 |
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.
What's the point of all these mtl
classes if you just run everything in SomeMonstrousMonad
anyway?
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.
🙃 ...
= "v1" | ||
:> ( Node.API | ||
:<|> Legacy.NodeApi | ||
) |
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.
Hooray, a v1
prefix!
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.
As a matter of fact, I think we are now "technically" at v2
😂 ...
@@ -8,8 +8,9 @@ module Cardano.Node.API where | |||
import Universum |
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 module is where most of the real work is done.
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.
Ah! Was looking for it 😛 ! Would have been nice to make two PRs I believe, but then I know.. CI.. :(
:: !SscContext | ||
, legacyCtxNodeDBs | ||
:: !DB.NodeDBs | ||
} |
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.
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) |
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 try
s for ServantError
s that are thrown via IO.
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.
🤦♂️
-> NtpConfiguration | ||
-> NodeResources ext | ||
-> NodeResources () |
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.
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 |
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 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.
0f397d8
to
d393b58
Compare
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.
Seems legit!
Would be good to drop the -fno-warn-orphans
if possible.
@@ -1,5 +1,7 @@ | |||
{-# LANGUAGE TypeFamilies #-} | |||
|
|||
{-# OPTIONS_GHC -fno-warn-orphans #-} | |||
|
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.
Is that really needed? I don't see any typeclass instances added to this file.
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.
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) |
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 is why I am against vertical alignment. This change is semanically null.
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.
strong agree
legacyNodeApi r = | ||
hoistServer | ||
(Proxy :: Proxy Legacy.NodeApi) | ||
(Handler . ExceptT . try . flip runReaderT r) |
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.
🤦♂️
Description
This PR unifies the two node APIs in the new Node API.