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

stable encoding #21

Merged
merged 7 commits into from
Oct 19, 2023
Merged

stable encoding #21

merged 7 commits into from
Oct 19, 2023

Conversation

rsoeldner
Copy link
Member

No description provided.

encodeDecimal d@(Decimal _ mantissa)
| isSafeInteger mantissa = J.build $ J.Aeson @Scientific $ fromRational $ toRational d
| otherwise = J.object [ "decimal" J..= T.pack (show d) ]
encodeUnit = J.object ["unit" J..= T.empty] -- TODO: Discuss?
Copy link
Member Author

@rsoeldner rsoeldner Oct 19, 2023

Choose a reason for hiding this comment

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

@jmcardon How should we handle unit

Copy link
Member

Choose a reason for hiding this comment

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

I think the empty text is fine 👍

-- | Stable encoding of `CapabilityGuard FullyQualifiedName PactValue`
instance J.Encode (StableEncoding (CapabilityGuard FullyQualifiedName PactValue)) where
build (StableEncoding (CapabilityGuard name args)) = J.object
[ "cgPactId" J..= (error "a" :: T.Text) -- TODO: Check availability
Copy link
Member Author

Choose a reason for hiding this comment

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

@jmcardon same here

instance J.Encode (StableEncoding ModRef) where
build (StableEncoding (ModRef mn imp _ref)) = J.object
[ "refSpec" J..= J.Array (StableEncoding <$> imp)
-- , "refInfo" J..= _modRefInfo o
Copy link
Member Author

Choose a reason for hiding this comment

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

@jmcardon same here

PGuard g -> J.build (StableEncoding g)
PObject o -> J.build (StableEncoding o)
PModRef mr -> J.build (StableEncoding mr)
PCapToken _ct -> error "not implemented"
Copy link
Member Author

Choose a reason for hiding this comment

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

@jmcardon and here


-- |
--
-- Stable encoding which matches Pacts StableEncoding.
Copy link
Contributor

@imalsogreg imalsogreg Oct 19, 2023

Choose a reason for hiding this comment

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

Some questions that could be addressed as documentation here in the haddock header:

  • What is this stable encoding for?
  • Where will the encoded results end up?
  • How stable does the encoding need to be? vis. the following question
  • What happens if we find a bug in the encoding and need to fix it?
  • Does this encoding constitute a public API? Will users/clients consume/produce values in this encoding, or is it internal?

Copy link
Member

@jmcardon jmcardon Oct 19, 2023

Choose a reason for hiding this comment

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

In Robert's absence, I can answer some of these, and maybe @rsoeldner can include this in the haddocks in a separate PR.

  • Stable encoding is for hashes and anything that produces an identifier with hashes, that is principals, pactIds, etc.
  • The encoded results may be pactIds, or even semantic values produced by hash
  • The encoding must match production. I've ported over some tests on hash.repl but this is not enough, soon with the new module hashing, we will use repl tests as goldens to ensure some of our hashes are computably stable.
  • There should not be bugs in the encoding. It has to match prod 1-1 and we have to enforce this long term. There cannot be bugs in this code when we launch core to the world.
  • This encoding may possibly be an API, but we're not even sure what core's API will be like yet. We cross that bridge when we get there, I think.

Copy link
Contributor

@0xd34df00d 0xd34df00d left a comment

Choose a reason for hiding this comment

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

Adds lots of things I could use for my stuff, so looking forward to it!

pact-core/Pact/Core/Names.hs Show resolved Hide resolved
encodeDecimal d@(Decimal _ mantissa)
| isSafeInteger mantissa = J.build $ J.Aeson @Scientific $ fromRational $ toRational d
| otherwise = J.object [ "decimal" J..= T.pack (show d) ]
encodeUnit = J.object ["unit" J..= T.empty] -- TODO: Discuss?
Copy link
Member

Choose a reason for hiding this comment

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

I think the empty text is fine 👍


-- |
--
-- Stable encoding which matches Pacts StableEncoding.
Copy link
Member

@jmcardon jmcardon Oct 19, 2023

Choose a reason for hiding this comment

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

In Robert's absence, I can answer some of these, and maybe @rsoeldner can include this in the haddocks in a separate PR.

  • Stable encoding is for hashes and anything that produces an identifier with hashes, that is principals, pactIds, etc.
  • The encoded results may be pactIds, or even semantic values produced by hash
  • The encoding must match production. I've ported over some tests on hash.repl but this is not enough, soon with the new module hashing, we will use repl tests as goldens to ensure some of our hashes are computably stable.
  • There should not be bugs in the encoding. It has to match prod 1-1 and we have to enforce this long term. There cannot be bugs in this code when we launch core to the world.
  • This encoding may possibly be an API, but we're not even sure what core's API will be like yet. We cross that bridge when we get there, I think.

@jmcardon jmcardon merged commit 2c4f387 into master Oct 19, 2023
3 checks passed
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.

4 participants