Skip to content

Commit

Permalink
Merge pull request #1266 from input-output-hk/fix-contest-observation
Browse files Browse the repository at this point in the history
Fix the observed contesters in Direct chain
  • Loading branch information
v0d1ch authored Mar 21, 2024
2 parents 4f327fa + 85a9b36 commit 013ae99
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
6 changes: 3 additions & 3 deletions hydra-node/src/Hydra/Chain/Direct/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,10 @@ observeContestTx utxo tx = do
datum <- fromScriptData oldHeadDatum
headId <- findStateToken headOutput
case (datum, redeemer) of
(Head.Closed{contesters}, Head.Contest{}) -> do
(Head.Closed{}, Head.Contest{}) -> do
(newHeadInput, newHeadOutput) <- findTxOutByScript @PlutusScriptV2 (utxoFromTx tx) headScript
newHeadDatum <- txOutScriptData $ toTxContext newHeadOutput
let (onChainSnapshotNumber, contestationDeadline) = decodeDatum newHeadDatum
let (onChainSnapshotNumber, contestationDeadline, contesters) = decodeDatum newHeadDatum
pure
ContestObservation
{ contestedThreadOutput = (newHeadInput, newHeadOutput)
Expand All @@ -1011,7 +1011,7 @@ observeContestTx utxo tx = do

decodeDatum headDatum =
case fromScriptData headDatum of
Just Head.Closed{snapshotNumber, contestationDeadline} -> (snapshotNumber, contestationDeadline)
Just Head.Closed{snapshotNumber, contestationDeadline, contesters} -> (snapshotNumber, contestationDeadline, contesters)
_ -> error "wrong state in output datum"

newtype FanoutObservation = FanoutObservation {headId :: HeadId} deriving stock (Eq, Show, Generic)
Expand Down
40 changes: 39 additions & 1 deletion hydra-node/test/Hydra/Chain/Direct/StateSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,45 @@ import Hydra.Chain.Direct.Contract.Mutation (
replacePolicyIdWith,
)
import Hydra.Chain.Direct.Fixture (slotLength, systemStart, testNetworkId)
import Hydra.Chain.Direct.State (ChainContext (..), ChainState (..), ClosedState (..), HasKnownUTxO (getKnownUTxO), HydraContext (..), InitialState (..), OpenState (..), abort, closedThreadOutput, commit, ctxHeadParameters, ctxParticipants, ctxParties, genChainStateWithTx, genCloseTx, genCollectComTx, genCommitFor, genCommits, genCommits', genContestTx, genFanoutTx, genHydraContext, genInitTx, genStInitial, getContestationDeadline, getKnownUTxO, initialize, observeClose, observeCollect, observeCommit, pickChainContext, unsafeAbort, unsafeClose, unsafeCollect, unsafeCommit, unsafeFanout, unsafeObserveInitAndCommits)
import Hydra.Chain.Direct.State (
ChainContext (..),
ChainState (..),
ClosedState (..),
HasKnownUTxO (getKnownUTxO),
HydraContext (..),
InitialState (..),
OpenState (..),
abort,
closedThreadOutput,
commit,
ctxHeadParameters,
ctxParticipants,
ctxParties,
genChainStateWithTx,
genCloseTx,
genCollectComTx,
genCommitFor,
genCommits,
genCommits',
genContestTx,
genFanoutTx,
genHydraContext,
genInitTx,
genStInitial,
getContestationDeadline,
getKnownUTxO,
initialize,
observeClose,
observeCollect,
observeCommit,
pickChainContext,
unsafeAbort,
unsafeClose,
unsafeCollect,
unsafeCommit,
unsafeFanout,
unsafeObserveInitAndCommits,
)
import Hydra.Chain.Direct.State qualified as Transition
import Hydra.Chain.Direct.Tx (
AbortObservation (..),
Expand Down

0 comments on commit 013ae99

Please sign in to comment.