From 95ea20acf274e21dbad8804218eee9fd07c32d01 Mon Sep 17 00:00:00 2001 From: Sebastian Nagel Date: Mon, 4 Mar 2024 17:20:10 +0100 Subject: [PATCH] Draft extension points in Hydra.Node.Run Current idea: Keep notes where extensions are possible so we don't change things by accident breaking external/custom code of users. --- hydra-node/src/Hydra/Events.hs | 2 ++ hydra-node/src/Hydra/Node/Run.hs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/hydra-node/src/Hydra/Events.hs b/hydra-node/src/Hydra/Events.hs index 9fbc5d8659a..e64eecd6bd5 100644 --- a/hydra-node/src/Hydra/Events.hs +++ b/hydra-node/src/Hydra/Events.hs @@ -2,6 +2,8 @@ -- 'EventSource' and 'EventSink' instances and is intended to be used as an -- extension point. A single 'EventSource' and zero or more 'EventSink' handles -- are used by the main 'HydraNode' handle to load and send out events. +-- +-- TODO: add an example event source sink (on top of the persistence one) module Hydra.Events where import Hydra.Prelude diff --git a/hydra-node/src/Hydra/Node/Run.hs b/hydra-node/src/Hydra/Node/Run.hs index 90e7b9e557c..08c2a538c16 100644 --- a/hydra-node/src/Hydra/Node/Run.hs +++ b/hydra-node/src/Hydra/Node/Run.hs @@ -76,20 +76,20 @@ run opts = do eq@EventQueue{putEvent} <- createEventQueue let RunOptions{chainConfig, ledgerConfig} = opts pparams <- readJsonFileThrow pparamsFromJson (cardanoLedgerProtocolParametersFile ledgerConfig) - globals <- getGlobalsForChain chainConfig - withCardanoLedger pparams globals $ \ledger -> do + -- Setup event source and sinks persistence <- createPersistenceIncremental $ persistenceDir <> "/state" - -- TODO(Elaine): remove in favor of eventSource/Sink directly - -- (eventSource, eventSink) <- createEventPairIncremental $ persistenceDir <> "/state" - - let (eventSource, eventSink) = eventPairFromPersistenceIncremental persistence - eventSinks = [eventSink] -- FIXME(Elaine): load other event sinks - -- eventSinksSansSource = [] --TODO(Elaine): this needs a better name. essentially, don't load events back into where they came from, at least until disk-based persistence can handle redelivery - -- persistence@(eventSource, eventSinks) <- createNewPersistenceIncremental $ persistenceDir <> "/state" + let (eventSource, filePersistenceSink) = eventPairFromPersistenceIncremental persistence + -- NOTE: Add any custom sink setup code here + -- customSink <- createCustomSink + let eventSinks = + [ filePersistenceSink + -- NOTE: Add any custom sinks here + -- , customSink + ] + -- Load events and hydrate sinks (hs, chainStateHistory) <- loadStateEventSource (contramap Node tracer) eventSource eventSinks initialChainState - checkHeadState (contramap Node tracer) env hs nodeState <- createNodeState hs -- Chain