Skip to content

Integration with ouroboros-network:cardano-diffusion #1570

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- update either of these.
index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2025-06-03T21:29:34Z
, hackage.haskell.org 2025-06-17T07:53:04Z
-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2025-06-03T13:42:38Z

Expand Down Expand Up @@ -57,14 +57,6 @@ if impl (ghc >= 9.12)
-- https://github.com/kapralVV/Unique/issues/11
, Unique:hashable

source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network
tag: 3e8d3b4b8c87ead794876c62d7fe25f32efb5142
--sha256: 08fpkx3iagj83nn413h9a865zjcj3lrf7017a756qd2wg2jg3amq
subdir:
ouroboros-network-api

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger
Expand Down Expand Up @@ -97,3 +89,25 @@ source-repository-package
libs/set-algebra
libs/small-steps
libs/vector-map

source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network
tag: 06d72973b3187758dd57d8f1e2c48c53f23aae1c
--sha256: sha256-i574WLPFteQjyxhogejbNyhQt2E0A0cDmNqWDOfkAw0=
subdir:
network-mux
ouroboros-network
ouroboros-network-api
ouroboros-network-framework
ouroboros-network-mock
ouroboros-network-protocols
ouroboros-network-testing

source-repository-package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for an s-r-p on fs-sim, this revision is already on Hackage.

type: git
location: https://github.com/input-output-hk/fs-sim
tag: ee0b75bee5bcd426cfc5433b6c69c67fe6319c1b
--sha256: 0ss4n302khl13fj5f4l6cxfj5vn558s2wk533ikmxhgigf9qas0q
subdir: fs-api
fs-sim
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ library
nothunks,
ouroboros-consensus ^>=0.27,
ouroboros-consensus-protocol ^>=0.12,
ouroboros-network-api ^>=0.14,
ouroboros-network-api ^>=0.15,
serialise ^>=0.2,
singletons ^>=3.0,
small-steps,
Expand Down Expand Up @@ -484,7 +484,7 @@ test-suite cardano-test
tasty,
tasty-hunit,
tasty-quickcheck,
typed-protocols ^>=0.3,
typed-protocols ^>=1.0,
unstable-byron-testlib,
unstable-cardano-testlib,
unstable-shelley-testlib,
Expand Down Expand Up @@ -566,7 +566,7 @@ library unstable-cardano-tools
directory,
dot,
filepath,
fs-api ^>=0.3,
fs-api ^>=0.4,
githash,
microlens,
mtl,
Expand All @@ -579,7 +579,7 @@ library unstable-cardano-tools
ouroboros-consensus-protocol:{ouroboros-consensus-protocol, unstable-protocol-testlib} ^>=0.12,
ouroboros-network,
ouroboros-network-api,
ouroboros-network-framework ^>=0.18,
ouroboros-network-framework ^>=0.19,
ouroboros-network-protocols,
resource-registry,
singletons,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ instance
supportedNodeToNodeVersions _ =
Map.fromList $
[ (NodeToNodeV_14, CardanoNodeToNodeVersion2)
, (NodeToNodeV_15, CardanoNodeToNodeVersion2)
]

supportedNodeToClientVersions _ =
Expand All @@ -391,10 +392,7 @@ instance
, (NodeToClientV_21, CardanoNodeToClientVersion17)
]

-- This is not set to NodeToClientV_21 on purpose because that one is just a
-- stub. Once we have a proper ouroboros-network to integrate that comes with
-- said version and we remove the SRP then we can bump this value.
latestReleasedNodeVersion _prx = (Just NodeToNodeV_14, Just NodeToClientV_20)
latestReleasedNodeVersion _prx = (Just NodeToNodeV_15, Just NodeToClientV_21)

{-------------------------------------------------------------------------------
ProtocolInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ instance SupportedNetworkProtocolVersion (ShelleyBlock proto era) where
supportedNodeToNodeVersions _ =
Map.fromList
[ (NodeToNodeV_14, ShelleyNodeToNodeVersion1)
, (NodeToNodeV_15, ShelleyNodeToNodeVersion1)
]
supportedNodeToClientVersions _ =
Map.fromList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Ouroboros.Consensus.Shelley.Ledger.Ledger
instance SL.EraCertState era => LedgerSupportsPeerSelection (ShelleyBlock proto era) where
getPeers ShelleyLedgerState{shelleyLedgerState} =
catMaybes
[ (poolStake,) <$> Map.lookup stakePool poolRelayAccessPoints
[ (poolStake,) <$> Map.lookup stakePool poolLedgerRelayAccessPoints
| (stakePool, poolStake) <- orderByStake poolDistr
]
where
Expand Down Expand Up @@ -60,41 +60,46 @@ instance SL.EraCertState era => LedgerSupportsPeerSelection (ShelleyBlock proto
. SL.nesEs
$ shelleyLedgerState

relayToRelayAccessPoint :: SL.StakePoolRelay -> Maybe RelayAccessPoint
relayToRelayAccessPoint (SL.SingleHostAddr (SJust (Port port)) (SJust ipv4) _) =
Just $ RelayAccessAddress (IPv4 ipv4) (fromIntegral port)
relayToRelayAccessPoint
relayToLedgerRelayAccessPoint :: SL.StakePoolRelay -> Maybe LedgerRelayAccessPoint
relayToLedgerRelayAccessPoint (SL.SingleHostAddr (SJust (Port port)) (SJust ipv4) _) =
Just $ LedgerRelayAccessAddress (IPv4 ipv4) (fromIntegral port)
relayToLedgerRelayAccessPoint
( SL.SingleHostAddr
(SJust (Port port))
SNothing
(SJust ipv6)
) =
Just $ RelayAccessAddress (IPv6 ipv6) (fromIntegral port)
relayToRelayAccessPoint (SL.SingleHostName (SJust (Port port)) dnsName) =
Just $ RelayAccessDomain (encodeUtf8 $ dnsToText dnsName) (fromIntegral port)
relayToRelayAccessPoint _ =
-- This could be an unsupported relay (SRV records) or an unusable
-- relay such as a relay with an IP address but without a port number.
Nothing
Just $ LedgerRelayAccessAddress (IPv6 ipv6) (fromIntegral port)
-- no IP address or no port number
relayToLedgerRelayAccessPoint (SL.SingleHostAddr SNothing _ _) = Nothing
relayToLedgerRelayAccessPoint (SL.SingleHostAddr _ SNothing _) = Nothing
relayToLedgerRelayAccessPoint (SL.SingleHostName (SJust (Port port)) dnsName) =
Just $ LedgerRelayAccessDomain (encodeUtf8 $ dnsToText dnsName) (fromIntegral port)
-- srv support: either `SingleHostName` without port number or
-- `MultiHostName`
relayToLedgerRelayAccessPoint (SL.SingleHostName SNothing dnsName) =
Just $ LedgerRelayAccessSRVDomain (encodeUtf8 $ dnsToText dnsName)
relayToLedgerRelayAccessPoint (SL.MultiHostName dnsName) =
Just $ LedgerRelayAccessSRVDomain (encodeUtf8 $ dnsToText dnsName)

-- \| Note that a stake pool can have multiple registered relays
pparamsRelayAccessPoints ::
(RelayAccessPoint -> StakePoolRelay) ->
pparamsLedgerRelayAccessPoints ::
(LedgerRelayAccessPoint -> StakePoolRelay) ->
SL.PoolParams ->
Maybe (NonEmpty StakePoolRelay)
pparamsRelayAccessPoints injStakePoolRelay =
pparamsLedgerRelayAccessPoints injStakePoolRelay =
NE.nonEmpty
. force
. mapMaybe (fmap injStakePoolRelay . relayToRelayAccessPoint)
. mapMaybe (fmap injStakePoolRelay . relayToLedgerRelayAccessPoint)
. toList
. SL.ppRelays

-- \| Combine the stake pools registered in the future and the current pool
-- parameters, and remove duplicates.
poolRelayAccessPoints ::
poolLedgerRelayAccessPoints ::
Map (SL.KeyHash 'SL.StakePool) (NonEmpty StakePoolRelay)
poolRelayAccessPoints =
poolLedgerRelayAccessPoints =
Map.unionWith
(\futureRelays currentRelays -> NE.nub (futureRelays <> currentRelays))
(Map.mapMaybe (pparamsRelayAccessPoints FutureRelay) futurePoolParams)
(Map.mapMaybe (pparamsRelayAccessPoints CurrentRelay) poolParams)
(Map.mapMaybe (pparamsLedgerRelayAccessPoints FutureRelay) futurePoolParams)
(Map.mapMaybe (pparamsLedgerRelayAccessPoints CurrentRelay) poolParams)
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ import Ouroboros.Consensus.Storage.ImmutableDB (ImmutableDbArgs (..))
import qualified Ouroboros.Consensus.Storage.ImmutableDB as ImmutableDB
import Ouroboros.Consensus.Util
import Ouroboros.Consensus.Util.IOLike
import Ouroboros.Network.ErrorPolicy (nullErrorPolicies)
import Ouroboros.Network.IOManager (withIOManager)
import Ouroboros.Network.Mux
import qualified Ouroboros.Network.NodeToNode as N2N
import Ouroboros.Network.PeerSelection.PeerSharing.Codec
( decodeRemoteAddress
, encodeRemoteAddress
)
import Ouroboros.Network.Protocol.Handshake (HandshakeArguments (..))
import qualified Ouroboros.Network.Protocol.Handshake as Handshake
import qualified Ouroboros.Network.Server.Simple as Server
import qualified Ouroboros.Network.Snocket as Snocket
import Ouroboros.Network.Socket (configureSocket)
import Ouroboros.Network.Socket (SomeResponderApplication (..), configureSocket)
import System.FS.API (SomeHasFS (..))
import System.FS.API.Types (MountPoint (MountPoint))
import System.FS.IO (ioHasFS)
Expand All @@ -48,32 +50,23 @@ serve ::
N2N.NodeToNodeVersionData
(OuroborosApplicationWithMinimalCtx 'Mux.ResponderMode SockAddr BL.ByteString IO Void ()) ->
IO Void
serve sockAddr application = withIOManager \iocp -> do
let sn = Snocket.socketSnocket iocp
family = Snocket.addrFamily sn sockAddr
bracket (Snocket.open sn family) (Snocket.close sn) \socket -> do
networkMutableState <- N2N.newNetworkMutableState
configureSocket socket (Just sockAddr)
Snocket.bind sn socket sockAddr
Snocket.listen sn socket
N2N.withServer
sn
N2N.nullNetworkServerTracers
{ N2N.nstHandshakeTracer = show >$< stdoutTracer
, N2N.nstErrorPolicyTracer = show >$< stdoutTracer
}
networkMutableState
acceptedConnectionsLimit
socket
application
nullErrorPolicies
where
acceptedConnectionsLimit =
N2N.AcceptedConnectionsLimit
{ N2N.acceptedConnectionsHardLimit = maxBound
, N2N.acceptedConnectionsSoftLimit = maxBound
, N2N.acceptedConnectionsDelay = 0
serve sockAddr application = withIOManager \iocp ->
Server.with
(Snocket.socketSnocket iocp)
Snocket.makeSocketBearer
(\sock addr -> configureSocket sock (Just addr))
sockAddr
HandshakeArguments
{ haHandshakeTracer = show >$< stdoutTracer
, haBearerTracer = show >$< stdoutTracer
, haHandshakeCodec = Handshake.nodeToNodeHandshakeCodec
, haVersionDataCodec = Handshake.cborTermVersionDataCodec N2N.nodeToNodeCodecCBORTerm
, haAcceptVersion = Handshake.acceptableVersion
, haQueryVersion = Handshake.queryVersion
, haTimeLimits = Handshake.timeLimitsHandshake
}
(SomeResponderApplication <$> application)
(\_ serverAsync -> wait serverAsync)

run ::
forall blk.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ fromShelleyLedgerExamples
( AccPoolStake 0.9
,
( PoolStake 0.9
, RelayAccessAddress (IPv4 "1.1.1.1") 1234 :| []
, LedgerRelayAccessAddress (IPv4 "1.1.1.1") 1234 :| []
)
)
]
Expand Down Expand Up @@ -335,7 +335,7 @@ fromShelleyLedgerExamplesPraos
( AccPoolStake 0.9
,
( PoolStake 0.9
, RelayAccessAddress (IPv4 "1.1.1.1") 1234 :| []
, LedgerRelayAccessAddress (IPv4 "1.1.1.1") 1234 :| []
)
)
]
Expand Down
Loading