-
Notifications
You must be signed in to change notification settings - Fork 217
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
Fixes for balanceTransaction in presence of scripts #2989
Conversation
@@ -715,7 +715,7 @@ executionUnitPricesFromPParams pp = | |||
fromAlonzoPrices prices | |||
where | |||
prices = getField @"_prices" pp |
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.
Just curious, do you know why it wouldn't be possible to use pp ^. #_prices
here?
(Apologies if I'm missing something.)
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.
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.
Yeah, I just saw the same error. 🤷🏻♂️
Oh well, I guess it's something we can save for another day!
executionCost (ExecutionUnitPrices perStep perMem) (W.ExecutionUnits steps mem) = | ||
perStep * (toRational steps) + perMem * (toRational mem) | ||
Coin.unsafeNaturalToCoin . ceiling $ | ||
perStep * (toRational steps) + perMem * (toRational mem) |
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 found this code a little hard to understand, since the field names used in this function are quite different from the field names of the original record types. I think it would be good to use consistent terminology everywhere, to help people trying to understand the code in future.
Looking at the types themselves, I think I prefer your names!
Can we change the field names of ExecutionUnitPrices
to something like:
data ExecutionUnitPrices = ExecutionUnitPrices
- { priceExecutionSteps
+ { pricePerStep
:: Rational
- , priceExecutionMemory
+ , pricePerMemoryUnit
:: Rational
} deriving (Eq, Generic, Show)
I think calling it perMemoryUnit
is also clearer from a plain English perspective (since "per memory" is a bit ambiguous).
Secondly, could we rewrite this function to use labels? Attempting to pattern match these records on a single line makes that line rather long. (This approach doesn't really scale if you have more parameters.)
So perhaps:
executionCost :: ExecutionUnitPrices -> ExecutionUnits -> Coin
executionCost ps us = Coin.unsafeNaturalToCoin . ceiling
$ (ps ^. #pricePerStep) * toRational (us ^. #steps)
+ (ps ^. #pricePerMemoryUnit) * toRational (us ^. #memoryUnits)
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.
Update: I made a commit with suggested changes, which you could cherry-pick if you prefer:
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.
Thanks, I think the renaming definitely makes sense.
Secondly, could we rewrite this function to use labels?
You do lose the ability to spot unused fields… but sure, its neater in other ways
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!
bors r+ |
2989: Fixes for balanceTransaction in presence of scripts r=Anviking a=Anviking - [x] Don't multiply with numberOfScripts in _maxScriptExecutionCost - [x] Fix mismatch of prMem and PrSteps in fromAlonzoPrices ### Comments - Thread: https://input-output-rnd.slack.com/archives/GBT05825V/p1634825136008200 - I believe our the fee minimisation using node functions otherwise hid the price mismatch. This is somewhat alarming, and it will be nice to both property test balanceTransaction as well as simplifying the implementation down the line. ### Behaviour after fix, which I don't quite understand: With manual `w <- fixtureWalletWith @n ctx [15_000_000]` ``` Failures: src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs:1341:54: 1) API Specifications, NEW_SHELLEY_TRANSACTIONS, Plutus scenarios, game state-machine uncaught exception: RequestException ClientError (Object (fromList [("code",String "insufficient_collateral"),("message",String "I'm unable to create this transaction because the balance of pure ada UTxOs in your wallet is insufficient to cover the minimum amount of collateral required. I need an ada amount of at least: 2.262900 The largest combination of pure ada UTxOs I could find is: [] To fix this, you'll need to add one or more pure ada UTxOs to your wallet that can cover the minimum amount required.")])) To rerun use: --match "/API Specifications/NEW_SHELLEY_TRANSACTIONS/Plutus scenarios/game state-machine/" src/Test/Integration/Scenario/API/Shelley/TransactionsNew.hs:1341:54: 2) API Specifications, NEW_SHELLEY_TRANSACTIONS, Plutus scenarios, mint-burn uncaught exception: RequestException ClientError (Object (fromList [("code",String "insufficient_collateral"),("message",String "I'm unable to create this transaction because the balance of pure ada UTxOs in your wallet is insufficient to cover the minimum amount of collateral required. I need an ada amount of at least: 2.214450 The largest combination of pure ada UTxOs I could find is: [] To fix this, you'll need to add one or more pure ada UTxOs to your wallet that can cover the minimum amount required.")])) ``` However I think it would be better to investigate _while_ creating property tests and/or with simplified implementation. <!-- Additional comments, links, or screenshots to attach, if any. --> ### Issue Number ADP-1227 Co-authored-by: Johannes Lund <[email protected]> Co-authored-by: Jonathan Knowles <[email protected]>
Build failed: #expected |
The maximum script execution cost is per /tx/, so multiplying with the number of scripts doesn't make sense. It seems rely on the function returning `Coin 0` if there are no scripts, however, so keeping that.
Use names that are more consistent with the meaning.
91b1d11
to
cdff38d
Compare
bors r+ |
Build succeeded: |
This is to account for recent fixes to the fee calculation logic within the `balanceTransaction` function, in particular: #2989
This is to account for recent fixes to the fee calculation logic within the `balanceTransaction` function, in particular: #2989
Comments
Behaviour after fix, which I don't quite understand:
With manual
w <- fixtureWalletWith @n ctx [15_000_000]
However I think it would be better to investigate while creating property tests and/or with simplified implementation.
Issue Number
ADP-1227