Skip to content

Commit

Permalink
Rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Mar 13, 2024
1 parent 0cbdf9a commit cd6ec4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions hydra-node/src/Hydra/HeadLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,12 @@ update env ledger st ev = case (st, ev) of
-- another party likely opened the head before us and it's okay to ignore.
(Open{}, ChainInput PostTxError{postChainTx = CollectComTx{}}) ->
noop
(Open OpenState{headId, coordinatedHeadState, currentSlot}, ClientEvent Decommit{decommitTx}) -> do
(Open OpenState{headId, coordinatedHeadState, currentSlot}, ClientInput Decommit{decommitTx}) -> do
onOpenClientDecommit env headId ledger currentSlot coordinatedHeadState decommitTx
(Open openState, NetworkEvent ttl _ (ReqDec{transaction})) ->
(Open openState, NetworkInput ttl _ (ReqDec{transaction})) ->
onOpenNetworkReqDec env ttl openState transaction
( Open OpenState{headId = ourHeadId}
, OnChainEvent Observation{observedTx = OnDecrementTx{headId}}
, ChainInput Observation{observedTx = OnDecrementTx{headId}}
)
-- TODO: What happens if observed decrement tx get's rolled back?
| ourHeadId == headId ->
Expand Down
6 changes: 3 additions & 3 deletions hydra-node/test/Hydra/HeadLogicSnapshotSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ spec = do
let bobEnv = envFor bobSk

it "sends ReqSn when leader and there are seen transactions" $ do
headState <- runEvents bobEnv simpleLedger (inOpenState threeParties) $ do
headState <- runHeadLogic bobEnv simpleLedger (inOpenState threeParties) $ do
step (NetworkInput defaultTTL alice $ ReqSn 1 [] Nothing)
step (NetworkInput defaultTTL carol $ ReqTx $ aValidTx 1)
step (ackFrom carolSk carol)
Expand All @@ -127,7 +127,7 @@ spec = do
`hasEffectSatisfying` sendReqSn

it "does NOT send ReqSn when we are the leader but there are NO seen transactions" $ do
headState <- runEvents bobEnv simpleLedger (inOpenState threeParties) $ do
headState <- runHeadLogic bobEnv simpleLedger (inOpenState threeParties) $ do
step (NetworkInput defaultTTL alice $ ReqSn 1 [] Nothing)
step (ackFrom carolSk carol)
step (ackFrom aliceSk alice)
Expand Down Expand Up @@ -156,7 +156,7 @@ spec = do
everybodyAcknowleged `hasNoEffectSatisfying` sendReqSn

it "updates seenSnapshot state when sending ReqSn" $ do
headState <- runEvents bobEnv simpleLedger (inOpenState threeParties) $ do
headState <- runHeadLogic bobEnv simpleLedger (inOpenState threeParties) $ do
step (NetworkInput defaultTTL alice $ ReqSn 1 [] Nothing)
step (NetworkInput defaultTTL carol $ ReqTx $ aValidTx 1)
step (ackFrom carolSk carol)
Expand Down
36 changes: 18 additions & 18 deletions hydra-node/test/Hydra/HeadLogicSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec =
let reqSn = NetworkInput defaultTTL alice $ ReqSn 1 [] Nothing
snapshot1 = Snapshot testHeadId 1 mempty [] mempty
ackFrom sk vk = NetworkInput defaultTTL vk $ AckSn (sign sk snapshot1) 1
snapshotInProgress <- runEvents bobEnv ledger (inOpenState threeParties) $ do
snapshotInProgress <- runHeadLogic bobEnv ledger (inOpenState threeParties) $ do
step reqSn
step (ackFrom carolSk carol)
step (ackFrom aliceSk alice)
Expand All @@ -137,7 +137,7 @@ spec =
it "observes DecommitRequested and ReqDec in an Open state" $
let decommitTx = SimpleTx 1 mempty (utxoRef 1)
reqDec = ReqDec{transaction = decommitTx, decommitRequester = alice}
event = NetworkEvent defaultTTL alice reqDec
event = NetworkInput defaultTTL alice reqDec
st = inOpenState threeParties
outcome = update aliceEnv ledger st event
in outcome
Expand All @@ -150,7 +150,7 @@ spec =

it "ignores ReqDec when not in Open state" $ monadicIO $ do
let reqDec = ReqDec{transaction = SimpleTx 1 mempty (utxoRef 1), decommitRequester = alice}
let event = NetworkEvent defaultTTL alice reqDec
let event = NetworkInput defaultTTL alice reqDec
st <- pickBlind $ oneof $ pure <$> [inInitialState threeParties, inIdleState, inClosedState threeParties]
pure $
update aliceEnv ledger st event
Expand All @@ -161,11 +161,11 @@ spec =
decommitTx2 = SimpleTx 2 mempty (utxoRef 2)
reqDec1 = ReqDec{transaction = decommitTx1, decommitRequester = alice}
reqDec2 = ReqDec{transaction = decommitTx2, decommitRequester = bob}
reqDecEvent1 = NetworkEvent defaultTTL alice reqDec1
reqDecEvent2 = NetworkEvent defaultTTL bob reqDec2
reqDecEvent1 = NetworkInput defaultTTL alice reqDec1
reqDecEvent2 = NetworkInput defaultTTL bob reqDec2
s0 = inOpenState threeParties

s1 <- runEvents aliceEnv ledger s0 $ do
s1 <- runHeadLogic aliceEnv ledger s0 $ do
step reqDecEvent1
getState

Expand All @@ -179,14 +179,14 @@ spec =
it "updates decommitTx on valid ReqDec" $ do
let decommitTx' = SimpleTx 1 mempty (utxoRef 1)
let reqDec = ReqDec{transaction = decommitTx', decommitRequester = alice}
reqDecEvent = NetworkEvent defaultTTL alice reqDec
reqDecEvent = NetworkInput defaultTTL alice reqDec
s0 = inOpenState threeParties

s0 `shouldSatisfy` \case
(Open OpenState{coordinatedHeadState = CoordinatedHeadState{decommitTx}}) -> decommitTx == Nothing
_ -> False

s1 <- runEvents aliceEnv ledger s0 $ do
s1 <- runHeadLogic aliceEnv ledger s0 $ do
step reqDecEvent
getState

Expand All @@ -195,7 +195,7 @@ spec =
_ -> False

-- running the 'ReqDec' again should not alter the recorded state
s2 <- runEvents aliceEnv ledger s1 $ do
s2 <- runHeadLogic aliceEnv ledger s1 $ do
step reqDecEvent
getState

Expand All @@ -211,7 +211,7 @@ spec =
(Open OpenState{coordinatedHeadState = CoordinatedHeadState{decommitTx}}) -> decommitTx == Nothing
_ -> False

let reqDecEvent = NetworkEvent defaultTTL alice ReqDec{transaction = decommitTx', decommitRequester = alice}
let reqDecEvent = NetworkInput defaultTTL alice ReqDec{transaction = decommitTx', decommitRequester = alice}
let reqSn = ReqSn{snapshotNumber = 1, transactionIds = [], decommitTx = Just decommitTx'}

let s1 = update aliceEnv ledger s0 reqDecEvent
Expand Down Expand Up @@ -337,7 +337,7 @@ spec =
it "waits if we receive a snapshot with transaction not applicable on previous snapshot" $ do
let reqTx42 = NetworkInput defaultTTL alice $ ReqTx (SimpleTx 42 mempty (utxoRef 1))
reqTx1 = NetworkInput defaultTTL alice $ ReqTx (SimpleTx 1 (utxoRef 1) (utxoRef 2))
event = NetworkInput defaultTTL alice $ ReqSn 1 [1] Nothing
input = NetworkInput defaultTTL alice $ ReqSn 1 [1] Nothing
s0 = inOpenState threeParties

s2 <- runHeadLogic bobEnv ledger s0 $ do
Expand Down Expand Up @@ -365,7 +365,7 @@ spec =
-- snapshot collection.

it "rejects if we receive a too far future snapshot" $ do
let event = NetworkInput defaultTTL bob $ ReqSn 2 [] Nothing
let input = NetworkInput defaultTTL bob $ ReqSn 2 [] Nothing
st = inOpenState threeParties
update bobEnv ledger st input `shouldBe` Error (RequireFailed $ ReqSnNumberInvalid 2 0)

Expand All @@ -383,22 +383,22 @@ spec =
it "acks signed snapshot from the constant leader" $ do
let leader = alice
snapshot = testSnapshot 1 mempty []
event = NetworkInput defaultTTL leader $ ReqSn (number snapshot) [] Nothing
input = NetworkInput defaultTTL leader $ ReqSn (number snapshot) [] Nothing
sig = sign bobSk snapshot
st = inOpenState threeParties
ack = AckSn sig (number snapshot)
update bobEnv ledger st input `hasEffect` NetworkEffect ack

it "does not ack snapshots from non-leaders" $ do
let event = NetworkInput defaultTTL notTheLeader $ ReqSn 1 [] Nothing
let input = NetworkInput defaultTTL notTheLeader $ ReqSn 1 [] Nothing
notTheLeader = bob
st = inOpenState threeParties
update bobEnv ledger st input `shouldSatisfy` \case
Error (RequireFailed ReqSnNotLeader{requestedSn = 1, leader}) -> leader == notTheLeader
_ -> False

it "rejects too-old snapshots" $ do
let event = NetworkInput defaultTTL theLeader $ ReqSn 2 [] Nothing
let input = NetworkInput defaultTTL theLeader $ ReqSn 2 [] Nothing
theLeader = alice
snapshot = testSnapshot 2 mempty []
st =
Expand All @@ -407,7 +407,7 @@ spec =
update bobEnv ledger st input `shouldBe` Error (RequireFailed $ ReqSnNumberInvalid 2 0)

it "rejects too-old snapshots when collecting signatures" $ do
let event = NetworkInput defaultTTL theLeader $ ReqSn 2 [] Nothing
let input = NetworkInput defaultTTL theLeader $ ReqSn 2 [] Nothing
theLeader = alice
snapshot = testSnapshot 2 mempty []
st =
Expand All @@ -419,7 +419,7 @@ spec =
update bobEnv ledger st input `shouldBe` Error (RequireFailed $ ReqSnNumberInvalid 2 3)

it "rejects too-new snapshots from the leader" $ do
let event = NetworkInput defaultTTL theLeader $ ReqSn 3 [] Nothing
let input = NetworkInput defaultTTL theLeader $ ReqSn 3 [] Nothing
theLeader = carol
st = inOpenState threeParties
update bobEnv ledger st input `shouldBe` Error (RequireFailed $ ReqSnNumberInvalid 3 0)
Expand Down Expand Up @@ -600,7 +600,7 @@ spec =

st <-
run $
runEvents bobEnv ledger st0 $ do
runHeadLogic bobEnv ledger st0 $ do
step (NetworkInput defaultTTL alice $ ReqSn 1 [] Nothing)
getState

Expand Down

0 comments on commit cd6ec4f

Please sign in to comment.