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

Update Cardano.Api.ProtocolParameters to ease integration with Alonzo #2634

Closed

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Apr 20, 2021

Prepare Cardano.Api.ProtocolParameters for Alonzo era.

In the Alonzo era we introduce 6 new protocol parameters and remove 1
protocol parameter. In anticipation of the Alonzo era, we make some
modifications to the ProtocolParameters type.

minUTxOValue becomes a Maybe (This parameter gets deprecated in Alonzo)

We introduce the following but note that they are currently ignored:

  • adaPerUTxoByte - Cost in ada per byte of UTxO storage (replaces
    minUTxOValue)
  • costmdls - The cost models for plutus scripts
  • prices - The prices of execution units for plutus scripts
  • maxTxExUnits - Max total script execution resource units allowed per tx
  • maxBlockExUnits - Max total script execution resource units allowed per block
  • maxValSize - Max size of a Value in a tx output

We introduce an era parameter in the ProtocolParameters type in order to
reduce boilerplate. We have avoided the typical GADT pattern in
cardano-api to prevent an explosion of types.

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

TODO: Break up Cardano.Api.ProtocolParameters module

cardano-cli/src/Cardano/CLI/Shelley/Run/Transaction.hs Outdated Show resolved Hide resolved
@@ -200,3 +213,7 @@ constraints:

package comonad
flags: -test-doctests

allow-newer:
monoidal-containers:aeson,
Copy link
Contributor

@newhoggy newhoggy Apr 21, 2021

Choose a reason for hiding this comment

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

You may not need monoidal-containers:aeson anymore as of now.

See IntersectMBO/cardano-ledger#2245

@Jimbo4350 Jimbo4350 force-pushed the jordan/alonzo-protocol-parameters-integration branch 6 times, most recently from d46dc08 to 0cd5588 Compare April 23, 2021 08:40
@Jimbo4350 Jimbo4350 mentioned this pull request Apr 26, 2021
Copy link
Contributor

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

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

Looking good!

cardano-api/src/Cardano/Api/Fees.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Script.hs Show resolved Hide resolved
@@ -101,7 +115,7 @@ import Cardano.Api.Value
--
-- There are also paramaters fixed in the Genesis file. See 'GenesisParameters'.
--
data ProtocolParameters =
data ProtocolParameters era =
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we need the era type param? We don't seem to use it below.

If we really don't need it to be era-parameterised, then it should simplify things elsewhere (e.g. in the cli code).

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 Apr 27, 2021

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I've had a look and I don't think that's the case. You're using it to restrict the fields we render to those from a specific era, but I don't see any need to do that. We can just render them all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think the strategy we're following here with the ProtocolParameters is that we just have all of them, taking the union of them from all eras, and in some eras we just done use them all. I've not yet seen any reason that that strategy will not work out ok.

In which case to follow the strategy we really should not have an era param at all, since nothing inside it needs it. And other functions like JSON serialisation also do not need to know the era because the strategy we're following is to take the collection of all params, from all eras.

If you think that's not going to work out for some reason then lets review it and we might need to change strategy and have a fully era-typed style where we enforce that only the params that are available are those that exist for each specific era. But let's not do a hybrid strategy. Typed or untyped, but not a mish-mash.

cardano-api/src/Cardano/Api/ProtocolParameters.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/ProtocolParameters.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/ProtocolParameters.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/ProtocolParameters.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/ProtocolParameters.hs Outdated Show resolved Hide resolved
@Jimbo4350 Jimbo4350 force-pushed the jordan/alonzo-protocol-parameters-integration branch 2 times, most recently from 0bd64ea to afa4b9a Compare April 28, 2021 15:07
@Jimbo4350
Copy link
Contributor Author

The hydra error will go away once the node's deps are updated and I rebase on master

@refi93
Copy link

refi93 commented May 3, 2021

@Jimbo4350 I assume maxValSize is the maximum size of the utxo "value" field in the serialized transaction in bytes - do we know what the value of maxValSize in Alonzo era will be? In Mary it was 4000 bytes if I understood correctly: https://github.com/input-output-hk/cardano-ledger-specs/pull/2099/files#diff-1dbf0b3dcad4b1ddcdf86e9df16469b461f3e9f906cf42d925d6fb3a386dd6c2R258

@Jimbo4350
Copy link
Contributor Author

@Jimbo4350 I assume maxValSize is the maximum size of the utxo "value" field in the serialized transaction in bytes - do we know what the value of maxValSize in Alonzo era will be? In Mary it was 4000 bytes if I understood correctly: https://github.com/input-output-hk/cardano-ledger-specs/pull/2099/files#diff-1dbf0b3dcad4b1ddcdf86e9df16469b461f3e9f906cf42d925d6fb3a386dd6c2R258

We haven't decided on any of the new protocol parameters introduced in the Alonzo era as yet. This will happen closer to the fork.

@Jimbo4350 Jimbo4350 force-pushed the jordan/alonzo-protocol-parameters-integration branch 7 times, most recently from 56cdaba to 2cf08e4 Compare May 11, 2021 12:33
Copy link
Contributor

@dcoutts dcoutts left a comment

Choose a reason for hiding this comment

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

There's obviously some overlap to make this PR and #2657. That's fine for the moment so they both pass CI independently.

Given that #2657 seems nearly ready and this one will need a bit more work, I think it probably makes most sense for this one to be rebased after that PR goes in (or rebased on that one's branch in the mean time).

cardano-api/src/Cardano/Api/ProtocolParameters.hs Outdated Show resolved Hide resolved
Comment on lines 201 to 204
-- | Cost models for non-native script languages.
protocolUpdateCostModels :: Map AnyScriptLanguage CostModel,

-- | Map AnyScriptLanguage ExecutionUnitPrices of execution units (for non-native script languages).
Copy link
Contributor

Choose a reason for hiding this comment

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

These are the other uses of the "native" script language terminology.

cardano-api/src/Cardano/Api/Eras.hs Outdated Show resolved Hide resolved
cardano-api/src/Cardano/Api/Fees.hs Show resolved Hide resolved
@@ -101,7 +115,7 @@ import Cardano.Api.Value
--
-- There are also paramaters fixed in the Genesis file. See 'GenesisParameters'.
--
data ProtocolParameters =
data ProtocolParameters era =
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think the strategy we're following here with the ProtocolParameters is that we just have all of them, taking the union of them from all eras, and in some eras we just done use them all. I've not yet seen any reason that that strategy will not work out ok.

In which case to follow the strategy we really should not have an era param at all, since nothing inside it needs it. And other functions like JSON serialisation also do not need to know the era because the strategy we're following is to take the collection of all params, from all eras.

If you think that's not going to work out for some reason then lets review it and we might need to change strategy and have a fully era-typed style where we enforce that only the params that are available are those that exist for each specific era. But let's not do a hybrid strategy. Typed or untyped, but not a mish-mash.

instance HasTextEnvelope UpdateProposal where
textEnvelopeType _ = "UpdateProposalShelley"

--TODO: Jordan UpdateProposal needs to be parameterized by era or have access to the era
Copy link
Contributor

Choose a reason for hiding this comment

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

If we think we might need the era just for this purpose, then we can either:

  1. Drop CBOR serialisation for these types. Do we really need separate serialisation for them?
  2. Do independent CBOR serialisation that does not involve converting to the underlying ledger type. This will not work in future precisely because we're taking the simple untyped approach of taking the union of all params for all eras.

--TODO decide how to handle parameter validation
UpdateProposal (Map.fromList [ (kh, params) | kh <- genesisKeyHashes ])

newtype CostModel = CostModel (Map.Map Text Integer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, looks like we've duplicated these types from the ProtocolParameters module. A good reason to unsplit the modules (once we make the original less enormous again) :-)

Comment on lines +436 to +438
-- ----------------------------------------------------------------------------
-- Conversion functions
--
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't tell what we've changed here since we've split the module. Can I suggest that's another good reason to not split them in this PR, or at least not split them and change them in a single commit.



instance Aeson.FromJSONKey AnyScriptLanguage where
fromJSONKey = Aeson.FromJSONKeyValue parseJSON
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand how this is supposed to work. A JSON key must be just a JSON string but this reuses the FromJSON above right? But that uses a JSON object not a JSON string. Am I missing something?

@@ -835,6 +871,7 @@ fromAllegraTimelock timelocks = go

instance ToJSON (Script lang) where
toJSON (SimpleScript _ script) = toJSON script
toJSON (PlutusScript _ _) = Aeson.Null
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps better to leave this as an error "TODO ..." rather than Null. The latter is too easy to forget or miss in a grep TODO.

In the Alonzo era we introduce 6 new protocol parameters and remove 1
protocol parameter. In anticipation of the Alonzo era, we make some
modifications to the ProtocolParameters type.

minUTxOValue becomes a Maybe (This parameter gets deprecated in Alonzo)

We introduce the following but note they are currently ignored:
- adaPerUTxoByte - Cost in ada per byte of UTxO storage (replaces
minUTxOValue)
- costmdls - The cost models for plutus scripts
- prices - The prices of execution units for plutus scripts
- maxTxExUnits - Max total script execution resource  units allowed per tx
- maxBlockExUnits - Max total script execution resource units allowed per block
- maxValSize - Max size of a Value in a tx output

We introduce an era parameter in the ProtocolParameters type in order to
reduce boilerplate. We have avoided the typical GADT pattern in
cardano-api to prevent an explosion of types.
@Jimbo4350
Copy link
Contributor Author

Closed in favour of #2699

@Jimbo4350 Jimbo4350 closed this May 17, 2021
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