Skip to content

Commit

Permalink
Trace params mismatch missconfiguration error when SavedNetworkPartie…
Browse files Browse the repository at this point in the history
…sInconsistent occur
  • Loading branch information
ffakenz committed Nov 24, 2023
1 parent c7a7630 commit 9e4fd02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions hydra-node/src/Hydra/Node/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ import Hydra.Prelude hiding (fromList, replicate)

import Control.Tracer (Tracer)
import Hydra.Crypto (HydraKey, SigningKey)
import Hydra.Logging (traceWith)
import Hydra.Logging.Messages (HydraLog (..))
import Hydra.Network (Host (..), IP, NetworkComponent, NodeId, PortNumber)
import Hydra.Network.Authenticate (Authenticated (Authenticated), Signed, withAuthentication)
import Hydra.Network.Heartbeat (ConnectionMessages, Heartbeat (..), withHeartbeat)
import Hydra.Network.Ouroboros (TraceOuroborosNetwork, WithHost, withOuroborosNetwork)
import Hydra.Network.Reliability (MessagePersistence, ReliableMsg, mkMessagePersistence, withReliability)
import Hydra.Node (HydraNodeLog (..))
import Hydra.Node.ParameterMismatch (ParamMismatch (..), ParameterMismatch (..))
import Hydra.Party (Party, deriveParty)
import Hydra.Persistence (Persistence (..), createPersistence, createPersistenceIncremental)
Expand Down Expand Up @@ -119,7 +121,7 @@ withNetwork tracer connectionMessages configuration callback action = do
let localhost = Host{hostname = show host, port}
me = deriveParty signingKey
numberOfParties = length $ me : otherParties
messagePersistence <- configureMessagePersistence persistenceDir numberOfParties
messagePersistence <- configureMessagePersistence (contramap Node tracer) persistenceDir numberOfParties

let reliability =
withFlipHeartbeats $
Expand All @@ -140,15 +142,19 @@ withNetwork tracer connectionMessages configuration callback action = do
-- * The number of parties is not the same as the number of acknowledgments saved.
configureMessagePersistence ::
(MonadIO m, MonadThrow m, FromJSON msg, ToJSON msg) =>
Tracer m (HydraNodeLog tx) ->
FilePath ->
Int ->
m (MessagePersistence m msg)
configureMessagePersistence persistenceDir numberOfParties = do
configureMessagePersistence tracer persistenceDir numberOfParties = do
msgPersistence <- createPersistenceIncremental $ persistenceDir <> "/network-messages"
ackPersistence@Persistence{load} <- createPersistence $ persistenceDir <> "/acks"
mAcks <- load
ackPersistence' <- case fmap (\acks -> length acks == numberOfParties) mAcks of
Just False -> throwIO $ ParameterMismatch [SavedNetworkPartiesInconsistent{numberOfParties}]
Just False -> do
let paramsMismatch = [SavedNetworkPartiesInconsistent{numberOfParties}]
traceWith tracer (Misconfiguration paramsMismatch)
throwIO $ ParameterMismatch paramsMismatch
_ -> pure ackPersistence
pure $ mkMessagePersistence numberOfParties msgPersistence ackPersistence'

Expand Down
4 changes: 2 additions & 2 deletions hydra-node/test/Hydra/NetworkSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Codec.CBOR.Read (deserialiseFromBytes)
import Codec.CBOR.Write (toLazyByteString)
import Control.Concurrent.Class.MonadSTM (newTQueue, readTQueue, writeTQueue)
import Hydra.Ledger.Simple (SimpleTx (..))
import Hydra.Logging (showLogsOnFailure)
import Hydra.Logging (nullTracer, showLogsOnFailure)
import Hydra.Network (Host (..), Network)
import Hydra.Network.Message (Message (..))
import Hydra.Network.Ouroboros (broadcast, withOuroborosNetwork)
Expand Down Expand Up @@ -59,7 +59,7 @@ spec = do
it "throws ParameterMismatch when configuring given number of acks does not match number of parties" $ do
withTempDir "persistence" $ \dir -> do
writeFile (dir </> "acks") "[0,0,0]"
configureMessagePersistence @_ @Int dir 4 `shouldThrow` (const True :: Selector ParameterMismatch)
configureMessagePersistence @_ @Int nullTracer dir 4 `shouldThrow` (const True :: Selector ParameterMismatch)

withNodeBroadcastingForever :: Network IO Integer -> Integer -> IO b -> IO b
withNodeBroadcastingForever node value = withNodesBroadcastingForever [(node, value)]
Expand Down

0 comments on commit 9e4fd02

Please sign in to comment.