Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create EventSource and EventSink handles #1267

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
22ead15
initial work (WIP)
cardenaso11 Jan 16, 2024
4182e5b
WIP checkpoint
cardenaso11 Feb 13, 2024
2585923
checkpoint apiserver
cardenaso11 Feb 13, 2024
75c56e4
WIP: stateChangeID into StateChanged, routed into disk-persistence ev…
cardenaso11 Feb 15, 2024
b0576d0
remove inaccurate fixme
cardenaso11 Feb 15, 2024
94d2995
checkpoint: lib build
cardenaso11 Feb 19, 2024
a0133ae
WIP: going back and forth on how to manage state in tests
cardenaso11 Feb 19, 2024
16890a2
eventid
cardenaso11 Feb 19, 2024
e4fe10e
remove newpersistence data type (in exchange for type synonym) stuff …
cardenaso11 Feb 19, 2024
d692b7d
checkpoint for testing
cardenaso11 Feb 19, 2024
2b22fe2
some tests
cardenaso11 Feb 20, 2024
b72c15d
checkpoint: fix all hydra-node tests besides golden
cardenaso11 Feb 21, 2024
e0be84a
Use eventPairFromPersistenceIncremental
cardenaso11 Mar 4, 2024
f8be89f
Use the original PersistenceIncremental in withAPIServer
ch1bo Mar 4, 2024
3679cf5
Only use eventPairFromPersistenceIncremental
ch1bo Mar 4, 2024
11da78f
remove NewPersistenceIncremental type, use eventSource + eventSinks d…
cardenaso11 Mar 4, 2024
02f3c46
Move EventSource and EventSink definitions into Hydra.Events
ch1bo Mar 4, 2024
1fde992
Add HasEventId class to ensure events can be identified
ch1bo Mar 4, 2024
0e59d98
Draft extension points in Hydra.Node.Run
ch1bo Mar 4, 2024
f0ce297
Rename getEvents' -> getEvents and putEvent' -> putEvent
ch1bo Mar 4, 2024
8a00c06
Restore usage of persistenceIncremental in Hydra.Network.Reliability
ch1bo Mar 4, 2024
dbd3be3
Draft a new way to wire HydraNode in Node.Run
ch1bo Mar 11, 2024
a058ff8
Add node-level tests for event source / sink handling
ch1bo Mar 11, 2024
68e9ab4
Unify Hydra.Node function signatures and refine NodeSpec
ch1bo Mar 11, 2024
e5c2eec
Merge loadStateEventSource into hydrate function
ch1bo Mar 11, 2024
46d83d4
Move Environment into dedicated module
ch1bo Mar 12, 2024
a71cb88
Generate compatible state change events when testing hydrate
ch1bo Mar 12, 2024
fa7d970
Add more tests on event ids being strictly monotonic
ch1bo Mar 12, 2024
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 hydra-cluster/src/Hydra/Cluster/Scenarios.hs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ threeNodesNoErrorsOnOpen tracer tmpDir node@RunningNode{nodeSocket} hydraScripts

let contestationPeriod = UnsafeContestationPeriod 2
let hydraTracer = contramap FromHydraNode tracer
withHydraCluster hydraTracer tmpDir nodeSocket 0 cardanoKeys hydraKeys hydraScriptsTxId contestationPeriod $ \(leader :| rest) -> do
withHydraCluster hydraTracer tmpDir nodeSocket 1 cardanoKeys hydraKeys hydraScriptsTxId contestationPeriod $ \(leader :| rest) -> do
let clients = leader : rest
waitForNodesConnected hydraTracer 20 clients

Expand Down
2 changes: 2 additions & 0 deletions hydra-node/hydra-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ library
Hydra.Chain.Offline
Hydra.ContestationPeriod
Hydra.Crypto
Hydra.Environment
Hydra.Events
Hydra.HeadId
Hydra.HeadLogic
Hydra.HeadLogic.Error
Expand Down
6 changes: 6 additions & 0 deletions hydra-node/src/Hydra/Chain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Hydra.Cardano.Api (
Witness,
)
import Hydra.ContestationPeriod (ContestationPeriod)
import Hydra.Environment (Environment (..))
import Hydra.HeadId (HeadId, HeadSeed)
import Hydra.Ledger (ChainSlot, IsTx, UTxOType)
import Hydra.OnChainId (OnChainId)
Expand Down Expand Up @@ -60,6 +61,11 @@ instance Arbitrary HeadParameters where
dedupParties HeadParameters{contestationPeriod, parties} =
HeadParameters{contestationPeriod, parties = nub parties}

-- | Make 'HeadParameters' that are consistent with the given 'Environment'.
mkHeadParameters :: Environment -> HeadParameters
mkHeadParameters Environment{party, otherParties, contestationPeriod} =
HeadParameters{contestationPeriod, parties = party : otherParties}

-- | Data type used to post transactions on chain. It holds everything to
-- construct corresponding Head protocol transactions.
data PostChainTx tx
Expand Down
36 changes: 36 additions & 0 deletions hydra-node/src/Hydra/Environment.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Hydra.Environment where

import Hydra.Prelude

import Hydra.ContestationPeriod (ContestationPeriod)
import Hydra.Crypto (HydraKey, SigningKey)
import Hydra.OnChainId (OnChainId)
import Hydra.Party (Party, deriveParty)

data Environment = Environment
{ party :: Party
-- ^ This is the p_i from the paper
, -- XXX: In the long run we would not want to keep the signing key in memory,
-- i.e. have an 'Effect' for signing or so.
signingKey :: SigningKey HydraKey
, otherParties :: [Party]
, -- XXX: Improve naming
participants :: [OnChainId]
, contestationPeriod :: ContestationPeriod
}
deriving stock (Show, Eq)

instance Arbitrary Environment where
arbitrary = do
signingKey <- arbitrary
otherParties <- arbitrary
participants <- arbitrary
contestationPeriod <- arbitrary
pure $
Environment
{ signingKey
, party = deriveParty signingKey
, otherParties
, contestationPeriod
, participants
}
37 changes: 37 additions & 0 deletions hydra-node/src/Hydra/Events.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- | This module defines the types and functions for creating '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

-- FIXME(Elaine): we have to figure out a better taxonomy/nomenclature for the events/statechange stuff
-- the eventID here is not the same as the eventID in Queued, that one is more fickle and influenced by non state change events
-- this one is only incremented when we have a new state change event
type EventId = Word64

class HasEventId a where
getEventId :: a -> EventId

instance HasEventId (EventId, a) where
getEventId = fst

newtype EventSource e m = EventSource
{ getEvents :: HasEventId e => m [e]
-- ^ Retrieve all events from the event source.
}

newtype EventSink e m = EventSink
{ putEvent :: HasEventId e => e -> m ()
-- ^ Send a single event to the event sink.
}

putEventToSinks :: (Monad m, HasEventId e) => [EventSink e m] -> e -> m ()
putEventToSinks sinks e = forM_ sinks $ \sink -> putEvent sink e

putEventsToSinks :: (Monad m, HasEventId e) => [EventSink e m] -> [e] -> m ()
putEventsToSinks sinks = mapM_ (putEventToSinks sinks)
Loading
Loading