Skip to content

Commit

Permalink
consensus: parameterize Node.run over the address types
Browse files Browse the repository at this point in the history
The ThreadNet tests uses CoreNodeId whereas the real node uses RemoteAddress
(ie SockAddr) and LocalAddress (ie FilePath).
  • Loading branch information
nfrisby committed Nov 3, 2020
1 parent 134f20e commit dee7a16
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions ouroboros-consensus/src/Ouroboros/Consensus/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module Ouroboros.Consensus.Node
, IPSubscriptionTarget (..)
, DnsSubscriptionTarget (..)
, ConnectionId (..)
, RemoteConnectionId
, ChainDB.RelativeMountPoint (..)
-- * Internal helpers
, openChainDB
Expand All @@ -51,9 +50,11 @@ import Control.Monad (when)
import Control.Tracer (Tracer, contramap)
import Data.ByteString.Lazy (ByteString)
import Data.Functor.Identity (Identity)
import Data.Hashable (Hashable)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import Data.Typeable (Typeable)
import System.FilePath ((</>))
import System.Random (StdGen, newStdGen, randomIO, randomRIO)

Expand All @@ -64,10 +65,10 @@ import Ouroboros.Network.BlockFetch (BlockFetchConfiguration (..))
import Ouroboros.Network.Diffusion
import Ouroboros.Network.Magic
import Ouroboros.Network.NodeToClient (LocalAddress,
LocalConnectionId, NodeToClientVersionData (..))
NodeToClientVersionData (..))
import Ouroboros.Network.NodeToNode (DiffusionMode,
MiniProtocolParameters (..), NodeToNodeVersionData (..),
RemoteAddress, RemoteConnectionId, combineVersions,
RemoteAddress, combineVersions,
defaultMiniProtocolParameters)
import Ouroboros.Network.Protocol.Limits (shortWait)

Expand Down Expand Up @@ -110,15 +111,15 @@ import Ouroboros.Consensus.Storage.VolatileDB
(BlockValidationPolicy (..), mkBlocksPerFile)

-- | Arguments required by 'runNode'
data RunNodeArgs m versionDataNTN versionDataNTC blk = RunNodeArgs {
data RunNodeArgs m addrNTN addrNTC versionDataNTN versionDataNTC blk = RunNodeArgs {
-- | Consensus tracers
rnTraceConsensus :: Tracers m RemoteConnectionId LocalConnectionId blk
rnTraceConsensus :: Tracers m (ConnectionId addrNTN) (ConnectionId addrNTC) blk

-- | Protocol tracers for node-to-node communication
, rnTraceNTN :: NTN.Tracers m RemoteConnectionId blk DeserialiseFailure
, rnTraceNTN :: NTN.Tracers m (ConnectionId addrNTN) blk DeserialiseFailure

-- | Protocol tracers for node-to-client communication
, rnTraceNTC :: NTC.Tracers m LocalConnectionId blk DeserialiseFailure
, rnTraceNTC :: NTC.Tracers m (ConnectionId addrNTC) blk DeserialiseFailure

-- | ChainDB tracer
, rnTraceDB :: Tracer m (ChainDB.TraceEvent blk)
Expand Down Expand Up @@ -151,8 +152,8 @@ data RunNodeArgs m versionDataNTN versionDataNTC blk = RunNodeArgs {
-> HardForkBlockchainTimeArgs m blk

-- | Customise the 'NodeArgs'
, rnCustomiseNodeArgs :: NodeArgs m RemoteConnectionId LocalConnectionId blk
-> NodeArgs m RemoteConnectionId LocalConnectionId blk
, rnCustomiseNodeArgs :: NodeArgs m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> NodeArgs m (ConnectionId addrNTN) (ConnectionId addrNTC) blk

-- | node-to-node protocol versions to run.
, rnNodeToNodeVersions :: Map NodeToNodeVersion (BlockNodeToNodeVersion blk)
Expand All @@ -165,7 +166,7 @@ data RunNodeArgs m versionDataNTN versionDataNTC blk = RunNodeArgs {
-- Called on the 'NodeKernel' after creating it, but before the network
-- layer is initialised.
, rnNodeKernelHook :: ResourceRegistry m
-> NodeKernel m RemoteConnectionId LocalConnectionId blk
-> NodeKernel m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> m ()

-- | Maximum clock skew.
Expand All @@ -182,7 +183,7 @@ data RunNodeArgs m versionDataNTN versionDataNTC blk = RunNodeArgs {
, rnRunDataDiffusion ::
ResourceRegistry m
-> DiffusionApplications
RemoteAddress LocalAddress
addrNTN addrNTC
versionDataNTN versionDataNTC
m
-> m ()
Expand All @@ -199,9 +200,11 @@ data RunNodeArgs m versionDataNTN versionDataNTC blk = RunNodeArgs {
-- network layer.
--
-- This function runs forever unless an exception is thrown.
run :: forall m versionDataNTN versionDataNTC blk.
(RunNode blk, IOLike m, MonadTime m, MonadTimer m)
=> RunNodeArgs m versionDataNTN versionDataNTC blk
run :: forall m addrNTN addrNTC versionDataNTN versionDataNTC blk.
( RunNode blk
, IOLike m, MonadTime m, MonadTimer m
, Hashable addrNTN, Ord addrNTN, Typeable addrNTN)
=> RunNodeArgs m addrNTN addrNTC versionDataNTN versionDataNTC blk
-> m ()
run RunNodeArgs{..} =

Expand Down Expand Up @@ -297,10 +300,10 @@ run RunNodeArgs{..} =
codecConfig = configCodec cfg

mkNodeToNodeApps
:: NodeArgs m RemoteConnectionId LocalConnectionId blk
-> NodeKernel m RemoteConnectionId LocalConnectionId blk
:: NodeArgs m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> NodeKernel m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> BlockNodeToNodeVersion blk
-> NTN.Apps m RemoteConnectionId ByteString ByteString ByteString ByteString ()
-> NTN.Apps m (ConnectionId addrNTN) ByteString ByteString ByteString ByteString ()
mkNodeToNodeApps nodeArgs nodeKernel version =
NTN.mkApps
nodeKernel
Expand All @@ -310,10 +313,10 @@ run RunNodeArgs{..} =
(NTN.mkHandlers nodeArgs nodeKernel)

mkNodeToClientApps
:: NodeArgs m RemoteConnectionId LocalConnectionId blk
-> NodeKernel m RemoteConnectionId LocalConnectionId blk
:: NodeArgs m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> NodeKernel m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> BlockNodeToClientVersion blk
-> NTC.Apps m LocalConnectionId ByteString ByteString ByteString ()
-> NTC.Apps m (ConnectionId addrNTC) ByteString ByteString ByteString ()
mkNodeToClientApps nodeArgs nodeKernel version =
NTC.mkApps
rnTraceNTC
Expand All @@ -323,13 +326,13 @@ run RunNodeArgs{..} =
mkDiffusionApplications
:: MiniProtocolParameters
-> ( BlockNodeToNodeVersion blk
-> NTN.Apps m RemoteConnectionId ByteString ByteString ByteString ByteString ()
-> NTN.Apps m (ConnectionId addrNTN) ByteString ByteString ByteString ByteString ()
)
-> ( BlockNodeToClientVersion blk
-> NTC.Apps m LocalConnectionId ByteString ByteString ByteString ()
-> NTC.Apps m (ConnectionId addrNTC) ByteString ByteString ByteString ()
)
-> DiffusionApplications
RemoteAddress LocalAddress
addrNTN addrNTC
versionDataNTN versionDataNTC
m
mkDiffusionApplications miniProtocolParams ntnApps ntcApps =
Expand Down Expand Up @@ -452,16 +455,16 @@ mkChainDbArgs tracer registry inFuture cfg initLedger
k = configSecurityParam cfg

mkNodeArgs
:: forall m blk. (RunNode blk, IOLike m)
:: forall m addrNTN addrNTC blk. (RunNode blk, IOLike m)
=> ResourceRegistry m
-> Int
-> StdGen
-> TopLevelConfig blk
-> [m (BlockForging m blk)]
-> Tracers m RemoteConnectionId LocalConnectionId blk
-> Tracers m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> BlockchainTime m
-> ChainDB m blk
-> m (NodeArgs m RemoteConnectionId LocalConnectionId blk)
-> m (NodeArgs m (ConnectionId addrNTN) (ConnectionId addrNTC) blk)
mkNodeArgs registry bfcSalt keepAliveRng cfg initBlockForging tracers btime chainDB = do
blockForging <- sequence initBlockForging
return NodeArgs
Expand Down Expand Up @@ -494,8 +497,8 @@ mkNodeArgs registry bfcSalt keepAliveRng cfg initBlockForging tracers btime chai
-- function makes sure we don't exceed those limits and that the values are
-- consistent.
nodeArgsEnforceInvariants
:: NodeArgs m RemoteConnectionId LocalConnectionId blk
-> NodeArgs m RemoteConnectionId LocalConnectionId blk
:: NodeArgs m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
-> NodeArgs m (ConnectionId addrNTN) (ConnectionId addrNTC) blk
nodeArgsEnforceInvariants nodeArgs@NodeArgs{..} = nodeArgs
{ miniProtocolParameters = miniProtocolParameters
-- If 'blockFetchPipeliningMax' exceeds the configured default, it
Expand Down

0 comments on commit dee7a16

Please sign in to comment.