From 3455bffa7703894a4ab898924580ea7257c6f185 Mon Sep 17 00:00:00 2001 From: Dzmitry Shuysky Date: Wed, 16 Aug 2023 14:45:40 +0200 Subject: [PATCH 1/6] feat: add `mustNotSpendUtxosWhere` balancer constraint Signed-off-by: Dzmitry Shuysky --- src/Contract/BalanceTxConstraints.purs | 2 + src/Internal/BalanceTx/BalanceTx.purs | 109 ++++++++++++++---------- src/Internal/BalanceTx/Constraints.purs | 31 ++++++- 3 files changed, 96 insertions(+), 46 deletions(-) diff --git a/src/Contract/BalanceTxConstraints.purs b/src/Contract/BalanceTxConstraints.purs index 531e16c63b..e86a23246b 100644 --- a/src/Contract/BalanceTxConstraints.purs +++ b/src/Contract/BalanceTxConstraints.purs @@ -4,8 +4,10 @@ module Contract.BalanceTxConstraints (module BalanceTxConstraints) where import Ctl.Internal.BalanceTx.Constraints ( BalanceTxConstraintsBuilder + , UtxoPredicate , mustGenChangeOutsWithMaxTokenQuantity , mustNotSpendUtxoWithOutRef + , mustNotSpendUtxosWhere , mustNotSpendUtxosWithOutRefs , mustSendChangeToAddress , mustSendChangeWithDatum diff --git a/src/Internal/BalanceTx/BalanceTx.purs b/src/Internal/BalanceTx/BalanceTx.purs index c9d95b8ba1..2d9a382d76 100644 --- a/src/Internal/BalanceTx/BalanceTx.purs +++ b/src/Internal/BalanceTx/BalanceTx.purs @@ -24,13 +24,13 @@ import Ctl.Internal.BalanceTx.Collateral.Select (selectCollateral) import Ctl.Internal.BalanceTx.Constraints ( BalanceTxConstraintsBuilder , _collateralUtxos - , _nonSpendableInputs ) import Ctl.Internal.BalanceTx.Constraints ( _changeAddress , _changeDatum , _maxChangeOutputTokenQuantity , _nonSpendableInputs + , _nonSpendableInputsPredicates , _selectionStrategy , _srcAddresses ) as Constraints @@ -144,14 +144,21 @@ import Data.Array.NonEmpty import Data.Array.NonEmpty as NEA import Data.Bifunctor (lmap) import Data.Either (Either, hush, note) -import Data.Foldable (fold, foldMap, foldr, length, null, sum) +import Data.Foldable (any, fold, foldMap, foldr, length, null, or, sum) import Data.Function (on) import Data.Lens.Getter ((^.)) import Data.Lens.Setter ((%~), (.~), (?~)) import Data.Log.Tag (TagSet, tag, tagSetTag) import Data.Log.Tag (fromArray) as TagSet import Data.Map (Map) -import Data.Map (empty, filterKeys, insert, lookup, toUnfoldable, union) as Map +import Data.Map + ( empty + , filterWithKey + , insert + , lookup + , toUnfoldable + , union + ) as Map import Data.Maybe (Maybe(Just, Nothing), fromMaybe, isJust, maybe) import Data.Newtype (class Newtype, unwrap, wrap) import Data.Set (Set) @@ -264,16 +271,23 @@ balanceTxWithConstraints transaction extraUtxos constraintsBuilder = do setTransactionCollateral :: Address -> Transaction -> BalanceTxM Transaction setTransactionCollateral changeAddr transaction = do - nonSpendableSet <- asksConstraints _nonSpendableInputs + nonSpendableSet <- asksConstraints Constraints._nonSpendableInputs + nonSpendableInputsPredicates <- asksConstraints + Constraints._nonSpendableInputsPredicates mbCollateralUtxos <- asksConstraints _collateralUtxos -- We must filter out UTxOs that are set as non-spendable in the balancer -- constraints - let isSpendable = not <<< flip Set.member nonSpendableSet + let + isSpendable = \input output -> + not (Set.member input nonSpendableSet) && + not (any (\f -> f input output) nonSpendableInputsPredicates) collateral <- case mbCollateralUtxos of -- if no collateral utxos are specified, use the wallet, but filter -- the unspendable ones Nothing -> do - let isSpendableUtxo = isSpendable <<< _.input <<< unwrap + let + isSpendableUtxo = \utxo -> isSpendable (unwrap utxo).input + (unwrap utxo).output { yes: spendableUtxos, no: filteredUtxos } <- Array.partition isSpendableUtxo <$> do liftEitherContract $ note CouldNotGetCollateral <$> @@ -291,7 +305,7 @@ setTransactionCollateral changeAddr transaction = do let coinsPerUtxoUnit = params.coinsPerUtxoUnit maxCollateralInputs = UInt.toInt $ params.maxCollateralInputs - utxoMap' = fromPlutusUtxoMap networkId $ Map.filterKeys isSpendable + utxoMap' = Map.filterWithKey isSpendable $ fromPlutusUtxoMap networkId utxoMap mbCollateral <- liftEffect $ map Array.fromFoldable <$> selectCollateral coinsPerUtxoUnit maxCollateralInputs utxoMap' @@ -359,44 +373,49 @@ runBalancer p = do liftContract $ Wallet.getWalletCollateral <#> fold >>> map (unwrap >>> _.input) >>> Set.fromFoldable else mempty - asksConstraints Constraints._nonSpendableInputs <#> - append nonSpendableCollateralInputs >>> - \nonSpendableInputs -> - foldr - ( \(oref /\ output) acc -> - let - hasInlineDatum :: Boolean - hasInlineDatum = case (unwrap output).datum of - OutputDatum _ -> true - _ -> false - - hasScriptRef :: Boolean - hasScriptRef = isJust (unwrap output).scriptRef - - spendable :: Boolean - spendable = not $ Set.member oref nonSpendableInputs || - Set.member oref - ( p.transaction ^. _transaction <<< _body <<< - _referenceInputs - ) - - validInContext :: Boolean - validInContext = not $ txHasPlutusV1 && - (hasInlineDatum || hasScriptRef) - in - case spendable, validInContext of - true, true -> acc - { spendable = Map.insert oref output acc.spendable } - true, false -> acc - { invalidInContext = Map.insert oref output - acc.invalidInContext - } - _, _ -> acc - ) - { spendable: Map.empty - , invalidInContext: Map.empty - } - (Map.toUnfoldable p.utxos :: Array _) + constraints <- unwrap <$> asks _.constraints + let + nonSpendableInputs = + constraints.nonSpendableInputs <> nonSpendableCollateralInputs + pure $ foldr + ( \(oref /\ output) acc -> + let + hasInlineDatum :: Boolean + hasInlineDatum = case (unwrap output).datum of + OutputDatum _ -> true + _ -> false + + hasScriptRef :: Boolean + hasScriptRef = isJust (unwrap output).scriptRef + + spendable :: Boolean + spendable = not $ or + [ Set.member oref nonSpendableInputs + , any (\f -> f oref output) + constraints.nonSpendableInputsPredicates + , Set.member oref + ( p.transaction ^. _transaction <<< _body <<< + _referenceInputs + ) + ] + + validInContext :: Boolean + validInContext = not $ txHasPlutusV1 && + (hasInlineDatum || hasScriptRef) + in + case spendable, validInContext of + true, true -> acc + { spendable = Map.insert oref output acc.spendable } + true, false -> acc + { invalidInContext = Map.insert oref output + acc.invalidInContext + } + _, _ -> acc + ) + { spendable: Map.empty + , invalidInContext: Map.empty + } + (Map.toUnfoldable p.utxos :: Array _) mainLoop :: BalancerState UnindexedTx -> BalanceTxM FinalizedTransaction mainLoop = worker <<< PrebalanceTx diff --git a/src/Internal/BalanceTx/Constraints.purs b/src/Internal/BalanceTx/Constraints.purs index b6a2c83278..b96e255565 100644 --- a/src/Internal/BalanceTx/Constraints.purs +++ b/src/Internal/BalanceTx/Constraints.purs @@ -1,8 +1,10 @@ module Ctl.Internal.BalanceTx.Constraints ( BalanceTxConstraints(BalanceTxConstraints) , BalanceTxConstraintsBuilder(BalanceTxConstraintsBuilder) + , UtxoPredicate , buildBalanceTxConstraints , mustGenChangeOutsWithMaxTokenQuantity + , mustNotSpendUtxosWhere , mustNotSpendUtxosWithOutRefs , mustNotSpendUtxoWithOutRef , mustSendChangeToAddress @@ -18,6 +20,7 @@ module Ctl.Internal.BalanceTx.Constraints , _changeDatum , _maxChangeOutputTokenQuantity , _nonSpendableInputs + , _nonSpendableInputsPredicates , _selectionStrategy , _srcAddresses ) where @@ -27,14 +30,17 @@ import Prelude import Ctl.Internal.BalanceTx.CoinSelection ( SelectionStrategy(SelectionStrategyOptimal) ) +import Ctl.Internal.Cardano.Types.Transaction (TransactionOutput) import Ctl.Internal.Plutus.Conversion ( fromPlutusAddress , fromPlutusAddressWithNetworkTag + , toPlutusTxOutputWithRefScript ) import Ctl.Internal.Plutus.Types.Address ( Address , AddressWithNetworkTag(AddressWithNetworkTag) ) as Plutus +import Ctl.Internal.Plutus.Types.Transaction (TransactionOutputWithRefScript) as Plutus import Ctl.Internal.Plutus.Types.Transaction (UtxoMap) import Ctl.Internal.Serialization.Address (Address, NetworkId) import Ctl.Internal.Types.OutputDatum (OutputDatum) @@ -46,7 +52,7 @@ import Data.Lens.Iso.Newtype (_Newtype) import Data.Lens.Record (prop) import Data.Lens.Setter (appendOver, set, setJust) import Data.Map (empty) as Map -import Data.Maybe (Maybe(Just, Nothing)) +import Data.Maybe (Maybe(Just, Nothing), fromMaybe) import Data.Newtype (class Newtype, over2, unwrap, wrap) import Data.Set (Set) import Data.Set (singleton) as Set @@ -58,6 +64,7 @@ newtype BalanceTxConstraints = BalanceTxConstraints , collateralUtxos :: Maybe UtxoMap , maxChangeOutputTokenQuantity :: Maybe BigInt , nonSpendableInputs :: Set TransactionInput + , nonSpendableInputsPredicates :: Array (UtxoPredicate TransactionOutput) , srcAddresses :: Maybe (Array Address) , changeAddress :: Maybe Address , changeDatum :: Maybe OutputDatum @@ -66,6 +73,8 @@ newtype BalanceTxConstraints = BalanceTxConstraints derive instance Newtype BalanceTxConstraints _ +type UtxoPredicate (output :: Type) = TransactionInput -> output -> Boolean + _additionalUtxos :: Lens' BalanceTxConstraints UtxoMap _additionalUtxos = _Newtype <<< prop (Proxy :: Proxy "additionalUtxos") @@ -79,6 +88,11 @@ _maxChangeOutputTokenQuantity = _nonSpendableInputs :: Lens' BalanceTxConstraints (Set TransactionInput) _nonSpendableInputs = _Newtype <<< prop (Proxy :: Proxy "nonSpendableInputs") +_nonSpendableInputsPredicates + :: Lens' BalanceTxConstraints (Array (UtxoPredicate TransactionOutput)) +_nonSpendableInputsPredicates = + _Newtype <<< prop (Proxy :: Proxy "nonSpendableInputsPredicates") + _srcAddresses :: Lens' BalanceTxConstraints (Maybe (Array Address)) _srcAddresses = _Newtype <<< prop (Proxy :: Proxy "srcAddresses") @@ -111,6 +125,7 @@ buildBalanceTxConstraints = applyFlipped defaultConstraints <<< unwrap , collateralUtxos: Nothing , maxChangeOutputTokenQuantity: Nothing , nonSpendableInputs: mempty + , nonSpendableInputsPredicates: mempty , srcAddresses: Nothing , changeDatum: Nothing , changeAddress: Nothing @@ -173,6 +188,20 @@ mustNotSpendUtxosWithOutRefs = wrap <<< appendOver _nonSpendableInputs mustNotSpendUtxoWithOutRef :: TransactionInput -> BalanceTxConstraintsBuilder mustNotSpendUtxoWithOutRef = mustNotSpendUtxosWithOutRefs <<< Set.singleton +-- | Tells the balancer not to spend UTxO's based on the given predicate. +-- | Note that `mustNotSpendUtxosWhere` constraints are stacked when specified +-- | multiple times, and utxos are tested against each predicate. The order of +-- | specifying multiple `mustNotSpendUtxosWhere` constraints does NOT affect +-- | the resulting set. +mustNotSpendUtxosWhere + :: UtxoPredicate Plutus.TransactionOutputWithRefScript + -> BalanceTxConstraintsBuilder +mustNotSpendUtxosWhere p = + wrap $ appendOver _nonSpendableInputsPredicates + ( Array.singleton \oref out -> + fromMaybe false $ p oref <$> toPlutusTxOutputWithRefScript out + ) + -- | Tells the balancer to use the provided UTxO set when evaluating script -- | execution units (sets `additionalUtxoSet` of Ogmios `EvaluateTx`). -- | Note that you need to use `unspentOutputs` lookup to make these UTxO's From 85ecbbb5fa7044dd1dc37ae0779a9a222e40dcb3 Mon Sep 17 00:00:00 2001 From: Dzmitry Shuysky Date: Thu, 5 Sep 2024 13:49:54 +0200 Subject: [PATCH 2/6] Fix PlutusV3 cost model decoding (cherry picked from commit 47e856ecb0d6bcd9ec0194121b2ba971a054060a) --- ...prod-7f56c39a71503c097c448dc4b47b0e34.json | 1 + ...view-659470119e7874ecf112dd05db4b691d.json | 1 + ...prod-aaa9a3fbcf526a678489845a2de49600.json | 1 + ...view-256d19f15eb1f722b0b66b25d20961b8.json | 1 + spago.dhall | 1 - src/Internal/Service/Blockfrost.purs | 29 +-- src/Internal/Types/ProtocolParameters.purs | 242 +----------------- .../GenerateFixtures/ProtocolParameters.purs | 41 ++- test/Blockfrost/ProtocolParameters.purs | 54 ---- test/ProtocolParameters.purs | 84 ++++++ test/ProtocolParams.purs | 24 -- test/Unit.purs | 6 +- 12 files changed, 133 insertions(+), 352 deletions(-) create mode 100644 fixtures/test/blockfrost/getProtocolParameters-preprod/getProtocolParameters-preprod-7f56c39a71503c097c448dc4b47b0e34.json create mode 100644 fixtures/test/blockfrost/getProtocolParameters-preview/getProtocolParameters-preview-659470119e7874ecf112dd05db4b691d.json create mode 100644 fixtures/test/ogmios/queryLedgerState-protocolParameters-preprod-aaa9a3fbcf526a678489845a2de49600.json create mode 100644 fixtures/test/ogmios/queryLedgerState-protocolParameters-preview-256d19f15eb1f722b0b66b25d20961b8.json delete mode 100644 test/Blockfrost/ProtocolParameters.purs create mode 100644 test/ProtocolParameters.purs delete mode 100644 test/ProtocolParams.purs diff --git a/fixtures/test/blockfrost/getProtocolParameters-preprod/getProtocolParameters-preprod-7f56c39a71503c097c448dc4b47b0e34.json b/fixtures/test/blockfrost/getProtocolParameters-preprod/getProtocolParameters-preprod-7f56c39a71503c097c448dc4b47b0e34.json new file mode 100644 index 0000000000..a4e8c2dd80 --- /dev/null +++ b/fixtures/test/blockfrost/getProtocolParameters-preprod/getProtocolParameters-preprod-7f56c39a71503c097c448dc4b47b0e34.json @@ -0,0 +1 @@ +{"epoch":165,"min_fee_a":44,"min_fee_b":155381,"max_block_size":90112,"max_tx_size":16384,"max_block_header_size":1100,"key_deposit":"2000000","pool_deposit":"500000000","e_max":18,"n_opt":500,"a0":0.3,"rho":0.003,"tau":0.2,"decentralisation_param":0,"extra_entropy":null,"protocol_major_ver":9,"protocol_minor_ver":0,"min_utxo":"4310","min_pool_cost":"170000000","nonce":"a7c4477e9fcfd519bf7dcba0d4ffe35a399125534bc8c60fa89ff6b50a060a7a","cost_models":{"PlutusV1":{"addInteger-cpu-arguments-intercept":100788,"addInteger-cpu-arguments-slope":420,"addInteger-memory-arguments-intercept":1,"addInteger-memory-arguments-slope":1,"appendByteString-cpu-arguments-intercept":1000,"appendByteString-cpu-arguments-slope":173,"appendByteString-memory-arguments-intercept":0,"appendByteString-memory-arguments-slope":1,"appendString-cpu-arguments-intercept":1000,"appendString-cpu-arguments-slope":59957,"appendString-memory-arguments-intercept":4,"appendString-memory-arguments-slope":1,"bData-cpu-arguments":11183,"bData-memory-arguments":32,"blake2b_256-cpu-arguments-intercept":201305,"blake2b_256-cpu-arguments-slope":8356,"blake2b_256-memory-arguments":4,"cekApplyCost-exBudgetCPU":16000,"cekApplyCost-exBudgetMemory":100,"cekBuiltinCost-exBudgetCPU":16000,"cekBuiltinCost-exBudgetMemory":100,"cekConstCost-exBudgetCPU":16000,"cekConstCost-exBudgetMemory":100,"cekDelayCost-exBudgetCPU":16000,"cekDelayCost-exBudgetMemory":100,"cekForceCost-exBudgetCPU":16000,"cekForceCost-exBudgetMemory":100,"cekLamCost-exBudgetCPU":16000,"cekLamCost-exBudgetMemory":100,"cekStartupCost-exBudgetCPU":100,"cekStartupCost-exBudgetMemory":100,"cekVarCost-exBudgetCPU":16000,"cekVarCost-exBudgetMemory":100,"chooseData-cpu-arguments":94375,"chooseData-memory-arguments":32,"chooseList-cpu-arguments":132994,"chooseList-memory-arguments":32,"chooseUnit-cpu-arguments":61462,"chooseUnit-memory-arguments":4,"consByteString-cpu-arguments-intercept":72010,"consByteString-cpu-arguments-slope":178,"consByteString-memory-arguments-intercept":0,"consByteString-memory-arguments-slope":1,"constrData-cpu-arguments":22151,"constrData-memory-arguments":32,"decodeUtf8-cpu-arguments-intercept":91189,"decodeUtf8-cpu-arguments-slope":769,"decodeUtf8-memory-arguments-intercept":4,"decodeUtf8-memory-arguments-slope":2,"divideInteger-cpu-arguments-constant":85848,"divideInteger-cpu-arguments-model-arguments-intercept":228465,"divideInteger-cpu-arguments-model-arguments-slope":122,"divideInteger-memory-arguments-intercept":0,"divideInteger-memory-arguments-minimum":1,"divideInteger-memory-arguments-slope":1,"encodeUtf8-cpu-arguments-intercept":1000,"encodeUtf8-cpu-arguments-slope":42921,"encodeUtf8-memory-arguments-intercept":4,"encodeUtf8-memory-arguments-slope":2,"equalsByteString-cpu-arguments-constant":24548,"equalsByteString-cpu-arguments-intercept":29498,"equalsByteString-cpu-arguments-slope":38,"equalsByteString-memory-arguments":1,"equalsData-cpu-arguments-intercept":898148,"equalsData-cpu-arguments-slope":27279,"equalsData-memory-arguments":1,"equalsInteger-cpu-arguments-intercept":51775,"equalsInteger-cpu-arguments-slope":558,"equalsInteger-memory-arguments":1,"equalsString-cpu-arguments-constant":39184,"equalsString-cpu-arguments-intercept":1000,"equalsString-cpu-arguments-slope":60594,"equalsString-memory-arguments":1,"fstPair-cpu-arguments":141895,"fstPair-memory-arguments":32,"headList-cpu-arguments":83150,"headList-memory-arguments":32,"iData-cpu-arguments":15299,"iData-memory-arguments":32,"ifThenElse-cpu-arguments":76049,"ifThenElse-memory-arguments":1,"indexByteString-cpu-arguments":13169,"indexByteString-memory-arguments":4,"lengthOfByteString-cpu-arguments":22100,"lengthOfByteString-memory-arguments":10,"lessThanByteString-cpu-arguments-intercept":28999,"lessThanByteString-cpu-arguments-slope":74,"lessThanByteString-memory-arguments":1,"lessThanEqualsByteString-cpu-arguments-intercept":28999,"lessThanEqualsByteString-cpu-arguments-slope":74,"lessThanEqualsByteString-memory-arguments":1,"lessThanEqualsInteger-cpu-arguments-intercept":43285,"lessThanEqualsInteger-cpu-arguments-slope":552,"lessThanEqualsInteger-memory-arguments":1,"lessThanInteger-cpu-arguments-intercept":44749,"lessThanInteger-cpu-arguments-slope":541,"lessThanInteger-memory-arguments":1,"listData-cpu-arguments":33852,"listData-memory-arguments":32,"mapData-cpu-arguments":68246,"mapData-memory-arguments":32,"mkCons-cpu-arguments":72362,"mkCons-memory-arguments":32,"mkNilData-cpu-arguments":7243,"mkNilData-memory-arguments":32,"mkNilPairData-cpu-arguments":7391,"mkNilPairData-memory-arguments":32,"mkPairData-cpu-arguments":11546,"mkPairData-memory-arguments":32,"modInteger-cpu-arguments-constant":85848,"modInteger-cpu-arguments-model-arguments-intercept":228465,"modInteger-cpu-arguments-model-arguments-slope":122,"modInteger-memory-arguments-intercept":0,"modInteger-memory-arguments-minimum":1,"modInteger-memory-arguments-slope":1,"multiplyInteger-cpu-arguments-intercept":90434,"multiplyInteger-cpu-arguments-slope":519,"multiplyInteger-memory-arguments-intercept":0,"multiplyInteger-memory-arguments-slope":1,"nullList-cpu-arguments":74433,"nullList-memory-arguments":32,"quotientInteger-cpu-arguments-constant":85848,"quotientInteger-cpu-arguments-model-arguments-intercept":228465,"quotientInteger-cpu-arguments-model-arguments-slope":122,"quotientInteger-memory-arguments-intercept":0,"quotientInteger-memory-arguments-minimum":1,"quotientInteger-memory-arguments-slope":1,"remainderInteger-cpu-arguments-constant":85848,"remainderInteger-cpu-arguments-model-arguments-intercept":228465,"remainderInteger-cpu-arguments-model-arguments-slope":122,"remainderInteger-memory-arguments-intercept":0,"remainderInteger-memory-arguments-minimum":1,"remainderInteger-memory-arguments-slope":1,"sha2_256-cpu-arguments-intercept":270652,"sha2_256-cpu-arguments-slope":22588,"sha2_256-memory-arguments":4,"sha3_256-cpu-arguments-intercept":1457325,"sha3_256-cpu-arguments-slope":64566,"sha3_256-memory-arguments":4,"sliceByteString-cpu-arguments-intercept":20467,"sliceByteString-cpu-arguments-slope":1,"sliceByteString-memory-arguments-intercept":4,"sliceByteString-memory-arguments-slope":0,"sndPair-cpu-arguments":141992,"sndPair-memory-arguments":32,"subtractInteger-cpu-arguments-intercept":100788,"subtractInteger-cpu-arguments-slope":420,"subtractInteger-memory-arguments-intercept":1,"subtractInteger-memory-arguments-slope":1,"tailList-cpu-arguments":81663,"tailList-memory-arguments":32,"trace-cpu-arguments":59498,"trace-memory-arguments":32,"unBData-cpu-arguments":20142,"unBData-memory-arguments":32,"unConstrData-cpu-arguments":24588,"unConstrData-memory-arguments":32,"unIData-cpu-arguments":20744,"unIData-memory-arguments":32,"unListData-cpu-arguments":25933,"unListData-memory-arguments":32,"unMapData-cpu-arguments":24623,"unMapData-memory-arguments":32,"verifyEd25519Signature-cpu-arguments-intercept":53384111,"verifyEd25519Signature-cpu-arguments-slope":14333,"verifyEd25519Signature-memory-arguments":10},"PlutusV2":{"addInteger-cpu-arguments-intercept":100788,"addInteger-cpu-arguments-slope":420,"addInteger-memory-arguments-intercept":1,"addInteger-memory-arguments-slope":1,"appendByteString-cpu-arguments-intercept":1000,"appendByteString-cpu-arguments-slope":173,"appendByteString-memory-arguments-intercept":0,"appendByteString-memory-arguments-slope":1,"appendString-cpu-arguments-intercept":1000,"appendString-cpu-arguments-slope":59957,"appendString-memory-arguments-intercept":4,"appendString-memory-arguments-slope":1,"bData-cpu-arguments":11183,"bData-memory-arguments":32,"blake2b_256-cpu-arguments-intercept":201305,"blake2b_256-cpu-arguments-slope":8356,"blake2b_256-memory-arguments":4,"cekApplyCost-exBudgetCPU":16000,"cekApplyCost-exBudgetMemory":100,"cekBuiltinCost-exBudgetCPU":16000,"cekBuiltinCost-exBudgetMemory":100,"cekConstCost-exBudgetCPU":16000,"cekConstCost-exBudgetMemory":100,"cekDelayCost-exBudgetCPU":16000,"cekDelayCost-exBudgetMemory":100,"cekForceCost-exBudgetCPU":16000,"cekForceCost-exBudgetMemory":100,"cekLamCost-exBudgetCPU":16000,"cekLamCost-exBudgetMemory":100,"cekStartupCost-exBudgetCPU":100,"cekStartupCost-exBudgetMemory":100,"cekVarCost-exBudgetCPU":16000,"cekVarCost-exBudgetMemory":100,"chooseData-cpu-arguments":94375,"chooseData-memory-arguments":32,"chooseList-cpu-arguments":132994,"chooseList-memory-arguments":32,"chooseUnit-cpu-arguments":61462,"chooseUnit-memory-arguments":4,"consByteString-cpu-arguments-intercept":72010,"consByteString-cpu-arguments-slope":178,"consByteString-memory-arguments-intercept":0,"consByteString-memory-arguments-slope":1,"constrData-cpu-arguments":22151,"constrData-memory-arguments":32,"decodeUtf8-cpu-arguments-intercept":91189,"decodeUtf8-cpu-arguments-slope":769,"decodeUtf8-memory-arguments-intercept":4,"decodeUtf8-memory-arguments-slope":2,"divideInteger-cpu-arguments-constant":85848,"divideInteger-cpu-arguments-model-arguments-intercept":228465,"divideInteger-cpu-arguments-model-arguments-slope":122,"divideInteger-memory-arguments-intercept":0,"divideInteger-memory-arguments-minimum":1,"divideInteger-memory-arguments-slope":1,"encodeUtf8-cpu-arguments-intercept":1000,"encodeUtf8-cpu-arguments-slope":42921,"encodeUtf8-memory-arguments-intercept":4,"encodeUtf8-memory-arguments-slope":2,"equalsByteString-cpu-arguments-constant":24548,"equalsByteString-cpu-arguments-intercept":29498,"equalsByteString-cpu-arguments-slope":38,"equalsByteString-memory-arguments":1,"equalsData-cpu-arguments-intercept":898148,"equalsData-cpu-arguments-slope":27279,"equalsData-memory-arguments":1,"equalsInteger-cpu-arguments-intercept":51775,"equalsInteger-cpu-arguments-slope":558,"equalsInteger-memory-arguments":1,"equalsString-cpu-arguments-constant":39184,"equalsString-cpu-arguments-intercept":1000,"equalsString-cpu-arguments-slope":60594,"equalsString-memory-arguments":1,"fstPair-cpu-arguments":141895,"fstPair-memory-arguments":32,"headList-cpu-arguments":83150,"headList-memory-arguments":32,"iData-cpu-arguments":15299,"iData-memory-arguments":32,"ifThenElse-cpu-arguments":76049,"ifThenElse-memory-arguments":1,"indexByteString-cpu-arguments":13169,"indexByteString-memory-arguments":4,"lengthOfByteString-cpu-arguments":22100,"lengthOfByteString-memory-arguments":10,"lessThanByteString-cpu-arguments-intercept":28999,"lessThanByteString-cpu-arguments-slope":74,"lessThanByteString-memory-arguments":1,"lessThanEqualsByteString-cpu-arguments-intercept":28999,"lessThanEqualsByteString-cpu-arguments-slope":74,"lessThanEqualsByteString-memory-arguments":1,"lessThanEqualsInteger-cpu-arguments-intercept":43285,"lessThanEqualsInteger-cpu-arguments-slope":552,"lessThanEqualsInteger-memory-arguments":1,"lessThanInteger-cpu-arguments-intercept":44749,"lessThanInteger-cpu-arguments-slope":541,"lessThanInteger-memory-arguments":1,"listData-cpu-arguments":33852,"listData-memory-arguments":32,"mapData-cpu-arguments":68246,"mapData-memory-arguments":32,"mkCons-cpu-arguments":72362,"mkCons-memory-arguments":32,"mkNilData-cpu-arguments":7243,"mkNilData-memory-arguments":32,"mkNilPairData-cpu-arguments":7391,"mkNilPairData-memory-arguments":32,"mkPairData-cpu-arguments":11546,"mkPairData-memory-arguments":32,"modInteger-cpu-arguments-constant":85848,"modInteger-cpu-arguments-model-arguments-intercept":228465,"modInteger-cpu-arguments-model-arguments-slope":122,"modInteger-memory-arguments-intercept":0,"modInteger-memory-arguments-minimum":1,"modInteger-memory-arguments-slope":1,"multiplyInteger-cpu-arguments-intercept":90434,"multiplyInteger-cpu-arguments-slope":519,"multiplyInteger-memory-arguments-intercept":0,"multiplyInteger-memory-arguments-slope":1,"nullList-cpu-arguments":74433,"nullList-memory-arguments":32,"quotientInteger-cpu-arguments-constant":85848,"quotientInteger-cpu-arguments-model-arguments-intercept":228465,"quotientInteger-cpu-arguments-model-arguments-slope":122,"quotientInteger-memory-arguments-intercept":0,"quotientInteger-memory-arguments-minimum":1,"quotientInteger-memory-arguments-slope":1,"remainderInteger-cpu-arguments-constant":85848,"remainderInteger-cpu-arguments-model-arguments-intercept":228465,"remainderInteger-cpu-arguments-model-arguments-slope":122,"remainderInteger-memory-arguments-intercept":0,"remainderInteger-memory-arguments-minimum":1,"remainderInteger-memory-arguments-slope":1,"serialiseData-cpu-arguments-intercept":955506,"serialiseData-cpu-arguments-slope":213312,"serialiseData-memory-arguments-intercept":0,"serialiseData-memory-arguments-slope":2,"sha2_256-cpu-arguments-intercept":270652,"sha2_256-cpu-arguments-slope":22588,"sha2_256-memory-arguments":4,"sha3_256-cpu-arguments-intercept":1457325,"sha3_256-cpu-arguments-slope":64566,"sha3_256-memory-arguments":4,"sliceByteString-cpu-arguments-intercept":20467,"sliceByteString-cpu-arguments-slope":1,"sliceByteString-memory-arguments-intercept":4,"sliceByteString-memory-arguments-slope":0,"sndPair-cpu-arguments":141992,"sndPair-memory-arguments":32,"subtractInteger-cpu-arguments-intercept":100788,"subtractInteger-cpu-arguments-slope":420,"subtractInteger-memory-arguments-intercept":1,"subtractInteger-memory-arguments-slope":1,"tailList-cpu-arguments":81663,"tailList-memory-arguments":32,"trace-cpu-arguments":59498,"trace-memory-arguments":32,"unBData-cpu-arguments":20142,"unBData-memory-arguments":32,"unConstrData-cpu-arguments":24588,"unConstrData-memory-arguments":32,"unIData-cpu-arguments":20744,"unIData-memory-arguments":32,"unListData-cpu-arguments":25933,"unListData-memory-arguments":32,"unMapData-cpu-arguments":24623,"unMapData-memory-arguments":32,"verifyEcdsaSecp256k1Signature-cpu-arguments":43053543,"verifyEcdsaSecp256k1Signature-memory-arguments":10,"verifyEd25519Signature-cpu-arguments-intercept":53384111,"verifyEd25519Signature-cpu-arguments-slope":14333,"verifyEd25519Signature-memory-arguments":10,"verifySchnorrSecp256k1Signature-cpu-arguments-intercept":43574283,"verifySchnorrSecp256k1Signature-cpu-arguments-slope":26308,"verifySchnorrSecp256k1Signature-memory-arguments":10},"PlutusV3":{"addInteger-cpu-arguments-intercept":100788,"addInteger-cpu-arguments-slope":420,"addInteger-memory-arguments-intercept":1,"addInteger-memory-arguments-slope":1,"appendByteString-cpu-arguments-intercept":1000,"appendByteString-cpu-arguments-slope":173,"appendByteString-memory-arguments-intercept":0,"appendByteString-memory-arguments-slope":1,"appendString-cpu-arguments-intercept":1000,"appendString-cpu-arguments-slope":59957,"appendString-memory-arguments-intercept":4,"appendString-memory-arguments-slope":1,"bData-cpu-arguments":11183,"bData-memory-arguments":32,"blake2b_256-cpu-arguments-intercept":201305,"blake2b_256-cpu-arguments-slope":8356,"blake2b_256-memory-arguments":4,"cekApplyCost-exBudgetCPU":16000,"cekApplyCost-exBudgetMemory":100,"cekBuiltinCost-exBudgetCPU":16000,"cekBuiltinCost-exBudgetMemory":100,"cekConstCost-exBudgetCPU":16000,"cekConstCost-exBudgetMemory":100,"cekDelayCost-exBudgetCPU":16000,"cekDelayCost-exBudgetMemory":100,"cekForceCost-exBudgetCPU":16000,"cekForceCost-exBudgetMemory":100,"cekLamCost-exBudgetCPU":16000,"cekLamCost-exBudgetMemory":100,"cekStartupCost-exBudgetCPU":100,"cekStartupCost-exBudgetMemory":100,"cekVarCost-exBudgetCPU":16000,"cekVarCost-exBudgetMemory":100,"chooseData-cpu-arguments":94375,"chooseData-memory-arguments":32,"chooseList-cpu-arguments":132994,"chooseList-memory-arguments":32,"chooseUnit-cpu-arguments":61462,"chooseUnit-memory-arguments":4,"consByteString-cpu-arguments-intercept":72010,"consByteString-cpu-arguments-slope":178,"consByteString-memory-arguments-intercept":0,"consByteString-memory-arguments-slope":1,"constrData-cpu-arguments":22151,"constrData-memory-arguments":32,"decodeUtf8-cpu-arguments-intercept":91189,"decodeUtf8-cpu-arguments-slope":769,"decodeUtf8-memory-arguments-intercept":4,"decodeUtf8-memory-arguments-slope":2,"divideInteger-cpu-arguments-constant":85848,"divideInteger-cpu-arguments-model-arguments-c00":123203,"divideInteger-cpu-arguments-model-arguments-c01":7305,"divideInteger-cpu-arguments-model-arguments-c02":-900,"divideInteger-cpu-arguments-model-arguments-c10":1716,"divideInteger-cpu-arguments-model-arguments-c11":549,"divideInteger-cpu-arguments-model-arguments-c20":57,"divideInteger-cpu-arguments-model-arguments-minimum":85848,"divideInteger-memory-arguments-intercept":0,"divideInteger-memory-arguments-minimum":1,"divideInteger-memory-arguments-slope":1,"encodeUtf8-cpu-arguments-intercept":1000,"encodeUtf8-cpu-arguments-slope":42921,"encodeUtf8-memory-arguments-intercept":4,"encodeUtf8-memory-arguments-slope":2,"equalsByteString-cpu-arguments-constant":24548,"equalsByteString-cpu-arguments-intercept":29498,"equalsByteString-cpu-arguments-slope":38,"equalsByteString-memory-arguments":1,"equalsData-cpu-arguments-intercept":898148,"equalsData-cpu-arguments-slope":27279,"equalsData-memory-arguments":1,"equalsInteger-cpu-arguments-intercept":51775,"equalsInteger-cpu-arguments-slope":558,"equalsInteger-memory-arguments":1,"equalsString-cpu-arguments-constant":39184,"equalsString-cpu-arguments-intercept":1000,"equalsString-cpu-arguments-slope":60594,"equalsString-memory-arguments":1,"fstPair-cpu-arguments":141895,"fstPair-memory-arguments":32,"headList-cpu-arguments":83150,"headList-memory-arguments":32,"iData-cpu-arguments":15299,"iData-memory-arguments":32,"ifThenElse-cpu-arguments":76049,"ifThenElse-memory-arguments":1,"indexByteString-cpu-arguments":13169,"indexByteString-memory-arguments":4,"lengthOfByteString-cpu-arguments":22100,"lengthOfByteString-memory-arguments":10,"lessThanByteString-cpu-arguments-intercept":28999,"lessThanByteString-cpu-arguments-slope":74,"lessThanByteString-memory-arguments":1,"lessThanEqualsByteString-cpu-arguments-intercept":28999,"lessThanEqualsByteString-cpu-arguments-slope":74,"lessThanEqualsByteString-memory-arguments":1,"lessThanEqualsInteger-cpu-arguments-intercept":43285,"lessThanEqualsInteger-cpu-arguments-slope":552,"lessThanEqualsInteger-memory-arguments":1,"lessThanInteger-cpu-arguments-intercept":44749,"lessThanInteger-cpu-arguments-slope":541,"lessThanInteger-memory-arguments":1,"listData-cpu-arguments":33852,"listData-memory-arguments":32,"mapData-cpu-arguments":68246,"mapData-memory-arguments":32,"mkCons-cpu-arguments":72362,"mkCons-memory-arguments":32,"mkNilData-cpu-arguments":7243,"mkNilData-memory-arguments":32,"mkNilPairData-cpu-arguments":7391,"mkNilPairData-memory-arguments":32,"mkPairData-cpu-arguments":11546,"mkPairData-memory-arguments":32,"modInteger-cpu-arguments-constant":85848,"modInteger-cpu-arguments-model-arguments-c00":123203,"modInteger-cpu-arguments-model-arguments-c01":7305,"modInteger-cpu-arguments-model-arguments-c02":-900,"modInteger-cpu-arguments-model-arguments-c10":1716,"modInteger-cpu-arguments-model-arguments-c11":549,"modInteger-cpu-arguments-model-arguments-c20":57,"modInteger-cpu-arguments-model-arguments-minimum":85848,"modInteger-memory-arguments-intercept":0,"modInteger-memory-arguments-slope":1,"multiplyInteger-cpu-arguments-intercept":90434,"multiplyInteger-cpu-arguments-slope":519,"multiplyInteger-memory-arguments-intercept":0,"multiplyInteger-memory-arguments-slope":1,"nullList-cpu-arguments":74433,"nullList-memory-arguments":32,"quotientInteger-cpu-arguments-constant":85848,"quotientInteger-cpu-arguments-model-arguments-c00":123203,"quotientInteger-cpu-arguments-model-arguments-c01":7305,"quotientInteger-cpu-arguments-model-arguments-c02":-900,"quotientInteger-cpu-arguments-model-arguments-c10":1716,"quotientInteger-cpu-arguments-model-arguments-c11":549,"quotientInteger-cpu-arguments-model-arguments-c20":57,"quotientInteger-cpu-arguments-model-arguments-minimum":85848,"quotientInteger-memory-arguments-intercept":0,"quotientInteger-memory-arguments-slope":1,"remainderInteger-cpu-arguments-constant":1,"remainderInteger-cpu-arguments-model-arguments-c00":85848,"remainderInteger-cpu-arguments-model-arguments-c01":123203,"remainderInteger-cpu-arguments-model-arguments-c02":7305,"remainderInteger-cpu-arguments-model-arguments-c10":-900,"remainderInteger-cpu-arguments-model-arguments-c11":1716,"remainderInteger-cpu-arguments-model-arguments-c20":549,"remainderInteger-cpu-arguments-model-arguments-minimum":57,"remainderInteger-memory-arguments-intercept":85848,"remainderInteger-memory-arguments-minimum":0,"remainderInteger-memory-arguments-slope":1,"serialiseData-cpu-arguments-intercept":955506,"serialiseData-cpu-arguments-slope":213312,"serialiseData-memory-arguments-intercept":0,"serialiseData-memory-arguments-slope":2,"sha2_256-cpu-arguments-intercept":270652,"sha2_256-cpu-arguments-slope":22588,"sha2_256-memory-arguments":4,"sha3_256-cpu-arguments-intercept":1457325,"sha3_256-cpu-arguments-slope":64566,"sha3_256-memory-arguments":4,"sliceByteString-cpu-arguments-intercept":20467,"sliceByteString-cpu-arguments-slope":1,"sliceByteString-memory-arguments-intercept":4,"sliceByteString-memory-arguments-slope":0,"sndPair-cpu-arguments":141992,"sndPair-memory-arguments":32,"subtractInteger-cpu-arguments-intercept":100788,"subtractInteger-cpu-arguments-slope":420,"subtractInteger-memory-arguments-intercept":1,"subtractInteger-memory-arguments-slope":1,"tailList-cpu-arguments":81663,"tailList-memory-arguments":32,"trace-cpu-arguments":59498,"trace-memory-arguments":32,"unBData-cpu-arguments":20142,"unBData-memory-arguments":32,"unConstrData-cpu-arguments":24588,"unConstrData-memory-arguments":32,"unIData-cpu-arguments":20744,"unIData-memory-arguments":32,"unListData-cpu-arguments":25933,"unListData-memory-arguments":32,"unMapData-cpu-arguments":24623,"unMapData-memory-arguments":32,"verifyEcdsaSecp256k1Signature-cpu-arguments":43053543,"verifyEcdsaSecp256k1Signature-memory-arguments":10,"verifyEd25519Signature-cpu-arguments-intercept":53384111,"verifyEd25519Signature-cpu-arguments-slope":14333,"verifyEd25519Signature-memory-arguments":10,"verifySchnorrSecp256k1Signature-cpu-arguments-intercept":43574283,"verifySchnorrSecp256k1Signature-cpu-arguments-slope":26308,"verifySchnorrSecp256k1Signature-memory-arguments":10,"cekConstrCost-exBudgetCPU":16000,"cekConstrCost-exBudgetMemory":100,"cekCaseCost-exBudgetCPU":16000,"cekCaseCost-exBudgetMemory":100,"bls12_381_G1_add-cpu-arguments":962335,"bls12_381_G1_add-memory-arguments":18,"bls12_381_G1_compress-cpu-arguments":2780678,"bls12_381_G1_compress-memory-arguments":6,"bls12_381_G1_equal-cpu-arguments":442008,"bls12_381_G1_equal-memory-arguments":1,"bls12_381_G1_hashToGroup-cpu-arguments-intercept":52538055,"bls12_381_G1_hashToGroup-cpu-arguments-slope":3756,"bls12_381_G1_hashToGroup-memory-arguments":18,"bls12_381_G1_neg-cpu-arguments":267929,"bls12_381_G1_neg-memory-arguments":18,"bls12_381_G1_scalarMul-cpu-arguments-intercept":76433006,"bls12_381_G1_scalarMul-cpu-arguments-slope":8868,"bls12_381_G1_scalarMul-memory-arguments":18,"bls12_381_G1_uncompress-cpu-arguments":52948122,"bls12_381_G1_uncompress-memory-arguments":18,"bls12_381_G2_add-cpu-arguments":1995836,"bls12_381_G2_add-memory-arguments":36,"bls12_381_G2_compress-cpu-arguments":3227919,"bls12_381_G2_compress-memory-arguments":12,"bls12_381_G2_equal-cpu-arguments":901022,"bls12_381_G2_equal-memory-arguments":1,"bls12_381_G2_hashToGroup-cpu-arguments-intercept":166917843,"bls12_381_G2_hashToGroup-cpu-arguments-slope":4307,"bls12_381_G2_hashToGroup-memory-arguments":36,"bls12_381_G2_neg-cpu-arguments":284546,"bls12_381_G2_neg-memory-arguments":36,"bls12_381_G2_scalarMul-cpu-arguments-intercept":158221314,"bls12_381_G2_scalarMul-cpu-arguments-slope":26549,"bls12_381_G2_scalarMul-memory-arguments":36,"bls12_381_G2_uncompress-cpu-arguments":74698472,"bls12_381_G2_uncompress-memory-arguments":36,"bls12_381_finalVerify-cpu-arguments":333849714,"bls12_381_finalVerify-memory-arguments":1,"bls12_381_millerLoop-cpu-arguments":254006273,"bls12_381_millerLoop-memory-arguments":72,"bls12_381_mulMlResult-cpu-arguments":2174038,"bls12_381_mulMlResult-memory-arguments":72,"keccak_256-cpu-arguments-intercept":2261318,"keccak_256-cpu-arguments-slope":64571,"keccak_256-memory-arguments":4,"blake2b_224-cpu-arguments-intercept":207616,"blake2b_224-cpu-arguments-slope":8310,"blake2b_224-memory-arguments":4,"integerToByteString-cpu-arguments-c0":1293828,"integerToByteString-cpu-arguments-c1":28716,"integerToByteString-cpu-arguments-c2":63,"integerToByteString-memory-arguments-intercept":0,"integerToByteString-memory-arguments-slope":1,"byteStringToInteger-cpu-arguments-c0":1006041,"byteStringToInteger-cpu-arguments-c1":43623,"byteStringToInteger-cpu-arguments-c2":251,"byteStringToInteger-memory-arguments-intercept":0,"byteStringToInteger-memory-arguments-slope":1}},"price_mem":0.0577,"price_step":0.0000721,"max_tx_ex_mem":"14000000","max_tx_ex_steps":"10000000000","max_block_ex_mem":"62000000","max_block_ex_steps":"20000000000","max_val_size":"5000","collateral_percent":150,"max_collateral_inputs":3,"coins_per_utxo_size":"4310","coins_per_utxo_word":"4310","pvt_motion_no_confidence":0.51,"pvt_committee_normal":0.51,"pvt_committee_no_confidence":0.51,"pvt_hard_fork_initiation":0.51,"dvt_motion_no_confidence":0.67,"dvt_committee_normal":0.67,"dvt_committee_no_confidence":0.6,"dvt_update_to_constitution":0.75,"dvt_hard_fork_initiation":0.6,"dvt_p_p_network_group":0.67,"dvt_p_p_economic_group":0.67,"dvt_p_p_technical_group":0.67,"dvt_p_p_gov_group":0.75,"dvt_treasury_withdrawal":0.67,"committee_min_size":"7","committee_max_term_length":"146","gov_action_lifetime":"6","gov_action_deposit":"100000000000","drep_deposit":"500000000","drep_activity":"20","pvtpp_security_group":0.51,"min_fee_ref_script_cost_per_byte":15} \ No newline at end of file diff --git a/fixtures/test/blockfrost/getProtocolParameters-preview/getProtocolParameters-preview-659470119e7874ecf112dd05db4b691d.json b/fixtures/test/blockfrost/getProtocolParameters-preview/getProtocolParameters-preview-659470119e7874ecf112dd05db4b691d.json new file mode 100644 index 0000000000..67401a37eb --- /dev/null +++ b/fixtures/test/blockfrost/getProtocolParameters-preview/getProtocolParameters-preview-659470119e7874ecf112dd05db4b691d.json @@ -0,0 +1 @@ +{"epoch":680,"min_fee_a":44,"min_fee_b":155381,"max_block_size":90112,"max_tx_size":16384,"max_block_header_size":1100,"key_deposit":"2000000","pool_deposit":"500000000","e_max":18,"n_opt":500,"a0":0.3,"rho":0.003,"tau":0.2,"decentralisation_param":0,"extra_entropy":null,"protocol_major_ver":9,"protocol_minor_ver":0,"min_utxo":"4310","min_pool_cost":"170000000","nonce":"70583fd9f87fefb17ab2ca61fad8cbce23c9d99f173567de8cfb7df6dd7475bf","cost_models":{"PlutusV1":{"addInteger-cpu-arguments-intercept":100788,"addInteger-cpu-arguments-slope":420,"addInteger-memory-arguments-intercept":1,"addInteger-memory-arguments-slope":1,"appendByteString-cpu-arguments-intercept":1000,"appendByteString-cpu-arguments-slope":173,"appendByteString-memory-arguments-intercept":0,"appendByteString-memory-arguments-slope":1,"appendString-cpu-arguments-intercept":1000,"appendString-cpu-arguments-slope":59957,"appendString-memory-arguments-intercept":4,"appendString-memory-arguments-slope":1,"bData-cpu-arguments":11183,"bData-memory-arguments":32,"blake2b_256-cpu-arguments-intercept":201305,"blake2b_256-cpu-arguments-slope":8356,"blake2b_256-memory-arguments":4,"cekApplyCost-exBudgetCPU":16000,"cekApplyCost-exBudgetMemory":100,"cekBuiltinCost-exBudgetCPU":16000,"cekBuiltinCost-exBudgetMemory":100,"cekConstCost-exBudgetCPU":16000,"cekConstCost-exBudgetMemory":100,"cekDelayCost-exBudgetCPU":16000,"cekDelayCost-exBudgetMemory":100,"cekForceCost-exBudgetCPU":16000,"cekForceCost-exBudgetMemory":100,"cekLamCost-exBudgetCPU":16000,"cekLamCost-exBudgetMemory":100,"cekStartupCost-exBudgetCPU":100,"cekStartupCost-exBudgetMemory":100,"cekVarCost-exBudgetCPU":16000,"cekVarCost-exBudgetMemory":100,"chooseData-cpu-arguments":94375,"chooseData-memory-arguments":32,"chooseList-cpu-arguments":132994,"chooseList-memory-arguments":32,"chooseUnit-cpu-arguments":61462,"chooseUnit-memory-arguments":4,"consByteString-cpu-arguments-intercept":72010,"consByteString-cpu-arguments-slope":178,"consByteString-memory-arguments-intercept":0,"consByteString-memory-arguments-slope":1,"constrData-cpu-arguments":22151,"constrData-memory-arguments":32,"decodeUtf8-cpu-arguments-intercept":91189,"decodeUtf8-cpu-arguments-slope":769,"decodeUtf8-memory-arguments-intercept":4,"decodeUtf8-memory-arguments-slope":2,"divideInteger-cpu-arguments-constant":85848,"divideInteger-cpu-arguments-model-arguments-intercept":228465,"divideInteger-cpu-arguments-model-arguments-slope":122,"divideInteger-memory-arguments-intercept":0,"divideInteger-memory-arguments-minimum":1,"divideInteger-memory-arguments-slope":1,"encodeUtf8-cpu-arguments-intercept":1000,"encodeUtf8-cpu-arguments-slope":42921,"encodeUtf8-memory-arguments-intercept":4,"encodeUtf8-memory-arguments-slope":2,"equalsByteString-cpu-arguments-constant":24548,"equalsByteString-cpu-arguments-intercept":29498,"equalsByteString-cpu-arguments-slope":38,"equalsByteString-memory-arguments":1,"equalsData-cpu-arguments-intercept":898148,"equalsData-cpu-arguments-slope":27279,"equalsData-memory-arguments":1,"equalsInteger-cpu-arguments-intercept":51775,"equalsInteger-cpu-arguments-slope":558,"equalsInteger-memory-arguments":1,"equalsString-cpu-arguments-constant":39184,"equalsString-cpu-arguments-intercept":1000,"equalsString-cpu-arguments-slope":60594,"equalsString-memory-arguments":1,"fstPair-cpu-arguments":141895,"fstPair-memory-arguments":32,"headList-cpu-arguments":83150,"headList-memory-arguments":32,"iData-cpu-arguments":15299,"iData-memory-arguments":32,"ifThenElse-cpu-arguments":76049,"ifThenElse-memory-arguments":1,"indexByteString-cpu-arguments":13169,"indexByteString-memory-arguments":4,"lengthOfByteString-cpu-arguments":22100,"lengthOfByteString-memory-arguments":10,"lessThanByteString-cpu-arguments-intercept":28999,"lessThanByteString-cpu-arguments-slope":74,"lessThanByteString-memory-arguments":1,"lessThanEqualsByteString-cpu-arguments-intercept":28999,"lessThanEqualsByteString-cpu-arguments-slope":74,"lessThanEqualsByteString-memory-arguments":1,"lessThanEqualsInteger-cpu-arguments-intercept":43285,"lessThanEqualsInteger-cpu-arguments-slope":552,"lessThanEqualsInteger-memory-arguments":1,"lessThanInteger-cpu-arguments-intercept":44749,"lessThanInteger-cpu-arguments-slope":541,"lessThanInteger-memory-arguments":1,"listData-cpu-arguments":33852,"listData-memory-arguments":32,"mapData-cpu-arguments":68246,"mapData-memory-arguments":32,"mkCons-cpu-arguments":72362,"mkCons-memory-arguments":32,"mkNilData-cpu-arguments":7243,"mkNilData-memory-arguments":32,"mkNilPairData-cpu-arguments":7391,"mkNilPairData-memory-arguments":32,"mkPairData-cpu-arguments":11546,"mkPairData-memory-arguments":32,"modInteger-cpu-arguments-constant":85848,"modInteger-cpu-arguments-model-arguments-intercept":228465,"modInteger-cpu-arguments-model-arguments-slope":122,"modInteger-memory-arguments-intercept":0,"modInteger-memory-arguments-minimum":1,"modInteger-memory-arguments-slope":1,"multiplyInteger-cpu-arguments-intercept":90434,"multiplyInteger-cpu-arguments-slope":519,"multiplyInteger-memory-arguments-intercept":0,"multiplyInteger-memory-arguments-slope":1,"nullList-cpu-arguments":74433,"nullList-memory-arguments":32,"quotientInteger-cpu-arguments-constant":85848,"quotientInteger-cpu-arguments-model-arguments-intercept":228465,"quotientInteger-cpu-arguments-model-arguments-slope":122,"quotientInteger-memory-arguments-intercept":0,"quotientInteger-memory-arguments-minimum":1,"quotientInteger-memory-arguments-slope":1,"remainderInteger-cpu-arguments-constant":85848,"remainderInteger-cpu-arguments-model-arguments-intercept":228465,"remainderInteger-cpu-arguments-model-arguments-slope":122,"remainderInteger-memory-arguments-intercept":0,"remainderInteger-memory-arguments-minimum":1,"remainderInteger-memory-arguments-slope":1,"sha2_256-cpu-arguments-intercept":270652,"sha2_256-cpu-arguments-slope":22588,"sha2_256-memory-arguments":4,"sha3_256-cpu-arguments-intercept":1457325,"sha3_256-cpu-arguments-slope":64566,"sha3_256-memory-arguments":4,"sliceByteString-cpu-arguments-intercept":20467,"sliceByteString-cpu-arguments-slope":1,"sliceByteString-memory-arguments-intercept":4,"sliceByteString-memory-arguments-slope":0,"sndPair-cpu-arguments":141992,"sndPair-memory-arguments":32,"subtractInteger-cpu-arguments-intercept":100788,"subtractInteger-cpu-arguments-slope":420,"subtractInteger-memory-arguments-intercept":1,"subtractInteger-memory-arguments-slope":1,"tailList-cpu-arguments":81663,"tailList-memory-arguments":32,"trace-cpu-arguments":59498,"trace-memory-arguments":32,"unBData-cpu-arguments":20142,"unBData-memory-arguments":32,"unConstrData-cpu-arguments":24588,"unConstrData-memory-arguments":32,"unIData-cpu-arguments":20744,"unIData-memory-arguments":32,"unListData-cpu-arguments":25933,"unListData-memory-arguments":32,"unMapData-cpu-arguments":24623,"unMapData-memory-arguments":32,"verifyEd25519Signature-cpu-arguments-intercept":53384111,"verifyEd25519Signature-cpu-arguments-slope":14333,"verifyEd25519Signature-memory-arguments":10},"PlutusV2":{"addInteger-cpu-arguments-intercept":100788,"addInteger-cpu-arguments-slope":420,"addInteger-memory-arguments-intercept":1,"addInteger-memory-arguments-slope":1,"appendByteString-cpu-arguments-intercept":1000,"appendByteString-cpu-arguments-slope":173,"appendByteString-memory-arguments-intercept":0,"appendByteString-memory-arguments-slope":1,"appendString-cpu-arguments-intercept":1000,"appendString-cpu-arguments-slope":59957,"appendString-memory-arguments-intercept":4,"appendString-memory-arguments-slope":1,"bData-cpu-arguments":11183,"bData-memory-arguments":32,"blake2b_256-cpu-arguments-intercept":201305,"blake2b_256-cpu-arguments-slope":8356,"blake2b_256-memory-arguments":4,"cekApplyCost-exBudgetCPU":16000,"cekApplyCost-exBudgetMemory":100,"cekBuiltinCost-exBudgetCPU":16000,"cekBuiltinCost-exBudgetMemory":100,"cekConstCost-exBudgetCPU":16000,"cekConstCost-exBudgetMemory":100,"cekDelayCost-exBudgetCPU":16000,"cekDelayCost-exBudgetMemory":100,"cekForceCost-exBudgetCPU":16000,"cekForceCost-exBudgetMemory":100,"cekLamCost-exBudgetCPU":16000,"cekLamCost-exBudgetMemory":100,"cekStartupCost-exBudgetCPU":100,"cekStartupCost-exBudgetMemory":100,"cekVarCost-exBudgetCPU":16000,"cekVarCost-exBudgetMemory":100,"chooseData-cpu-arguments":94375,"chooseData-memory-arguments":32,"chooseList-cpu-arguments":132994,"chooseList-memory-arguments":32,"chooseUnit-cpu-arguments":61462,"chooseUnit-memory-arguments":4,"consByteString-cpu-arguments-intercept":72010,"consByteString-cpu-arguments-slope":178,"consByteString-memory-arguments-intercept":0,"consByteString-memory-arguments-slope":1,"constrData-cpu-arguments":22151,"constrData-memory-arguments":32,"decodeUtf8-cpu-arguments-intercept":91189,"decodeUtf8-cpu-arguments-slope":769,"decodeUtf8-memory-arguments-intercept":4,"decodeUtf8-memory-arguments-slope":2,"divideInteger-cpu-arguments-constant":85848,"divideInteger-cpu-arguments-model-arguments-intercept":228465,"divideInteger-cpu-arguments-model-arguments-slope":122,"divideInteger-memory-arguments-intercept":0,"divideInteger-memory-arguments-minimum":1,"divideInteger-memory-arguments-slope":1,"encodeUtf8-cpu-arguments-intercept":1000,"encodeUtf8-cpu-arguments-slope":42921,"encodeUtf8-memory-arguments-intercept":4,"encodeUtf8-memory-arguments-slope":2,"equalsByteString-cpu-arguments-constant":24548,"equalsByteString-cpu-arguments-intercept":29498,"equalsByteString-cpu-arguments-slope":38,"equalsByteString-memory-arguments":1,"equalsData-cpu-arguments-intercept":898148,"equalsData-cpu-arguments-slope":27279,"equalsData-memory-arguments":1,"equalsInteger-cpu-arguments-intercept":51775,"equalsInteger-cpu-arguments-slope":558,"equalsInteger-memory-arguments":1,"equalsString-cpu-arguments-constant":39184,"equalsString-cpu-arguments-intercept":1000,"equalsString-cpu-arguments-slope":60594,"equalsString-memory-arguments":1,"fstPair-cpu-arguments":141895,"fstPair-memory-arguments":32,"headList-cpu-arguments":83150,"headList-memory-arguments":32,"iData-cpu-arguments":15299,"iData-memory-arguments":32,"ifThenElse-cpu-arguments":76049,"ifThenElse-memory-arguments":1,"indexByteString-cpu-arguments":13169,"indexByteString-memory-arguments":4,"lengthOfByteString-cpu-arguments":22100,"lengthOfByteString-memory-arguments":10,"lessThanByteString-cpu-arguments-intercept":28999,"lessThanByteString-cpu-arguments-slope":74,"lessThanByteString-memory-arguments":1,"lessThanEqualsByteString-cpu-arguments-intercept":28999,"lessThanEqualsByteString-cpu-arguments-slope":74,"lessThanEqualsByteString-memory-arguments":1,"lessThanEqualsInteger-cpu-arguments-intercept":43285,"lessThanEqualsInteger-cpu-arguments-slope":552,"lessThanEqualsInteger-memory-arguments":1,"lessThanInteger-cpu-arguments-intercept":44749,"lessThanInteger-cpu-arguments-slope":541,"lessThanInteger-memory-arguments":1,"listData-cpu-arguments":33852,"listData-memory-arguments":32,"mapData-cpu-arguments":68246,"mapData-memory-arguments":32,"mkCons-cpu-arguments":72362,"mkCons-memory-arguments":32,"mkNilData-cpu-arguments":7243,"mkNilData-memory-arguments":32,"mkNilPairData-cpu-arguments":7391,"mkNilPairData-memory-arguments":32,"mkPairData-cpu-arguments":11546,"mkPairData-memory-arguments":32,"modInteger-cpu-arguments-constant":85848,"modInteger-cpu-arguments-model-arguments-intercept":228465,"modInteger-cpu-arguments-model-arguments-slope":122,"modInteger-memory-arguments-intercept":0,"modInteger-memory-arguments-minimum":1,"modInteger-memory-arguments-slope":1,"multiplyInteger-cpu-arguments-intercept":90434,"multiplyInteger-cpu-arguments-slope":519,"multiplyInteger-memory-arguments-intercept":0,"multiplyInteger-memory-arguments-slope":1,"nullList-cpu-arguments":74433,"nullList-memory-arguments":32,"quotientInteger-cpu-arguments-constant":85848,"quotientInteger-cpu-arguments-model-arguments-intercept":228465,"quotientInteger-cpu-arguments-model-arguments-slope":122,"quotientInteger-memory-arguments-intercept":0,"quotientInteger-memory-arguments-minimum":1,"quotientInteger-memory-arguments-slope":1,"remainderInteger-cpu-arguments-constant":85848,"remainderInteger-cpu-arguments-model-arguments-intercept":228465,"remainderInteger-cpu-arguments-model-arguments-slope":122,"remainderInteger-memory-arguments-intercept":0,"remainderInteger-memory-arguments-minimum":1,"remainderInteger-memory-arguments-slope":1,"serialiseData-cpu-arguments-intercept":955506,"serialiseData-cpu-arguments-slope":213312,"serialiseData-memory-arguments-intercept":0,"serialiseData-memory-arguments-slope":2,"sha2_256-cpu-arguments-intercept":270652,"sha2_256-cpu-arguments-slope":22588,"sha2_256-memory-arguments":4,"sha3_256-cpu-arguments-intercept":1457325,"sha3_256-cpu-arguments-slope":64566,"sha3_256-memory-arguments":4,"sliceByteString-cpu-arguments-intercept":20467,"sliceByteString-cpu-arguments-slope":1,"sliceByteString-memory-arguments-intercept":4,"sliceByteString-memory-arguments-slope":0,"sndPair-cpu-arguments":141992,"sndPair-memory-arguments":32,"subtractInteger-cpu-arguments-intercept":100788,"subtractInteger-cpu-arguments-slope":420,"subtractInteger-memory-arguments-intercept":1,"subtractInteger-memory-arguments-slope":1,"tailList-cpu-arguments":81663,"tailList-memory-arguments":32,"trace-cpu-arguments":59498,"trace-memory-arguments":32,"unBData-cpu-arguments":20142,"unBData-memory-arguments":32,"unConstrData-cpu-arguments":24588,"unConstrData-memory-arguments":32,"unIData-cpu-arguments":20744,"unIData-memory-arguments":32,"unListData-cpu-arguments":25933,"unListData-memory-arguments":32,"unMapData-cpu-arguments":24623,"unMapData-memory-arguments":32,"verifyEcdsaSecp256k1Signature-cpu-arguments":43053543,"verifyEcdsaSecp256k1Signature-memory-arguments":10,"verifyEd25519Signature-cpu-arguments-intercept":53384111,"verifyEd25519Signature-cpu-arguments-slope":14333,"verifyEd25519Signature-memory-arguments":10,"verifySchnorrSecp256k1Signature-cpu-arguments-intercept":43574283,"verifySchnorrSecp256k1Signature-cpu-arguments-slope":26308,"verifySchnorrSecp256k1Signature-memory-arguments":10},"PlutusV3":{"0":100788,"1":420,"2":1,"3":1,"4":1000,"5":173,"6":0,"7":1,"8":1000,"9":59957,"10":4,"11":1,"12":11183,"13":32,"14":201305,"15":8356,"16":4,"17":16000,"18":100,"19":16000,"20":100,"21":16000,"22":100,"23":16000,"24":100,"25":16000,"26":100,"27":16000,"28":100,"29":100,"30":100,"31":16000,"32":100,"33":94375,"34":32,"35":132994,"36":32,"37":61462,"38":4,"39":72010,"40":178,"41":0,"42":1,"43":22151,"44":32,"45":91189,"46":769,"47":4,"48":2,"49":85848,"50":123203,"51":7305,"52":-900,"53":1716,"54":549,"55":57,"56":85848,"57":0,"58":1,"59":1,"60":1000,"61":42921,"62":4,"63":2,"64":24548,"65":29498,"66":38,"67":1,"68":898148,"69":27279,"70":1,"71":51775,"72":558,"73":1,"74":39184,"75":1000,"76":60594,"77":1,"78":141895,"79":32,"80":83150,"81":32,"82":15299,"83":32,"84":76049,"85":1,"86":13169,"87":4,"88":22100,"89":10,"90":28999,"91":74,"92":1,"93":28999,"94":74,"95":1,"96":43285,"97":552,"98":1,"99":44749,"100":541,"101":1,"102":33852,"103":32,"104":68246,"105":32,"106":72362,"107":32,"108":7243,"109":32,"110":7391,"111":32,"112":11546,"113":32,"114":85848,"115":123203,"116":7305,"117":-900,"118":1716,"119":549,"120":57,"121":85848,"122":0,"123":1,"124":90434,"125":519,"126":0,"127":1,"128":74433,"129":32,"130":85848,"131":123203,"132":7305,"133":-900,"134":1716,"135":549,"136":57,"137":85848,"138":0,"139":1,"140":1,"141":85848,"142":123203,"143":7305,"144":-900,"145":1716,"146":549,"147":57,"148":85848,"149":0,"150":1,"151":955506,"152":213312,"153":0,"154":2,"155":270652,"156":22588,"157":4,"158":1457325,"159":64566,"160":4,"161":20467,"162":1,"163":4,"164":0,"165":141992,"166":32,"167":100788,"168":420,"169":1,"170":1,"171":81663,"172":32,"173":59498,"174":32,"175":20142,"176":32,"177":24588,"178":32,"179":20744,"180":32,"181":25933,"182":32,"183":24623,"184":32,"185":43053543,"186":10,"187":53384111,"188":14333,"189":10,"190":43574283,"191":26308,"192":10,"193":16000,"194":100,"195":16000,"196":100,"197":962335,"198":18,"199":2780678,"200":6,"201":442008,"202":1,"203":52538055,"204":3756,"205":18,"206":267929,"207":18,"208":76433006,"209":8868,"210":18,"211":52948122,"212":18,"213":1995836,"214":36,"215":3227919,"216":12,"217":901022,"218":1,"219":166917843,"220":4307,"221":36,"222":284546,"223":36,"224":158221314,"225":26549,"226":36,"227":74698472,"228":36,"229":333849714,"230":1,"231":254006273,"232":72,"233":2174038,"234":72,"235":2261318,"236":64571,"237":4,"238":207616,"239":8310,"240":4,"241":1293828,"242":28716,"243":63,"244":0,"245":1,"246":1006041,"247":43623,"248":251,"249":0,"250":1}},"price_mem":0.0577,"price_step":0.0000721,"max_tx_ex_mem":"14000000","max_tx_ex_steps":"10000000000","max_block_ex_mem":"62000000","max_block_ex_steps":"20000000000","max_val_size":"5000","collateral_percent":150,"max_collateral_inputs":3,"coins_per_utxo_size":"4310","coins_per_utxo_word":"4310","pvt_motion_no_confidence":0.51,"pvt_committee_normal":0.51,"pvt_committee_no_confidence":0.51,"pvt_hard_fork_initiation":0.51,"dvt_motion_no_confidence":0.67,"dvt_committee_normal":0.67,"dvt_committee_no_confidence":0.6,"dvt_update_to_constitution":0.75,"dvt_hard_fork_initiation":0.6,"dvt_p_p_network_group":0.67,"dvt_p_p_economic_group":0.67,"dvt_p_p_technical_group":0.67,"dvt_p_p_gov_group":0.75,"dvt_treasury_withdrawal":0.67,"committee_min_size":"0","committee_max_term_length":"365","gov_action_lifetime":"30","gov_action_deposit":"100000000000","drep_deposit":"500000000","drep_activity":"20","pvtpp_security_group":0.51,"min_fee_ref_script_cost_per_byte":15} \ No newline at end of file diff --git a/fixtures/test/ogmios/queryLedgerState-protocolParameters-preprod-aaa9a3fbcf526a678489845a2de49600.json b/fixtures/test/ogmios/queryLedgerState-protocolParameters-preprod-aaa9a3fbcf526a678489845a2de49600.json new file mode 100644 index 0000000000..d3c5acb4af --- /dev/null +++ b/fixtures/test/ogmios/queryLedgerState-protocolParameters-preprod-aaa9a3fbcf526a678489845a2de49600.json @@ -0,0 +1 @@ +{"jsonrpc":"2.0","method":"queryLedgerState/protocolParameters","result":{"minFeeCoefficient":44,"minFeeConstant":{"ada":{"lovelace":155381}},"minFeeReferenceScripts":{"base":15,"range":25600,"multiplier":1.2},"maxBlockBodySize":{"bytes":90112},"maxBlockHeaderSize":{"bytes":1100},"maxTransactionSize":{"bytes":16384},"maxReferenceScriptsSize":{"bytes":204800},"stakeCredentialDeposit":{"ada":{"lovelace":2000000}},"stakePoolDeposit":{"ada":{"lovelace":500000000}},"stakePoolRetirementEpochBound":18,"desiredNumberOfStakePools":500,"stakePoolPledgeInfluence":"3/10","monetaryExpansion":"3/1000","treasuryExpansion":"1/5","minStakePoolCost":{"ada":{"lovelace":170000000}},"minUtxoDepositConstant":{"ada":{"lovelace":0}},"minUtxoDepositCoefficient":4310,"plutusCostModels":{"plutus:v1":[100788,420,1,1,1000,173,0,1,1000,59957,4,1,11183,32,201305,8356,4,16000,100,16000,100,16000,100,16000,100,16000,100,16000,100,100,100,16000,100,94375,32,132994,32,61462,4,72010,178,0,1,22151,32,91189,769,4,2,85848,228465,122,0,1,1,1000,42921,4,2,24548,29498,38,1,898148,27279,1,51775,558,1,39184,1000,60594,1,141895,32,83150,32,15299,32,76049,1,13169,4,22100,10,28999,74,1,28999,74,1,43285,552,1,44749,541,1,33852,32,68246,32,72362,32,7243,32,7391,32,11546,32,85848,228465,122,0,1,1,90434,519,0,1,74433,32,85848,228465,122,0,1,1,85848,228465,122,0,1,1,270652,22588,4,1457325,64566,4,20467,1,4,0,141992,32,100788,420,1,1,81663,32,59498,32,20142,32,24588,32,20744,32,25933,32,24623,32,53384111,14333,10],"plutus:v2":[100788,420,1,1,1000,173,0,1,1000,59957,4,1,11183,32,201305,8356,4,16000,100,16000,100,16000,100,16000,100,16000,100,16000,100,100,100,16000,100,94375,32,132994,32,61462,4,72010,178,0,1,22151,32,91189,769,4,2,85848,228465,122,0,1,1,1000,42921,4,2,24548,29498,38,1,898148,27279,1,51775,558,1,39184,1000,60594,1,141895,32,83150,32,15299,32,76049,1,13169,4,22100,10,28999,74,1,28999,74,1,43285,552,1,44749,541,1,33852,32,68246,32,72362,32,7243,32,7391,32,11546,32,85848,228465,122,0,1,1,90434,519,0,1,74433,32,85848,228465,122,0,1,1,85848,228465,122,0,1,1,955506,213312,0,2,270652,22588,4,1457325,64566,4,20467,1,4,0,141992,32,100788,420,1,1,81663,32,59498,32,20142,32,24588,32,20744,32,25933,32,24623,32,43053543,10,53384111,14333,10,43574283,26308,10],"plutus:v3":[100788,420,1,1,1000,173,0,1,1000,59957,4,1,11183,32,201305,8356,4,16000,100,16000,100,16000,100,16000,100,16000,100,16000,100,100,100,16000,100,94375,32,132994,32,61462,4,72010,178,0,1,22151,32,91189,769,4,2,85848,123203,7305,-900,1716,549,57,85848,0,1,1,1000,42921,4,2,24548,29498,38,1,898148,27279,1,51775,558,1,39184,1000,60594,1,141895,32,83150,32,15299,32,76049,1,13169,4,22100,10,28999,74,1,28999,74,1,43285,552,1,44749,541,1,33852,32,68246,32,72362,32,7243,32,7391,32,11546,32,85848,123203,7305,-900,1716,549,57,85848,0,1,90434,519,0,1,74433,32,85848,123203,7305,-900,1716,549,57,85848,0,1,1,85848,123203,7305,-900,1716,549,57,85848,0,1,955506,213312,0,2,270652,22588,4,1457325,64566,4,20467,1,4,0,141992,32,100788,420,1,1,81663,32,59498,32,20142,32,24588,32,20744,32,25933,32,24623,32,43053543,10,53384111,14333,10,43574283,26308,10,16000,100,16000,100,962335,18,2780678,6,442008,1,52538055,3756,18,267929,18,76433006,8868,18,52948122,18,1995836,36,3227919,12,901022,1,166917843,4307,36,284546,36,158221314,26549,36,74698472,36,333849714,1,254006273,72,2174038,72,2261318,64571,4,207616,8310,4,1293828,28716,63,0,1,1006041,43623,251,0,1]},"scriptExecutionPrices":{"memory":"577/10000","cpu":"721/10000000"},"maxExecutionUnitsPerTransaction":{"memory":14000000,"cpu":10000000000},"maxExecutionUnitsPerBlock":{"memory":62000000,"cpu":20000000000},"maxValueSize":{"bytes":5000},"collateralPercentage":150,"maxCollateralInputs":3,"version":{"major":9,"minor":0},"stakePoolVotingThresholds":{"noConfidence":"51/100","constitutionalCommittee":{"default":"51/100","stateOfNoConfidence":"51/100"},"hardForkInitiation":"51/100"},"delegateRepresentativeVotingThresholds":{"noConfidence":"67/100","constitutionalCommittee":{"default":"67/100","stateOfNoConfidence":"3/5"},"constitution":"3/4","hardForkInitiation":"3/5","protocolParametersUpdate":{"network":"67/100","economic":"67/100","technical":"67/100","governance":"3/4"},"treasuryWithdrawals":"67/100"},"constitutionalCommitteeMinSize":7,"constitutionalCommitteeMaxTermLength":146,"governanceActionLifetime":6,"governanceActionDeposit":{"ada":{"lovelace":100000000000}},"delegateRepresentativeDeposit":{"ada":{"lovelace":500000000}},"delegateRepresentativeMaxIdleTime":20},"id":"queryLedgerState/protocolParameters-hfkgab9xm0nxky8u"} diff --git a/fixtures/test/ogmios/queryLedgerState-protocolParameters-preview-256d19f15eb1f722b0b66b25d20961b8.json b/fixtures/test/ogmios/queryLedgerState-protocolParameters-preview-256d19f15eb1f722b0b66b25d20961b8.json new file mode 100644 index 0000000000..9531f27118 --- /dev/null +++ b/fixtures/test/ogmios/queryLedgerState-protocolParameters-preview-256d19f15eb1f722b0b66b25d20961b8.json @@ -0,0 +1 @@ +{"jsonrpc":"2.0","method":"queryLedgerState/protocolParameters","result":{"minFeeCoefficient":44,"minFeeConstant":{"ada":{"lovelace":155381}},"minFeeReferenceScripts":{"base":15,"range":25600,"multiplier":1.2},"maxBlockBodySize":{"bytes":90112},"maxBlockHeaderSize":{"bytes":1100},"maxTransactionSize":{"bytes":16384},"maxReferenceScriptsSize":{"bytes":204800},"stakeCredentialDeposit":{"ada":{"lovelace":2000000}},"stakePoolDeposit":{"ada":{"lovelace":500000000}},"stakePoolRetirementEpochBound":18,"desiredNumberOfStakePools":500,"stakePoolPledgeInfluence":"3/10","monetaryExpansion":"3/1000","treasuryExpansion":"1/5","minStakePoolCost":{"ada":{"lovelace":170000000}},"minUtxoDepositConstant":{"ada":{"lovelace":0}},"minUtxoDepositCoefficient":4310,"plutusCostModels":{"plutus:v1":[100788,420,1,1,1000,173,0,1,1000,59957,4,1,11183,32,201305,8356,4,16000,100,16000,100,16000,100,16000,100,16000,100,16000,100,100,100,16000,100,94375,32,132994,32,61462,4,72010,178,0,1,22151,32,91189,769,4,2,85848,228465,122,0,1,1,1000,42921,4,2,24548,29498,38,1,898148,27279,1,51775,558,1,39184,1000,60594,1,141895,32,83150,32,15299,32,76049,1,13169,4,22100,10,28999,74,1,28999,74,1,43285,552,1,44749,541,1,33852,32,68246,32,72362,32,7243,32,7391,32,11546,32,85848,228465,122,0,1,1,90434,519,0,1,74433,32,85848,228465,122,0,1,1,85848,228465,122,0,1,1,270652,22588,4,1457325,64566,4,20467,1,4,0,141992,32,100788,420,1,1,81663,32,59498,32,20142,32,24588,32,20744,32,25933,32,24623,32,53384111,14333,10],"plutus:v2":[100788,420,1,1,1000,173,0,1,1000,59957,4,1,11183,32,201305,8356,4,16000,100,16000,100,16000,100,16000,100,16000,100,16000,100,100,100,16000,100,94375,32,132994,32,61462,4,72010,178,0,1,22151,32,91189,769,4,2,85848,228465,122,0,1,1,1000,42921,4,2,24548,29498,38,1,898148,27279,1,51775,558,1,39184,1000,60594,1,141895,32,83150,32,15299,32,76049,1,13169,4,22100,10,28999,74,1,28999,74,1,43285,552,1,44749,541,1,33852,32,68246,32,72362,32,7243,32,7391,32,11546,32,85848,228465,122,0,1,1,90434,519,0,1,74433,32,85848,228465,122,0,1,1,85848,228465,122,0,1,1,955506,213312,0,2,270652,22588,4,1457325,64566,4,20467,1,4,0,141992,32,100788,420,1,1,81663,32,59498,32,20142,32,24588,32,20744,32,25933,32,24623,32,43053543,10,53384111,14333,10,43574283,26308,10],"plutus:v3":[100788,420,1,1,1000,173,0,1,1000,59957,4,1,11183,32,201305,8356,4,16000,100,16000,100,16000,100,16000,100,16000,100,16000,100,100,100,16000,100,94375,32,132994,32,61462,4,72010,178,0,1,22151,32,91189,769,4,2,85848,123203,7305,-900,1716,549,57,85848,0,1,1,1000,42921,4,2,24548,29498,38,1,898148,27279,1,51775,558,1,39184,1000,60594,1,141895,32,83150,32,15299,32,76049,1,13169,4,22100,10,28999,74,1,28999,74,1,43285,552,1,44749,541,1,33852,32,68246,32,72362,32,7243,32,7391,32,11546,32,85848,123203,7305,-900,1716,549,57,85848,0,1,90434,519,0,1,74433,32,85848,123203,7305,-900,1716,549,57,85848,0,1,1,85848,123203,7305,-900,1716,549,57,85848,0,1,955506,213312,0,2,270652,22588,4,1457325,64566,4,20467,1,4,0,141992,32,100788,420,1,1,81663,32,59498,32,20142,32,24588,32,20744,32,25933,32,24623,32,43053543,10,53384111,14333,10,43574283,26308,10,16000,100,16000,100,962335,18,2780678,6,442008,1,52538055,3756,18,267929,18,76433006,8868,18,52948122,18,1995836,36,3227919,12,901022,1,166917843,4307,36,284546,36,158221314,26549,36,74698472,36,333849714,1,254006273,72,2174038,72,2261318,64571,4,207616,8310,4,1293828,28716,63,0,1,1006041,43623,251,0,1]},"scriptExecutionPrices":{"memory":"577/10000","cpu":"721/10000000"},"maxExecutionUnitsPerTransaction":{"memory":14000000,"cpu":10000000000},"maxExecutionUnitsPerBlock":{"memory":62000000,"cpu":20000000000},"maxValueSize":{"bytes":5000},"collateralPercentage":150,"maxCollateralInputs":3,"version":{"major":9,"minor":0},"stakePoolVotingThresholds":{"noConfidence":"51/100","constitutionalCommittee":{"default":"51/100","stateOfNoConfidence":"51/100"},"hardForkInitiation":"51/100"},"delegateRepresentativeVotingThresholds":{"noConfidence":"67/100","constitutionalCommittee":{"default":"67/100","stateOfNoConfidence":"3/5"},"constitution":"3/4","hardForkInitiation":"3/5","protocolParametersUpdate":{"network":"67/100","economic":"67/100","technical":"67/100","governance":"3/4"},"treasuryWithdrawals":"67/100"},"constitutionalCommitteeMinSize":0,"constitutionalCommitteeMaxTermLength":365,"governanceActionLifetime":30,"governanceActionDeposit":{"ada":{"lovelace":100000000000}},"delegateRepresentativeDeposit":{"ada":{"lovelace":500000000}},"delegateRepresentativeMaxIdleTime":20},"id":"queryLedgerState/protocolParameters-hfkg7bmym0nw5eup"} diff --git a/spago.dhall b/spago.dhall index dd58114a56..0407bf0f7b 100644 --- a/spago.dhall +++ b/spago.dhall @@ -44,7 +44,6 @@ You can edit this file as you like. , "foreign-object" , "formatters" , "functions" - , "heterogeneous" , "http-methods" , "identity" , "integers" diff --git a/src/Internal/Service/Blockfrost.purs b/src/Internal/Service/Blockfrost.purs index e873e691ad..b640071598 100644 --- a/src/Internal/Service/Blockfrost.purs +++ b/src/Internal/Service/Blockfrost.purs @@ -87,6 +87,7 @@ import Cardano.Serialization.Lib (toBytes) import Cardano.Types ( AssetClass(AssetClass) , AuxiliaryData + , CostModel , DataHash , GeneralTransactionMetadata(GeneralTransactionMetadata) , Language(PlutusV3, PlutusV2, PlutusV1) @@ -118,6 +119,7 @@ import Cardano.Types.Epoch (Epoch(Epoch)) import Cardano.Types.ExUnitPrices (ExUnitPrices(ExUnitPrices)) import Cardano.Types.ExUnits (ExUnits(ExUnits)) import Cardano.Types.GeneralTransactionMetadata as GeneralTransactionMetadata +import Cardano.Types.Int (Int) as Cardano import Cardano.Types.NativeScript ( NativeScript ( ScriptAll @@ -193,13 +195,7 @@ import Ctl.Internal.Types.EraSummaries , EraSummaryParameters ) import Ctl.Internal.Types.ProtocolParameters - ( CostModelV1 - , CostModelV2 - , CostModelV3 - , ProtocolParameters(ProtocolParameters) - , convertPlutusV1CostModel - , convertPlutusV2CostModel - , convertPlutusV3CostModel + ( ProtocolParameters(ProtocolParameters) ) import Ctl.Internal.Types.Rational (Rational, reduce) import Ctl.Internal.Types.StakeValidatorHash (StakeValidatorHash) @@ -238,6 +234,7 @@ import Effect.Aff.Class (liftAff) import Effect.Class (liftEffect) import Effect.Exception (error) import Foreign.Object (Object) +import Foreign.Object (values) as Object import Foreign.Object as ForeignObject import JS.BigInt (fromString, toNumber) as BigInt import Prim.TypeError (class Warn, Text) @@ -1519,9 +1516,9 @@ type BlockfrostProtocolParametersRaw = , "protocol_minor_ver" :: UInt , "min_pool_cost" :: Stringed BigNum , "cost_models" :: - { "PlutusV1" :: { | CostModelV1 } - , "PlutusV2" :: { | CostModelV2 } - , "PlutusV3" :: CostModelV3 + { "PlutusV1" :: Object Cardano.Int + , "PlutusV2" :: Object Cardano.Int + , "PlutusV3" :: Object Cardano.Int } , "price_mem" :: FiniteBigNumber , "price_step" :: FiniteBigNumber @@ -1588,9 +1585,6 @@ instance DecodeAeson BlockfrostProtocolParameters where maybe (Left $ AtKey "coins_per_utxo_size" $ MissingValue) pure $ (Coin <<< unwrap <$> raw.coins_per_utxo_size) - plutusV3CostModel <- note (AtKey "PlutusV3" $ TypeMismatch "CostModel") $ - convertPlutusV3CostModel raw.cost_models."PlutusV3" - pure $ BlockfrostProtocolParameters $ ProtocolParameters { protocolVersion: raw.protocol_major_ver /\ raw.protocol_minor_ver -- The following two parameters were removed from Babbage @@ -1610,9 +1604,9 @@ instance DecodeAeson BlockfrostProtocolParameters where , treasuryCut , coinsPerUtxoByte: coinsPerUtxoByte , costModels: Map.fromFoldable - [ PlutusV1 /\ convertPlutusV1CostModel raw.cost_models."PlutusV1" - , PlutusV2 /\ convertPlutusV2CostModel raw.cost_models."PlutusV2" - , PlutusV3 /\ plutusV3CostModel + [ PlutusV1 /\ convertPlutusCostModel raw.cost_models."PlutusV1" + , PlutusV2 /\ convertPlutusCostModel raw.cost_models."PlutusV2" + , PlutusV3 /\ convertPlutusCostModel raw.cost_models."PlutusV3" ] , prices , maxTxExUnits: @@ -1631,6 +1625,9 @@ instance DecodeAeson BlockfrostProtocolParameters where , govActionDeposit: Coin $ unwrap raw.gov_action_deposit , drepDeposit: Coin $ unwrap raw.drep_deposit } + where + convertPlutusCostModel :: Object Cardano.Int -> CostModel + convertPlutusCostModel = wrap <<< Object.values -------------------------------------------------------------------------------- -- BlockfrostRewards diff --git a/src/Internal/Types/ProtocolParameters.purs b/src/Internal/Types/ProtocolParameters.purs index 36b74c3a5c..1c924e26bb 100644 --- a/src/Internal/Types/ProtocolParameters.purs +++ b/src/Internal/Types/ProtocolParameters.purs @@ -1,41 +1,17 @@ module Ctl.Internal.Types.ProtocolParameters ( ProtocolParameters(ProtocolParameters) - , CostModelV1 - , CostModelV2 - , CostModelV3 - , convertPlutusV1CostModel - , convertPlutusV2CostModel - , convertPlutusV3CostModel ) where import Prelude -import Cardano.Types.Coin (Coin) -import Cardano.Types.CostModel (CostModel) -import Cardano.Types.Epoch (Epoch) -import Cardano.Types.ExUnitPrices (ExUnitPrices) -import Cardano.Types.ExUnits (ExUnits) -import Cardano.Types.Int as Cardano -import Cardano.Types.Language (Language) +import Cardano.Types (Coin, CostModel, Epoch, ExUnitPrices, ExUnits, Language) import Ctl.Internal.Types.Rational (Rational) -import Data.Array (reverse) -import Data.Array (sortWith) as Array -import Data.Bitraversable (ltraverse) import Data.Generic.Rep (class Generic) -import Data.Int (fromString) as Int -import Data.List (List) -import Data.List as List import Data.Map (Map) -import Data.Maybe (Maybe) -import Data.Newtype (class Newtype, wrap) +import Data.Newtype (class Newtype) import Data.Show.Generic (genericShow) -import Data.Traversable (traverse) -import Data.Tuple (fst, snd) import Data.Tuple.Nested (type (/\)) import Data.UInt (UInt) -import Foreign.Object (Object) -import Foreign.Object (toUnfoldable) as Object -import Heterogeneous.Folding (class HFoldl, hfoldl) -- Based on `Cardano.Api.ProtocolParameters.ProtocolParameters` from -- `cardano-api`. @@ -73,217 +49,3 @@ derive instance Eq ProtocolParameters instance Show ProtocolParameters where show = genericShow - --- | A type that represents a JSON-encoded Costmodel in format used by Ogmios -type CostModelV1 = - ( "addInteger-cpu-arguments-intercept" :: Cardano.Int - , "addInteger-cpu-arguments-slope" :: Cardano.Int - , "addInteger-memory-arguments-intercept" :: Cardano.Int - , "addInteger-memory-arguments-slope" :: Cardano.Int - , "appendByteString-cpu-arguments-intercept" :: Cardano.Int - , "appendByteString-cpu-arguments-slope" :: Cardano.Int - , "appendByteString-memory-arguments-intercept" :: Cardano.Int - , "appendByteString-memory-arguments-slope" :: Cardano.Int - , "appendString-cpu-arguments-intercept" :: Cardano.Int - , "appendString-cpu-arguments-slope" :: Cardano.Int - , "appendString-memory-arguments-intercept" :: Cardano.Int - , "appendString-memory-arguments-slope" :: Cardano.Int - , "bData-cpu-arguments" :: Cardano.Int - , "bData-memory-arguments" :: Cardano.Int - , "blake2b_256-cpu-arguments-intercept" :: Cardano.Int - , "blake2b_256-cpu-arguments-slope" :: Cardano.Int - , "blake2b_256-memory-arguments" :: Cardano.Int - , "cekApplyCost-exBudgetCPU" :: Cardano.Int - , "cekApplyCost-exBudgetMemory" :: Cardano.Int - , "cekBuiltinCost-exBudgetCPU" :: Cardano.Int - , "cekBuiltinCost-exBudgetMemory" :: Cardano.Int - , "cekConstCost-exBudgetCPU" :: Cardano.Int - , "cekConstCost-exBudgetMemory" :: Cardano.Int - , "cekDelayCost-exBudgetCPU" :: Cardano.Int - , "cekDelayCost-exBudgetMemory" :: Cardano.Int - , "cekForceCost-exBudgetCPU" :: Cardano.Int - , "cekForceCost-exBudgetMemory" :: Cardano.Int - , "cekLamCost-exBudgetCPU" :: Cardano.Int - , "cekLamCost-exBudgetMemory" :: Cardano.Int - , "cekStartupCost-exBudgetCPU" :: Cardano.Int - , "cekStartupCost-exBudgetMemory" :: Cardano.Int - , "cekVarCost-exBudgetCPU" :: Cardano.Int - , "cekVarCost-exBudgetMemory" :: Cardano.Int - , "chooseData-cpu-arguments" :: Cardano.Int - , "chooseData-memory-arguments" :: Cardano.Int - , "chooseList-cpu-arguments" :: Cardano.Int - , "chooseList-memory-arguments" :: Cardano.Int - , "chooseUnit-cpu-arguments" :: Cardano.Int - , "chooseUnit-memory-arguments" :: Cardano.Int - , "consByteString-cpu-arguments-intercept" :: Cardano.Int - , "consByteString-cpu-arguments-slope" :: Cardano.Int - , "consByteString-memory-arguments-intercept" :: Cardano.Int - , "consByteString-memory-arguments-slope" :: Cardano.Int - , "constrData-cpu-arguments" :: Cardano.Int - , "constrData-memory-arguments" :: Cardano.Int - , "decodeUtf8-cpu-arguments-intercept" :: Cardano.Int - , "decodeUtf8-cpu-arguments-slope" :: Cardano.Int - , "decodeUtf8-memory-arguments-intercept" :: Cardano.Int - , "decodeUtf8-memory-arguments-slope" :: Cardano.Int - , "divideInteger-cpu-arguments-constant" :: Cardano.Int - , "divideInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int - , "divideInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int - , "divideInteger-memory-arguments-intercept" :: Cardano.Int - , "divideInteger-memory-arguments-minimum" :: Cardano.Int - , "divideInteger-memory-arguments-slope" :: Cardano.Int - , "encodeUtf8-cpu-arguments-intercept" :: Cardano.Int - , "encodeUtf8-cpu-arguments-slope" :: Cardano.Int - , "encodeUtf8-memory-arguments-intercept" :: Cardano.Int - , "encodeUtf8-memory-arguments-slope" :: Cardano.Int - , "equalsByteString-cpu-arguments-constant" :: Cardano.Int - , "equalsByteString-cpu-arguments-intercept" :: Cardano.Int - , "equalsByteString-cpu-arguments-slope" :: Cardano.Int - , "equalsByteString-memory-arguments" :: Cardano.Int - , "equalsData-cpu-arguments-intercept" :: Cardano.Int - , "equalsData-cpu-arguments-slope" :: Cardano.Int - , "equalsData-memory-arguments" :: Cardano.Int - , "equalsInteger-cpu-arguments-intercept" :: Cardano.Int - , "equalsInteger-cpu-arguments-slope" :: Cardano.Int - , "equalsInteger-memory-arguments" :: Cardano.Int - , "equalsString-cpu-arguments-constant" :: Cardano.Int - , "equalsString-cpu-arguments-intercept" :: Cardano.Int - , "equalsString-cpu-arguments-slope" :: Cardano.Int - , "equalsString-memory-arguments" :: Cardano.Int - , "fstPair-cpu-arguments" :: Cardano.Int - , "fstPair-memory-arguments" :: Cardano.Int - , "headList-cpu-arguments" :: Cardano.Int - , "headList-memory-arguments" :: Cardano.Int - , "iData-cpu-arguments" :: Cardano.Int - , "iData-memory-arguments" :: Cardano.Int - , "ifThenElse-cpu-arguments" :: Cardano.Int - , "ifThenElse-memory-arguments" :: Cardano.Int - , "indexByteString-cpu-arguments" :: Cardano.Int - , "indexByteString-memory-arguments" :: Cardano.Int - , "lengthOfByteString-cpu-arguments" :: Cardano.Int - , "lengthOfByteString-memory-arguments" :: Cardano.Int - , "lessThanByteString-cpu-arguments-intercept" :: Cardano.Int - , "lessThanByteString-cpu-arguments-slope" :: Cardano.Int - , "lessThanByteString-memory-arguments" :: Cardano.Int - , "lessThanEqualsByteString-cpu-arguments-intercept" :: Cardano.Int - , "lessThanEqualsByteString-cpu-arguments-slope" :: Cardano.Int - , "lessThanEqualsByteString-memory-arguments" :: Cardano.Int - , "lessThanEqualsInteger-cpu-arguments-intercept" :: Cardano.Int - , "lessThanEqualsInteger-cpu-arguments-slope" :: Cardano.Int - , "lessThanEqualsInteger-memory-arguments" :: Cardano.Int - , "lessThanInteger-cpu-arguments-intercept" :: Cardano.Int - , "lessThanInteger-cpu-arguments-slope" :: Cardano.Int - , "lessThanInteger-memory-arguments" :: Cardano.Int - , "listData-cpu-arguments" :: Cardano.Int - , "listData-memory-arguments" :: Cardano.Int - , "mapData-cpu-arguments" :: Cardano.Int - , "mapData-memory-arguments" :: Cardano.Int - , "mkCons-cpu-arguments" :: Cardano.Int - , "mkCons-memory-arguments" :: Cardano.Int - , "mkNilData-cpu-arguments" :: Cardano.Int - , "mkNilData-memory-arguments" :: Cardano.Int - , "mkNilPairData-cpu-arguments" :: Cardano.Int - , "mkNilPairData-memory-arguments" :: Cardano.Int - , "mkPairData-cpu-arguments" :: Cardano.Int - , "mkPairData-memory-arguments" :: Cardano.Int - , "modInteger-cpu-arguments-constant" :: Cardano.Int - , "modInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int - , "modInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int - , "modInteger-memory-arguments-intercept" :: Cardano.Int - , "modInteger-memory-arguments-minimum" :: Cardano.Int - , "modInteger-memory-arguments-slope" :: Cardano.Int - , "multiplyInteger-cpu-arguments-intercept" :: Cardano.Int - , "multiplyInteger-cpu-arguments-slope" :: Cardano.Int - , "multiplyInteger-memory-arguments-intercept" :: Cardano.Int - , "multiplyInteger-memory-arguments-slope" :: Cardano.Int - , "nullList-cpu-arguments" :: Cardano.Int - , "nullList-memory-arguments" :: Cardano.Int - , "quotientInteger-cpu-arguments-constant" :: Cardano.Int - , "quotientInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int - , "quotientInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int - , "quotientInteger-memory-arguments-intercept" :: Cardano.Int - , "quotientInteger-memory-arguments-minimum" :: Cardano.Int - , "quotientInteger-memory-arguments-slope" :: Cardano.Int - , "remainderInteger-cpu-arguments-constant" :: Cardano.Int - , "remainderInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int - , "remainderInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int - , "remainderInteger-memory-arguments-intercept" :: Cardano.Int - , "remainderInteger-memory-arguments-minimum" :: Cardano.Int - , "remainderInteger-memory-arguments-slope" :: Cardano.Int - , "sha2_256-cpu-arguments-intercept" :: Cardano.Int - , "sha2_256-cpu-arguments-slope" :: Cardano.Int - , "sha2_256-memory-arguments" :: Cardano.Int - , "sha3_256-cpu-arguments-intercept" :: Cardano.Int - , "sha3_256-cpu-arguments-slope" :: Cardano.Int - , "sha3_256-memory-arguments" :: Cardano.Int - , "sliceByteString-cpu-arguments-intercept" :: Cardano.Int - , "sliceByteString-cpu-arguments-slope" :: Cardano.Int - , "sliceByteString-memory-arguments-intercept" :: Cardano.Int - , "sliceByteString-memory-arguments-slope" :: Cardano.Int - , "sndPair-cpu-arguments" :: Cardano.Int - , "sndPair-memory-arguments" :: Cardano.Int - , "subtractInteger-cpu-arguments-intercept" :: Cardano.Int - , "subtractInteger-cpu-arguments-slope" :: Cardano.Int - , "subtractInteger-memory-arguments-intercept" :: Cardano.Int - , "subtractInteger-memory-arguments-slope" :: Cardano.Int - , "tailList-cpu-arguments" :: Cardano.Int - , "tailList-memory-arguments" :: Cardano.Int - , "trace-cpu-arguments" :: Cardano.Int - , "trace-memory-arguments" :: Cardano.Int - , "unBData-cpu-arguments" :: Cardano.Int - , "unBData-memory-arguments" :: Cardano.Int - , "unConstrData-cpu-arguments" :: Cardano.Int - , "unConstrData-memory-arguments" :: Cardano.Int - , "unIData-cpu-arguments" :: Cardano.Int - , "unIData-memory-arguments" :: Cardano.Int - , "unListData-cpu-arguments" :: Cardano.Int - , "unListData-memory-arguments" :: Cardano.Int - , "unMapData-cpu-arguments" :: Cardano.Int - , "unMapData-memory-arguments" :: Cardano.Int - , "verifyEd25519Signature-cpu-arguments-intercept" :: Cardano.Int - , "verifyEd25519Signature-cpu-arguments-slope" :: Cardano.Int - , "verifyEd25519Signature-memory-arguments" :: Cardano.Int - ) - -type CostModelV2 = - ( "serialiseData-cpu-arguments-intercept" :: Cardano.Int - , "serialiseData-cpu-arguments-slope" :: Cardano.Int - , "serialiseData-memory-arguments-intercept" :: Cardano.Int - , "serialiseData-memory-arguments-slope" :: Cardano.Int - , "verifyEcdsaSecp256k1Signature-cpu-arguments" :: Cardano.Int - , "verifyEcdsaSecp256k1Signature-memory-arguments" :: Cardano.Int - , "verifySchnorrSecp256k1Signature-cpu-arguments-intercept" :: Cardano.Int - , "verifySchnorrSecp256k1Signature-cpu-arguments-slope" :: Cardano.Int - , "verifySchnorrSecp256k1Signature-memory-arguments" :: Cardano.Int - | CostModelV1 - ) - -type CostModelV3 = Object Cardano.Int - --- This assumes that cost models are stored in lexicographical order -convertCostModel - :: forall costModel - . HFoldl (List Cardano.Int -> Cardano.Int -> List Cardano.Int) - (List Cardano.Int) - costModel - (List Cardano.Int) - => costModel - -> CostModel -convertCostModel model = wrap $ reverse $ List.toUnfoldable $ hfoldl - ( (\xs x -> x List.: xs) - :: List Cardano.Int -> Cardano.Int -> List Cardano.Int - ) - (mempty :: List Cardano.Int) - model - --- Specialized conversions to only perform the type level traversals once - -convertPlutusV1CostModel :: Record CostModelV1 -> CostModel -convertPlutusV1CostModel = convertCostModel - -convertPlutusV2CostModel :: Record CostModelV2 -> CostModel -convertPlutusV2CostModel = convertCostModel - -convertPlutusV3CostModel :: CostModelV3 -> Maybe CostModel -convertPlutusV3CostModel costModelRaw = - wrap <<< map snd <<< Array.sortWith fst <$> - traverse (ltraverse Int.fromString) (Object.toUnfoldable costModelRaw) diff --git a/test/Blockfrost/GenerateFixtures/ProtocolParameters.purs b/test/Blockfrost/GenerateFixtures/ProtocolParameters.purs index 097fe784fc..34d240b1ac 100644 --- a/test/Blockfrost/GenerateFixtures/ProtocolParameters.purs +++ b/test/Blockfrost/GenerateFixtures/ProtocolParameters.purs @@ -1,4 +1,6 @@ -module Test.Ctl.Blockfrost.GenerateFixtures.ProtocolParameters (main) where +module Test.Ctl.Blockfrost.GenerateFixtures.ProtocolParameters + ( main + ) where import Prelude @@ -9,7 +11,8 @@ import Ctl.Internal.Service.Blockfrost ) import Ctl.Internal.Service.Blockfrost (getProtocolParameters) as Blockfrost import Data.Either (either) -import Data.Maybe (Maybe(Just, Nothing)) +import Data.Maybe (Maybe(Just, Nothing), maybe) +import Data.String (take) as String import Effect (Effect) import Effect.Aff (Aff, launchAff_) import Effect.Class (liftEffect) @@ -24,20 +27,32 @@ main = launchAff_ generateFixture generateFixture :: Aff Unit generateFixture = do - backend <- liftEffect blockfrostBackend + backend@{ blockfrostApiKey } <- liftEffect blockfrostBackend + let + onBlockfrostRawResponse + :: BlockfrostEndpoint + -> BlockfrostRawResponse + -> Aff Unit + onBlockfrostRawResponse query rawResp = + case query of + LatestProtocolParameters -> + storeBlockfrostFixture + zero + ( "getProtocolParameters" <> maybe mempty (append "-") + (networkNameFromApiKey <$> blockfrostApiKey) + ) + rawResp + _ -> + pure unit pparams <- runBlockfrostServiceTestM (const (pure unit)) backend (Just onBlockfrostRawResponse) Nothing Blockfrost.getProtocolParameters either (liftEffect <<< throw <<< show) (const (pure unit)) pparams - where - onBlockfrostRawResponse - :: BlockfrostEndpoint - -> BlockfrostRawResponse - -> Aff Unit - onBlockfrostRawResponse query rawResp = - case query of - LatestProtocolParameters -> - storeBlockfrostFixture zero "getProtocolParameters" rawResp - _ -> pure unit + +networkNameFromApiKey :: String -> String +networkNameFromApiKey = + String.take 7 >>> case _ of + "sanchon" -> "sanchonet" + network -> network diff --git a/test/Blockfrost/ProtocolParameters.purs b/test/Blockfrost/ProtocolParameters.purs deleted file mode 100644 index 47378bfd85..0000000000 --- a/test/Blockfrost/ProtocolParameters.purs +++ /dev/null @@ -1,54 +0,0 @@ -module Test.Ctl.Blockfrost.ProtocolParameters (main, suite) where - -import Prelude - -import Aeson (class DecodeAeson, decodeJsonString) -import Contract.Test.Mote (TestPlanM, interpretWithConfig) -import Control.Monad.Error.Class (liftEither) -import Ctl.Internal.QueryM.Ogmios - ( OgmiosProtocolParameters(OgmiosProtocolParameters) - ) -import Ctl.Internal.Service.Blockfrost - ( BlockfrostProtocolParameters(BlockfrostProtocolParameters) - ) -import Data.Bifunctor (lmap) -import Effect (Effect) -import Effect.Aff (Aff, error, launchAff_) -import Mote (group, test) -import Node.Encoding (Encoding(UTF8)) -import Node.FS.Aff (readTextFile) -import Test.Spec.Assertions (shouldEqual) -import Test.Spec.Runner (defaultConfig) - --- These fixtures were acquired soon after each other, so we can compare their --- parsed results - -blockfrostFixture :: String -blockfrostFixture = - "blockfrost/getProtocolParameters/getProtocolParameters-6ac22050d53def4302608de2fa695f02.json" - -ogmiosFixture :: String -ogmiosFixture = - "ogmios/queryLedgerState-protocolParameters-1d8c6233b8bfb7c028f1dd60eb113d40.json" - -loadFixture :: forall (a :: Type). DecodeAeson a => String -> Aff a -loadFixture fixture = - readTextFile UTF8 ("fixtures/test/" <> fixture) - <#> decodeJsonString >>> lmap (show >>> error) - >>= liftEither - -main :: Effect Unit -main = launchAff_ do - interpretWithConfig - defaultConfig - suite - -suite :: TestPlanM (Aff Unit) Unit -suite = group "Blockfrost" do - test "ProtocolParameter parsing verification" do - BlockfrostProtocolParameters blockfrostFixture' <- loadFixture - blockfrostFixture - { result: OgmiosProtocolParameters ogmiosFixture' } - :: { result :: OgmiosProtocolParameters } <- loadFixture ogmiosFixture - - blockfrostFixture' `shouldEqual` ogmiosFixture' diff --git a/test/ProtocolParameters.purs b/test/ProtocolParameters.purs new file mode 100644 index 0000000000..5f582d1372 --- /dev/null +++ b/test/ProtocolParameters.purs @@ -0,0 +1,84 @@ +module Test.Ctl.ProtocolParameters + ( main + , suite + ) where + +import Prelude + +import Aeson (class DecodeAeson, decodeJsonString) +import Contract.Test.Mote (TestPlanM, interpretWithConfig) +import Control.Monad.Error.Class (liftEither) +import Ctl.Internal.QueryM.Ogmios + ( OgmiosProtocolParameters(OgmiosProtocolParameters) + ) +import Ctl.Internal.Service.Blockfrost + ( BlockfrostProtocolParameters(BlockfrostProtocolParameters) + ) +import Data.Bifunctor (lmap) +import Effect (Effect) +import Effect.Aff (Aff, error, launchAff_) +import Mote (group, test) +import Node.Encoding (Encoding(UTF8)) +import Node.FS.Aff (readTextFile) +import Test.Spec.Assertions (shouldEqual) +import Test.Spec.Runner (defaultConfig) + +-- These fixtures were acquired soon after each other, so we can compare their +-- parsed results + +blockfrostPreprodFixture :: String +blockfrostPreprodFixture = + "blockfrost/getProtocolParameters-preprod/getProtocolParameters-preprod-7f56c39a71503c097c448dc4b47b0e34.json" + +blockfrostPreviewFixture :: String +blockfrostPreviewFixture = + "blockfrost/getProtocolParameters-preview/getProtocolParameters-preview-659470119e7874ecf112dd05db4b691d.json" + +ogmiosPreprodFixture :: String +ogmiosPreprodFixture = + "ogmios/queryLedgerState-protocolParameters-preprod-aaa9a3fbcf526a678489845a2de49600.json" + +ogmiosPreviewFixture :: String +ogmiosPreviewFixture = + "ogmios/queryLedgerState-protocolParameters-preview-256d19f15eb1f722b0b66b25d20961b8.json" + +loadFixture :: forall (a :: Type). DecodeAeson a => String -> Aff a +loadFixture fixture = + readTextFile UTF8 ("fixtures/test/" <> fixture) + <#> decodeJsonString >>> lmap (show >>> error) + >>= liftEither + +main :: Effect Unit +main = launchAff_ do + interpretWithConfig + defaultConfig + suite + +suite :: TestPlanM (Aff Unit) Unit +suite = group "Blockfrost" do + testProtocolParameters "preprod" + { blockfrostFixture: blockfrostPreprodFixture + , ogmiosFixture: ogmiosPreprodFixture + } + testProtocolParameters "preview" + { blockfrostFixture: blockfrostPreviewFixture + , ogmiosFixture: ogmiosPreviewFixture + } + +testProtocolParameters + :: String + -> { blockfrostFixture :: String, ogmiosFixture :: String } + -> TestPlanM (Aff Unit) Unit +testProtocolParameters network { blockfrostFixture, ogmiosFixture } = do + test + ( "Blockfrost <> Ogmios ProtocolParameters parsing verification (" + <> network + <> ")" + ) + do + BlockfrostProtocolParameters blockfrostFixture' <- loadFixture + blockfrostFixture + { result: OgmiosProtocolParameters ogmiosFixture' } + :: { result :: OgmiosProtocolParameters } <- loadFixture ogmiosFixture + + blockfrostFixture' `shouldEqual` ogmiosFixture' diff --git a/test/ProtocolParams.purs b/test/ProtocolParams.purs deleted file mode 100644 index e76972d95b..0000000000 --- a/test/ProtocolParams.purs +++ /dev/null @@ -1,24 +0,0 @@ -module Test.Ctl.ProtocolParams - ( suite - ) where - -import Prelude - -import Aeson (decodeAeson) -import Ctl.Internal.QueryM.Ogmios (OgmiosProtocolParameters) -import Data.Either (Either, isRight) -import Effect.Aff (Aff) -import Mote (group, test) -import Mote.TestPlanM (TestPlanM) -import Test.Ctl.Utils as Utils -import Test.Spec.Assertions (shouldSatisfy) - -suite :: TestPlanM (Aff Unit) Unit -suite = do - aeson <- Utils.readAeson - "./fixtures/test/ogmios/queryLedgerState-protocolParameters-1d8c6233b8bfb7c028f1dd60eb113d40.json" - group "ProtocolParameters parser" $ do - test "is able to parse ogmios response fixture" $ - (decodeAeson aeson :: Either _ { result :: OgmiosProtocolParameters }) - `shouldSatisfy` - isRight diff --git a/test/Unit.purs b/test/Unit.purs index 36b3835a6c..9dae79756b 100644 --- a/test/Unit.purs +++ b/test/Unit.purs @@ -13,7 +13,6 @@ import Effect.Class (liftEffect) import Mote.Monad (mapTest) import Test.Ctl.ApplyArgs as ApplyArgs import Test.Ctl.Blockfrost.Aeson.Suite as Blockfrost.Aeson -import Test.Ctl.Blockfrost.ProtocolParameters as Blockfrost.ProtocolParameters import Test.Ctl.CoinSelection as CoinSelection import Test.Ctl.CslGc as CslGc import Test.Ctl.Data as Data @@ -25,7 +24,7 @@ import Test.Ctl.NativeScript as NativeScript import Test.Ctl.Ogmios.Aeson as Ogmios.Aeson import Test.Ctl.Ogmios.EvaluateTx as Ogmios.EvaluateTx import Test.Ctl.Partition as Partition -import Test.Ctl.ProtocolParams as ProtocolParams +import Test.Ctl.ProtocolParameters as ProtocolParameters import Test.Ctl.Serialization as Serialization import Test.Ctl.Serialization.Hash as Serialization.Hash import Test.Ctl.Testnet.DistributeFunds as Testnet.DistributeFunds @@ -62,9 +61,8 @@ testPlan = do UsedTxOuts.suite Ogmios.Aeson.suite Ogmios.EvaluateTx.suite - ProtocolParams.suite + ProtocolParameters.suite Blockfrost.Aeson.suite - Blockfrost.ProtocolParameters.suite Types.TokenName.suite Types.Transaction.suite Ctl.Data.Interval.suite From 4d1136d0a3c8de6c821dc1d7332af73a1ec2b621 Mon Sep 17 00:00:00 2001 From: Dzmitry Shuysky Date: Thu, 5 Sep 2024 13:53:56 +0200 Subject: [PATCH 3/6] Enforce PlutusV3 cost model key order (cherry picked from commit 5aa8e078deacf1c71bd8533373c7736a065a85c8) --- .../blockfrost/getProtocolParameters/.gitkeep | 0 spago.dhall | 1 + src/Internal/Service/Blockfrost.purs | 29 +- src/Internal/Types/ProtocolParameters.purs | 495 +++++++++++++++++- 4 files changed, 513 insertions(+), 12 deletions(-) create mode 100644 fixtures/test/blockfrost/getProtocolParameters/.gitkeep diff --git a/fixtures/test/blockfrost/getProtocolParameters/.gitkeep b/fixtures/test/blockfrost/getProtocolParameters/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spago.dhall b/spago.dhall index 0407bf0f7b..dd58114a56 100644 --- a/spago.dhall +++ b/spago.dhall @@ -44,6 +44,7 @@ You can edit this file as you like. , "foreign-object" , "formatters" , "functions" + , "heterogeneous" , "http-methods" , "identity" , "integers" diff --git a/src/Internal/Service/Blockfrost.purs b/src/Internal/Service/Blockfrost.purs index b640071598..54c9b2994f 100644 --- a/src/Internal/Service/Blockfrost.purs +++ b/src/Internal/Service/Blockfrost.purs @@ -87,7 +87,6 @@ import Cardano.Serialization.Lib (toBytes) import Cardano.Types ( AssetClass(AssetClass) , AuxiliaryData - , CostModel , DataHash , GeneralTransactionMetadata(GeneralTransactionMetadata) , Language(PlutusV3, PlutusV2, PlutusV1) @@ -195,7 +194,13 @@ import Ctl.Internal.Types.EraSummaries , EraSummaryParameters ) import Ctl.Internal.Types.ProtocolParameters - ( ProtocolParameters(ProtocolParameters) + ( CostModelV1 + , CostModelV2 + , ProtocolParameters(ProtocolParameters) + , convertPlutusV1CostModel + , convertPlutusV2CostModel + , convertPlutusV3CostModel + , convertUnnamedPlutusCostModel ) import Ctl.Internal.Types.Rational (Rational, reduce) import Ctl.Internal.Types.StakeValidatorHash (StakeValidatorHash) @@ -234,7 +239,6 @@ import Effect.Aff.Class (liftAff) import Effect.Class (liftEffect) import Effect.Exception (error) import Foreign.Object (Object) -import Foreign.Object (values) as Object import Foreign.Object as ForeignObject import JS.BigInt (fromString, toNumber) as BigInt import Prim.TypeError (class Warn, Text) @@ -1516,8 +1520,8 @@ type BlockfrostProtocolParametersRaw = , "protocol_minor_ver" :: UInt , "min_pool_cost" :: Stringed BigNum , "cost_models" :: - { "PlutusV1" :: Object Cardano.Int - , "PlutusV2" :: Object Cardano.Int + { "PlutusV1" :: { | CostModelV1 } + , "PlutusV2" :: { | CostModelV2 } , "PlutusV3" :: Object Cardano.Int } , "price_mem" :: FiniteBigNumber @@ -1585,6 +1589,12 @@ instance DecodeAeson BlockfrostProtocolParameters where maybe (Left $ AtKey "coins_per_utxo_size" $ MissingValue) pure $ (Coin <<< unwrap <$> raw.coins_per_utxo_size) + let plutusV3CostModelRaw = raw.cost_models."PlutusV3" + plutusV3CostModel <- + note (AtKey "cost_models" $ AtKey "PlutusV3" $ TypeMismatch "CostModel") + ( convertPlutusV3CostModel plutusV3CostModelRaw + <|> convertUnnamedPlutusCostModel plutusV3CostModelRaw + ) pure $ BlockfrostProtocolParameters $ ProtocolParameters { protocolVersion: raw.protocol_major_ver /\ raw.protocol_minor_ver -- The following two parameters were removed from Babbage @@ -1604,9 +1614,9 @@ instance DecodeAeson BlockfrostProtocolParameters where , treasuryCut , coinsPerUtxoByte: coinsPerUtxoByte , costModels: Map.fromFoldable - [ PlutusV1 /\ convertPlutusCostModel raw.cost_models."PlutusV1" - , PlutusV2 /\ convertPlutusCostModel raw.cost_models."PlutusV2" - , PlutusV3 /\ convertPlutusCostModel raw.cost_models."PlutusV3" + [ PlutusV1 /\ convertPlutusV1CostModel raw.cost_models."PlutusV1" + , PlutusV2 /\ convertPlutusV2CostModel raw.cost_models."PlutusV2" + , PlutusV3 /\ plutusV3CostModel ] , prices , maxTxExUnits: @@ -1625,9 +1635,6 @@ instance DecodeAeson BlockfrostProtocolParameters where , govActionDeposit: Coin $ unwrap raw.gov_action_deposit , drepDeposit: Coin $ unwrap raw.drep_deposit } - where - convertPlutusCostModel :: Object Cardano.Int -> CostModel - convertPlutusCostModel = wrap <<< Object.values -------------------------------------------------------------------------------- -- BlockfrostRewards diff --git a/src/Internal/Types/ProtocolParameters.purs b/src/Internal/Types/ProtocolParameters.purs index 1c924e26bb..01574f7262 100644 --- a/src/Internal/Types/ProtocolParameters.purs +++ b/src/Internal/Types/ProtocolParameters.purs @@ -1,17 +1,36 @@ module Ctl.Internal.Types.ProtocolParameters ( ProtocolParameters(ProtocolParameters) + , CostModelV1 + , CostModelV2 + , convertPlutusV1CostModel + , convertPlutusV2CostModel + , convertPlutusV3CostModel + , convertUnnamedPlutusCostModel ) where import Prelude import Cardano.Types (Coin, CostModel, Epoch, ExUnitPrices, ExUnits, Language) +import Cardano.Types.Int (fromString) as Cardano.Int +import Cardano.Types.Int as Cardano import Ctl.Internal.Types.Rational (Rational) +import Data.Array (reverse) +import Data.Array (sortWith) as Array +import Data.Bitraversable (ltraverse) import Data.Generic.Rep (class Generic) +import Data.List (List) +import Data.List as List import Data.Map (Map) -import Data.Newtype (class Newtype) +import Data.Maybe (Maybe) +import Data.Newtype (class Newtype, wrap) import Data.Show.Generic (genericShow) +import Data.Traversable (traverse) +import Data.Tuple (fst, snd) import Data.Tuple.Nested (type (/\)) import Data.UInt (UInt) +import Foreign.Object (Object) +import Foreign.Object (lookup, toUnfoldable) as Object +import Heterogeneous.Folding (class HFoldl, hfoldl) -- Based on `Cardano.Api.ProtocolParameters.ProtocolParameters` from -- `cardano-api`. @@ -49,3 +68,477 @@ derive instance Eq ProtocolParameters instance Show ProtocolParameters where show = genericShow + +-- | A type that represents a JSON-encoded Costmodel in format used by Ogmios +type CostModelV1 = + ( "addInteger-cpu-arguments-intercept" :: Cardano.Int + , "addInteger-cpu-arguments-slope" :: Cardano.Int + , "addInteger-memory-arguments-intercept" :: Cardano.Int + , "addInteger-memory-arguments-slope" :: Cardano.Int + , "appendByteString-cpu-arguments-intercept" :: Cardano.Int + , "appendByteString-cpu-arguments-slope" :: Cardano.Int + , "appendByteString-memory-arguments-intercept" :: Cardano.Int + , "appendByteString-memory-arguments-slope" :: Cardano.Int + , "appendString-cpu-arguments-intercept" :: Cardano.Int + , "appendString-cpu-arguments-slope" :: Cardano.Int + , "appendString-memory-arguments-intercept" :: Cardano.Int + , "appendString-memory-arguments-slope" :: Cardano.Int + , "bData-cpu-arguments" :: Cardano.Int + , "bData-memory-arguments" :: Cardano.Int + , "blake2b_256-cpu-arguments-intercept" :: Cardano.Int + , "blake2b_256-cpu-arguments-slope" :: Cardano.Int + , "blake2b_256-memory-arguments" :: Cardano.Int + , "cekApplyCost-exBudgetCPU" :: Cardano.Int + , "cekApplyCost-exBudgetMemory" :: Cardano.Int + , "cekBuiltinCost-exBudgetCPU" :: Cardano.Int + , "cekBuiltinCost-exBudgetMemory" :: Cardano.Int + , "cekConstCost-exBudgetCPU" :: Cardano.Int + , "cekConstCost-exBudgetMemory" :: Cardano.Int + , "cekDelayCost-exBudgetCPU" :: Cardano.Int + , "cekDelayCost-exBudgetMemory" :: Cardano.Int + , "cekForceCost-exBudgetCPU" :: Cardano.Int + , "cekForceCost-exBudgetMemory" :: Cardano.Int + , "cekLamCost-exBudgetCPU" :: Cardano.Int + , "cekLamCost-exBudgetMemory" :: Cardano.Int + , "cekStartupCost-exBudgetCPU" :: Cardano.Int + , "cekStartupCost-exBudgetMemory" :: Cardano.Int + , "cekVarCost-exBudgetCPU" :: Cardano.Int + , "cekVarCost-exBudgetMemory" :: Cardano.Int + , "chooseData-cpu-arguments" :: Cardano.Int + , "chooseData-memory-arguments" :: Cardano.Int + , "chooseList-cpu-arguments" :: Cardano.Int + , "chooseList-memory-arguments" :: Cardano.Int + , "chooseUnit-cpu-arguments" :: Cardano.Int + , "chooseUnit-memory-arguments" :: Cardano.Int + , "consByteString-cpu-arguments-intercept" :: Cardano.Int + , "consByteString-cpu-arguments-slope" :: Cardano.Int + , "consByteString-memory-arguments-intercept" :: Cardano.Int + , "consByteString-memory-arguments-slope" :: Cardano.Int + , "constrData-cpu-arguments" :: Cardano.Int + , "constrData-memory-arguments" :: Cardano.Int + , "decodeUtf8-cpu-arguments-intercept" :: Cardano.Int + , "decodeUtf8-cpu-arguments-slope" :: Cardano.Int + , "decodeUtf8-memory-arguments-intercept" :: Cardano.Int + , "decodeUtf8-memory-arguments-slope" :: Cardano.Int + , "divideInteger-cpu-arguments-constant" :: Cardano.Int + , "divideInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int + , "divideInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int + , "divideInteger-memory-arguments-intercept" :: Cardano.Int + , "divideInteger-memory-arguments-minimum" :: Cardano.Int + , "divideInteger-memory-arguments-slope" :: Cardano.Int + , "encodeUtf8-cpu-arguments-intercept" :: Cardano.Int + , "encodeUtf8-cpu-arguments-slope" :: Cardano.Int + , "encodeUtf8-memory-arguments-intercept" :: Cardano.Int + , "encodeUtf8-memory-arguments-slope" :: Cardano.Int + , "equalsByteString-cpu-arguments-constant" :: Cardano.Int + , "equalsByteString-cpu-arguments-intercept" :: Cardano.Int + , "equalsByteString-cpu-arguments-slope" :: Cardano.Int + , "equalsByteString-memory-arguments" :: Cardano.Int + , "equalsData-cpu-arguments-intercept" :: Cardano.Int + , "equalsData-cpu-arguments-slope" :: Cardano.Int + , "equalsData-memory-arguments" :: Cardano.Int + , "equalsInteger-cpu-arguments-intercept" :: Cardano.Int + , "equalsInteger-cpu-arguments-slope" :: Cardano.Int + , "equalsInteger-memory-arguments" :: Cardano.Int + , "equalsString-cpu-arguments-constant" :: Cardano.Int + , "equalsString-cpu-arguments-intercept" :: Cardano.Int + , "equalsString-cpu-arguments-slope" :: Cardano.Int + , "equalsString-memory-arguments" :: Cardano.Int + , "fstPair-cpu-arguments" :: Cardano.Int + , "fstPair-memory-arguments" :: Cardano.Int + , "headList-cpu-arguments" :: Cardano.Int + , "headList-memory-arguments" :: Cardano.Int + , "iData-cpu-arguments" :: Cardano.Int + , "iData-memory-arguments" :: Cardano.Int + , "ifThenElse-cpu-arguments" :: Cardano.Int + , "ifThenElse-memory-arguments" :: Cardano.Int + , "indexByteString-cpu-arguments" :: Cardano.Int + , "indexByteString-memory-arguments" :: Cardano.Int + , "lengthOfByteString-cpu-arguments" :: Cardano.Int + , "lengthOfByteString-memory-arguments" :: Cardano.Int + , "lessThanByteString-cpu-arguments-intercept" :: Cardano.Int + , "lessThanByteString-cpu-arguments-slope" :: Cardano.Int + , "lessThanByteString-memory-arguments" :: Cardano.Int + , "lessThanEqualsByteString-cpu-arguments-intercept" :: Cardano.Int + , "lessThanEqualsByteString-cpu-arguments-slope" :: Cardano.Int + , "lessThanEqualsByteString-memory-arguments" :: Cardano.Int + , "lessThanEqualsInteger-cpu-arguments-intercept" :: Cardano.Int + , "lessThanEqualsInteger-cpu-arguments-slope" :: Cardano.Int + , "lessThanEqualsInteger-memory-arguments" :: Cardano.Int + , "lessThanInteger-cpu-arguments-intercept" :: Cardano.Int + , "lessThanInteger-cpu-arguments-slope" :: Cardano.Int + , "lessThanInteger-memory-arguments" :: Cardano.Int + , "listData-cpu-arguments" :: Cardano.Int + , "listData-memory-arguments" :: Cardano.Int + , "mapData-cpu-arguments" :: Cardano.Int + , "mapData-memory-arguments" :: Cardano.Int + , "mkCons-cpu-arguments" :: Cardano.Int + , "mkCons-memory-arguments" :: Cardano.Int + , "mkNilData-cpu-arguments" :: Cardano.Int + , "mkNilData-memory-arguments" :: Cardano.Int + , "mkNilPairData-cpu-arguments" :: Cardano.Int + , "mkNilPairData-memory-arguments" :: Cardano.Int + , "mkPairData-cpu-arguments" :: Cardano.Int + , "mkPairData-memory-arguments" :: Cardano.Int + , "modInteger-cpu-arguments-constant" :: Cardano.Int + , "modInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int + , "modInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int + , "modInteger-memory-arguments-intercept" :: Cardano.Int + , "modInteger-memory-arguments-minimum" :: Cardano.Int + , "modInteger-memory-arguments-slope" :: Cardano.Int + , "multiplyInteger-cpu-arguments-intercept" :: Cardano.Int + , "multiplyInteger-cpu-arguments-slope" :: Cardano.Int + , "multiplyInteger-memory-arguments-intercept" :: Cardano.Int + , "multiplyInteger-memory-arguments-slope" :: Cardano.Int + , "nullList-cpu-arguments" :: Cardano.Int + , "nullList-memory-arguments" :: Cardano.Int + , "quotientInteger-cpu-arguments-constant" :: Cardano.Int + , "quotientInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int + , "quotientInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int + , "quotientInteger-memory-arguments-intercept" :: Cardano.Int + , "quotientInteger-memory-arguments-minimum" :: Cardano.Int + , "quotientInteger-memory-arguments-slope" :: Cardano.Int + , "remainderInteger-cpu-arguments-constant" :: Cardano.Int + , "remainderInteger-cpu-arguments-model-arguments-intercept" :: Cardano.Int + , "remainderInteger-cpu-arguments-model-arguments-slope" :: Cardano.Int + , "remainderInteger-memory-arguments-intercept" :: Cardano.Int + , "remainderInteger-memory-arguments-minimum" :: Cardano.Int + , "remainderInteger-memory-arguments-slope" :: Cardano.Int + , "sha2_256-cpu-arguments-intercept" :: Cardano.Int + , "sha2_256-cpu-arguments-slope" :: Cardano.Int + , "sha2_256-memory-arguments" :: Cardano.Int + , "sha3_256-cpu-arguments-intercept" :: Cardano.Int + , "sha3_256-cpu-arguments-slope" :: Cardano.Int + , "sha3_256-memory-arguments" :: Cardano.Int + , "sliceByteString-cpu-arguments-intercept" :: Cardano.Int + , "sliceByteString-cpu-arguments-slope" :: Cardano.Int + , "sliceByteString-memory-arguments-intercept" :: Cardano.Int + , "sliceByteString-memory-arguments-slope" :: Cardano.Int + , "sndPair-cpu-arguments" :: Cardano.Int + , "sndPair-memory-arguments" :: Cardano.Int + , "subtractInteger-cpu-arguments-intercept" :: Cardano.Int + , "subtractInteger-cpu-arguments-slope" :: Cardano.Int + , "subtractInteger-memory-arguments-intercept" :: Cardano.Int + , "subtractInteger-memory-arguments-slope" :: Cardano.Int + , "tailList-cpu-arguments" :: Cardano.Int + , "tailList-memory-arguments" :: Cardano.Int + , "trace-cpu-arguments" :: Cardano.Int + , "trace-memory-arguments" :: Cardano.Int + , "unBData-cpu-arguments" :: Cardano.Int + , "unBData-memory-arguments" :: Cardano.Int + , "unConstrData-cpu-arguments" :: Cardano.Int + , "unConstrData-memory-arguments" :: Cardano.Int + , "unIData-cpu-arguments" :: Cardano.Int + , "unIData-memory-arguments" :: Cardano.Int + , "unListData-cpu-arguments" :: Cardano.Int + , "unListData-memory-arguments" :: Cardano.Int + , "unMapData-cpu-arguments" :: Cardano.Int + , "unMapData-memory-arguments" :: Cardano.Int + , "verifyEd25519Signature-cpu-arguments-intercept" :: Cardano.Int + , "verifyEd25519Signature-cpu-arguments-slope" :: Cardano.Int + , "verifyEd25519Signature-memory-arguments" :: Cardano.Int + ) + +type CostModelV2 = + ( "serialiseData-cpu-arguments-intercept" :: Cardano.Int + , "serialiseData-cpu-arguments-slope" :: Cardano.Int + , "serialiseData-memory-arguments-intercept" :: Cardano.Int + , "serialiseData-memory-arguments-slope" :: Cardano.Int + , "verifyEcdsaSecp256k1Signature-cpu-arguments" :: Cardano.Int + , "verifyEcdsaSecp256k1Signature-memory-arguments" :: Cardano.Int + , "verifySchnorrSecp256k1Signature-cpu-arguments-intercept" :: Cardano.Int + , "verifySchnorrSecp256k1Signature-cpu-arguments-slope" :: Cardano.Int + , "verifySchnorrSecp256k1Signature-memory-arguments" :: Cardano.Int + | CostModelV1 + ) + +costModelV3Names :: Array String +costModelV3Names = + [ "addInteger-cpu-arguments-intercept" + , "addInteger-cpu-arguments-slope" + , "addInteger-memory-arguments-intercept" + , "addInteger-memory-arguments-slope" + , "appendByteString-cpu-arguments-intercept" + , "appendByteString-cpu-arguments-slope" + , "appendByteString-memory-arguments-intercept" + , "appendByteString-memory-arguments-slope" + , "appendString-cpu-arguments-intercept" + , "appendString-cpu-arguments-slope" + , "appendString-memory-arguments-intercept" + , "appendString-memory-arguments-slope" + , "bData-cpu-arguments" + , "bData-memory-arguments" + , "blake2b_256-cpu-arguments-intercept" + , "blake2b_256-cpu-arguments-slope" + , "blake2b_256-memory-arguments" + , "cekApplyCost-exBudgetCPU" + , "cekApplyCost-exBudgetMemory" + , "cekBuiltinCost-exBudgetCPU" + , "cekBuiltinCost-exBudgetMemory" + , "cekConstCost-exBudgetCPU" + , "cekConstCost-exBudgetMemory" + , "cekDelayCost-exBudgetCPU" + , "cekDelayCost-exBudgetMemory" + , "cekForceCost-exBudgetCPU" + , "cekForceCost-exBudgetMemory" + , "cekLamCost-exBudgetCPU" + , "cekLamCost-exBudgetMemory" + , "cekStartupCost-exBudgetCPU" + , "cekStartupCost-exBudgetMemory" + , "cekVarCost-exBudgetCPU" + , "cekVarCost-exBudgetMemory" + , "chooseData-cpu-arguments" + , "chooseData-memory-arguments" + , "chooseList-cpu-arguments" + , "chooseList-memory-arguments" + , "chooseUnit-cpu-arguments" + , "chooseUnit-memory-arguments" + , "consByteString-cpu-arguments-intercept" + , "consByteString-cpu-arguments-slope" + , "consByteString-memory-arguments-intercept" + , "consByteString-memory-arguments-slope" + , "constrData-cpu-arguments" + , "constrData-memory-arguments" + , "decodeUtf8-cpu-arguments-intercept" + , "decodeUtf8-cpu-arguments-slope" + , "decodeUtf8-memory-arguments-intercept" + , "decodeUtf8-memory-arguments-slope" + , "divideInteger-cpu-arguments-constant" + , "divideInteger-cpu-arguments-model-arguments-c00" + , "divideInteger-cpu-arguments-model-arguments-c01" + , "divideInteger-cpu-arguments-model-arguments-c02" + , "divideInteger-cpu-arguments-model-arguments-c10" + , "divideInteger-cpu-arguments-model-arguments-c11" + , "divideInteger-cpu-arguments-model-arguments-c20" + , "divideInteger-cpu-arguments-model-arguments-minimum" + , "divideInteger-memory-arguments-intercept" + , "divideInteger-memory-arguments-minimum" + , "divideInteger-memory-arguments-slope" + , "encodeUtf8-cpu-arguments-intercept" + , "encodeUtf8-cpu-arguments-slope" + , "encodeUtf8-memory-arguments-intercept" + , "encodeUtf8-memory-arguments-slope" + , "equalsByteString-cpu-arguments-constant" + , "equalsByteString-cpu-arguments-intercept" + , "equalsByteString-cpu-arguments-slope" + , "equalsByteString-memory-arguments" + , "equalsData-cpu-arguments-intercept" + , "equalsData-cpu-arguments-slope" + , "equalsData-memory-arguments" + , "equalsInteger-cpu-arguments-intercept" + , "equalsInteger-cpu-arguments-slope" + , "equalsInteger-memory-arguments" + , "equalsString-cpu-arguments-constant" + , "equalsString-cpu-arguments-intercept" + , "equalsString-cpu-arguments-slope" + , "equalsString-memory-arguments" + , "fstPair-cpu-arguments" + , "fstPair-memory-arguments" + , "headList-cpu-arguments" + , "headList-memory-arguments" + , "iData-cpu-arguments" + , "iData-memory-arguments" + , "ifThenElse-cpu-arguments" + , "ifThenElse-memory-arguments" + , "indexByteString-cpu-arguments" + , "indexByteString-memory-arguments" + , "lengthOfByteString-cpu-arguments" + , "lengthOfByteString-memory-arguments" + , "lessThanByteString-cpu-arguments-intercept" + , "lessThanByteString-cpu-arguments-slope" + , "lessThanByteString-memory-arguments" + , "lessThanEqualsByteString-cpu-arguments-intercept" + , "lessThanEqualsByteString-cpu-arguments-slope" + , "lessThanEqualsByteString-memory-arguments" + , "lessThanEqualsInteger-cpu-arguments-intercept" + , "lessThanEqualsInteger-cpu-arguments-slope" + , "lessThanEqualsInteger-memory-arguments" + , "lessThanInteger-cpu-arguments-intercept" + , "lessThanInteger-cpu-arguments-slope" + , "lessThanInteger-memory-arguments" + , "listData-cpu-arguments" + , "listData-memory-arguments" + , "mapData-cpu-arguments" + , "mapData-memory-arguments" + , "mkCons-cpu-arguments" + , "mkCons-memory-arguments" + , "mkNilData-cpu-arguments" + , "mkNilData-memory-arguments" + , "mkNilPairData-cpu-arguments" + , "mkNilPairData-memory-arguments" + , "mkPairData-cpu-arguments" + , "mkPairData-memory-arguments" + , "modInteger-cpu-arguments-constant" + , "modInteger-cpu-arguments-model-arguments-c00" + , "modInteger-cpu-arguments-model-arguments-c01" + , "modInteger-cpu-arguments-model-arguments-c02" + , "modInteger-cpu-arguments-model-arguments-c10" + , "modInteger-cpu-arguments-model-arguments-c11" + , "modInteger-cpu-arguments-model-arguments-c20" + , "modInteger-cpu-arguments-model-arguments-minimum" + , "modInteger-memory-arguments-intercept" + , "modInteger-memory-arguments-slope" + , "multiplyInteger-cpu-arguments-intercept" + , "multiplyInteger-cpu-arguments-slope" + , "multiplyInteger-memory-arguments-intercept" + , "multiplyInteger-memory-arguments-slope" + , "nullList-cpu-arguments" + , "nullList-memory-arguments" + , "quotientInteger-cpu-arguments-constant" + , "quotientInteger-cpu-arguments-model-arguments-c00" + , "quotientInteger-cpu-arguments-model-arguments-c01" + , "quotientInteger-cpu-arguments-model-arguments-c02" + , "quotientInteger-cpu-arguments-model-arguments-c10" + , "quotientInteger-cpu-arguments-model-arguments-c11" + , "quotientInteger-cpu-arguments-model-arguments-c20" + , "quotientInteger-cpu-arguments-model-arguments-minimum" + , "quotientInteger-memory-arguments-intercept" + , "quotientInteger-memory-arguments-slope" + , "remainderInteger-cpu-arguments-constant" + , "remainderInteger-cpu-arguments-model-arguments-c00" + , "remainderInteger-cpu-arguments-model-arguments-c01" + , "remainderInteger-cpu-arguments-model-arguments-c02" + , "remainderInteger-cpu-arguments-model-arguments-c10" + , "remainderInteger-cpu-arguments-model-arguments-c11" + , "remainderInteger-cpu-arguments-model-arguments-c20" + , "remainderInteger-cpu-arguments-model-arguments-minimum" + , "remainderInteger-memory-arguments-intercept" + , "remainderInteger-memory-arguments-minimum" + , "remainderInteger-memory-arguments-slope" + , "serialiseData-cpu-arguments-intercept" + , "serialiseData-cpu-arguments-slope" + , "serialiseData-memory-arguments-intercept" + , "serialiseData-memory-arguments-slope" + , "sha2_256-cpu-arguments-intercept" + , "sha2_256-cpu-arguments-slope" + , "sha2_256-memory-arguments" + , "sha3_256-cpu-arguments-intercept" + , "sha3_256-cpu-arguments-slope" + , "sha3_256-memory-arguments" + , "sliceByteString-cpu-arguments-intercept" + , "sliceByteString-cpu-arguments-slope" + , "sliceByteString-memory-arguments-intercept" + , "sliceByteString-memory-arguments-slope" + , "sndPair-cpu-arguments" + , "sndPair-memory-arguments" + , "subtractInteger-cpu-arguments-intercept" + , "subtractInteger-cpu-arguments-slope" + , "subtractInteger-memory-arguments-intercept" + , "subtractInteger-memory-arguments-slope" + , "tailList-cpu-arguments" + , "tailList-memory-arguments" + , "trace-cpu-arguments" + , "trace-memory-arguments" + , "unBData-cpu-arguments" + , "unBData-memory-arguments" + , "unConstrData-cpu-arguments" + , "unConstrData-memory-arguments" + , "unIData-cpu-arguments" + , "unIData-memory-arguments" + , "unListData-cpu-arguments" + , "unListData-memory-arguments" + , "unMapData-cpu-arguments" + , "unMapData-memory-arguments" + , "verifyEcdsaSecp256k1Signature-cpu-arguments" + , "verifyEcdsaSecp256k1Signature-memory-arguments" + , "verifyEd25519Signature-cpu-arguments-intercept" + , "verifyEd25519Signature-cpu-arguments-slope" + , "verifyEd25519Signature-memory-arguments" + , "verifySchnorrSecp256k1Signature-cpu-arguments-intercept" + , "verifySchnorrSecp256k1Signature-cpu-arguments-slope" + , "verifySchnorrSecp256k1Signature-memory-arguments" + , "cekConstrCost-exBudgetCPU" + , "cekConstrCost-exBudgetMemory" + , "cekCaseCost-exBudgetCPU" + , "cekCaseCost-exBudgetMemory" + , "bls12_381_G1_add-cpu-arguments" + , "bls12_381_G1_add-memory-arguments" + , "bls12_381_G1_compress-cpu-arguments" + , "bls12_381_G1_compress-memory-arguments" + , "bls12_381_G1_equal-cpu-arguments" + , "bls12_381_G1_equal-memory-arguments" + , "bls12_381_G1_hashToGroup-cpu-arguments-intercept" + , "bls12_381_G1_hashToGroup-cpu-arguments-slope" + , "bls12_381_G1_hashToGroup-memory-arguments" + , "bls12_381_G1_neg-cpu-arguments" + , "bls12_381_G1_neg-memory-arguments" + , "bls12_381_G1_scalarMul-cpu-arguments-intercept" + , "bls12_381_G1_scalarMul-cpu-arguments-slope" + , "bls12_381_G1_scalarMul-memory-arguments" + , "bls12_381_G1_uncompress-cpu-arguments" + , "bls12_381_G1_uncompress-memory-arguments" + , "bls12_381_G2_add-cpu-arguments" + , "bls12_381_G2_add-memory-arguments" + , "bls12_381_G2_compress-cpu-arguments" + , "bls12_381_G2_compress-memory-arguments" + , "bls12_381_G2_equal-cpu-arguments" + , "bls12_381_G2_equal-memory-arguments" + , "bls12_381_G2_hashToGroup-cpu-arguments-intercept" + , "bls12_381_G2_hashToGroup-cpu-arguments-slope" + , "bls12_381_G2_hashToGroup-memory-arguments" + , "bls12_381_G2_neg-cpu-arguments" + , "bls12_381_G2_neg-memory-arguments" + , "bls12_381_G2_scalarMul-cpu-arguments-intercept" + , "bls12_381_G2_scalarMul-cpu-arguments-slope" + , "bls12_381_G2_scalarMul-memory-arguments" + , "bls12_381_G2_uncompress-cpu-arguments" + , "bls12_381_G2_uncompress-memory-arguments" + , "bls12_381_finalVerify-cpu-arguments" + , "bls12_381_finalVerify-memory-arguments" + , "bls12_381_millerLoop-cpu-arguments" + , "bls12_381_millerLoop-memory-arguments" + , "bls12_381_mulMlResult-cpu-arguments" + , "bls12_381_mulMlResult-memory-arguments" + , "keccak_256-cpu-arguments-intercept" + , "keccak_256-cpu-arguments-slope" + , "keccak_256-memory-arguments" + , "blake2b_224-cpu-arguments-intercept" + , "blake2b_224-cpu-arguments-slope" + , "blake2b_224-memory-arguments" + , "integerToByteString-cpu-arguments-c0" + , "integerToByteString-cpu-arguments-c1" + , "integerToByteString-cpu-arguments-c2" + , "integerToByteString-memory-arguments-intercept" + , "integerToByteString-memory-arguments-slope" + , "byteStringToInteger-cpu-arguments-c0" + , "byteStringToInteger-cpu-arguments-c1" + , "byteStringToInteger-cpu-arguments-c2" + , "byteStringToInteger-memory-arguments-intercept" + , "byteStringToInteger-memory-arguments-slope" + ] + +-- This assumes that cost models are stored in lexicographical order +convertCostModel + :: forall costModel + . HFoldl (List Cardano.Int -> Cardano.Int -> List Cardano.Int) + (List Cardano.Int) + costModel + (List Cardano.Int) + => costModel + -> CostModel +convertCostModel model = wrap $ reverse $ List.toUnfoldable $ hfoldl + ( (\xs x -> x List.: xs) + :: List Cardano.Int -> Cardano.Int -> List Cardano.Int + ) + (mempty :: List Cardano.Int) + model + +-- Specialized conversions to only perform the type level traversals once + +convertPlutusV1CostModel :: Record CostModelV1 -> CostModel +convertPlutusV1CostModel = convertCostModel + +convertPlutusV2CostModel :: Record CostModelV2 -> CostModel +convertPlutusV2CostModel = convertCostModel + +convertPlutusV3CostModel :: Object Cardano.Int -> Maybe CostModel +convertPlutusV3CostModel costModelRaw = + wrap <$> traverse + (flip Object.lookup costModelRaw) + costModelV3Names + +convertUnnamedPlutusCostModel :: Object Cardano.Int -> Maybe CostModel +convertUnnamedPlutusCostModel costModelRaw = + wrap <<< map snd <<< Array.sortWith fst <$> + traverse (ltraverse Cardano.Int.fromString) + (Object.toUnfoldable costModelRaw) From 6854799ec9abbd97f05c858215ba1fe8b8427729 Mon Sep 17 00:00:00 2001 From: Dzmitry Shuysky Date: Mon, 16 Sep 2024 16:45:28 +0200 Subject: [PATCH 4/6] Handle non-spendable utxos when selecting collateral --- src/Internal/BalanceTx/BalanceTx.purs | 80 ++++++++++++++++++--------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/src/Internal/BalanceTx/BalanceTx.purs b/src/Internal/BalanceTx/BalanceTx.purs index a22a508d61..fec897cef6 100644 --- a/src/Internal/BalanceTx/BalanceTx.purs +++ b/src/Internal/BalanceTx/BalanceTx.purs @@ -22,6 +22,7 @@ import Cardano.Types , Transaction , TransactionBody , TransactionOutput + , TransactionUnspentOutput , UtxoMap , Value(Value) , _amount @@ -41,9 +42,10 @@ import Cardano.Types.Address (Address) import Cardano.Types.BigNum as BigNum import Cardano.Types.Coin as Coin import Cardano.Types.OutputDatum (OutputDatum(OutputDatum)) -import Cardano.Types.TransactionBody (_votingProposals) +import Cardano.Types.TransactionBody (_collateral, _votingProposals) import Cardano.Types.TransactionInput (TransactionInput) -import Cardano.Types.TransactionUnspentOutput as TransactionUnspentOutputs +import Cardano.Types.TransactionUnspentOutput (_output) +import Cardano.Types.TransactionUnspentOutput as TransactionUnspentOutput import Cardano.Types.TransactionWitnessSet (_redeemers) import Cardano.Types.UtxoMap (pprintUtxoMap) import Cardano.Types.Value (getMultiAsset, mkValue, pprintValue) @@ -65,7 +67,10 @@ import Ctl.Internal.BalanceTx.Collateral ( addTxCollateral , addTxCollateralReturn ) -import Ctl.Internal.BalanceTx.Collateral.Select (selectCollateral) +import Ctl.Internal.BalanceTx.Collateral.Select + ( minRequiredCollateral + , selectCollateral + ) as Collateral import Ctl.Internal.BalanceTx.Constraints ( BalanceTxConstraintsBuilder , _collateralUtxos @@ -137,7 +142,7 @@ import Data.Array.NonEmpty import Data.Array.NonEmpty as NEA import Data.Bitraversable (ltraverse) import Data.Either (Either, hush, note) -import Data.Foldable (fold, foldMap, foldr, length, null, sum) +import Data.Foldable (foldMap, foldr, length, null, sum) import Data.Lens (view) import Data.Lens.Getter ((^.)) import Data.Lens.Setter ((%~), (.~), (?~)) @@ -209,11 +214,6 @@ balanceTxWithConstraints transaction extraUtxos constraintsBuilder = <#> traverse (note CouldNotGetUtxos) >>> map (foldr Map.union Map.empty) -- merge all utxos into one map - unbalancedCollTx <- transactionWithNetworkId >>= - if Array.null (transaction ^. _witnessSet <<< _redeemers) - -- Don't set collateral if tx doesn't contain phase-2 scripts: - then pure - else setTransactionCollateral changeAddress let allUtxos :: UtxoMap allUtxos = @@ -223,6 +223,12 @@ balanceTxWithConstraints transaction extraUtxos constraintsBuilder = availableUtxos <- liftContract $ filterLockedUtxos allUtxos + unbalancedCollTx <- transactionWithNetworkId >>= + if Array.null (transaction ^. _witnessSet <<< _redeemers) + -- Don't set collateral if tx doesn't contain phase-2 scripts: + then pure + else setTransactionCollateral changeAddress availableUtxos + Logger.info (pprintUtxoMap allUtxos) "balanceTxWithConstraints: all UTxOs" Logger.info (pprintUtxoMap availableUtxos) "balanceTxWithConstraints: available UTxOs" @@ -253,8 +259,9 @@ balanceTxWithConstraints transaction extraUtxos constraintsBuilder = (transaction ^. _body <<< _networkId) pure (transaction # _body <<< _networkId ?~ networkId) -setTransactionCollateral :: Address -> Transaction -> BalanceTxM Transaction -setTransactionCollateral changeAddr transaction = do +setTransactionCollateral + :: Address -> UtxoMap -> Transaction -> BalanceTxM Transaction +setTransactionCollateral changeAddr availableUtxos transaction = do nonSpendableSet <- asksConstraints _nonSpendableInputs mbCollateralUtxos <- asksConstraints _collateralUtxos -- We must filter out UTxOs that are set as non-spendable in the balancer @@ -272,21 +279,42 @@ setTransactionCollateral changeAddr transaction = do when (not $ Array.null filteredUtxos) do logWarn' $ pprintTagSet "Some of the collateral UTxOs returned by the wallet were marked as non-spendable and ignored" - (pprintUtxoMap (TransactionUnspentOutputs.toUtxoMap filteredUtxos)) - pure spendableUtxos + (pprintUtxoMap (TransactionUnspentOutput.toUtxoMap filteredUtxos)) + let + collVal = + foldMap (Val.fromValue <<< view (_output <<< _amount)) + spendableUtxos + minRequiredCollateral = + BigNum.toBigInt $ + unwrap Collateral.minRequiredCollateral + if (Val.getCoin collVal < minRequiredCollateral) then do + logWarn' $ pprintTagSet + "Filtered collateral UTxOs do not cover the minimum required \ + \collateral, reselecting collateral using CTL algorithm." + (pprintUtxoMap (TransactionUnspentOutput.toUtxoMap spendableUtxos)) + selectCollateral availableUtxos + else pure spendableUtxos -- otherwise, get all the utxos, filter out unspendable, and select -- collateral using internal algo, that is also used in KeyWallet - Just utxoMap -> do - ProtocolParameters params <- liftContract getProtocolParameters - let - maxCollateralInputs = UInt.toInt $ params.maxCollateralInputs - mbCollateral = - Array.fromFoldable <$> - selectCollateral params.coinsPerUtxoByte maxCollateralInputs utxoMap - liftEither $ note (InsufficientCollateralUtxos utxoMap) mbCollateral + Just utxoMap -> selectCollateral utxoMap addTxCollateralReturn collateral (addTxCollateral collateral transaction) changeAddr +-- | Select collateral from the provided utxos using internal CTL +-- | collateral selection algorithm. +selectCollateral :: UtxoMap -> BalanceTxM (Array TransactionUnspentOutput) +selectCollateral utxos = do + pparams <- unwrap <$> liftContract getProtocolParameters + let + maxCollateralInputs = UInt.toInt $ pparams.maxCollateralInputs + mbCollateral = + Array.fromFoldable <$> Collateral.selectCollateral + pparams.coinsPerUtxoByte + maxCollateralInputs + utxos + liftEither $ note (InsufficientCollateralUtxos utxos) + mbCollateral + -------------------------------------------------------------------------------- -- Balancing Algorithm -------------------------------------------------------------------------------- @@ -346,11 +374,11 @@ runBalancer p = do isCip30 <- liftContract $ isCip30Wallet -- Get collateral inputs to mark them as unspendable. -- Some CIP-30 wallets don't allow to sign Txs that spend it. - nonSpendableCollateralInputs <- - if isCip30 then - liftContract $ Wallet.getWalletCollateral <#> - fold >>> map (unwrap >>> _.input) >>> Set.fromFoldable - else mempty + let + nonSpendableCollateralInputs = + if isCip30 then + Set.fromFoldable $ p.transaction ^. _body <<< _collateral + else mempty asksConstraints Constraints._nonSpendableInputs <#> append nonSpendableCollateralInputs >>> \nonSpendableInputs -> From 79875287ada12a967041762489b4c99b6bc812f3 Mon Sep 17 00:00:00 2001 From: Dzmitry Shuysky Date: Mon, 16 Sep 2024 18:11:03 +0200 Subject: [PATCH 5/6] Select collateral from available pkh utxos as fallback, Add test --- src/Internal/BalanceTx/BalanceTx.purs | 12 +++++- test/Testnet/Contract.purs | 55 ++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/Internal/BalanceTx/BalanceTx.purs b/src/Internal/BalanceTx/BalanceTx.purs index fec897cef6..01659630a3 100644 --- a/src/Internal/BalanceTx/BalanceTx.purs +++ b/src/Internal/BalanceTx/BalanceTx.purs @@ -39,8 +39,10 @@ import Cardano.Types , _witnessSet ) import Cardano.Types.Address (Address) +import Cardano.Types.Address (getPaymentCredential) as Address import Cardano.Types.BigNum as BigNum import Cardano.Types.Coin as Coin +import Cardano.Types.Credential (asPubKeyHash) as Credential import Cardano.Types.OutputDatum (OutputDatum(OutputDatum)) import Cardano.Types.TransactionBody (_collateral, _votingProposals) import Cardano.Types.TransactionInput (TransactionInput) @@ -152,6 +154,7 @@ import Data.Map (Map) import Data.Map ( empty , filter + , filterKeys , insert , isEmpty , lookup @@ -292,7 +295,14 @@ setTransactionCollateral changeAddr availableUtxos transaction = do "Filtered collateral UTxOs do not cover the minimum required \ \collateral, reselecting collateral using CTL algorithm." (pprintUtxoMap (TransactionUnspentOutput.toUtxoMap spendableUtxos)) - selectCollateral availableUtxos + let + isPkhUtxo txOut = isJust do + cred <- Address.getPaymentCredential $ (unwrap txOut).address + Credential.asPubKeyHash $ unwrap cred + availableUtxos' <- liftContract $ + Map.filter isPkhUtxo <<< Map.filterKeys isSpendable <$> + filterLockedUtxos availableUtxos + selectCollateral availableUtxos' else pure spendableUtxos -- otherwise, get all the utxos, filter out unspendable, and select -- collateral using internal algo, that is also used in KeyWallet diff --git a/test/Testnet/Contract.purs b/test/Testnet/Contract.purs index 7bf1b3d658..bcfdb3823c 100644 --- a/test/Testnet/Contract.purs +++ b/test/Testnet/Contract.purs @@ -166,7 +166,7 @@ import Data.Either (Either(Left, Right), hush, isLeft, isRight) import Data.Foldable (fold, foldM, length) import Data.Lens (view) import Data.Map as Map -import Data.Maybe (Maybe(Just, Nothing), fromJust, fromMaybe, isJust) +import Data.Maybe (Maybe(Just, Nothing), fromJust, fromMaybe, isJust, maybe) import Data.Newtype (unwrap, wrap) import Data.Traversable (traverse, traverse_) import Data.Tuple (Tuple(Tuple)) @@ -223,7 +223,7 @@ suite = do withWallets distribution \alice -> do withKeyWallet alice ManyAssets.contract test - "#1509 - Collateral set to one of the inputs in mustNotSpendUtxosWithOutRefs " + "#1509 - Collateral set to one of the inputs in mustNotSpendUtxosWithOutRefs" do let someUtxos = @@ -253,6 +253,57 @@ suite = do ) res `shouldSatisfy` isLeft + test + "#1581 - Fallback to CTL collateral selection when all collateral inputs are non-spendable" + do + let + distribution = + [ BigNum.fromInt 10_000_000 + , BigNum.fromInt 10_000_000 + ] + withWallets distribution \alice -> + withKeyWallet alice do + validator <- AlwaysSucceeds.alwaysSucceedsScript + let vhash = validatorHash validator + logInfo' "Attempt to lock value" + txId <- AlwaysSucceeds.payToAlwaysSucceeds vhash + awaitTxConfirmed txId + logInfo' "Try to spend locked values" + + scriptAddress <- mkAddress (wrap $ ScriptHashCredential vhash) + Nothing + utxos <- utxosAt scriptAddress + scriptUtxo <- + liftM + ( error + ( "The id " + <> show txId + <> " does not have output locked at: " + <> show scriptAddress + ) + ) + $ head (lookupTxHash txId utxos) + + unbalancedTx <- buildTx + [ SpendOutput scriptUtxo $ Just $ PlutusScriptOutput + (ScriptValue validator) + RedeemerDatum.unit + (Just $ DatumValue PlutusData.unit) + ] + + collUtxos <- getWalletCollateral + let + balancerConstraints = + maybe + mempty + (mustNotSpendUtxosWithOutRefs <<< Map.keys <<< toUtxoMap) + collUtxos + + balancedTx <- balanceTx unbalancedTx (toUtxoMap [ scriptUtxo ]) + balancerConstraints + balancedSignedTx <- signTransaction balancedTx + submitAndLog balancedSignedTx + test "#1480 - test that does nothing but fails" do let someUtxos = From 566e7153c88fdab7005a3b4b02e6fec41c7d5c94 Mon Sep 17 00:00:00 2001 From: Dzmitry Shuysky Date: Tue, 17 Sep 2024 17:05:44 +0200 Subject: [PATCH 6/6] Restore onClusterStartup hook for cardano-testnet --- src/Internal/Contract/Hooks.purs | 7 ++--- src/Internal/Testnet/Contract.purs | 7 ++++- test/Testnet.purs | 3 +- test/Testnet/ClusterParameters.purs | 43 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 test/Testnet/ClusterParameters.purs diff --git a/src/Internal/Contract/Hooks.purs b/src/Internal/Contract/Hooks.purs index 52a2d55582..ca4bf4dc5f 100644 --- a/src/Internal/Contract/Hooks.purs +++ b/src/Internal/Contract/Hooks.purs @@ -6,11 +6,11 @@ module Ctl.Internal.Contract.Hooks import Prelude -import Cardano.Types.PrivateKey (PrivateKey) import Cardano.Types.Transaction (Transaction) import Data.Maybe (Maybe(Nothing)) import Effect (Effect) import Effect.Exception (Error) +import Node.Path (FilePath) type Hooks = { beforeSign :: Maybe (Effect Unit) @@ -22,10 +22,7 @@ type Hooks = } type ClusterParameters = - { privateKeys :: Array PrivateKey - , nodeSocketPath :: String - , nodeConfigPath :: String - , privateKeysDirectory :: String + { nodeSocketPath :: FilePath } emptyHooks :: Hooks diff --git a/src/Internal/Testnet/Contract.purs b/src/Internal/Testnet/Contract.purs index 98180a48d3..fdcfb8a070 100644 --- a/src/Internal/Testnet/Contract.purs +++ b/src/Internal/Testnet/Contract.purs @@ -77,8 +77,8 @@ import Ctl.Internal.Testnet.Utils import Data.Array (concat, fromFoldable, zip) as Array import Data.Bifunctor (lmap) import Data.Map (values) as Map +import Effect.Aff (apathize, try) import Effect.Aff (bracket) as Aff -import Effect.Aff (try) import Effect.Exception (error) import Effect.Ref (Ref) import Effect.Ref (new, read, write) as Ref @@ -246,6 +246,11 @@ startTestnetContractEnv cfg distr cleanupRef = do { env, printLogs, clearLogs } <- makeClusterContractEnv cleanupRef cfg let env' = env { networkId = TestnetId } wallets <- mkWallets env' cluster + apathize $ liftEffect $ + for_ env.hooks.onClusterStartup \onClusterStartup -> + onClusterStartup + { nodeSocketPath: (unwrap cluster).paths.nodeSocketPath + } pure { cluster , env: env' diff --git a/test/Testnet.purs b/test/Testnet.purs index ad5fe4720e..c4d0fa0f66 100644 --- a/test/Testnet.purs +++ b/test/Testnet.purs @@ -26,6 +26,7 @@ import Mote.Monad (mapTest) import Mote.TestPlanM as Utils import Test.Ctl.BalanceTx.ChangeGeneration as ChangeGeneration import Test.Ctl.QueryM.AffInterface as QueryM.AffInterface +import Test.Ctl.Testnet.ClusterParameters (runTest) as ClusterParameters import Test.Ctl.Testnet.Contract as Contract import Test.Ctl.Testnet.Contract.Assert as Assert import Test.Ctl.Testnet.Contract.Mnemonics as Mnemonics @@ -63,7 +64,7 @@ main = interruptOnSignal SIGINT =<< launchAff do UtxoDistribution.suite testTestnetContracts config OgmiosMempool.suite runTestnetTestPlan config SameWallets.suite --- FIXME: ClusterParameters.runTest + ClusterParameters.runTest {- configWithMaxExUnits :: PlutipConfig diff --git a/test/Testnet/ClusterParameters.purs b/test/Testnet/ClusterParameters.purs new file mode 100644 index 0000000000..14a62c0a05 --- /dev/null +++ b/test/Testnet/ClusterParameters.purs @@ -0,0 +1,43 @@ +module Test.Ctl.Testnet.ClusterParameters + ( mkSuite + , runTest + ) where + +import Prelude + +import Contract.Log (logDebug') +import Contract.Test (ContractTest, withWallets) +import Contract.Test.Mote (TestPlanM) +import Contract.Test.Testnet (defaultTestnetConfig, testTestnetContracts) +import Ctl.Internal.Contract.Hooks (ClusterParameters) +import Data.Maybe (Maybe(Just)) +import Effect.Aff (Aff) +import Effect.Class (liftEffect) +import Effect.Ref (Ref) +import Effect.Ref as Ref +import Mote (group, test) +import Test.Spec.Assertions (shouldNotEqual) + +runTest :: TestPlanM (Aff Unit) Unit +runTest = do + clusterParamsRef <- + liftEffect $ Ref.new + { nodeSocketPath: mempty + } + testTestnetContracts + defaultTestnetConfig + { hooks = defaultTestnetConfig.hooks + { onClusterStartup = Just (flip Ref.write clusterParamsRef) + } + } + (mkSuite clusterParamsRef) + +mkSuite :: Ref ClusterParameters -> TestPlanM ContractTest Unit +mkSuite ref = do + group "ClusterParameters" do + test "Reading cardano-testnet cluster parameters" do + withWallets unit \_ -> do + clusterParams <- liftEffect $ Ref.read ref + clusterParams.nodeSocketPath `shouldNotEqual` mempty + logDebug' $ "ClusterParameters: " <> show clusterParams + pure unit