-
Notifications
You must be signed in to change notification settings - Fork 9
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
Principals #22
Principals #22
Conversation
pact-core/Pact/Core/Gas.hs
Outdated
coreGasPerLegacyGas :: Semiring r => r | ||
coreGasPerLegacyGas = fromNatural 1000 |
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 super ugly and I'd like this to go away, but we'll need to settle down with proper gas accounting first.
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.
Good work so far!
In general, the main changes are:
- Removing principals are pactvalues. They are not. I like the idea though!!! I think we need to pitch it to the team and discuss how we could work with it moving forward.
- Remove all uses of gas. Gas is a task on its own. We will work on gas overall for pact-core as a large task.
pact-core/Pact/Core/Type.hs
Outdated
@@ -111,6 +114,9 @@ pattern TyBool = TyPrim PrimBool | |||
pattern TyString :: Type | |||
pattern TyString = TyPrim PrimString | |||
|
|||
pattern TyPrincipal :: Type | |||
pattern TyPrincipal = TyPrim PrimPrincipal |
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 needs to be removed until we settle on things actually returning principals as a type
pact-core/Pact/Core/Type.hs
Outdated
@@ -53,6 +54,7 @@ data PrimType = | |||
PrimString | | |||
PrimGuard | | |||
PrimTime | | |||
PrimPrincipal | |
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.
Ditto here, delete this
pact-core/Pact/Core/Type.hs
Outdated
@@ -16,6 +16,7 @@ module Pact.Core.Type | |||
, pattern TyTime | |||
, pattern TyBool | |||
, pattern TyString | |||
, pattern TyPrincipal |
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.
Principal "type" needs to be removed, at least for now.
createPrincipalForGuard :: (MonadGas m) => Guard FullyQualifiedName PactValue -> m Pr.Principal | ||
createPrincipalForGuard g = do | ||
-- TODO make gas charging actually go through the model | ||
chargeGas coreGasPerLegacyGas |
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.
Remove all uses of gas. Gas in core is not implemented yet.
Moreover, this is my fault, I should clarify: we do not have to match legacy on gas.
mkHash bss = do | ||
let bs = mconcat bss | ||
-- the original pact impl charged 1 gas per 64 bytes of hashing, | ||
void $ chargeGas $ coreGasPerLegacyGas <> Gas (fromIntegral (BS.length bs) * coreGasPerLegacyGas `quot` 64) |
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.
Here as well, remove the gas code.
chargeGas coreGasPerLegacyGas | ||
case g of | ||
GKeyset (KeySet ks pf) -> case (toList ks, predicateToString pf) of | ||
([k], "keys-all") -> pure $ Pr.K k |
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.
no need to predicate-to-string
, you can match on the predicate itself.
@@ -184,6 +198,7 @@ instance J.Encode (StableEncoding PactValue) where | |||
PModRef mr -> J.build (StableEncoding mr) | |||
PCapToken _ct -> error "not implemented" | |||
PTime pt -> J.build (StableEncoding pt) | |||
PPrincipal pr -> J.build (StableEncoding pr) |
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.
Remove, principals are not pact values yet. We don't produce principals are their own pactValues
pact-core/Pact/Core/Gas.hs
Outdated
@@ -37,6 +38,9 @@ newtype Gas | |||
deriving (Semigroup, Monoid) via (Sum Word64) | |||
deriving (Semiring, Enum) via Word64 | |||
|
|||
coreGasPerLegacyGas :: Semiring r => 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.
No gas just yet. Remove.
pact-core/Pact/Core/Errors.hs
Outdated
@@ -231,6 +232,7 @@ instance Pretty ArgTypeError where | |||
ATETable -> "[table]" | |||
ATEClosure -> "[closure]" | |||
ATEModRef -> "[modref]" | |||
ATEPrincipal -> "[principal]" |
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.
Remove here as well.
@jmcardon addressed, thanks for the review! De-gassified and de-pactvalue-tized. |
@@ -28,12 +32,18 @@ newtype PublicKeyText = PublicKeyText { _pubKey :: Text } | |||
instance Pretty PublicKeyText where | |||
pretty (PublicKeyText t) = pretty t | |||
|
|||
renderPublicKeyText :: PublicKeyText -> Text |
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 feel like this is unnecessary and prefer the usage of _pubKey
which we might rename as _publicKeyText
?
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 wanted to make the intent of (stable-)rendering it explicit. And shall we ever change/extend the representation, that'd be easier to achieve.
@@ -8,6 +8,7 @@ | |||
{-# LANGUAGE DerivingVia #-} | |||
{-# LANGUAGE ConstraintKinds #-} | |||
{-# LANGUAGE MultiWayIf #-} | |||
{-# LANGUAGE ImportQualifiedPost #-} |
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.
{-# LANGUAGE ImportQualifiedPost #-} |
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.
Personal preference — I find this syntax more readable, especially where otherwise you'd have
import Data.Vector(Vector)
import Data.Text(Text)
-- bunch of other unqualified imports
import qualified Data.Vector as V
import qualified Data.Text as T
-- bunch of other qualified imports
while with the post
-syntax it's easier to see what gets imported from a given package/module when everything's grouped by the actual module name.
In fact, I did think of making a pass converting everything to ImportQualifiedPost
(of course, after discussing this with the rest of the team when we'll have some time), so I can surely remove this for now for consistency.
@@ -55,6 +58,7 @@ import Pact.Core.Persistence | |||
import Pact.Core.DefPacts.Types | |||
import Pact.Core.Environment | |||
import Pact.Core.Capabilities | |||
import Pact.Core.Principal qualified as Pr |
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 think throughout the codebase, we have not used it and I would personally prefer the standard way
import Pact.Core.Principal qualified as Pr | |
import qualified Pact.Core.Principal as Pr |
also is this actually needed? Most of pact-core can be just imported without name clash
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.
Yep, the C
ctor clashes with Pact.Core.IR.Eval.Runtime.C
, for example. I could've renamed the constructors themselves into PrC
/etc, but I wanted to keep consistent with the old version, and personally I prefer disambiguating at module import time (oh, I wish haskell had agda's import renames!)
GUserGuard (UserGuard f args) -> do | ||
h <- mkHash $ map encodeStable args | ||
pure $ Pr.U (Pretty.renderText f) (hashToText h) | ||
-- TODO orig pact gets here ^^^^ a Name |
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.
Todo still pending?
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.
Yep. I think we agreed to sort this out later on when dealing with Name
s more thoroughly.
let args' = map encodeStable args | ||
f' = T.encodeUtf8 $ renderQualName $ fqnToQualName f | ||
pid' = T.encodeUtf8 . renderDefPactId <$> pid | ||
h <- mkHash $ f' : args' ++ maybe [] pure pid' |
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.
Could be expressed using maybeToList
?
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.
Great suggestion, thanks!
h <- mkHash $ f' : args' ++ maybe [] pure pid' | ||
pure $ Pr.C $ hashToText h | ||
where | ||
mkHash bss = pure $ pactHash $ mconcat bss |
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.
why the Monad constraint and use of pure? I feel like here a type signature would be beneficial
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.
That's for when we'll eventually have gas. It was all in MonadGas
originally, but MonadGas
was removed recently, so I changed that to Monad
, while still keeping monadic syntax, so that (re)introducing gas would require less changes later on.
LMK if you'd nevertheless like to purify this function (for now?)
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.
Could just make it pure for now.
pact-core/Pact/Core/Principal.hs
Outdated
@@ -0,0 +1,175 @@ | |||
{-# LANGUAGE ImportQualifiedPost #-} |
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.
same
nameMatcher = asMatcher $ qualifiedNameMatcher | ||
<|> bareNameMatcher | ||
where | ||
bareNameMatcher :: Parser () |
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 is the reason, we use the Parsers
package and not plain attoparsec here?
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.
There are some things missing in atto. Some are easy to reimplement (like oneOf
), others are a tad more involved (like ident
). Since the legacy pact used parsers
, depending on that package in pact-core
as well both simplifies the implementation and helps ensure backwards compatible behavior.
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.
Tbh, we don't need parsers
either to parse an ident either but we can punt this to later.
GModuleGuard (ModuleGuard mn n) -> pure $ Pr.M mn n | ||
GUserGuard (UserGuard f args) -> do | ||
h <- mkHash $ map encodeStable args | ||
pure $ Pr.U (Pretty.renderText f) (hashToText h) |
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.
Remove Pretty.renderText
here and replace with renderQualName (fqnToQualName f)
h <- mkHash $ f' : args' ++ maybe [] pure pid' | ||
pure $ Pr.C $ hashToText h | ||
where | ||
mkHash bss = pure $ pactHash $ mconcat bss |
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.
Could just make it pure for now.
nameMatcher = asMatcher $ qualifiedNameMatcher | ||
<|> bareNameMatcher | ||
where | ||
bareNameMatcher :: Parser () |
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.
Tbh, we don't need parsers
either to parse an ident either but we can punt this to later.
@jmcardon done! Except for the parsers — let's indeed do this later. |
create-principal
is-principal
typeof-principal
validate-principal