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

Fix building of Alonzo transaction in Babbage era. #4166

Merged
merged 1 commit into from
Jul 23, 2022

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented Jul 11, 2022

This is achieved by auto-converting from Babbage field protocolParamUTxOCostPerByte to Alonzo field protocolParamUTxOCostPerWord, which is a multiplication by 8.

Fixes #4164

@newhoggy newhoggy marked this pull request as ready for review July 11, 2022 13:11
} =
let !coinsPerUTxOWord = fromMaybe
(error "toAlonzoPParams: must specify protocolParamUTxOCostPerWord or protocolParamUTxOCostPerByte") $
protocolParamUTxOCostPerWord <|> ((* 8) <$> protocolParamUTxOCostPerByte)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The conversion occurs here.

@Jimbo4350
Copy link
Contributor

Jimbo4350 commented Jul 13, 2022

So in the interest of time we should probably let this through but we need a long term solution otherwise we will always be adding ad hoc fixes like this. What about the following for a long term solution:

In the case of build-raw we don't know what era the node is in (and we can't because this is meant to be a completely offline transaction construction command). The protocol parameters varies between eras and will likely continue to vary in the future. So I propose the following:

We:

  • Create a GADT wrapper type as follows:
data ProtocolParameters' txEra where
   ProtocolParameters' :: ShelleyBasedEra pparamsEra -> ProtocolParameters -> ProtocolParameters' txEra
  • Create a function as follows (I use the if then else clause just as a crude example):
determinePParamsEra :: ProtocolParameters -> ProtocolParameters' era
determinePParamsEra pp = 
  if True
  then ProtocolParameters' ShelleyBasedEraShelley pp
  else ProtocolParameters' ShelleyBasedEraAlonzo pp

We can check for the existence of the era relevant ProtocolParameters fields (in determinePParamsEra) and return the appropriate ShelleyBasedEra pparamsEra in the ProtocolParameters' txEra type.

When we eventually call toLedgerPParams :: ShelleyBasedEra era -> ProtocolParameters -> Ledger.PParams (ShelleyLedgerEra era) in transaction construction we can provide the correct ShelleyBasedEra era and avoid having to modify the individual toAlonzoPParams, toBabbagePParams etc in the future.

I think this is the path of least resistance as we avoid modifying ProtocolParameters era whilst resolving compatibility issues. Open to other long term suggestions. We also need to think of better names.

#4186

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.

One minor adjustment then I will approve

@@ -119,6 +120,7 @@ import Cardano.Api.StakePoolMetadata
import Cardano.Api.TxMetadata
import Cardano.Api.Utils
import Cardano.Api.Value
import Control.Applicative ((<|>))
Copy link
Contributor

Choose a reason for hiding this comment

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

This module should not be here

This is achieved by auto-converting from Babbage field protocolParamUTxOCostPerByte to Alonzo field protocolParamUTxOCostPerWord.
@newhoggy newhoggy force-pushed the newhoggy/auto-convert-utxo-cost-per-byte-to-word branch from 9df6bd6 to 51b9a22 Compare July 22, 2022 15:18
@newhoggy newhoggy requested a review from Jimbo4350 July 22, 2022 15:24
@newhoggy newhoggy dismissed Jimbo4350’s stale review July 22, 2022 15:24

comments addressed

@Jimbo4350 Jimbo4350 self-requested a review July 22, 2022 18:28
@newhoggy
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jul 23, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit f7d574e into master Jul 23, 2022
@iohk-bors iohk-bors bot deleted the newhoggy/auto-convert-utxo-cost-per-byte-to-word branch July 23, 2022 03:23
@CarlosLopezDeLara CarlosLopezDeLara mentioned this pull request Aug 3, 2022
12 tasks
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.

[BUG] - building Alonzo-era Plutus tx on Babbage fails due to missing protocolParamUTxOCostPerWord
2 participants