Skip to content

Commit

Permalink
Revert unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbertra committed Nov 6, 2023
1 parent 4f11864 commit d7888ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Language.Marlowe.Runtime.ChainIndexer.Store (
chainStore,
) where

import Colog (Message, WithLog, logInfo)
import Colog (Message, WithLog)
import Control.Concurrent.Component
import Control.Concurrent.STM (STM, newTVar, readTVar)
import Control.Concurrent.STM.Delay (Delay, newDelay, waitDelay)
Expand Down Expand Up @@ -77,9 +77,7 @@ chainStore = component "indexer-chain-store" \ChainStoreDependencies{..} -> do
case mDbGenesisBlock of
Just dbGenesisBlock -> unless (dbGenesisBlock == genesisBlock) do
liftIO $ fail "Existing genesis block does not match computed genesis block"
Nothing -> do
logInfo "Saving Genesis block"
runCommitGenesisBlock commitGenesisBlock genesisBlock
Nothing -> runCommitGenesisBlock commitGenesisBlock genesisBlock
atomically $ writeTVar readyVar True
go Nothing
where
Expand All @@ -97,7 +95,7 @@ chainStore = component "indexer-chain-store" \ChainStoreDependencies{..} -> do
computeDelay :: UTCTime -> IO (Maybe Delay)
computeDelay lastWrite = runMaybeT do
currentTime <- lift getCurrentTime
let nextWrite = addUTCTime 0 lastWrite
let nextWrite = addUTCTime rateLimit lastWrite
guard $ nextWrite > currentTime
let delay = nextWrite `diffUTCTime` currentTime
let delayMicroseconds = floor $ 1_000_000 * nominalDiffTimeToSeconds delay
Expand Down
2 changes: 1 addition & 1 deletion marlowe-integration/src/Test/Integration/Marlowe/Local.hs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ withLocalMarloweRuntime' MarloweRuntimeOptions{..} test = withRunInIO \runInIO -
byronGenesisConfig
shelleyGenesisConfig

chainIndexerDatabaseQueries = ChainIndexer.databaseQueries 10 pool genesisBlock
chainIndexerDatabaseQueries = ChainIndexer.databaseQueries pool genesisBlock

chainSyncDatabaseQueries = ChainSync.databaseQueries pool localNodeNetworkId

Expand Down
33 changes: 9 additions & 24 deletions marlowe-runtime/marlowe-runtime/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
module Main where

import Cardano.Api (
AnyCardanoEra (..),
CardanoMode,
ConsensusMode (..),
ConsensusModeIsMultiEra (..),
ConsensusModeParams (..),
EpochSlots (..),
EraInMode (..),
Expand All @@ -26,7 +23,6 @@ import Cardano.Api (
QueryInShelleyBasedEra (..),
ShelleyBasedEra (..),
queryNodeLocalState,
toEraInMode,
)
import qualified Cardano.Api as Cardano
import Cardano.Api.Byron (toByronRequiresNetworkMagic)
Expand Down Expand Up @@ -126,31 +122,13 @@ run Options{..} = bracket (Pool.acquire 100 (Just 5000000) (fromString databaseU
}

genesisBlock = computeGenesisBlock (abstractHashToBytes hash) genesisConfig shelleyGenesis
Right (AnyCardanoEra era) <-
queryNodeLocalState localNodeConnectInfo Nothing $ QueryCurrentEra CardanoModeIsMultiEra
eraInMode <- case toEraInMode era CardanoMode of
Nothing -> fail $ "cannot convert " <> show era <> " to era in mode"
Just eraInMode -> pure eraInMode
shelleyBasedEra <- case eraInMode of
ByronEraInCardanoMode -> fail "Cannot query shelley in byron era"
ShelleyEraInCardanoMode -> pure ShelleyBasedEraShelley
AllegraEraInCardanoMode -> pure ShelleyBasedEraAllegra
MaryEraInCardanoMode -> pure ShelleyBasedEraMary
AlonzoEraInCardanoMode -> pure ShelleyBasedEraAlonzo
BabbageEraInCardanoMode -> pure ShelleyBasedEraBabbage
ConwayEraInCardanoMode -> pure ShelleyBasedEraConway
Right (Right GenesisParameters{..}) <-
queryNodeLocalState localNodeConnectInfo Nothing $
QueryInEra eraInMode $
QueryInShelleyBasedEra shelleyBasedEra QueryGenesisParameters
let securityParameter = fromIntegral protocolParamSecurity

scripts <- case ScriptRegistry.getScripts MarloweV1 of
NESet.IsEmpty -> fail "No known marlowe scripts"
NESet.IsNonEmpty scripts -> pure scripts

runAppMTraced instrumentationLibrary (renderRootSelectorOTel dbName dbUser dbHost dbPort) do
let chainIndexerDatabaseQueries = ChainIndexerPostgres.databaseQueries securityParameter pool genesisBlock
let chainIndexerDatabaseQueries = ChainIndexerPostgres.databaseQueries pool genesisBlock

runGetGenesisBlock (getGenesisBlock chainIndexerDatabaseQueries) >>= \case
Just dbGenesisBlock -> unless (dbGenesisBlock == genesisBlock) do
Expand All @@ -159,6 +137,13 @@ run Options{..} = bracket (Pool.acquire 100 (Just 5000000) (fromString databaseU

contractStore <- traceContractStore inject <$> createContractStore ContractStoreOptions{..}

securityParameter <-
liftIO $
(either (fail . show) (either (fail . show) $ pure . protocolParamSecurity) =<<) $
queryNodeLocalState localNodeConnectInfo Nothing $
QueryInEra BabbageEraInCardanoMode $
QueryInShelleyBasedEra ShelleyBasedEraBabbage QueryGenesisParameters

flip runComponent_ () proc _ -> do
MarloweRuntime{..} <-
marloweRuntime
Expand All @@ -176,7 +161,7 @@ run Options{..} = bracket (Pool.acquire 100 (Just 5000000) (fromString databaseU
, contractStore
, costModel
, genesisBlock
, marloweIndexerDatabaseQueries = IndexerPostgreSQL.databaseQueries pool protocolParamSecurity
, marloweIndexerDatabaseQueries = IndexerPostgreSQL.databaseQueries pool securityParameter
, maxCost
, marloweScriptHashes = NESet.map ScriptRegistry.marloweScript scripts
, payoutScriptHashes = NESet.map ScriptRegistry.payoutScript scripts
Expand Down

0 comments on commit d7888ea

Please sign in to comment.