-
Couldn't load subscription status.
- Fork 482
Use Data backed ledger types for COOP #7235
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,21 +13,15 @@ import PlutusTx.Plugin () | |
| import PlutusTx.Prelude | ||
| import Prelude () | ||
|
|
||
| import PlutusLedgerApi.V1.Interval (contains) | ||
| import PlutusLedgerApi.V1.Value (AssetClass (AssetClass), isZero, unAssetClass, valueOf, | ||
| withCurrencySymbol) | ||
| import PlutusLedgerApi.V1.Value qualified as Value | ||
| import PlutusLedgerApi.V2 (Datum, Extended (PosInf), Interval (Interval, ivTo), | ||
| LedgerBytes (getLedgerBytes), LowerBound (LowerBound), | ||
| ScriptContext (ScriptContext), ScriptPurpose (Minting), | ||
| TokenName (TokenName), TxId (getTxId), TxInInfo (TxInInfo), | ||
| TxInfo (TxInfo, txInfoData, txInfoInputs, txInfoMint, txInfoOutputs, txInfoReferenceInputs, txInfoSignatories, txInfoValidRange), | ||
| TxOut (TxOut, txOutAddress, txOutDatum, txOutValue), | ||
| TxOutRef (TxOutRef, txOutRefId, txOutRefIdx), UpperBound (UpperBound), | ||
| Value (Value, getValue)) | ||
| import PlutusTx.AssocMap qualified as AssocMap | ||
| import PlutusLedgerApi.Data.V2 | ||
| import PlutusLedgerApi.V1.Data.Interval (contains) | ||
| import PlutusLedgerApi.V1.Data.Value (isZero, unAssetClass, valueOf, withCurrencySymbol) | ||
| import PlutusLedgerApi.V1.Data.Value qualified as Value | ||
|
|
||
| import PlutusTx.Builtins.Internal qualified as BI | ||
| import PlutusTx.List (elem, find, foldl, null) | ||
| import PlutusTx.Data.AssocMap qualified as AssocMap | ||
| import PlutusTx.Data.List (cons, elem, foldl, null) | ||
| import PlutusTx.List qualified as BIList | ||
|
|
||
| import PlutusBenchmark.Coop.Types | ||
| import PlutusBenchmark.Coop.Utils | ||
|
|
@@ -113,14 +107,14 @@ fsMp' | |
| let | ||
| predicate (CertDatum {..}) = | ||
| 0 < valueOf txInVal ap'authTokenCs (TokenName $ getLedgerBytes cert'id) | ||
| in case find predicate validCerts of | ||
| in case BIList.find predicate validCerts of | ||
| Nothing -> traceError "$AUTH must be validated with a $CERT" | ||
| Just (CertDatum {..}) -> | ||
| let | ||
| shouldbeBurned' = | ||
| shouldBeBurned | ||
| <> Value.singleton ap'authTokenCs (TokenName $ getLedgerBytes cert'id) (-1) | ||
| in (txIn : validAuthInputs'', shouldbeBurned') | ||
| in (cons txIn validAuthInputs'', shouldbeBurned') | ||
| else acc | ||
|
|
||
| (validAuthInputs', authTokensToBurn) = foldl go' (mempty, mempty) txInfoInputs | ||
|
|
@@ -147,9 +141,9 @@ fsMp' | |
| in if (Value $ AssocMap.singleton ownCs ownCurrValue) | ||
| == Value.singleton ownCs fsTokenName 1 | ||
| then (Just fsTokenName, unusedAuthInputs'') | ||
| else (Nothing, authInput : unusedAuthInputs'') | ||
| else (Nothing, cons authInput unusedAuthInputs'') | ||
| matchWithAuth (myFsTn', unusedAuthInputs'') authInput = | ||
| (myFsTn', (authInput : unusedAuthInputs'')) | ||
| (myFsTn', (cons authInput unusedAuthInputs'')) | ||
|
|
||
| (mayFsTn, unusedAuthInputs') = foldl matchWithAuth (Nothing, mempty) unusedAuthInputs | ||
| in case mayFsTn of | ||
|
|
@@ -210,7 +204,7 @@ authMp' | |
| "Must mint at least one $AUTH token:\n" | ||
| <> "Must have a specified CurrencySymbol in the Value" | ||
| Just tokenNameMap -> | ||
| case AssocMap.toList tokenNameMap of | ||
| case AssocMap.toSOPList tokenNameMap of | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be one of the reasons there is a performance decrease. |
||
| [(k, v)] | k == (TokenName authId) -> | ||
| errorIfFalse "Must mint at least one $AUTH token" (0 < v) | ||
| _ -> | ||
|
|
@@ -231,7 +225,7 @@ certMp' | |
| let | ||
| tnBytes = | ||
| let | ||
| AssetClass (aaCs, aaTn) = cmp'authAuthorityAc | ||
| (aaCs, aaTn) = unAssetClass cmp'authAuthorityAc | ||
| go acc@(aaVal, tnBytes'') (TxInInfo (TxOutRef {txOutRefId = txId, txOutRefIdx = txIdx}) (TxOut {txOutValue = txInVal})) = | ||
| if hasCurrency aaCs txInVal | ||
| then (aaVal + valueOf txInVal aaCs aaTn, tnBytes'' <> consByteString txIdx (getTxId txId)) | ||
|
|
@@ -280,7 +274,7 @@ certMp' | |
| contains | ||
| (Interval (LowerBound certValidUntil False) (UpperBound PosInf True)) | ||
| txInfoValidRange | ||
| AssetClass (redeemerCs, redeemerName) = cert'redeemerAc | ||
| (redeemerCs, redeemerName) = unAssetClass cert'redeemerAc | ||
| inputSum = | ||
| foldl (\acc (TxInInfo _ (TxOut {txOutValue})) -> acc + txOutValue) mempty txInfoInputs | ||
| !_spendAtLeast = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| CPU: 275_949_863 | ||
| Memory: 1_044_479 | ||
| Term Size: 1_908 | ||
| Flat Size: 5_925 | ||
| CPU: 22_532_179 | ||
| Memory: 58_279 | ||
| Term Size: 908 | ||
| Flat Size: 4_859 | ||
|
|
||
| (con unit ()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| CPU: 595_852_740 | ||
| Memory: 2_373_857 | ||
| Term Size: 1_908 | ||
| Flat Size: 7_322 | ||
| CPU: 321_845_423 | ||
| Memory: 852_311 | ||
| Term Size: 908 | ||
| Flat Size: 6_260 | ||
|
|
||
| (con unit ()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| CPU: 2_041_041_180 | ||
| Memory: 11_330_335 | ||
| Term Size: 3_698 | ||
| Flat Size: 8_707 | ||
| CPU: 7_153_841_977 | ||
| Memory: 23_035_266 | ||
| Term Size: 3_856 | ||
| Flat Size: 8_833 | ||
|
|
||
| (con unit ()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| CPU: 628_642_273 | ||
| Memory: 2_544_349 | ||
| Term Size: 3_698 | ||
| Flat Size: 9_230 | ||
| CPU: 450_505_963 | ||
| Memory: 1_349_628 | ||
| Term Size: 3_856 | ||
| Flat Size: 9_355 | ||
|
|
||
| (con unit ()) |
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.
Again, Data <-> SOP conversions are expensive. Can this be avoided here? You won't be able to use the list comprehension, unfortunately, but there should be a way to write this code using builtins. Let me know if you need help with this and we can take a look together.