Skip to content

Commit

Permalink
Remove sender from NetworkInput
Browse files Browse the repository at this point in the history
  • Loading branch information
locallycompact committed Apr 16, 2024
1 parent 4ac64c0 commit 1d0f703
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
10 changes: 5 additions & 5 deletions hydra-node/src/Hydra/HeadLogic.hs
Expand Up @@ -713,14 +713,14 @@ update env ledger st ev = case (st, ev) of
onOpenClientClose openState
(Open{}, ClientInput (NewTx tx)) ->
onOpenClientNewTx tx
(Open openState, NetworkInput ttl _ (OffchainProtocolMessage{msg = ReqTx tx})) ->
(Open openState, NetworkInput ttl (OffchainProtocolMessage{msg = ReqTx tx})) ->
onOpenNetworkReqTx env ledger openState ttl tx
(Open openState, NetworkInput _ otherParty (OffchainProtocolMessage{msg = ReqSn sn txIds})) ->
(Open openState, NetworkInput _ (OffchainProtocolMessage{sender, msg = ReqSn sn txIds})) ->
-- XXX: ttl == 0 not handled for ReqSn
onOpenNetworkReqSn env ledger openState otherParty sn txIds
(Open openState, NetworkInput _ otherParty (OffchainProtocolMessage{msg = AckSn snapshotSignature sn})) ->
onOpenNetworkReqSn env ledger openState sender sn txIds
(Open openState, NetworkInput _ (OffchainProtocolMessage{sender, msg = AckSn snapshotSignature sn})) ->
-- XXX: ttl == 0 not handled for AckSn
onOpenNetworkAckSn env openState otherParty snapshotSignature sn
onOpenNetworkAckSn env openState sender snapshotSignature sn
( Open openState@OpenState{headId = ourHeadId}
, ChainInput Observation{observedTx = OnCloseTx{headId, snapshotNumber = closedSnapshotNumber, contestationDeadline}, newChainState}
)
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/HeadLogic/Input.hs
Expand Up @@ -19,7 +19,7 @@ data Input tx
--
-- * `ttl` is a simple counter that's decreased every time the event is
-- reenqueued due to a wait. It's default value is `defaultTTL`
NetworkInput {ttl :: TTL, party :: Party, message :: NetworkMessage (Message tx)}
NetworkInput {ttl :: TTL, message :: NetworkMessage (Message tx)}
| -- | Input received from the chain via a "Hydra.Chain".
ChainInput {chainEvent :: ChainEvent tx}
deriving stock (Generic)
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/src/Hydra/Logging/Monitoring.hs
Expand Up @@ -89,7 +89,7 @@ monitor ::
HydraLog tx net ->
m ()
monitor transactionsMap metricsMap = \case
(Node BeginInput{input = NetworkInput _ _ (OffchainProtocolMessage{msg = ReqTx tx})}) -> do
(Node BeginInput{input = NetworkInput _ (OffchainProtocolMessage{msg = ReqTx tx})}) -> do
t <- getMonotonicTime
-- NOTE: If a requested transaction never gets confirmed, it might stick
-- forever in the transactions map which could lead to unbounded growth and
Expand Down
11 changes: 5 additions & 6 deletions hydra-node/src/Hydra/Node.hs
Expand Up @@ -57,7 +57,6 @@ import Hydra.Node.InputQueue (InputQueue (..), Queued (..), createInputQueue)
import Hydra.Node.ParameterMismatch (ParamMismatch (..), ParameterMismatch (..))
import Hydra.Options (ChainConfig (..), DirectChainConfig (..), RunOptions (..), defaultContestationPeriod)
import Hydra.Party (HasParty (..), Party (..), deriveParty)
import Prelude qualified

-- * Environment Handling

Expand Down Expand Up @@ -206,10 +205,10 @@ wireNetworkInput :: DraftHydraNode tx m -> NetworkMessage (Message tx) -> m ()
wireNetworkInput node = \case
ConnectivityMessage con ->
-- FIXME: remove the party from the input
enqueue $ NetworkInput defaultTTL (Prelude.error "TODO: should not be needed and never accessed") (ConnectivityMessage con)
enqueue $ NetworkInput defaultTTL (ConnectivityMessage con)
OffchainProtocolMessage{sender, msg} ->
-- FIXME: don't duplicate sender in input
enqueue $ NetworkInput defaultTTL sender OffchainProtocolMessage{sender, msg}
enqueue $ NetworkInput defaultTTL OffchainProtocolMessage{sender, msg}
where
DraftHydraNode{inputQueue = InputQueue{enqueue}} = node

Expand Down Expand Up @@ -280,8 +279,8 @@ stepHydraNode node = do
where
maybeReenqueue q@Queued{queuedId, queuedItem} =
case queuedItem of
NetworkInput ttl aParty msg
| ttl > 0 -> reenqueue waitDelay q{queuedItem = NetworkInput (ttl - 1) aParty msg}
NetworkInput ttl msg
| ttl > 0 -> reenqueue waitDelay q{queuedItem = NetworkInput (ttl - 1) msg}
_ -> traceWith tracer $ DroppedFromQueue{inputId = queuedId, input = queuedItem}

Environment{party} = env
Expand Down Expand Up @@ -336,7 +335,7 @@ processEffects node tracer inputId effects = do
traceWith tracer $ BeginEffect party inputId effectId effect
case effect of
ClientEffect i -> sendOutput server i
NetworkEffect msg -> broadcast hn msg >> enqueue (NetworkInput defaultTTL party (OffchainProtocolMessage{sender = party, msg}))
NetworkEffect msg -> broadcast hn msg >> enqueue (NetworkInput defaultTTL (OffchainProtocolMessage{sender = party, msg}))
OnChainEffect{postChainTx} ->
postTx postChainTx
`catch` \(postTxError :: PostTxError tx) ->
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/BehaviorSpec.hs
Expand Up @@ -686,7 +686,7 @@ createMockNetwork node nodes =
mapM_ (`handleMessage` msg) otherNodes

handleMessage HydraNode{inputQueue} msg =
enqueue inputQueue . NetworkInput defaultTTL sender $ OffchainProtocolMessage{sender, msg}
enqueue inputQueue . NetworkInput defaultTTL $ OffchainProtocolMessage{sender, msg}

sender = getParty node

Expand Down
4 changes: 2 additions & 2 deletions hydra-node/test/Hydra/HeadLogicSpec.hs
Expand Up @@ -89,7 +89,7 @@ spec =
let inputs = utxoRef 1
tx = SimpleTx 2 inputs mempty
ttl = 0
reqTx = NetworkInput ttl alice $ OffchainProtocolMessage{sender = alice, msg = ReqTx tx}
reqTx = NetworkInput ttl $ OffchainProtocolMessage{sender = alice, msg = ReqTx tx}
s0 = inOpenState threeParties

update bobEnv ledger s0 reqTx `hasEffectSatisfying` \case
Expand Down Expand Up @@ -587,7 +587,7 @@ receiveMessage = receiveMessageFrom alice
-- from given sender.
receiveMessageFrom :: Party -> Message tx -> Input tx
receiveMessageFrom sender msg =
NetworkInput defaultTTL sender $ OffchainProtocolMessage{sender, msg}
NetworkInput defaultTTL $ OffchainProtocolMessage{sender, msg}

-- | Create a chain effect with fixed chain state and slot.
chainEffect :: PostChainTx SimpleTx -> Effect SimpleTx
Expand Down
2 changes: 1 addition & 1 deletion hydra-node/test/Hydra/Model/MockChain.hs
Expand Up @@ -351,7 +351,7 @@ createMockNetwork draftNode nodes =
mapM_ (`handleMessage` msg) otherNodes

handleMessage HydraNode{inputQueue} msg =
enqueue inputQueue . NetworkInput defaultTTL sender $ OffchainProtocolMessage{sender, msg}
enqueue inputQueue . NetworkInput defaultTTL $ OffchainProtocolMessage{sender, msg}

sender = getParty draftNode

Expand Down

0 comments on commit 1d0f703

Please sign in to comment.