Skip to content

Commit

Permalink
Merge pull request #1150 from Plutonomicon/jy14898/cache-pparam
Browse files Browse the repository at this point in the history
Cache ProtocolParameters during balancing
  • Loading branch information
klntsky committed Oct 27, 2022
2 parents 886ac0a + e9a471e commit ccb328d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 30 deletions.
4 changes: 3 additions & 1 deletion src/Contract/ProtocolParameters.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ module Contract.ProtocolParameters
) where

import Contract.Monad (Contract, wrapContract)
import Ctl.Internal.QueryM (getProtocolParameters) as QueryM
import Ctl.Internal.QueryM.Ogmios (ProtocolParameters)
import Ctl.Internal.QueryM.ProtocolParameters (getProtocolParameters) as QueryM

-- | Returns the `ProtocolParameters` from the `Contract` environment.
-- | Note that this is not necessarily the current value from the ledger.
getProtocolParameters :: forall (r :: Row Type). Contract r ProtocolParameters
getProtocolParameters = wrapContract QueryM.getProtocolParameters
3 changes: 1 addition & 2 deletions src/Internal/Plutip/Server.purs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import Ctl.Internal.QueryM
)
import Ctl.Internal.QueryM as QueryM
import Ctl.Internal.QueryM.Logging (setupLogs)
import Ctl.Internal.QueryM.ProtocolParameters as Ogmios
import Ctl.Internal.QueryM.UniqueId (uniqueId)
import Ctl.Internal.Types.UsedTxOuts (newUsedTxOuts)
import Ctl.Internal.Wallet.Key (PrivatePaymentKey(PrivatePaymentKey))
Expand Down Expand Up @@ -491,7 +490,7 @@ mkClusterContractEnv plutipCfg logger customLogger = do
, host = plutipCfg.ogmiosConfig.host
}
usedTxOuts <- newUsedTxOuts
pparams <- Ogmios.getProtocolParametersAff ogmiosWs logger
pparams <- QueryM.getProtocolParametersAff ogmiosWs logger
pure $ ContractEnv
{ config:
{ ctlServerConfig: plutipCfg.ctlServerConfig
Expand Down
7 changes: 7 additions & 0 deletions src/Internal/QueryM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Ctl.Internal.QueryM
, getDatumsByHashes
, getDatumsByHashesWithErrors
, getLogger
, getProtocolParameters
, getProtocolParametersAff
, getWalletAddresses
, liftQueryM
Expand Down Expand Up @@ -453,6 +454,12 @@ runQueryMInRuntime
runQueryMInRuntime config runtime = do
flip runReaderT { config, runtime, extraConfig: {} } <<< unwrap

-- | Returns the `ProtocolParameters` from the `QueryM` environment.
-- | Note that this is not necessarily the current value from the ledger.
getProtocolParameters :: QueryM Ogmios.ProtocolParameters
getProtocolParameters =
asks $ _.runtime >>> _.pparams

getProtocolParametersAff
:: OgmiosWebSocket
-> (LogLevel -> String -> Effect Unit)
Expand Down
3 changes: 1 addition & 2 deletions src/Internal/QueryM/MinFee.purs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import Ctl.Internal.Cardano.Types.TransactionUnspentOutput
)
import Ctl.Internal.Cardano.Types.Value (Coin)
import Ctl.Internal.Helpers (liftM, liftedM)
import Ctl.Internal.QueryM (QueryM, getWalletAddresses)
import Ctl.Internal.QueryM.ProtocolParameters (getProtocolParameters)
import Ctl.Internal.QueryM (QueryM, getProtocolParameters, getWalletAddresses)
import Ctl.Internal.QueryM.Utxos (getUtxo, getWalletCollateral)
import Ctl.Internal.Serialization.Address
( Address
Expand Down
17 changes: 0 additions & 17 deletions src/Internal/QueryM/ProtocolParameters.purs

This file was deleted.

8 changes: 6 additions & 2 deletions src/Internal/Types/ScriptLookups.purs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ import Ctl.Internal.Plutus.Types.Transaction (TransactionOutputWithRefScript) as
import Ctl.Internal.Plutus.Types.TransactionUnspentOutput
( TransactionUnspentOutput(TransactionUnspentOutput)
)
import Ctl.Internal.QueryM (QueryM, QueryMExtended, getDatumByHash)
import Ctl.Internal.QueryM
( QueryM
, QueryMExtended
, getDatumByHash
, getProtocolParameters
)
import Ctl.Internal.QueryM.EraSummaries (getEraSummaries)
import Ctl.Internal.QueryM.ProtocolParameters (getProtocolParameters)
import Ctl.Internal.QueryM.SystemStart (getSystemStart)
import Ctl.Internal.Scripts
( mintingPolicyHash
Expand Down
6 changes: 0 additions & 6 deletions test/AffInterface.purs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Ctl.Internal.QueryM
import Ctl.Internal.QueryM.CurrentEpoch (getCurrentEpoch)
import Ctl.Internal.QueryM.EraSummaries (getEraSummaries)
import Ctl.Internal.QueryM.Ogmios (OgmiosAddress)
import Ctl.Internal.QueryM.ProtocolParameters (getProtocolParameters)
import Ctl.Internal.QueryM.SystemStart (getSystemStart)
import Ctl.Internal.QueryM.Utxos (utxosAt)
import Ctl.Internal.QueryM.WaitUntilSlot (waitUntilSlot)
Expand Down Expand Up @@ -55,7 +54,6 @@ suite = do
test "Get ChainTip" testGetChainTip
test "Get waitUntilSlot" testWaitUntilSlot
test "Get EraSummaries" testGetEraSummaries
test "Get ProtocolParameters" testGetProtocolParameters
test "Get CurrentEpoch" testGetCurrentEpoch
test "Get SystemStart" testGetSystemStart
group "Ogmios error" do
Expand Down Expand Up @@ -117,10 +115,6 @@ testSubmitTxFailure = do
let bytes = hexToByteArrayUnsafe "00"
void $ submitTxOgmios bytes (wrap bytes)

testGetProtocolParameters :: QueryM Unit
testGetProtocolParameters = do
void getProtocolParameters

testGetCurrentEpoch :: QueryM Unit
testGetCurrentEpoch = do
void getCurrentEpoch
Expand Down

0 comments on commit ccb328d

Please sign in to comment.