-
Notifications
You must be signed in to change notification settings - Fork 84
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
Guard against non-expected parties during init observation. #295
Changes from all commits
f13d00b
d19f707
265767f
1fa86d6
f7a5b9a
f65726e
f95de75
a4bc8ad
7df5d2c
7814721
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ import qualified Text.Show | |
-- happening on the layer-1 for a given Hydra head. | ||
data OnChainHeadState (st :: HeadStateKind) = OnChainHeadState | ||
{ networkId :: NetworkId | ||
, peerVerificationKeys :: [VerificationKey PaymentKey] | ||
, ownVerificationKey :: VerificationKey PaymentKey | ||
, ownParty :: Party | ||
, stateMachine :: HydraStateMachine st | ||
|
@@ -180,12 +181,14 @@ reifyState OnChainHeadState{stateMachine} = | |
-- | Initialize a new 'OnChainHeadState'. | ||
idleOnChainHeadState :: | ||
NetworkId -> | ||
[VerificationKey PaymentKey] -> | ||
VerificationKey PaymentKey -> | ||
Party -> | ||
OnChainHeadState 'StIdle | ||
idleOnChainHeadState networkId ownVerificationKey ownParty = | ||
idleOnChainHeadState networkId peerVerificationKeys ownVerificationKey ownParty = | ||
OnChainHeadState | ||
{ networkId | ||
, peerVerificationKeys | ||
, ownVerificationKey | ||
, ownParty | ||
, stateMachine = Idle | ||
|
@@ -316,14 +319,16 @@ instance HasTransition 'StIdle where | |
] | ||
|
||
instance ObserveTx 'StIdle 'StInitialized where | ||
observeTx tx OnChainHeadState{networkId, ownParty, ownVerificationKey} = do | ||
(event, observation) <- observeInitTx networkId ownParty tx | ||
observeTx tx OnChainHeadState{networkId, peerVerificationKeys, ownParty, ownVerificationKey} = do | ||
let allVerificationKeys = ownVerificationKey : peerVerificationKeys | ||
(event, observation) <- observeInitTx networkId allVerificationKeys ownParty tx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we are not very consistent in what we store or pass as arguments to functions: Sometimes we pass all keys including ours, sometimes only our peers'... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but this is very much context dependent... I started with all keys in the State, but, since the state also stored the ownVerificationKey, there was redundancy in the state which is room for hazards. Within the observation function however, we care not about this distinction and all keys can be treated the same.. Not very consistent but,... I don't know, still preferable? |
||
let InitObservation{threadOutput, initials, commits, headId, headTokenScript} = observation | ||
let st' = | ||
OnChainHeadState | ||
{ networkId | ||
, ownParty | ||
, ownVerificationKey | ||
, peerVerificationKeys | ||
, stateMachine = | ||
Initialized | ||
{ initialThreadOutput = threadOutput | ||
|
@@ -370,14 +375,15 @@ instance ObserveTx 'StInitialized 'StInitialized where | |
} = stateMachine | ||
|
||
instance ObserveTx 'StInitialized 'StOpen where | ||
observeTx tx st@OnChainHeadState{networkId, ownVerificationKey, ownParty, stateMachine} = do | ||
observeTx tx st@OnChainHeadState{networkId, peerVerificationKeys, ownVerificationKey, ownParty, stateMachine} = do | ||
let utxo = getKnownUTxO st | ||
(event, observation) <- observeCollectComTx utxo tx | ||
let CollectComObservation{threadOutput, headId} = observation | ||
guard (headId == initialHeadId) | ||
let st' = | ||
OnChainHeadState | ||
{ networkId | ||
, peerVerificationKeys | ||
, ownVerificationKey | ||
, ownParty | ||
, stateMachine = | ||
|
@@ -395,12 +401,13 @@ instance ObserveTx 'StInitialized 'StOpen where | |
} = stateMachine | ||
|
||
instance ObserveTx 'StInitialized 'StIdle where | ||
observeTx tx st@OnChainHeadState{networkId, ownVerificationKey, ownParty} = do | ||
observeTx tx st@OnChainHeadState{networkId, peerVerificationKeys, ownVerificationKey, ownParty} = do | ||
let utxo = getKnownUTxO st | ||
(event, ()) <- observeAbortTx utxo tx | ||
let st' = | ||
OnChainHeadState | ||
{ networkId | ||
, peerVerificationKeys | ||
, ownVerificationKey | ||
, ownParty | ||
, stateMachine = Idle | ||
|
@@ -417,14 +424,15 @@ instance HasTransition 'StOpen where | |
] | ||
|
||
instance ObserveTx 'StOpen 'StClosed where | ||
observeTx tx st@OnChainHeadState{networkId, ownVerificationKey, ownParty, stateMachine} = do | ||
observeTx tx st@OnChainHeadState{networkId, peerVerificationKeys, ownVerificationKey, ownParty, stateMachine} = do | ||
let utxo = getKnownUTxO st | ||
(event, observation) <- observeCloseTx utxo tx | ||
let CloseObservation{threadOutput, headId} = observation | ||
guard (headId == openHeadId) | ||
let st' = | ||
OnChainHeadState | ||
{ networkId | ||
, peerVerificationKeys | ||
, ownVerificationKey | ||
, ownParty | ||
, stateMachine = | ||
|
@@ -451,12 +459,13 @@ instance HasTransition 'StClosed where | |
] | ||
|
||
instance ObserveTx 'StClosed 'StIdle where | ||
observeTx tx st@OnChainHeadState{networkId, ownVerificationKey, ownParty} = do | ||
observeTx tx st@OnChainHeadState{networkId, peerVerificationKeys, ownVerificationKey, ownParty} = do | ||
let utxo = getKnownUTxO st | ||
(event, ()) <- observeFanoutTx utxo tx | ||
let st' = | ||
OnChainHeadState | ||
{ networkId | ||
, peerVerificationKeys | ||
, ownVerificationKey | ||
, ownParty | ||
, stateMachine = Idle | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Perhaps worthwhile to detail the comment on line 151 so that this line makes more within the context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just pass only peers' keys?