Skip to content

Commit

Permalink
Add a function that starts the configured node.
Browse files Browse the repository at this point in the history
  • Loading branch information
raduom committed Jan 17, 2022
1 parent 18da7f7 commit 83551a0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
16 changes: 8 additions & 8 deletions plutus-pab-executables/tx-inject/config.yaml
Expand Up @@ -13,18 +13,18 @@ walletServerConfig:
baseUrl: http://localhost:9081

nodeServerConfig:
mscBaseUrl: http://localhost:9082
mscSocketPath: /tmp/node-server.sock
mscKeptBlocks: 100000
mscNetworkId: "1097911063"
mscSlotConfig:
pscBaseUrl: http://localhost:9082
pscSocketPath: /tmp/node-server.sock
pscKeptBlocks: 100000
pscNetworkId: "1097911063"
pscSlotConfig:
scSlotZeroTime: 1596059091000 # Wednesday, July 29, 2020 21:44:51 - shelley launch time in milliseconds
scSlotLength: 1000 # In milliseconds
mscFeeConfig:
pscFeeConfig:
fcConstantFee:
getLovelace: 10 # Constant fee per transaction in lovelace
fcScriptsFeeFactor: 1.0 # Factor by which to multiply size-dependent scripts fee in lovelace
mscInitialTxWallets:
pscInitialTxWallets:
- getWallet: 1
- getWallet: 2
- getWallet: 3
Expand All @@ -35,7 +35,7 @@ nodeServerConfig:
- getWallet: 8
- getWallet: 9
- getWallet: 10
mscNodeMode: AlonzoNode
pscNodeMode: AlonzoNode

chainIndexConfig:
ciBaseUrl: http://localhost:9083
Expand Down
22 changes: 19 additions & 3 deletions plutus-pab/src/Cardano/Node/Client.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
Expand All @@ -15,8 +16,9 @@ import Ledger.TimeSlot (SlotConfig)
import Servant (NoContent, (:<|>) (..))
import Servant.Client (ClientM, client)

import Cardano.Api.NetworkId.Extra (NetworkIdWrapper (..))
import Cardano.Node.API (API)
import Cardano.Node.Types (ChainSyncHandle, PABServerConfig, PABServerLogMsg)
import Cardano.Node.Types (ChainSyncHandle, NodeMode (..), PABServerConfig (..), PABServerLogMsg)
import Cardano.Protocol.Socket.Client qualified as Client
import Cardano.Protocol.Socket.Mock.Client qualified as MockClient
import Control.Monad.Freer.Extras.Log (LogMessage)
Expand Down Expand Up @@ -51,8 +53,22 @@ handleNodeClientClient slotCfg e = do
either (liftIO . MockClient.getCurrentSlot) (liftIO . Client.getCurrentSlot) chainSyncHandle
GetClientSlotConfig -> pure slotCfg

-- | This does not seem to support resuming so it means that the slot tick will
-- be behind everything else. This is due to having 2 connections to the node
-- one for chainSync/block transfer and one for chainSync/currentSlot information.
-- TODO: Think about merging the two functionalities, or keep them in sync.
runChainSyncWithCfg ::
PABServerConfig
-> IO ChainSyncHandle
runChainSyncWithCfg = undefined

runChainSyncWithCfg PABServerConfig { pscSocketPath
, pscNodeMode
, pscNetworkId
, pscSlotConfig } =
case pscNodeMode of
AlonzoNode ->
Right <$> Client.runChainSync' pscSocketPath
pscSlotConfig
(unNetworkIdWrapper pscNetworkId)
[]
MockNode ->
Left <$> MockClient.runChainSync' pscSocketPath pscSlotConfig
6 changes: 3 additions & 3 deletions plutus-pab/src/Plutus/PAB/App.hs
Expand Up @@ -33,7 +33,7 @@ import Cardano.Api.ProtocolParameters ()
import Cardano.Api.Shelley (ProtocolParameters)
import Cardano.BM.Trace (Trace, logDebug)
import Cardano.ChainIndex.Types qualified as ChainIndex
import Cardano.Node.Client (handleNodeClientClient)
import Cardano.Node.Client (handleNodeClientClient, runChainSyncWithCfg)
import Cardano.Node.Types (ChainSyncHandle, NodeMode (AlonzoNode, MockNode),
PABServerConfig (PABServerConfig, pscBaseUrl, pscNetworkId, pscNodeMode, pscProtocolParametersJsonPath, pscSlotConfig, pscSocketPath))
import Cardano.Protocol.Socket.Mock.Client qualified as MockClient
Expand Down Expand Up @@ -250,7 +250,7 @@ data StorageBackend = BeamSqliteBackend | InMemoryBackend

mkEnv :: Trace IO (PABLogMsg (Builtin a)) -> Config -> IO (AppEnv a)
mkEnv appTrace appConfig@Config { dbConfig
, nodeServerConfig = PABServerConfig{pscBaseUrl, pscSocketPath, pscSlotConfig, pscProtocolParametersJsonPath}
, nodeServerConfig = PABServerConfig{pscBaseUrl, pscSocketPath, pscProtocolParametersJsonPath}
, walletServerConfig
, chainIndexConfig
} = do
Expand All @@ -260,7 +260,7 @@ mkEnv appTrace appConfig@Config { dbConfig
dbConnection <- dbConnect appTrace dbConfig
txSendHandle <- liftIO $ MockClient.runTxSender pscSocketPath
-- This is for access to the slot number in the interpreter
chainSyncHandle <- Left <$> (liftIO $ MockClient.runChainSync' pscSocketPath pscSlotConfig)
chainSyncHandle <- runChainSyncWithCfg $ nodeServerConfig appConfig
appInMemContractStore <- liftIO initialInMemInstances
protocolParameters <- maybe (pure def) readPP pscProtocolParametersJsonPath
pure AppEnv {..}
Expand Down

0 comments on commit 83551a0

Please sign in to comment.