Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ main = do
run :: Options -> IO ()
run Options{..} = do
config@CM.ConfigMap{..} <-
CM.readConfigMap scriptYaml networkId socketPath >>= either error pure
CM.readConfigMap scriptYaml networkId socketPath leashId >>= either error pure

start <- maybe (C.chainTipToChainPoint <$> C.getLocalChainTip cmLocalNodeConn) pure cmStart
let points = [start]
Expand Down
11 changes: 11 additions & 0 deletions app/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Cardano.Api
import Data.Foldable (fold)
import Network.Wai.Handler.Warp (Port)
import Options.Applicative
import Ouroboros.Network.Protocol.LocalStateQuery.Type (LeashID (..))
import System.Environment.Blank (getEnvDefault)
import Text.Read (readMaybe)

Expand All @@ -24,6 +25,7 @@ data Options = Options
, httpServerPort :: Port
, logsPath :: Maybe FilePath
, sqlitePath :: Maybe FilePath
, leashId :: LeashID
}
deriving (Show, Eq)

Expand All @@ -39,6 +41,7 @@ mkParseOptions = do
<*> optHTTPServerPort
<*> optional optLogsPath
<*> optional optSqlitePath
<*> optLeashId
where
optSocketPath nodeSocketPath =
( File
Expand Down Expand Up @@ -95,6 +98,14 @@ mkParseOptions = do
<> metavar "SQLITE_PATH"
<> help "Path to sqlite database"
)
optLeashId =
LeashID
<$> option
auto
( long "leash-id"
<> metavar "LEASH_ID"
<> help "ID to use when leashing the node"
)

mkPsrOpts :: IO (ParserInfo Options)
mkPsrOpts = do
Expand Down
12 changes: 6 additions & 6 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,24 @@ constraints:
source-repository-package
type: git
location: https://github.com/tweag/ouroboros-network
tag: 8aa240eef5673d4f397f2037fa95b6fec250f89b
--sha256: sha256-rBWeRG83zu67KJGl+eYxB1tZ7GWyjeKaegVnk+YUcCE=
tag: 63601d2bd9fa447c1f21efa1a2466e131945cf6e
--sha256: sha256-FC/CI67Jk4GNgPPyrWCWl5trCxeon2RSHzhHRZHluak=
subdir:
ouroboros-network-protocols

source-repository-package
type: git
location: https://github.com/tweag/ouroboros-consensus
tag: c65cc4b73f9bd17d67bb0d50caf1b0da2a650013
--sha256: sha256-mimWIpW6DBeYPjqPY+K1ZiPzyHJvlzYdtvU26BUZOAU=
tag: 5ac599db62d287ee5db7823008f81a801e1384b8
--sha256: sha256-UnrXFqOBIUmjYwJJMy88KNEtVvHN5IHCXu+c9vzqQMw=
subdir:
ouroboros-consensus
ouroboros-consensus-diffusion

source-repository-package
type: git
location: https://github.com/tweag/cardano-api
tag: 9ffe8b21aff66862506fef05b9711e7d62c158fd
--sha256: sha256-yqOdD2gA+g146UjUGE+ynlPrzIvlci2JUm0fgPb8msg=
tag: df4db4a4b49c54661743f62c487539e18426c5a5
--sha256: sha256-Es4iWiR4oFPV29KRA2/AlcI6+k50M4u/uDrWM4oToD4=
subdir:
cardano-api
2 changes: 1 addition & 1 deletion dev-local/process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ processes:
disabled: true

script-reexecutor:
command: "cabal run plutus-script-reexecutor -- run --node-socket devnet-env/socket/node1/sock --testnet-magic 42 --script-yaml local-config/scripts.yaml --logs-path events.log --sqlite-path plutus-script-reexecutor.db --http-server-port 8090"
command: "cabal run plutus-script-reexecutor -- run --node-socket devnet-env/socket/node1/sock --testnet-magic 42 --script-yaml local-config/scripts.yaml --logs-path events.log --sqlite-path plutus-script-reexecutor.db --http-server-port 8090 --leash-id 2600"
depends_on:
cardano-testnet:
condition: process_healthy
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@

flake-utils.url = "github:numtide/flake-utils";

cardano-node.url = "github:tweag/cardano-node/fc02d1ef2126ffe5b62a6eda5a08a52347ebb6ef";
cardano-node.url = "github:tweag/cardano-node/276fe0b213d2f2235306872e136df65617c70686";
};

outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
import ./nix/outputs.nix { inherit inputs system; }
);

nixConfig = {
extra-substituters = [
"https://cache.iog.io"
"https://cache.zw3rk.com"
extra-substituters = [
"https://cache.iog.io"
"https://cache.zw3rk.com"
"https://plutus-script-reexecutor.cachix.org"
];
extra-trusted-public-keys = [
Expand Down
5 changes: 3 additions & 2 deletions lib/PSR/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ sysStartQuery = do

runLocalStateQueryExpr ::
C.LocalNodeConnectInfo ->
Net.Query.LeashID ->
C.ChainPoint ->
C.LocalStateQueryExpr C.BlockInMode C.ChainPoint C.QueryInMode () IO a ->
IO a
runLocalStateQueryExpr conn cp query = do
res <- C.executeLocalStateQueryExprLeashed conn (Net.Query.SpecificPoint cp) query
runLocalStateQueryExpr conn leashId cp query = do
res <- C.executeLocalStateQueryExprLeashed conn leashId False (Net.Query.SpecificPoint cp) query
case res of
Left err -> throw $ QeAcquiringFailure err
Right val -> pure val
Expand Down
7 changes: 5 additions & 2 deletions lib/PSR/ConfigMap.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Data.Map qualified as Map
import Data.Text (Text)
import Data.Text qualified as Text
import Data.Yaml (decodeFileEither)
import Ouroboros.Network.Protocol.LocalStateQuery.Type (LeashID)
import PSR.Chain (mkLocalNodeConnectInfo)
import PSR.Types (deriveJSONRecord, deriveJSONSimpleSum)
import PlutusLedgerApi.Common (
Expand Down Expand Up @@ -81,6 +82,7 @@ data ConfigMap = ConfigMap
{ cmStart :: Maybe C.ChainPoint
, cmScripts :: Map C.ScriptHash [ResolvedScript]
, cmLocalNodeConn :: C.LocalNodeConnectInfo
, cmLeashId :: LeashID
}

-- | Information relating to a loaded script
Expand Down Expand Up @@ -181,8 +183,8 @@ readScriptFile scriptYamlDir scrutScriptHash (ix, ScriptDetails{..}) = do
}

-- | Parse the config from a given Yaml file on disk
readConfigMap :: FilePath -> C.NetworkId -> C.SocketPath -> IO (Either String ConfigMap)
readConfigMap scriptYaml networkId socketPath = runExceptT $ do
readConfigMap :: FilePath -> C.NetworkId -> C.SocketPath -> LeashID -> IO (Either String ConfigMap)
readConfigMap scriptYaml networkId socketPath leashId = runExceptT $ do
ConfigMapFile{..} <- withExceptT show $ ExceptT $ decodeFileEither scriptYaml
let scriptYamlDir = dropFileName scriptYaml
-- NOTE: The list of substitutions here can be empty, it just signals that
Expand All @@ -200,4 +202,5 @@ readConfigMap scriptYaml networkId socketPath = runExceptT $ do
{ cmStart = cmfStart
, cmScripts = Map.fromList kvPairs
, cmLocalNodeConn = mkLocalNodeConnectInfo networkId socketPath
, cmLeashId = leashId
}
13 changes: 8 additions & 5 deletions lib/PSR/ContextBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Data.Map.Ordered qualified as OMap
import Data.Maybe (mapMaybe)
import Data.Set (Set)
import Data.Set qualified as Set
import Ouroboros.Network.Protocol.LocalStateQuery.Type (LeashID)
import PSR.Chain
import PSR.ConfigMap (ConfigMap (..), ResolvedScript (..))
import PSR.Evaluation.Api (evaluateTransactionExecutionUnitsShelley)
Expand Down Expand Up @@ -95,11 +96,12 @@ mkBlockContext ::
ContextBuilderMetrics ->
C.BlockHeader ->
C.LocalNodeConnectInfo ->
LeashID ->
C.ChainPoint ->
C.AlonzoEraOnwards era ->
[C.Tx era] ->
IO (BlockContext era)
mkBlockContext metrics bh conn prevCp era txs = do
mkBlockContext metrics bh conn leashId prevCp era txs = do
let sbe = C.convert era
query =
BlockContext bh prevCp era txs
Expand All @@ -109,17 +111,18 @@ mkBlockContext metrics bh conn prevCp era txs = do
<*> sysStartQuery
-- NOTE: We can catch CostModelsQueryException and choose to retry or skip.
observeDuration metrics.mkBlockContext_query $
runLocalStateQueryExpr conn prevCp query
runLocalStateQueryExpr conn leashId prevCp query

-- NOTE: This is a costly function, but we only run it once.
getSpendProjectedUtxoMap ::
C.LocalNodeConnectInfo ->
LeashID ->
C.ChainPoint ->
C.ShelleyBasedEra era ->
Set C.ScriptHash ->
IO (Map C.TxIn C.ScriptHash)
getSpendProjectedUtxoMap conn cp sbe confHashes = do
C.UTxO umap <- runLocalStateQueryExpr conn cp (utxoWholeQuery sbe)
getSpendProjectedUtxoMap conn leashId cp sbe confHashes = do
C.UTxO umap <- runLocalStateQueryExpr conn leashId cp (utxoWholeQuery sbe)
pure $ Map.filter (flip Set.member confHashes) $ Map.mapMaybe getTxOutScriptAddr umap

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -336,5 +339,5 @@ evaluateTransaction BlockContext{..} (C.ShelleyTx era tx) scriptMap = do
-- TODO: Report this error to the user.
mkLedgerScript ResolvedScript{..} = do
scr <- C.toScriptInEra (C.convert ctxAlonzoEraOnwards) rsScriptFileContent
pure $ (rsName, C.toShelleyScript scr)
pure (rsName, C.toShelleyScript scr)
subMap = Map.map (mapMaybe mkLedgerScript) scriptMap
6 changes: 3 additions & 3 deletions lib/PSR/Streaming.hs
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ mainLoop events cm@CM.ConfigMap{..} points = do
& void
where
confHashes = Map.keysSet cmScripts
consumeBlock metrics cbMetrics mUtxoMap (previousChainPt, (Block bh sbe txList)) = do
consumeBlock metrics cbMetrics mUtxoMap (previousChainPt, Block bh sbe txList) = do
let getUtxoMap =
case mUtxoMap of
Nothing ->
getSpendProjectedUtxoMap cmLocalNodeConn previousChainPt sbe confHashes
getSpendProjectedUtxoMap cmLocalNodeConn cmLeashId previousChainPt sbe confHashes
Just utxoMap -> pure utxoMap
-- NOTE: We only consume a specific set of transactions and not all
-- the transactions in a block. We use the internal UTxO map to
-- decide which transaction meet the criteria.
consumeTransactions era selectedTxs = do
ctx1 <- mkBlockContext cbMetrics bh cmLocalNodeConn previousChainPt era selectedTxs
ctx1 <- mkBlockContext cbMetrics bh cmLocalNodeConn cmLeashId previousChainPt era selectedTxs
streamTransactionContext cbMetrics cm ctx1
& Stream.trace (traceTransactionExecutionResult events)
& Stream.fold Fold.drain
Expand Down
3 changes: 2 additions & 1 deletion plutus-script-reexecutor.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ executable plutus-script-reexecutor
hs-source-dirs: app
build-depends:
, async
, base >=4.9 && <5
, base >=4.9 && <5
, cardano-api
, optparse-applicative
, ouroboros-network-protocols
, plutus-script-reexecutor
, streamly-core
, warp
Expand Down