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

Add utxoCostPerByte protocol parameter #4141

Merged

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Jul 6, 2022

@newhoggy newhoggy marked this pull request as ready for review July 6, 2022 04:42
@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch from 10c8fbb to 26176ec Compare July 6, 2022 05:02
lehins
lehins previously requested changes Jul 6, 2022
Copy link
Contributor

@lehins lehins left a comment

Choose a reason for hiding this comment

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

Thank you for doing this change, that is exactly what I was advocating for. There are two more things need to be done, I believe, to make this change complete:

  1. Json field name needs to be adjusted:

https://github.com/input-output-hk/cardano-node/blob/0cd6878769a10097e7c780e15efb9919fb94f669/cardano-api/src/Cardano/Api/ProtocolParameters.hs#L315

and

https://github.com/input-output-hk/cardano-node/blob/0cd6878769a10097e7c780e15efb9919fb94f669/cardano-api/src/Cardano/Api/ProtocolParameters.hs#L346

I don't know if it is OK to break backwards compatibility when it comes to json representation, but just renaming the field naturally will break it

  1. ProtocolParametersUpdate also needs the rename:

https://github.com/input-output-hk/cardano-node/blob/0cd6878769a10097e7c780e15efb9919fb94f669/cardano-api/src/Cardano/Api/ProtocolParameters.hs#L481

@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch 2 times, most recently from eb9ff82 to c0cfc27 Compare July 6, 2022 12:56
@newhoggy
Copy link
Contributor Author

newhoggy commented Jul 6, 2022

Thanks @lehins . I did another pass through the code and identified a lot more cases that needed changing.

@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch from c0cfc27 to a66e638 Compare July 6, 2022 13:02
@newhoggy newhoggy dismissed lehins’s stale review July 6, 2022 13:02

comments addressed

@newhoggy newhoggy requested a review from lehins July 6, 2022 13:02
@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch 4 times, most recently from 5f4fb59 to d1eb9ea Compare July 6, 2022 13:06
Copy link
Contributor

@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.

We should make this change backwards compatible

@@ -312,7 +312,7 @@ instance FromJSON ProtocolParameters where
<*> o .: "poolPledgeInfluence"
<*> o .: "monetaryExpansion"
<*> o .: "treasuryCut"
<*> o .:? "utxoCostPerWord"
Copy link
Contributor

Choose a reason for hiding this comment

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

So we have a problem. We are breaking backwards compatibility here. We should parse for both "utxoCostPerWord" and "utxoCostPerByte" in the event somebody is running an Alonzo only network. There is also a typo: utxoCostPerBytes

Copy link
Contributor

Choose a reason for hiding this comment

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

I might be wrong, but I think it could be sufficient to keep backwards compatibility at the JSON deserialization level. Something along the lines:

maybePerWord <- o .:? "utxoCostPerWord"
maybePerByte <- o .:? "utxoCostPerByte"
utxoCostPerByte <- 
  case maybePerWord of
    Nothing -> pure maybePerByte
    Just _ | Just _ <- maybePerByte <- fail "Cannot supply both utxoCostPerWord and utxoCostPerByte"
    Just perWord -> pure $ coinsPerUTxOWordToCoinsPerUTxOByte perWord

Copy link
Contributor

Choose a reason for hiding this comment

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

It would work but it would be confusing when looking at the ProtocolParameters type. It's better to make the changes obvious rather than having it only at the JSON deserialization level.

--
-- /Introduced in Alonzo/
protocolUpdateUTxOCostPerWord :: Maybe Lovelace,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the proper way to do this would not be to modify existing Alonzo fields, but to add a new protocolUpdateUTxOCostPerByte field

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

Copy link
Contributor

Choose a reason for hiding this comment

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

See my comment, maybe we can get away with renaming. After Babbage is released creating PPUpdates for Alonzo doesn't make much sense, or does it?

In retrospective we should not have renamed it ledger. In particular using the binary flag 17 for perWord and perByte was a mistake, IMHO. But that ship have sailed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might for chains other than mainnet if we care about those?

Copy link
Contributor

@Jimbo4350 Jimbo4350 Jul 7, 2022

Choose a reason for hiding this comment

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

maybe we can get away with renaming.

If we were already in Babbage maybe but keeping backwards compatibility also makes it clear to whoever is looking at the code that this particular field was renamed at the Alonzo -> Babbage boundary which is useful. This has always been the approach in the api.

@@ -795,6 +795,7 @@ genProtocolParametersUpdate = do
protocolUpdateMaxValueSize <- Gen.maybe genNat
protocolUpdateCollateralPercent <- Gen.maybe genNat
protocolUpdateMaxCollateralInputs <- Gen.maybe genNat
protocolUpdateUTxOCostPerByte <- Gen.maybe genLovelace
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it make sense to generate both the protocolUpdateUTxOCostPerWord and the protocolUpdateUTxOCostPerByte in the same update?

Copy link
Contributor Author

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.

For now yeah

@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch from 435ae33 to 66ce20d Compare July 7, 2022 14:26
@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch 2 times, most recently from 305e182 to 8138352 Compare July 7, 2022 14:45
@newhoggy newhoggy dismissed Jimbo4350’s stale review July 7, 2022 14:46

Comments addressed

@newhoggy newhoggy requested a review from Jimbo4350 July 7, 2022 14:46
@newhoggy newhoggy changed the title Rename utxoCostPerWord to utxoCostPerByte Add utxoCostPerByte protocol parameter Jul 7, 2022
@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch from 8138352 to 705fc3c Compare July 7, 2022 14:47
@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch from 705fc3c to 79df3c5 Compare July 7, 2022 14:52
-- | The 'ProtocolParameters' must provide the value for the cost per
-- byte parameter, for eras that use this parameter.
| TxBodyErrorMissingParamCostPerByte

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both TxBodyErrorMissingParamCostPerWord and TxBodyErrorMissingParamCostPerByte appear to be unused. Should I delete @Jimbo4350? Or is a change needed to ensure they are used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted

@@ -1260,6 +1267,7 @@ calculateMinimumUTxO era txout@(TxOut _ v _ _) pparams' =
data MinimumUTxOError =
PParamsMinUTxOMissing
| PParamsUTxOCostPerWordMissing
| PParamsUTxOCostPerByteMissing
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both PParamsUTxOCostPerWordMissing and PParamsUTxOCostPerByteMissing appear to be unused. Should I delete @Jimbo4350? Or is a change needed to ensure they are used?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove them both 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleted

@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch 4 times, most recently from 45801c4 to 2343b86 Compare July 7, 2022 15:09
@@ -1460,7 +1483,8 @@ toAlonzoPParams ProtocolParameters {
(Ledger.boundRational protocolParamTreasuryCut)

-- New params in Alonzo:
, Alonzo._coinsPerUTxOWord = toShelleyLovelace utxoCostPerWord
, Alonzo._coinsPerUTxOWord = -- adapted from babbage protocol parameter field
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the comment? I don't understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Left over comment from when I previously did the byte to work conversion. Deleting.

@@ -1506,7 +1530,7 @@ toBabbagePParams ProtocolParameters {
protocolParamPoolPledgeInfluence,
protocolParamMonetaryExpansion,
protocolParamTreasuryCut,
protocolParamUTxOCostPerWord = Just utxoCostPerWord,
protocolParamUTxOCostPerByte = Just utxoCostPerByte,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -1693,6 +1717,7 @@ fromAlonzoPParams
, protocolParamMaxValueSize = Just _maxValSize
, protocolParamCollateralPercent = Just _collateralPercentage
, protocolParamMaxCollateralInputs = Just _maxCollateralInputs
, protocolParamUTxOCostPerByte = Nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding a comment here explaining this is deprecated in Babbage would be useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment.

@@ -262,14 +263,16 @@ friendlyProtocolParametersUpdate
("monetary expansion" .=) . friendlyRational
, protocolUpdateTreasuryCut <&> ("treasury expansion" .=) . friendlyRational
, protocolUpdateUTxOCostPerWord <&>
("UTxO storage cost per unit" .=) . friendlyLovelace
("UTxO storage cost per word" .=) . friendlyLovelace
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -1260,6 +1267,7 @@ calculateMinimumUTxO era txout@(TxOut _ v _ _) pparams' =
data MinimumUTxOError =
PParamsMinUTxOMissing
| PParamsUTxOCostPerWordMissing
| PParamsUTxOCostPerByteMissing
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove them both 👍

@Jimbo4350
Copy link
Contributor

LGTM, minor suggestions

@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch from 2343b86 to f6d5ada Compare July 7, 2022 22:36
@@ -18,7 +18,7 @@ update proposal:
updates:
- genesis key hash: 1bafa294233a5a7ffbf539ae798da0943aa83d2a19398c2d0e5af114
update:
UTxO storage cost per unit: 194 Lovelace
UTxO storage cost per word: 194 Lovelace
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this golden file has changed.

@newhoggy newhoggy force-pushed the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch from f6d5ada to 7193afe Compare July 8, 2022 01:19
@newhoggy
Copy link
Contributor Author

newhoggy commented Jul 8, 2022

bors r+

iohk-bors bot added a commit that referenced this pull request Jul 8, 2022
4141: Add utxoCostPerByte protocol parameter r=newhoggy a=newhoggy

Resolves #4052
See cardano-foundation/CIPs#265

Co-authored-by: John Ky <john.ky@iohk.io>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 8, 2022

Timed out.

@newhoggy
Copy link
Contributor Author

newhoggy commented Jul 8, 2022

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 8, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 9c217ae into master Jul 8, 2022
@iohk-bors iohk-bors bot deleted the newhoggy/rename-utxoCostPerWord-to-utxoCostPerByte branch July 8, 2022 12:39
@gitmachtl
Copy link
Contributor

gitmachtl commented Jul 8, 2022

tested latest master. ok so the protocol parameters query will introduce the utxoCostPerWord parameter on the switch to alonzo-era like

...
    "txFeeFixed": 155381,
    "txFeePerByte": 44,
    "utxoCostPerByte": null,
    "utxoCostPerWord": 34482
...

and will remove or set the parameter again in babbage-era like

...
    "txFeeFixed": 155381,
    "txFeePerByte": 44,
    "utxoCostPerByte": 4310,
    "utxoCostPerWord": null
...

Will this behaviour stay for a while? Because Tools are looking out for those parameters in the protocol to do the minUtxo calculation based on it (not using the inbuilt cli function).

@gitmachtl
Copy link
Contributor

gitmachtl commented Jul 24, 2022

@Jimbo4350 why was this PR not included in the tag 1.35.2 ?

whats the plan for the release version? we have external tools depending on the cli protocol-parameters output. with "utxoCostPerByte" present its clear that the minOutUtxo must be calculated with the new perByte method. or is the plan to not show this parameter at all and use the new method if a protocolVersion.major>=7 is present?

thx

@lehins
Copy link
Contributor

lehins commented Jul 24, 2022

@gitmachtl From what I understand 1.35.2 only includes an important bug fix that is necessary for the upcoming hard fork. All other minor bug fixes and features, which applies to utxoCostPerByte param, will be included in the subsequent minor release.

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.

utxoCostPerWord in the ProtocolParameters needs to be renamed to utxoCostPerByte
5 participants