-
Notifications
You must be signed in to change notification settings - Fork 15
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
Update cardano-api to 9.4.0.0 #936
Conversation
Fixes: #754 |
635008c
to
2a7e32e
Compare
2003836
to
b0cd6a8
Compare
@@ -293,6 +297,16 @@ friendlyTxBodyImpl | |||
friendlyLedgerProposals cOnwards proposalProcedures = | |||
Array $ fromList $ map (friendlyLedgerProposal cOnwards) proposalProcedures | |||
|
|||
-- | API doesn't yet show that supplemental datums are alonzo onwards. So we do it in this prototype, | |||
-- even if we don't use the witness. | |||
friendlySupplementalDatums |
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 an important function to review.
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 fine. What you should do next is update the friendly rendering to use the experimental api. It will simplify things.
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.
We should render the datum hashes as well. See my other comment.
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.
Changed from:
instance ToJSON HashableScriptData where
toJSON = scriptDataToJsonDetailedSchema
to:
instance ToJSON HashableScriptData where
toJSON hsd =
object
[ "bytes" .= (String $ Text.decodeUtf8 $ getOriginalScriptDataBytes hsd)
, "json" .= scriptDataToJsonDetailedSchema hsd
]
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 this is not that useful. We want the hash otherwise users will need to calculate the hash themselves.
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 sorry I didn't understood that the first time. Did this change:
@@ -29,6 +28,6 @@ instance (L.EraTxOut ledgerera, L.EraGov ledgerera) => ToJSON (L.NewEpochState l
instance ToJSON HashableScriptData where
toJSON hsd =
object
- [ "bytes" .= String (Text.decodeUtf8 $ getOriginalScriptDataBytes hsd)
+ [ "hash" .= hashScriptDataBytes hsd
, "json" .= scriptDataToJsonDetailedSchema hsd
]
@@ -23,3 +24,6 @@ instance (L.EraTxOut ledgerera, L.EraGov ledgerera) => ToJSON (L.NewEpochState l | |||
, "rewardUpdate" .= nesRu | |||
, "currentStakeDistribution" .= nesPd | |||
] | |||
|
|||
instance ToJSON HashableScriptData where | |||
toJSON = scriptDataToJsonDetailedSchema |
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 an important choice to review.
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.
Vide comment from cardano-api
:
-- | Warning: Creating 'HashableScriptData' from a 'ScriptData' value pretty
-- much guarantees the original bytes used to create the 'ScriptData'
-- value will be different if we serialize `HashableScriptData` again.
-- Do not use this.
unsafeHashableScriptData :: ScriptData -> HashableScriptData
unsafeHashableScriptData sd = HashableScriptData (serialiseToCBOR sd) sd
I understand that it means that we can't be sure that deserialisation from JSON representation into HashableScriptData
will generate the value with the same CBOR representation. (why?)
If that is the case here, we should prohibit from deserialising from JSON I think, for example like that:
instance TypeError (Text "Cannot deserialise HashableScriptData." :$$:
Text "Some good justification")
=> FromJSON HashableScriptData where
fromJSON = error "unreachable"
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 understand that it means that we can't be sure that deserialisation from JSON representation into HashableScriptData will generate the value with the same CBOR representation.
Ledger's CBOR serialization is not guaranteed to round trip and this can change the hash. See IntersectMBO/cardano-ledger#2943 (comment)
However I don't see the issue here. scriptDataToJsonDetailedSchema
does not call unsafeHashableScriptData
. If we were rendering the hash (which we should) then we have to be careful and use hashScriptDataBytes
.
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.
@Jimbo4350 there's no issue yet. It's about making hidden assumptions clear. If someone writes naive FromJSON
instance those two expressions could give different results:
hsd = undefined :: HashableScriptData
Right $ hashScriptDataBytes hsd
and
(hashScriptDataBytes . scriptDataFromJsonNoSchema) <$> (Aeson.eitherDecode $ Aeson.encode hsd)
My point is to make that non-roundtripping assumption clearer, or somehow expressed in the type system.
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.
LGTM, but i'm leaving an approval to @Jimbo4350 since I'm not sure about the two places you pointed out.
@@ -23,3 +24,6 @@ instance (L.EraTxOut ledgerera, L.EraGov ledgerera) => ToJSON (L.NewEpochState l | |||
, "rewardUpdate" .= nesRu | |||
, "currentStakeDistribution" .= nesPd | |||
] | |||
|
|||
instance ToJSON HashableScriptData where | |||
toJSON = scriptDataToJsonDetailedSchema |
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.
Vide comment from cardano-api
:
-- | Warning: Creating 'HashableScriptData' from a 'ScriptData' value pretty
-- much guarantees the original bytes used to create the 'ScriptData'
-- value will be different if we serialize `HashableScriptData` again.
-- Do not use this.
unsafeHashableScriptData :: ScriptData -> HashableScriptData
unsafeHashableScriptData sd = HashableScriptData (serialiseToCBOR sd) sd
I understand that it means that we can't be sure that deserialisation from JSON representation into HashableScriptData
will generate the value with the same CBOR representation. (why?)
If that is the case here, we should prohibit from deserialising from JSON I think, for example like that:
instance TypeError (Text "Cannot deserialise HashableScriptData." :$$:
Text "Some good justification")
=> FromJSON HashableScriptData where
fromJSON = error "unreachable"
c64a854
to
262f4d0
Compare
262f4d0
to
4e01efc
Compare
4e01efc
to
12f4c62
Compare
12f4c62
to
a27d5f8
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.
LGTM!
Changelog
How to trust this PR
Review the parts highlighted in comments below 👇 (This is an important ... to review).