Skip to content

Commit

Permalink
Offline mode: allow for multi-party heads
Browse files Browse the repository at this point in the history
This simulates the corresponding initTx and commitTx transactions
  • Loading branch information
ch1bo committed Sep 17, 2024
1 parent af2e37b commit 26bc95a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions hydra-node/src/Hydra/Chain/Offline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ withOfflineChain ::
NodeId ->
OfflineChainConfig ->
Party ->
[Party] ->
-- | Last known chain state as loaded from persistence.
ChainStateHistory Tx ->
ChainComponent Tx IO a
withOfflineChain nodeId OfflineChainConfig{ledgerGenesisFile, initialUTxOFile} party chainStateHistory callback action = do
withOfflineChain nodeId OfflineChainConfig{ledgerGenesisFile, initialUTxOFile} party otherParties chainStateHistory callback action = do
initializeOfflineHead
genesis <- loadGenesisFile ledgerGenesisFile
withAsync (tickForever genesis callback) $ \tickThread -> do
Expand Down Expand Up @@ -103,7 +104,7 @@ withOfflineChain nodeId OfflineChainConfig{ledgerGenesisFile, initialUTxOFile} p
, headSeed = offlineHeadSeed nodeId
, headParameters =
HeadParameters
{ parties = [party]
{ parties = sort (party : otherParties)
, -- NOTE: This is irrelevant in offline mode.
contestationPeriod = defaultContestationPeriod
}
Expand All @@ -120,6 +121,17 @@ withOfflineChain nodeId OfflineChainConfig{ledgerGenesisFile, initialUTxOFile} p
, headId
}
}
forM_ otherParties $ \p ->
callback $
Observation
{ newChainState = initialChainState
, observedTx =
OnCommitTx
{ party = p
, committed = mempty
, headId
}
}
callback $
Observation
{ newChainState = initialChainState
Expand Down
4 changes: 2 additions & 2 deletions hydra-node/src/Hydra/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ run opts = do
let ledgerEnv = newLedgerEnv protocolParams
in action (cardanoLedger globals ledgerEnv)

prepareChainComponent tracer Environment{party} = \case
prepareChainComponent tracer Environment{party, otherParties} = \case
Offline cfg ->
pure $ withOfflineChain nodeId cfg party
pure $ withOfflineChain nodeId cfg party otherParties
Direct cfg -> do
ctx <- loadChainContext cfg party
wallet <- mkTinyWallet (contramap DirectChain tracer) cfg
Expand Down

0 comments on commit 26bc95a

Please sign in to comment.